@o3r/localization 9.3.0-alpha.6 → 9.3.0-alpha.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/builders/helpers/localization.generator.d.ts.map +1 -1
- package/builders/helpers/localization.generator.js +6 -5
- package/builders/i18n/index.js +2 -2
- package/builders/localization/index.d.ts.map +1 -1
- package/builders/localization/index.js +3 -2
- package/builders/localization-extractor/index.d.ts.map +1 -1
- package/builders/localization-extractor/index.js +2 -1
- package/package.json +7 -7
- package/schematics/add-localization-key/index.d.ts.map +1 -1
- package/schematics/add-localization-key/index.js +2 -2
- package/schematics/cms-adapter/index.d.ts +0 -1
- package/schematics/cms-adapter/index.d.ts.map +1 -1
- package/schematics/cms-adapter/index.js +5 -9
- package/schematics/localization-base/index.d.ts +2 -1
- package/schematics/localization-base/index.d.ts.map +1 -1
- package/schematics/localization-base/index.js +18 -25
- package/schematics/localization-to-component/index.d.ts.map +1 -1
- package/schematics/localization-to-component/index.js +2 -2
- package/schematics/ng-add/index.d.ts +0 -1
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +6 -4
package/README.md
CHANGED
|
@@ -717,5 +717,5 @@ Otter framework provides a set of code generators based on [angular schematics](
|
|
|
717
717
|
| Schematics | Description | How to use |
|
|
718
718
|
| ------------------------------ | -------------------------------------------------------------- | ------------------------------------ |
|
|
719
719
|
| add | Include Otter localization module in a library / application. | `ng add @o3r/localization` |
|
|
720
|
-
| localization-to-component | Add localization architecture to an Otter component
|
|
721
|
-
| localization-key-to-component | Add localization key to an Otter component
|
|
720
|
+
| localization-to-component | Add localization architecture to an Otter component | `ng g localization-to-component` |
|
|
721
|
+
| localization-key-to-component | Add a localization key to an Otter component | `ng g localization-key-to-component` |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization.generator.d.ts","sourceRoot":"","sources":["../../../builders/helpers/localization.generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"localization.generator.d.ts","sourceRoot":"","sources":["../../../builders/helpers/localization.generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAUhF,4DAA4D;AAC5D,MAAM,WAAW,yBAAyB;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAC;CACjC;AAED,6BAA6B;AAC7B,MAAM,WAAW,qBAAqB;IACpC,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iDAAiD;IACjD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,kCAAkC;AAClC,MAAM,WAAW,oBAAoB;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAC;CACtC;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,CAAC,IAAI,EAAE,MAAM,GAAG;QACd,IAAI,EAAE,oBAAoB,CAAC;QAC3B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH;AAED,4BAA4B;AAC5B,MAAM,WAAW,kBAAkB;IACjC,CAAC,mBAAmB,EAAE,MAAM,GAAG,oBAAoB,CAAC;CACrD;AAED;;GAEG;AACH,qBAAa,qBAAqB;IAEhC,sCAAsC;IACtC,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,MAAM,CAAoB;gBAEtB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS;IAK3D,8CAA8C;IAC9C,OAAO,CAAC,oBAAoB;IAK5B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IA4B3B;;;;;OAKG;IACH,OAAO,CAAC,qCAAqC;IAyB7C;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IA0B1B;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;;;;OAKG;IACH,OAAO,CAAC,oCAAoC;IA4B5C;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAYnB,kDAAkD;IAC3C,uBAAuB;;;;;IAc9B;;;;;;OAMG;IACU,kBAAkB,CAAC,iBAAiB,EAAE,MAAM,EAAE,EAAE,kBAAkB,GAAE,MAAM,EAAO,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA2BnJ;;;;OAIG;IACU,+BAA+B,CAAC,sBAAsB,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA8BjH;;;;OAIG;IACU,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE;IAQzD;;;;OAIG;IACU,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE;IASzD;;;;;;;;;OASG;IACI,gBAAgB,CAAC,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE;QACrE,mBAAmB,EAAE,OAAO,CAAC;QAC7B,eAAe,EAAE,kBAAkB,CAAC;QACpC,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,OAAO,CAAC;KACnB,GAAG,oBAAoB;CAkCzB"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalizationExtractor = void 0;
|
|
4
4
|
const extractors_1 = require("@o3r/extractors");
|
|
5
|
+
const schematics_1 = require("@o3r/schematics");
|
|
5
6
|
const fs = require("node:fs");
|
|
6
7
|
const glob = require("globby");
|
|
7
8
|
const path = require("node:path");
|
|
@@ -19,7 +20,7 @@ class LocalizationExtractor {
|
|
|
19
20
|
/** Get the list of file from tsconfig.json */
|
|
20
21
|
getFilesFromTsConfig() {
|
|
21
22
|
const { include, exclude, cwd } = this.getPatternsFromTsConfig();
|
|
22
|
-
return glob(include, { ignore: exclude, cwd });
|
|
23
|
+
return glob.sync(include, { ignore: exclude, cwd });
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Return the class node if the class is an angular element
|
|
@@ -147,7 +148,7 @@ class LocalizationExtractor {
|
|
|
147
148
|
}
|
|
148
149
|
if (typeof loc.defaultValue === 'undefined' && typeof loc.$ref === 'undefined' && !loc.dictionary) {
|
|
149
150
|
this.logger.error(`${key} has no default value or $ref defined`);
|
|
150
|
-
throw new
|
|
151
|
+
throw new schematics_1.O3rCliError(`${key} has no default value or $ref defined`);
|
|
151
152
|
}
|
|
152
153
|
return res;
|
|
153
154
|
}
|
|
@@ -173,7 +174,7 @@ class LocalizationExtractor {
|
|
|
173
174
|
const tsconfigResult = ts.readConfigFile(this.tsconfigPath, ts.sys.readFile);
|
|
174
175
|
if (tsconfigResult.error) {
|
|
175
176
|
this.logger.error(tsconfigResult.error.messageText.toString());
|
|
176
|
-
throw new
|
|
177
|
+
throw new schematics_1.O3rCliError(tsconfigResult.error.messageText.toString());
|
|
177
178
|
}
|
|
178
179
|
const include = [...(tsconfigResult.config.files || []), ...(tsconfigResult.config.include || [])];
|
|
179
180
|
const exclude = tsconfigResult.config.exclude || [];
|
|
@@ -216,7 +217,7 @@ class LocalizationExtractor {
|
|
|
216
217
|
* @param extraLocalizationFiles Additional translations to add
|
|
217
218
|
*/
|
|
218
219
|
async extractLocalizationFromTsConfig(extraLocalizationFiles = []) {
|
|
219
|
-
const files =
|
|
220
|
+
const files = this.getFilesFromTsConfig();
|
|
220
221
|
const tsFiles = files
|
|
221
222
|
.filter((file) => /\.ts$/.test(file))
|
|
222
223
|
.map((file) => path.join(path.dirname(this.tsconfigPath), file));
|
|
@@ -282,7 +283,7 @@ class LocalizationExtractor {
|
|
|
282
283
|
}
|
|
283
284
|
else {
|
|
284
285
|
this.logger.error(`The key ${data.key} from ${origin} try to override the previous value (${metadata[data.key].value || 'ref ' + metadata[data.key].ref} -> ${data.value || 'ref ' + data.ref})`);
|
|
285
|
-
throw new
|
|
286
|
+
throw new schematics_1.O3rCliError('Duplicate key');
|
|
286
287
|
}
|
|
287
288
|
}
|
|
288
289
|
metadata[data.key] = data;
|
package/builders/i18n/index.js
CHANGED
|
@@ -24,8 +24,8 @@ exports.default = (0, architect_1.createBuilder)((options, context) => {
|
|
|
24
24
|
recursive: true
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
fs.writeFileSync(
|
|
27
|
+
const defaultLanguageFile = path.join(i18nPath, options.defaultLanguageFile);
|
|
28
|
+
fs.writeFileSync(defaultLanguageFile, newContent + '\n');
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../builders/localization/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../builders/localization/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAgFrD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;IAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,CAGvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAC1C,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC9C,cAAc,GAAE,GAAG,CAAC,MAAM,CAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA8BjE;;AAgLD,wBA0MG"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTranslationsForLanguage = exports.loadTranslations = void 0;
|
|
4
4
|
const architect_1 = require("@angular-devkit/architect");
|
|
5
|
+
const schematics_1 = require("@o3r/schematics");
|
|
5
6
|
const fs = require("node:fs");
|
|
6
7
|
const globby_1 = require("globby");
|
|
7
8
|
const path = require("node:path");
|
|
@@ -54,7 +55,7 @@ function checkUnusedTranslation(language, defaultBundle, customTranslations, con
|
|
|
54
55
|
.filter((key) => !dictionaryKeysPatterns.some((dictionaryKeyPattern) => key.startsWith(dictionaryKeyPattern)));
|
|
55
56
|
missingMetadata.forEach((key) => context.logger[failIfMissingMetadata ? 'error' : 'warn'](`The key "${key}" from "${language}" is not part of the MetaData`));
|
|
56
57
|
if (missingMetadata.length && failIfMissingMetadata) {
|
|
57
|
-
throw new
|
|
58
|
+
throw new schematics_1.O3rCliError(`There is missing metadata for ${language}`);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
@@ -98,7 +99,7 @@ function getTranslationsForLanguage(language, filesPerLanguage, defaultLanguageM
|
|
|
98
99
|
if (defaultLanguage) {
|
|
99
100
|
// Throw an error if we find a circular dependency
|
|
100
101
|
if (dependencyPath.has(defaultLanguage)) {
|
|
101
|
-
throw new
|
|
102
|
+
throw new schematics_1.O3rCliError(`Circular dependency found: ${[...Array.from(dependencyPath), defaultLanguage].join('->')}`);
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
105
|
// Else, recursively resolve its bundle and use it as a base for the current language
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../builders/localization-extractor/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../builders/localization-extractor/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;AAI9D,cAAc,UAAU,CAAC;;AAEzB,wBA4LG"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const architect_1 = require("@angular-devkit/architect");
|
|
5
|
+
const schematics_1 = require("@o3r/schematics");
|
|
5
6
|
const chokidar = require("chokidar");
|
|
6
7
|
const fs = require("node:fs");
|
|
7
8
|
const globby_1 = require("globby");
|
|
@@ -61,7 +62,7 @@ exports.default = (0, architect_1.createBuilder)(async (options, context) => {
|
|
|
61
62
|
.filter((metadataItem) => !!metadataItem.value &&
|
|
62
63
|
validations_1.validators.reduce((isInvalid, validator) => isInvalid || !validator(metadataItem.value), false));
|
|
63
64
|
if (translationsWithIssue.length) {
|
|
64
|
-
throw new
|
|
65
|
+
throw new schematics_1.O3rCliError(`The following translations are invalid: ${translationsWithIssue.map((translation) => translation.key).join(', ')}`);
|
|
65
66
|
}
|
|
66
67
|
context.reportProgress(STEP_NUMBER, STEP_NUMBER, 'Generating metadata');
|
|
67
68
|
// Create output folder if does not exist
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3r/localization",
|
|
3
|
-
"version": "9.3.0-alpha.
|
|
3
|
+
"version": "9.3.0-alpha.60",
|
|
4
4
|
"description": "This module provides a runtime dynamic language/translation support and debug tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"localization",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"@formatjs/intl-numberformat": "^8.0.2",
|
|
21
21
|
"@ngrx/store": "~16.2.0",
|
|
22
22
|
"@ngx-translate/core": "~15.0.0",
|
|
23
|
-
"@o3r/core": "^9.3.0-alpha.
|
|
24
|
-
"@o3r/dynamic-content": "^9.3.0-alpha.
|
|
25
|
-
"@o3r/extractors": "^9.3.0-alpha.
|
|
26
|
-
"@o3r/logger": "^9.3.0-alpha.
|
|
27
|
-
"@o3r/schematics": "^9.3.0-alpha.
|
|
23
|
+
"@o3r/core": "^9.3.0-alpha.60",
|
|
24
|
+
"@o3r/dynamic-content": "^9.3.0-alpha.60",
|
|
25
|
+
"@o3r/extractors": "^9.3.0-alpha.60",
|
|
26
|
+
"@o3r/logger": "^9.3.0-alpha.60",
|
|
27
|
+
"@o3r/schematics": "^9.3.0-alpha.60",
|
|
28
28
|
"@schematics/angular": "~16.2.0",
|
|
29
29
|
"chokidar": "^3.5.2",
|
|
30
30
|
"intl-messageformat": "~10.5.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"tslib": "^2.5.3"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
|
-
"node": ">=
|
|
64
|
+
"node": ">=18.0.0"
|
|
65
65
|
},
|
|
66
66
|
"builders": "./builders.json",
|
|
67
67
|
"schematics": "./collection.json",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/add-localization-key/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EAIL,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/add-localization-key/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EAIL,MAAM,4BAA4B,CAAC;AAapC,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,UAAU,CAAC;AA8FrE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,oCAAoC,GAAG,IAAI,CAyJxF"}
|
|
@@ -58,7 +58,7 @@ const getLocalizationInformation = (componentPath, tree) => {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
if (!defaultTranslationVariableName) {
|
|
61
|
-
throw new
|
|
61
|
+
throw new schematics_2.O3rCliError(`Unable to find initialization of ${translationsVariableName} in ${componentPath}.`);
|
|
62
62
|
}
|
|
63
63
|
const importDeclaration = componentSourceFile.statements.find((statement) => ts.isImportDeclaration(statement)
|
|
64
64
|
&& ts.isStringLiteral(statement.moduleSpecifier)
|
|
@@ -67,7 +67,7 @@ const getLocalizationInformation = (componentPath, tree) => {
|
|
|
67
67
|
&& ts.isNamedImports(statement.importClause.namedBindings)
|
|
68
68
|
&& !!statement.importClause.namedBindings.elements.find((element) => ts.isIdentifier(element.name) && element.name.escapedText.toString() === defaultTranslationVariableName));
|
|
69
69
|
if (!importDeclaration) {
|
|
70
|
-
throw new
|
|
70
|
+
throw new schematics_2.O3rCliError(`Unable to find import declaration of ${defaultTranslationVariableName} in ${componentPath}`);
|
|
71
71
|
}
|
|
72
72
|
const translationsPath = node_path_1.posix.join((0, node_path_1.dirname)(componentPath), `${importDeclaration.moduleSpecifier.text}.ts`);
|
|
73
73
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/cms-adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAKvF
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/cms-adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAKvF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,IAAI,CAoEpF"}
|
|
@@ -6,7 +6,6 @@ const schematics_2 = require("@o3r/schematics");
|
|
|
6
6
|
const path = require("node:path");
|
|
7
7
|
/**
|
|
8
8
|
* Update CMS adapter tools
|
|
9
|
-
*
|
|
10
9
|
* @param options @see RuleFactory.options
|
|
11
10
|
* @param options.projectName
|
|
12
11
|
* @param rootPath @see RuleFactory.rootPath
|
|
@@ -17,15 +16,14 @@ function updateCmsAdapter(options) {
|
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Add cms extractors builder into the angular.json
|
|
20
|
-
*
|
|
21
19
|
* @param tree
|
|
22
20
|
* @param _context
|
|
23
21
|
* @param context
|
|
24
22
|
*/
|
|
25
23
|
const editAngularJson = (tree, context) => {
|
|
26
|
-
const workspace = (0, schematics_2.
|
|
27
|
-
const workspaceProject =
|
|
28
|
-
if (!workspaceProject) {
|
|
24
|
+
const workspace = (0, schematics_2.getWorkspaceConfig)(tree);
|
|
25
|
+
const workspaceProject = options.projectName ? workspace?.projects[options.projectName] : undefined;
|
|
26
|
+
if (!workspace || !workspaceProject) {
|
|
29
27
|
context.logger.error('No project detected, the extractors will not be added');
|
|
30
28
|
return tree;
|
|
31
29
|
}
|
|
@@ -39,20 +37,18 @@ function updateCmsAdapter(options) {
|
|
|
39
37
|
libraries: []
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
|
-
|
|
43
|
-
workspace.projects[name] = newProject;
|
|
40
|
+
workspace.projects[options.projectName] = workspaceProject;
|
|
44
41
|
tree.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
|
|
45
42
|
return tree;
|
|
46
43
|
};
|
|
47
44
|
/**
|
|
48
45
|
* Add cms extractors scripts into the package.json
|
|
49
|
-
*
|
|
50
46
|
* @param tree
|
|
51
47
|
* @param _context
|
|
52
48
|
* @param context
|
|
53
49
|
*/
|
|
54
50
|
const addExtractorsScripts = (tree, context) => {
|
|
55
|
-
const workspaceProject = (0, schematics_2.
|
|
51
|
+
const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
|
|
56
52
|
if (!workspaceProject) {
|
|
57
53
|
context.logger.error('No package detected, the extractor scripts will not be added');
|
|
58
54
|
return tree;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Rule } from '@angular-devkit/schematics';
|
|
2
2
|
/**
|
|
3
3
|
* Add Otter localization support
|
|
4
|
-
*
|
|
5
4
|
* @param options @see RuleFactory.options
|
|
6
5
|
* @param options.projectName
|
|
7
6
|
* @param rootPath @see RuleFactory.rootPath
|
|
@@ -11,6 +10,8 @@ export declare function updateLocalization(options: {
|
|
|
11
10
|
}, rootPath: string): Rule;
|
|
12
11
|
/**
|
|
13
12
|
*
|
|
13
|
+
* @param options
|
|
14
|
+
* @param options.projectName
|
|
14
15
|
*/
|
|
15
16
|
export declare function updateI18n(options: {
|
|
16
17
|
projectName?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/localization-base/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,IAAI,EAAyC,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/localization-base/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,IAAI,EAAyC,MAAM,4BAA4B,CAAC;AAgC7I;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CA6a/G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAC,GAAG,IAAI,CAwC5E"}
|
|
@@ -14,7 +14,6 @@ const formatjsIntlNumberformatDep = '@formatjs/intl-numberformat';
|
|
|
14
14
|
const angularCdkDep = '@angular/cdk';
|
|
15
15
|
/**
|
|
16
16
|
* Add Otter localization support
|
|
17
|
-
*
|
|
18
17
|
* @param options @see RuleFactory.options
|
|
19
18
|
* @param options.projectName
|
|
20
19
|
* @param rootPath @see RuleFactory.rootPath
|
|
@@ -27,12 +26,11 @@ function updateLocalization(options, rootPath) {
|
|
|
27
26
|
const devResourcesFolder = 'dev-resources';
|
|
28
27
|
/**
|
|
29
28
|
* Generate locales folder
|
|
30
|
-
*
|
|
31
29
|
* @param tree
|
|
32
30
|
* @param context
|
|
33
31
|
*/
|
|
34
32
|
const generateLocalesFolder = (tree, context) => {
|
|
35
|
-
const workingDirectory = (0, schematics_2.
|
|
33
|
+
const workingDirectory = (options.projectName && (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName]?.root) || '.';
|
|
36
34
|
let gitIgnoreContent = '';
|
|
37
35
|
const gitIgnorePath = path.posix.join(workingDirectory, '.gitignore');
|
|
38
36
|
if (tree.exists(gitIgnorePath)) {
|
|
@@ -56,14 +54,13 @@ function updateLocalization(options, rootPath) {
|
|
|
56
54
|
};
|
|
57
55
|
/**
|
|
58
56
|
* Add translation generation builders into angular.json
|
|
59
|
-
*
|
|
60
57
|
* @param tree
|
|
61
58
|
* @param context
|
|
62
59
|
*/
|
|
63
60
|
const updateAngularJson = (tree, context) => {
|
|
64
|
-
const workspace = (0, schematics_2.
|
|
65
|
-
const projectName = options.projectName
|
|
66
|
-
const workspaceProject =
|
|
61
|
+
const workspace = (0, schematics_2.getWorkspaceConfig)(tree);
|
|
62
|
+
const projectName = options.projectName;
|
|
63
|
+
const workspaceProject = options.projectName ? workspace?.projects[options.projectName] : undefined;
|
|
67
64
|
const projectRoot = path.posix.join(workspaceProject?.root || '');
|
|
68
65
|
const distFolder = (workspaceProject &&
|
|
69
66
|
workspaceProject.architect &&
|
|
@@ -72,7 +69,7 @@ function updateLocalization(options, rootPath) {
|
|
|
72
69
|
(workspaceProject.architect.build.configurations && workspaceProject.architect.build.configurations.production && workspaceProject.architect.build.configurations.production.outputPath ||
|
|
73
70
|
workspaceProject.architect.build.options.outputPath)) || './dist';
|
|
74
71
|
// exit if not an application
|
|
75
|
-
if (!workspaceProject) {
|
|
72
|
+
if (!workspace || !projectName || !workspaceProject) {
|
|
76
73
|
context.logger.debug('No application project found to add translation extraction');
|
|
77
74
|
return tree;
|
|
78
75
|
}
|
|
@@ -167,16 +164,15 @@ function updateLocalization(options, rootPath) {
|
|
|
167
164
|
};
|
|
168
165
|
/**
|
|
169
166
|
* Changed package.json start script to run localization generation
|
|
170
|
-
*
|
|
171
167
|
* @param tree
|
|
172
168
|
* @param context
|
|
173
169
|
*/
|
|
174
170
|
const updatePackageJson = (tree, context) => {
|
|
175
|
-
const workspace = (0, schematics_2.
|
|
176
|
-
const projectName = options.projectName
|
|
177
|
-
const workspaceProject =
|
|
171
|
+
const workspace = (0, schematics_2.getWorkspaceConfig)(tree);
|
|
172
|
+
const projectName = options.projectName;
|
|
173
|
+
const workspaceProject = options.projectName ? workspace?.projects[options.projectName] : undefined;
|
|
178
174
|
const packageManagerRunner = (0, schematics_2.getPackageManagerRunner)((0, schematics_2.getWorkspaceConfig)(tree));
|
|
179
|
-
if (!workspaceProject) {
|
|
175
|
+
if (!projectName || !workspace || !workspaceProject) {
|
|
180
176
|
context.logger.debug('No application project found to add translation extraction');
|
|
181
177
|
return tree;
|
|
182
178
|
}
|
|
@@ -198,7 +194,6 @@ function updateLocalization(options, rootPath) {
|
|
|
198
194
|
};
|
|
199
195
|
/**
|
|
200
196
|
* Edit main module with the translation required configuration
|
|
201
|
-
*
|
|
202
197
|
* @param tree
|
|
203
198
|
* @param context
|
|
204
199
|
*/
|
|
@@ -252,7 +247,6 @@ function updateLocalization(options, rootPath) {
|
|
|
252
247
|
};
|
|
253
248
|
/**
|
|
254
249
|
* Set language as default on application bootstrap
|
|
255
|
-
*
|
|
256
250
|
* @param tree
|
|
257
251
|
* @param context
|
|
258
252
|
*/
|
|
@@ -302,7 +296,6 @@ function updateLocalization(options, rootPath) {
|
|
|
302
296
|
};
|
|
303
297
|
/**
|
|
304
298
|
* Add mockTranslationModule to application tests.
|
|
305
|
-
*
|
|
306
299
|
* @param tree
|
|
307
300
|
* @param context
|
|
308
301
|
*/
|
|
@@ -335,15 +328,15 @@ function updateLocalization(options, rootPath) {
|
|
|
335
328
|
};
|
|
336
329
|
/**
|
|
337
330
|
* Add location required dependencies
|
|
338
|
-
*
|
|
339
331
|
* @param tree
|
|
340
332
|
* @param _context
|
|
341
333
|
* @param context
|
|
342
334
|
*/
|
|
343
335
|
const addDependencies = (tree, context) => {
|
|
344
|
-
const
|
|
336
|
+
const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
|
|
337
|
+
const workingDirectory = workspaceProject?.root || '.';
|
|
338
|
+
const type = (0, schematics_2.getProjectNewDependenciesType)(workspaceProject);
|
|
345
339
|
const generatorDependencies = [ngxTranslateCoreDep, intlMessageFormatDep, formatjsIntlNumberformatDep, angularCdkDep];
|
|
346
|
-
const workingDirectory = (0, schematics_2.getProjectRootDir)(tree, options.projectName);
|
|
347
340
|
try {
|
|
348
341
|
return (0, schematics_2.ngAddPeerDependencyPackages)(generatorDependencies, packageJsonPath, type, { ...options, workingDirectory, skipNgAddSchematicRun: true })(tree, context);
|
|
349
342
|
}
|
|
@@ -370,6 +363,8 @@ function updateLocalization(options, rootPath) {
|
|
|
370
363
|
exports.updateLocalization = updateLocalization;
|
|
371
364
|
/**
|
|
372
365
|
*
|
|
366
|
+
* @param options
|
|
367
|
+
* @param options.projectName
|
|
373
368
|
*/
|
|
374
369
|
function updateI18n(options) {
|
|
375
370
|
if (!options.projectName) {
|
|
@@ -377,13 +372,12 @@ function updateI18n(options) {
|
|
|
377
372
|
}
|
|
378
373
|
/**
|
|
379
374
|
* Add i18n generation builders into angular.json
|
|
380
|
-
*
|
|
381
375
|
* @param tree
|
|
382
376
|
*/
|
|
383
377
|
const updateAngularJson = (tree) => {
|
|
384
|
-
const workspace = (0, schematics_2.
|
|
385
|
-
const workspaceProject =
|
|
386
|
-
if (!workspaceProject) {
|
|
378
|
+
const workspace = (0, schematics_2.getWorkspaceConfig)(tree);
|
|
379
|
+
const workspaceProject = options.projectName ? workspace?.projects[options.projectName] : undefined;
|
|
380
|
+
if (!workspace || !workspaceProject) {
|
|
387
381
|
return tree;
|
|
388
382
|
}
|
|
389
383
|
if (!workspaceProject.architect) {
|
|
@@ -401,8 +395,7 @@ function updateI18n(options) {
|
|
|
401
395
|
}
|
|
402
396
|
};
|
|
403
397
|
}
|
|
404
|
-
|
|
405
|
-
workspace.projects[name] = newProject;
|
|
398
|
+
workspace.projects[options.projectName] = workspaceProject;
|
|
406
399
|
return (0, schematics_2.writeAngularJson)(tree, workspace);
|
|
407
400
|
};
|
|
408
401
|
return (0, schematics_1.chain)([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/localization-to-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,IAAI,EAML,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/localization-to-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,IAAI,EAML,MAAM,4BAA4B,CAAC;AAqBpC,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAkClE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iCAAiC,GAAG,IAAI,CA6SlF"}
|
|
@@ -16,7 +16,7 @@ const checkLocalization = (componentPath, tree, baseFileName) => {
|
|
|
16
16
|
node_path_1.posix.join((0, node_path_1.dirname)(componentPath), `${baseFileName}.translation.ts`)
|
|
17
17
|
];
|
|
18
18
|
if (files.some((file) => tree.exists(file))) {
|
|
19
|
-
throw new
|
|
19
|
+
throw new schematics_2.O3rCliError(`Unable to add localization to this component because it already has at least one of these files: ${files.join(', ')}.`);
|
|
20
20
|
}
|
|
21
21
|
const componentSourceFile = ts.createSourceFile(componentPath, tree.readText(componentPath), ts.ScriptTarget.ES2020, true);
|
|
22
22
|
const o3rClassDeclaration = componentSourceFile.statements.find((statement) => ts.isClassDeclaration(statement)
|
|
@@ -24,7 +24,7 @@ const checkLocalization = (componentPath, tree, baseFileName) => {
|
|
|
24
24
|
if (o3rClassDeclaration.members.find((classElement) => ts.isPropertyDeclaration(classElement)
|
|
25
25
|
&& ts.isIdentifier(classElement.name)
|
|
26
26
|
&& localizationProperties.includes(classElement.name.escapedText.toString()))) {
|
|
27
|
-
throw new
|
|
27
|
+
throw new schematics_2.O3rCliError(`Unable to add localization to this component because it already has at least one of these properties: ${localizationProperties.join(', ')}.`);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
@@ -2,7 +2,6 @@ import { Rule } from '@angular-devkit/schematics';
|
|
|
2
2
|
import type { NgAddSchematicsSchema } from './schema';
|
|
3
3
|
/**
|
|
4
4
|
* Add Otter localization to an Angular Project
|
|
5
|
-
*
|
|
6
5
|
* @param options for the dependencies installations
|
|
7
6
|
*/
|
|
8
7
|
export declare function ngAdd(options: NgAddSchematicsSchema): Rule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAKvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAKvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAoD1D"}
|
|
@@ -8,13 +8,12 @@ const schematics_2 = require("@o3r/schematics");
|
|
|
8
8
|
const cms_adapter_1 = require("../cms-adapter");
|
|
9
9
|
/**
|
|
10
10
|
* Add Otter localization to an Angular Project
|
|
11
|
-
*
|
|
12
11
|
* @param options for the dependencies installations
|
|
13
12
|
*/
|
|
14
13
|
function ngAdd(options) {
|
|
15
14
|
return async (tree, context) => {
|
|
16
15
|
try {
|
|
17
|
-
const { applyEsLintFix, install,
|
|
16
|
+
const { applyEsLintFix, install, getProjectNewDependenciesType, getWorkspaceConfig, ngAddPackages, ngAddPeerDependencyPackages, getO3rPeerDeps } = await Promise.resolve().then(() => require('@o3r/schematics'));
|
|
18
17
|
const { updateI18n, updateLocalization } = await Promise.resolve().then(() => require('../localization-base'));
|
|
19
18
|
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
|
|
20
19
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf-8' }));
|
|
@@ -23,7 +22,9 @@ function ngAdd(options) {
|
|
|
23
22
|
context.logger.info('Get information on https://github.com/AmadeusITGroup/otter/tree/main/docs/localization/LOCALIZATION.md#Debugging');
|
|
24
23
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
25
24
|
const { NodeDependencyType } = await Promise.resolve().then(() => require('@schematics/angular/utility/dependencies'));
|
|
26
|
-
const
|
|
25
|
+
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
|
|
26
|
+
const workingDirectory = workspaceProject?.root || '.';
|
|
27
|
+
const dependencyType = getProjectNewDependenciesType(workspaceProject);
|
|
27
28
|
return () => (0, schematics_1.chain)([
|
|
28
29
|
updateLocalization(options, __dirname),
|
|
29
30
|
updateI18n(options),
|
|
@@ -34,7 +35,8 @@ function ngAdd(options) {
|
|
|
34
35
|
skipConfirmation: true,
|
|
35
36
|
version: depsInfo.packageVersion,
|
|
36
37
|
parentPackageInfo: `${depsInfo.packageName} - setup`,
|
|
37
|
-
|
|
38
|
+
projectName: options.projectName,
|
|
39
|
+
dependencyType,
|
|
38
40
|
workingDirectory
|
|
39
41
|
})(t, c),
|
|
40
42
|
ngAddPeerDependencyPackages(['chokidar'], packageJsonPath, NodeDependencyType.Dev, { ...options, workingDirectory, skipNgAddSchematicRun: true }, '@o3r/localization - install builder dependency'),
|