diff --git a/docs/core/generators/application.md b/docs/core/generators/application.md index bdc2c6dc..3d125124 100644 --- a/docs/core/generators/application.md +++ b/docs/core/generators/application.md @@ -46,7 +46,7 @@ Generate a dotnet project under the application directory. ### skipSwaggerLib -- (): By default, if using webapi template, an additional library is scaffolded for swagger files. This skips that setup. +- (boolean): By default, if using webapi template, an additional library is scaffolded for swagger files. This skips that setup. ### pathScheme diff --git a/docs/core/generators/library.md b/docs/core/generators/library.md index 5839b6e2..0a4308aa 100644 --- a/docs/core/generators/library.md +++ b/docs/core/generators/library.md @@ -42,7 +42,7 @@ Generate a dotnet project under the library directory. ### skipSwaggerLib -- (): By default, if using webapi template, an additional library is scaffolded for swagger files. This skips that setup. +- (boolean): By default, if using webapi template, an additional library is scaffolded for swagger files. This skips that setup. ### pathScheme diff --git a/e2e/core-e2e/tests/nx-dotnet.spec.ts b/e2e/core-e2e/tests/nx-dotnet.spec.ts index da07b329..38f2a4bc 100644 --- a/e2e/core-e2e/tests/nx-dotnet.spec.ts +++ b/e2e/core-e2e/tests/nx-dotnet.spec.ts @@ -471,7 +471,7 @@ public class UnitTest1 it('should generate swagger project for webapi', async () => { const api = uniq('api'); await runNxCommandAsync( - `generate @nx-dotnet/core:app ${api} --language="C#" --template="webapi"`, + `generate @nx-dotnet/core:app ${api} --language="C#" --template="webapi" --skipSwaggerLib=false`, ); expect(() => checkFilesExist(`apps/${api}`)).not.toThrow(); diff --git a/package.json b/package.json index ad14d88a..14d75e00 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "@types/is-ci": "^3.0.0", "@types/jest": "27.4.1", "@types/node": "17.0.18", + "@types/node-fetch": "^2.6.2", "@types/react": "18.0.8", "@types/react-dom": "18.0.3", "@types/rimraf": "^3.0.2", @@ -95,6 +96,7 @@ "jsonc-eslint-parser": "^2.1.0", "kill-port": "^1.6.1", "lint-staged": "^12.3.4", + "node-fetch": "2.6.6", "nx": "14.2.2", "openapi-types": "^11.0.1", "prettier": "2.6.2", diff --git a/packages/core/src/generators/app/schema.json b/packages/core/src/generators/app/schema.json index b24cdc25..e4bd96f0 100644 --- a/packages/core/src/generators/app/schema.json +++ b/packages/core/src/generators/app/schema.json @@ -79,6 +79,7 @@ "aliases": ["solution", "s"] }, "skipSwaggerLib": { + "type": "boolean", "description": "By default, if using webapi template, an additional library is scaffolded for swagger files. This skips that setup.", "default": true }, diff --git a/packages/core/src/generators/lib/schema.json b/packages/core/src/generators/lib/schema.json index 440e2e9e..db37e35d 100644 --- a/packages/core/src/generators/lib/schema.json +++ b/packages/core/src/generators/lib/schema.json @@ -73,8 +73,9 @@ "aliases": ["solution", "s"] }, "skipSwaggerLib": { + "type": "boolean", "description": "By default, if using webapi template, an additional library is scaffolded for swagger files. This skips that setup.", - "default": false + "default": true }, "pathScheme": { "description": "Determines if the project should follow NX or dotnet path naming conventions", diff --git a/packages/core/src/generators/utils/generate-project.ts b/packages/core/src/generators/utils/generate-project.ts index 3546fbe7..898cdf39 100644 --- a/packages/core/src/generators/utils/generate-project.ts +++ b/packages/core/src/generators/utils/generate-project.ts @@ -242,7 +242,10 @@ export async function GenerateProject( await manipulateXmlProjectFile(host, normalizedOptions); } - if (normalizedOptions.projectTemplate === 'webapi') { + if ( + normalizedOptions.projectTemplate === 'webapi' && + !normalizedOptions.skipSwaggerLib + ) { await generateSwaggerSetup(host, { project: normalizedOptions.projectName, swaggerProject: `${normalizedOptions.projectName}-swagger`, diff --git a/packages/dotnet/src/lib/utils/language-mappings/cs.ts b/packages/dotnet/src/lib/utils/language-mappings/cs.ts new file mode 100644 index 00000000..3b735130 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/cs.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Jazyk: 'languages', + 'Krรกtkรฝ nรกzev': 'shortNames', + Znaฤky: 'tags', + 'Nรกzev ลกablony': 'templateName', + ล ablony: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/de.ts b/packages/dotnet/src/lib/utils/language-mappings/de.ts new file mode 100644 index 00000000..0b83806e --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/de.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Sprache: 'languages', + Kurzname: 'shortNames', + Tags: 'tags', + Vorlagenname: 'templateName', + Vorlagen: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/en.ts b/packages/dotnet/src/lib/utils/language-mappings/en.ts new file mode 100644 index 00000000..36e0c2eb --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/en.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Language: 'languages', + 'Short Name': 'shortNames', + Tags: 'tags', + Templates: 'templateName', + 'Template Name': 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/es.ts b/packages/dotnet/src/lib/utils/language-mappings/es.ts new file mode 100644 index 00000000..02b41bbe --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/es.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Idioma: 'languages', + 'Nombre corto': 'shortNames', + Etiquetas: 'tags', + 'Nombre de la plantilla': 'templateName', + Plantillas: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/fr.ts b/packages/dotnet/src/lib/utils/language-mappings/fr.ts new file mode 100644 index 00000000..c278e4f2 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/fr.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Langue: 'languages', + 'Nom court': 'shortNames', + Balises: 'tags', + 'Nom du modรจle': 'templateName', + Modรจles: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/index.ts b/packages/dotnet/src/lib/utils/language-mappings/index.ts new file mode 100644 index 00000000..a7fec644 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/index.ts @@ -0,0 +1,45 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +import { DotnetTemplate } from '../../models'; + +import { FieldNameMap as EnFieldMap } from './en'; +import { FieldNameMap as CsFieldMap } from './cs'; +import { FieldNameMap as DeFieldMap } from './de'; +import { FieldNameMap as EsFieldMap } from './es'; +import { FieldNameMap as FrFieldMap } from './fr'; +import { FieldNameMap as ItFieldMap } from './it'; +import { FieldNameMap as JaFieldMap } from './ja'; +import { FieldNameMap as KoFieldMap } from './ko'; +import { FieldNameMap as PlFieldMap } from './pl'; +import { FieldNameMap as PtBRFieldMap } from './pt-BR'; +import { FieldNameMap as RuFieldMap } from './ru'; +import { FieldNameMap as TrFieldMap } from './tr'; +import { FieldNameMap as ZhHansFieldMap } from './zh-Hans'; +import { FieldNameMap as ZhHantFieldMap } from './zh-Hant'; + +export const CombinedFieldMap = { + ...EnFieldMap, + ...CsFieldMap, + ...DeFieldMap, + ...EsFieldMap, + ...FrFieldMap, + ...ItFieldMap, + ...JaFieldMap, + ...KoFieldMap, + ...PlFieldMap, + ...PtBRFieldMap, + ...RuFieldMap, + ...TrFieldMap, + ...ZhHansFieldMap, + ...ZhHantFieldMap, +} as unknown as Record; diff --git a/packages/dotnet/src/lib/utils/language-mappings/it.ts b/packages/dotnet/src/lib/utils/language-mappings/it.ts new file mode 100644 index 00000000..b58a4d10 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/it.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Lingua: 'languages', + 'Nome breve': 'shortNames', + Tag: 'tags', + 'Nome modello': 'templateName', + Modelli: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/ja.ts b/packages/dotnet/src/lib/utils/language-mappings/ja.ts new file mode 100644 index 00000000..1c5205e3 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/ja.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + ่จ€่ชž: 'languages', + ็Ÿญใ„ๅๅ‰: 'shortNames', + ใ‚ฟใ‚ฐ: 'tags', + ใƒ†ใƒณใƒ—ใƒฌใƒผใƒˆๅ: 'templateName', + ใƒ†ใƒณใƒ—ใƒฌใƒผใƒˆ: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/ko.ts b/packages/dotnet/src/lib/utils/language-mappings/ko.ts new file mode 100644 index 00000000..ce32f5f7 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/ko.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + ์–ธ์–ด: 'languages', + '์•ฝ์‹ ์ด๋ฆ„': 'shortNames', + ํƒœ๊ทธ: 'tags', + 'ํ…œํ”Œ๋ฆฟ ์ด๋ฆ„': 'templateName', + ํ…œํ”Œ๋ฆฟ: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/pl.ts b/packages/dotnet/src/lib/utils/language-mappings/pl.ts new file mode 100644 index 00000000..68e66345 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/pl.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Jฤ™zyk: 'languages', + 'Skrรณcona nazwa': 'shortNames', + Tagi: 'tags', + 'Nazwa szablonu': 'templateName', + Szablony: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/pt-BR.ts b/packages/dotnet/src/lib/utils/language-mappings/pt-BR.ts new file mode 100644 index 00000000..1e5fd015 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/pt-BR.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Idioma: 'languages', + 'Nome Curto': 'shortNames', + Tags: 'tags', + 'Nome do modelo': 'templateName', + Modelos: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/ru.ts b/packages/dotnet/src/lib/utils/language-mappings/ru.ts new file mode 100644 index 00000000..bd7fcb6f --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/ru.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + ะฏะทั‹ะบ: 'languages', + 'ะšะพั€ะพั‚ะบะพะต ะธะผั': 'shortNames', + ะขะตะณะธ: 'tags', + 'ะ˜ะผั ัˆะฐะฑะปะพะฝะฐ': 'templateName', + ะจะฐะฑะปะพะฝั‹: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/tr.ts b/packages/dotnet/src/lib/utils/language-mappings/tr.ts new file mode 100644 index 00000000..c7d06fcc --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/tr.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + Dil: 'languages', + 'Kฤฑsa Ad': 'shortNames', + Etiketler: 'tags', + 'ลžablon Adฤฑ': 'templateName', + ลžablonlar: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/zh-Hans.ts b/packages/dotnet/src/lib/utils/language-mappings/zh-Hans.ts new file mode 100644 index 00000000..09520ef7 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/zh-Hans.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + ่ฏญ่จ€: 'languages', + ็Ÿญๅ็งฐ: 'shortNames', + ๆ ‡่ฎฐ: 'tags', + ๆจกๆฟๅ: 'templateName', + ๆจกๆฟ: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/language-mappings/zh-Hant.ts b/packages/dotnet/src/lib/utils/language-mappings/zh-Hant.ts new file mode 100644 index 00000000..20f29a49 --- /dev/null +++ b/packages/dotnet/src/lib/utils/language-mappings/zh-Hant.ts @@ -0,0 +1,19 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + ่ชž่จ€: 'languages', + ็ฐก็Ÿญๅ็จฑ: 'shortNames', + ๆจ™่จ˜: 'tags', + ็ฏ„ๆœฌๅ็จฑ: 'templateName', + ็ฏ„ๆœฌ: 'templateName', +}; diff --git a/packages/dotnet/src/lib/utils/parse-dotnet-new-list-output.spec.ts b/packages/dotnet/src/lib/utils/parse-dotnet-new-list-output.spec.ts new file mode 100644 index 00000000..6920502e --- /dev/null +++ b/packages/dotnet/src/lib/utils/parse-dotnet-new-list-output.spec.ts @@ -0,0 +1,88 @@ +import { DotnetTemplate } from '../models'; +import { parseDotnetNewListOutput } from './parse-dotnet-new-list-output'; + +const TEST_CASES: [string[], DotnetTemplate[]][] = [ + [ + [ + `Search for 'ASP.NET':`, + ``, + `Templates Short Name Language`, + `--------------- ----------- ------------`, + `ASP.NET Core aspnetcore C#`, + ], + [ + { + shortNames: ['aspnetcore'], + templateName: 'ASP.NET Core', + languages: ['C#'], + }, + ], + ], + [ + [ + `Template Name Short Name Language Tags`, + `-------------------------------------------- ------------------- ---------- -------------------------------------`, + `ASP.NET Core Empty web [C#],F# Web/Empty`, + ], + [ + { + shortNames: ['web'], + templateName: 'ASP.NET Core Empty', + languages: ['C#', 'F#'], + tags: ['Web', 'Empty'], + }, + ], + ], + [ + [ + `Ces modรจles correspondent ร  votre entrรฉe : .`, + ``, + `Nom du modรจle Nom court Langue Balises `, + `-------------------------------------------- -------------- ---------- --------------------------`, + `ASP.NET Core Empty web [C#],F# Web/Empty `, + ], + [ + { + shortNames: ['web'], + templateName: 'ASP.NET Core Empty', + languages: ['C#', 'F#'], + tags: ['Web', 'Empty'], + }, + ], + ], + [ + [ + `Template Name Short Name Language Tags`, + `-------------------------------------------- ------------------- ---------- -------------------------------------`, + `ASP.NET Core Web App razor,webapp [C#] Web/MVC/Razor Pages`, + `ASP.NET Core Web App (Model-View-Controller) mvc [C#],F# Web/MVC`, + `ASP.NET Core with Angular angular [C#] Web/MVC/SPA`, + ], + [ + { + shortNames: ['razor', 'webapp'], + templateName: 'ASP.NET Core Web App', + languages: ['C#'], + tags: ['Web', 'MVC', 'Razor Pages'], + }, + { + shortNames: ['mvc'], + templateName: 'ASP.NET Core Web App (Model-View-Controller)', + languages: ['C#', 'F#'], + tags: ['Web', 'MVC'], + }, + { + shortNames: ['angular'], + templateName: 'ASP.NET Core with Angular', + languages: ['C#'], + tags: ['Web', 'MVC', 'SPA'], + }, + ], + ], +]; + +describe('parseDotnetNewListOutput', () => { + it.each(TEST_CASES)('should handle test case %#', (raw, parsed) => { + expect(parseDotnetNewListOutput(raw.join('\n'))).toEqual(parsed); + }); +}); diff --git a/packages/dotnet/src/lib/utils/parse-dotnet-new-list-output.ts b/packages/dotnet/src/lib/utils/parse-dotnet-new-list-output.ts index aa23ce97..14a8d15c 100644 --- a/packages/dotnet/src/lib/utils/parse-dotnet-new-list-output.ts +++ b/packages/dotnet/src/lib/utils/parse-dotnet-new-list-output.ts @@ -1,4 +1,5 @@ import { DotnetTemplate } from '../models'; +import { CombinedFieldMap } from './language-mappings'; /** * Expected input is from running `dotnet new --list`. @@ -52,7 +53,7 @@ export function parseDotnetNewListOutput(rawOutput: string): DotnetTemplate[] { const fieldLine = lines[sepLineIdx - 1]; const fields = columnIndicies.map((start, idx) => { // Values end at the beginning of the next column, or the end of the line - const end = columnIndicies[idx + 1] || fieldLine.length; + const end = columnIndicies[idx + 1] || sepLine.length; return { start, end, @@ -65,17 +66,36 @@ export function parseDotnetNewListOutput(rawOutput: string): DotnetTemplate[] { // Construct an object from its fields fields.reduce((obj, field) => { const value = l.slice(field.start, field.end).trim(); - // Map field name + value into expected form - if (field.name === 'Short Name') { - obj.shortNames = value.split(',') as [string, ...string[]]; - } else if (field.name === 'Template Name' || field.name === 'Templates') { - obj.templateName = value; - } else if (field.name === 'Language') { - obj.languages = value.replace(/[[\]]/g, '').split(','); - } else if (field.name === 'Tags') { - obj.tags = value.split('/'); - } + const propertyName = CombinedFieldMap[field.name]; + const mappedValue = fieldMappingFunction(propertyName)(value); + // Typescript doesn't really like this. Its not easy to statically check, + // which is sad. We will ignore it here. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + obj[propertyName] = mappedValue; return obj; }, {} as DotnetTemplate), ); } + +function fieldMappingFunction( + field: T, +): (value: string) => DotnetTemplate[T] { + type FieldMap = { + [key in keyof DotnetTemplate]: (value: string) => DotnetTemplate[key]; + }; + + const mappedFields: Partial = { + shortNames: (value) => value.split(',') as [string, ...string[]], + languages: (value) => value.replace(/[[\]]/g, '').split(','), + tags: (value) => value.split('/'), + }; + + if (!mappedFields[field]) { + return (v) => v as unknown as DotnetTemplate[T]; + } + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return mappedFields[field]; +} diff --git a/tools/generators/update-dotnet-localization-files/files/__language__.ts__tmpl__ b/tools/generators/update-dotnet-localization-files/files/__language__.ts__tmpl__ new file mode 100644 index 00000000..b128f564 --- /dev/null +++ b/tools/generators/update-dotnet-localization-files/files/__language__.ts__tmpl__ @@ -0,0 +1,17 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +export const FieldNameMap = { + <% for (const translation of pairs) {-%> + '<%= translation.localizedName %>': '<%= KeyPropertyMap[translation.key] %>', + <% } %> +} \ No newline at end of file diff --git a/tools/generators/update-dotnet-localization-files/index.ts b/tools/generators/update-dotnet-localization-files/index.ts new file mode 100644 index 00000000..152993ca --- /dev/null +++ b/tools/generators/update-dotnet-localization-files/index.ts @@ -0,0 +1,114 @@ +import { + Tree, + formatFiles, + installPackagesTask, + workspaceRoot, + joinPathFragments, + logger, + generateFiles, + names, +} from '@nrwl/devkit'; +import { XmlDocument } from 'xmldoc'; +import fetch from 'node-fetch'; +import { join, relative } from 'path'; + +const KeyPropertyMap: Record = { + ColumnNameLanguage: 'languages', + ColumnNameTags: 'tags', + ColumnNameShortName: 'shortNames', + ColumnNameTemplateName: 'templateName', + Templates: 'templateName', +}; + +const outputDirectory = joinPathFragments( + 'packages/dotnet/src/lib/utils/language-mappings', +); + +type Translation = { + key: string; + localizedName?: string; +}; + +export default async function (tree: Tree, schema: any) { + const enXml = await fetch( + `https://raw.githubusercontent.com/dotnet/templating/master/src/Microsoft.TemplateEngine.Cli/LocalizableStrings.resx`, + ).then((x) => x.text()); + + const translationDirectoryContents = (await fetch( + `https://api.github.com/repos/dotnet/templating/contents/src/Microsoft.TemplateEngine.Cli/xlf`, + ).then((x) => x.json())) as { path: string; download_url: string }[]; + const translations: { lang: string; pairs: Translation[] }[] = [ + { + lang: 'en', + pairs: getEnTranslations(new XmlDocument(enXml)), + }, + ]; + + const regexp = /LocalizableStrings\.(?.*)\.xlf/; + + for (const translationFile of translationDirectoryContents) { + const language = translationFile.path.match(regexp)?.groups?.lang; + if (language) { + const langXml = await fetch(translationFile.download_url).then((x) => + x.text(), + ); + translations.push({ + lang: language, + pairs: getTranslationsFromXlf(new XmlDocument(langXml)), + }); + } else { + logger.warn( + `Unable to determine language for translation: ${translationFile.path}`, + ); + } + } + + const languages = []; + for (const translation of translations) { + generateFiles(tree, join(__dirname, 'files'), outputDirectory, { + tmpl: '', + language: translation.lang, + pairs: translation.pairs, + KeyPropertyMap, + }); + languages.push({ ...names(translation.lang), raw: translation.lang }); + } + generateFiles(tree, join(__dirname, 'index_tmpl_'), outputDirectory, { + tmpl: '', + languages, + }); + + await formatFiles(tree); + return () => { + installPackagesTask(tree); + }; +} + +function getEnTranslations(xml: XmlDocument): Translation[] { + return xml.childrenNamed('data').reduce((translations, node) => { + if (KeyPropertyMap[node.attr.name]) { + translations.push({ + key: node.attr.name, + localizedName: node.childNamed('value')?.val, + }); + } + return translations; + }, [] as Translation[]); +} + +function getTranslationsFromXlf(xml: XmlDocument): Translation[] { + return ( + xml + .descendantWithPath('file.body') + ?.childrenNamed('trans-unit') + ?.reduce((translations, node) => { + if (KeyPropertyMap[node.attr.id]) { + translations.push({ + key: node.attr.id, + localizedName: node.childWithAttribute('state', 'translated')?.val, + }); + } + return translations; + }, [] as Translation[]) ?? [] + ); +} diff --git a/tools/generators/update-dotnet-localization-files/index_tmpl_/index.ts__tmpl__ b/tools/generators/update-dotnet-localization-files/index_tmpl_/index.ts__tmpl__ new file mode 100644 index 00000000..5ec1cb5b --- /dev/null +++ b/tools/generators/update-dotnet-localization-files/index_tmpl_/index.ts__tmpl__ @@ -0,0 +1,23 @@ +// ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ DO NOT EDIT THIS FILE ๐Ÿ’€โšก๐Ÿ’€ + +/*//////////////////////////////////////////////////////////////////////////////////////////////// + + ##### ##### ##### ##### | This file is autogenerated using an Nx workspace schematic. + # # # # # # | Manual changes should not be needed. After adding your feature + ##### # # # ##### | to software security, simply regenerate this file by running + # # # # # | `nx workspace-schematic update-dotnet-localization-files`. If there is an issue + ##### # ##### # | with the generated file, check tools/generators/update-dotnet-localization-files + +////////////////////////////////////////////////////////////////////////////////////////////////*/ + +import { DotnetTemplate } from '../../models'; + +<% for (const language of languages) {-%> +import { FieldNameMap as <%= language.className%>FieldMap %> } from './<%= language.raw %>'; +<% } -%> + +export const CombinedFieldMap = { + <% for (const language of languages) {-%> + ...<%= language.className %>FieldMap %>, + <% } -%> +} as unknown as Record \ No newline at end of file diff --git a/tools/generators/update-dotnet-localization-files/schema.json b/tools/generators/update-dotnet-localization-files/schema.json new file mode 100644 index 00000000..7f42f24b --- /dev/null +++ b/tools/generators/update-dotnet-localization-files/schema.json @@ -0,0 +1,7 @@ +{ + "$schema": "http://json-schema.org/schema", + "cli": "nx", + "$id": "update-dotnet-localization-files", + "type": "object", + "properties": {} +} diff --git a/yarn.lock b/yarn.lock index 36e17ba4..0e79f48b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4133,6 +4133,14 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ== +"@types/node-fetch@^2.6.2": + version "2.6.2" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.2.tgz#d1a9c5fd049d9415dce61571557104dec3ec81da" + integrity sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A== + dependencies: + "@types/node" "*" + form-data "^3.0.0" + "@types/node@*", "@types/node@>=12", "@types/node@^17.0.5": version "17.0.24" resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.24.tgz#20ba1bf69c1b4ab405c7a01e950c4f446b05029f" @@ -11845,6 +11853,13 @@ node-emoji@^1.10.0, node-emoji@^1.11.0: dependencies: lodash "^4.17.21" +node-fetch@2.6.6: + version "2.6.6" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89" + integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA== + dependencies: + whatwg-url "^5.0.0" + node-fetch@2.6.7, node-fetch@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"