@jsverse/transloco-schematics 8.0.0
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/package.json +34 -0
- package/schematics-core/index.d.ts +9 -0
- package/schematics-core/index.js +36 -0
- package/schematics-core/index.js.map +1 -0
- package/schematics-core/utils/collections.d.ts +3 -0
- package/schematics-core/utils/collections.js +11 -0
- package/schematics-core/utils/collections.js.map +1 -0
- package/schematics-core/utils/file.d.ts +6 -0
- package/schematics-core/utils/file.js +21 -0
- package/schematics-core/utils/file.js.map +1 -0
- package/schematics-core/utils/find-module.d.ts +23 -0
- package/schematics-core/utils/find-module.js +112 -0
- package/schematics-core/utils/find-module.js.map +1 -0
- package/schematics-core/utils/package.d.ts +2 -0
- package/schematics-core/utils/package.js +15 -0
- package/schematics-core/utils/package.js.map +1 -0
- package/schematics-core/utils/schematic.d.ts +6 -0
- package/schematics-core/utils/schematic.js +17 -0
- package/schematics-core/utils/schematic.js.map +1 -0
- package/schematics-core/utils/translation.d.ts +20 -0
- package/schematics-core/utils/translation.js +83 -0
- package/schematics-core/utils/translation.js.map +1 -0
- package/schematics-core/utils/transloco.d.ts +5 -0
- package/schematics-core/utils/transloco.js +31 -0
- package/schematics-core/utils/transloco.js.map +1 -0
- package/schematics-core/utils/workspace.d.ts +6 -0
- package/schematics-core/utils/workspace.js +43 -0
- package/schematics-core/utils/workspace.js.map +1 -0
- package/src/collection.json +41 -0
- package/src/join/index.d.ts +3 -0
- package/src/join/index.js +66 -0
- package/src/join/index.js.map +1 -0
- package/src/join/schema.d.ts +23 -0
- package/src/join/schema.js +3 -0
- package/src/join/schema.js.map +1 -0
- package/src/join/schema.json +36 -0
- package/src/keys-manager/index.d.ts +5 -0
- package/src/keys-manager/index.js +93 -0
- package/src/keys-manager/index.js.map +1 -0
- package/src/keys-manager/schema.d.ts +19 -0
- package/src/keys-manager/schema.js +3 -0
- package/src/keys-manager/schema.js.map +1 -0
- package/src/keys-manager/schema.json +33 -0
- package/src/ng-migrate/index.d.ts +3 -0
- package/src/ng-migrate/index.js +14 -0
- package/src/ng-migrate/index.js.map +1 -0
- package/src/ng-migrate/ng-migrate.d.ts +5 -0
- package/src/ng-migrate/ng-migrate.js +105 -0
- package/src/ng-migrate/ng-migrate.js.map +1 -0
- package/src/ng-migrate/schema.d.ts +14 -0
- package/src/ng-migrate/schema.js +3 -0
- package/src/ng-migrate/schema.js.map +1 -0
- package/src/ng-migrate/schema.json +27 -0
- package/src/ngx-migrate/index.d.ts +4 -0
- package/src/ngx-migrate/index.js +78 -0
- package/src/ngx-migrate/index.js.map +1 -0
- package/src/ngx-migrate/migration-matchers.d.ts +15 -0
- package/src/ngx-migrate/migration-matchers.js +132 -0
- package/src/ngx-migrate/migration-matchers.js.map +1 -0
- package/src/ngx-migrate/schema.d.ts +6 -0
- package/src/ngx-migrate/schema.js +3 -0
- package/src/ngx-migrate/schema.js.map +1 -0
- package/src/ngx-migrate/schema.json +16 -0
- package/src/scope/index.d.ts +3 -0
- package/src/scope/index.js +100 -0
- package/src/scope/index.js.map +1 -0
- package/src/scope/schema.d.ts +28 -0
- package/src/scope/schema.js +3 -0
- package/src/scope/schema.js.map +1 -0
- package/src/scope/schema.json +84 -0
- package/src/scope/utils.d.ts +4 -0
- package/src/scope/utils.js +14 -0
- package/src/scope/utils.js.map +1 -0
- package/src/split/index.d.ts +3 -0
- package/src/split/index.js +50 -0
- package/src/split/index.js.map +1 -0
- package/src/split/schema.d.ts +15 -0
- package/src/split/schema.js +3 -0
- package/src/split/schema.js.map +1 -0
- package/src/split/schema.json +28 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const core_1 = require("@angular-devkit/core");
|
|
6
|
+
const fs_extra_1 = require("fs-extra");
|
|
7
|
+
const schematics_core_1 = require("../../schematics-core");
|
|
8
|
+
function getDefaultLang(options) {
|
|
9
|
+
return options.defaultLang || (0, schematics_core_1.getGlobalConfig)().defaultLang;
|
|
10
|
+
}
|
|
11
|
+
function reduceTranslations(host, dirPath, translationJson, lang, key = '') {
|
|
12
|
+
const dir = host.getDir(dirPath);
|
|
13
|
+
if (!(0, schematics_core_1.hasFiles)(dir) && !(0, schematics_core_1.hasSubdirs)(dir))
|
|
14
|
+
return translationJson;
|
|
15
|
+
dir.subfiles
|
|
16
|
+
.filter((fileName) => fileName.includes(`${lang}.json`))
|
|
17
|
+
.forEach((fileName) => {
|
|
18
|
+
if (translationJson[key]) {
|
|
19
|
+
throw new schematics_1.SchematicsException(`key: ${key} already exist in translation file, please rename it and rerun the command.`);
|
|
20
|
+
}
|
|
21
|
+
translationJson[key] = (0, schematics_core_1.getJsonFileContent)(fileName, dir);
|
|
22
|
+
});
|
|
23
|
+
if ((0, schematics_core_1.hasSubdirs)(dir)) {
|
|
24
|
+
dir.subdirs.forEach((subDirName) => {
|
|
25
|
+
const subDir = dir.dir(subDirName);
|
|
26
|
+
const nestedKey = (0, schematics_core_1.getTranslationKey)(key, subDirName);
|
|
27
|
+
reduceTranslations(host, (0, core_1.normalize)(subDir.path).slice(1), translationJson, lang, nestedKey);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return translationJson;
|
|
31
|
+
}
|
|
32
|
+
function deletePrevFiles(host, options) {
|
|
33
|
+
if ((0, fs_extra_1.existsSync)(options.outDir)) {
|
|
34
|
+
(0, fs_extra_1.removeSync)(options.outDir);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function jsonBuilder(tree, path, content) {
|
|
38
|
+
tree.create(`${path}.json`, JSON.stringify(content, null, 2));
|
|
39
|
+
}
|
|
40
|
+
function default_1(options) {
|
|
41
|
+
return (host) => {
|
|
42
|
+
deletePrevFiles(host, options);
|
|
43
|
+
const root = (0, schematics_core_1.getTranslationsRoot)(host, options);
|
|
44
|
+
const defaultLang = getDefaultLang(options);
|
|
45
|
+
if (options.includeDefaultLang && !defaultLang) {
|
|
46
|
+
throw new schematics_1.SchematicsException(`Please specify the default project's language using --default-Lang or in transloco.config.ts file.`);
|
|
47
|
+
}
|
|
48
|
+
let rootTranslations = (0, schematics_core_1.getTranslationFiles)(host, root);
|
|
49
|
+
const translationEntryPaths = (0, schematics_core_1.getTranslationEntryPaths)(host, root);
|
|
50
|
+
if (!options.includeDefaultLang) {
|
|
51
|
+
rootTranslations = rootTranslations.filter((t) => t.lang !== defaultLang);
|
|
52
|
+
}
|
|
53
|
+
const output = rootTranslations.map((t) => ({
|
|
54
|
+
lang: t.lang,
|
|
55
|
+
translation: translationEntryPaths.reduce((acc, entryPath) => {
|
|
56
|
+
return reduceTranslations(host, entryPath.path, t.translation, t.lang, entryPath.scope);
|
|
57
|
+
}, t.translation),
|
|
58
|
+
}));
|
|
59
|
+
const treeSource = new schematics_1.EmptyTree();
|
|
60
|
+
output.forEach((o) => {
|
|
61
|
+
jsonBuilder(treeSource, `${options.outDir}/${o.lang}`, o.translation);
|
|
62
|
+
});
|
|
63
|
+
return treeSource;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/join/index.ts"],"names":[],"mappings":";;AA4EA,4BAqCC;AAjHD,2DAKoC;AACpC,+CAAiD;AACjD,uCAAkD;AAElD,2DAS+B;AAI/B,SAAS,cAAc,CAAC,OAAsB;IAC5C,OAAO,OAAO,CAAC,WAAW,IAAI,IAAA,iCAAe,GAAE,CAAC,WAAW,CAAC;AAC9D,CAAC;AAED,SAAS,kBAAkB,CACzB,IAAU,EACV,OAAe,EACf,eAAwC,EACxC,IAAY,EACZ,GAAG,GAAG,EAAE;IAER,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,IAA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,WAAW,CAAC;SAClB,CAAC,CAAC,CAAC;QAEJ,MAAM,UAAU,GAAG,IAAI,sBAAS,EAAE,CAAC;QACnC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACnB,WAAW,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema } from '@schematics/angular/module/schema';
|
|
2
|
+
export interface SchemaOptions extends Schema {
|
|
3
|
+
/**
|
|
4
|
+
* The folder that contain the root translation files.
|
|
5
|
+
*/
|
|
6
|
+
translationPath: string;
|
|
7
|
+
/**
|
|
8
|
+
* The default language of the project.
|
|
9
|
+
*/
|
|
10
|
+
defaultLang: string;
|
|
11
|
+
/**
|
|
12
|
+
* Determine rather join also the default language
|
|
13
|
+
*/
|
|
14
|
+
includeDefaultLang: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The output directory.
|
|
17
|
+
*/
|
|
18
|
+
outDir: string;
|
|
19
|
+
/**
|
|
20
|
+
* The root project name.
|
|
21
|
+
*/
|
|
22
|
+
project: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/join/schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "SchematicsTranslocoJoin",
|
|
4
|
+
"title": "Merge all of the project's translation files into one.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"translationPath": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The folder that contain the root translation files.",
|
|
10
|
+
"alias": "root"
|
|
11
|
+
},
|
|
12
|
+
"outDir": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The output directory path.",
|
|
15
|
+
"default": "dist-i18n",
|
|
16
|
+
"alias": "o"
|
|
17
|
+
},
|
|
18
|
+
"defaultLang": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The default language of the project"
|
|
21
|
+
},
|
|
22
|
+
"includeDefaultLang": {
|
|
23
|
+
"type": "boolean",
|
|
24
|
+
"description": "Determine rather join also the default language",
|
|
25
|
+
"default": false
|
|
26
|
+
},
|
|
27
|
+
"project": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "The root project name.",
|
|
30
|
+
"$default": {
|
|
31
|
+
"$source": "projectName"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"required": []
|
|
36
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
2
|
+
import { SchemaOptions } from './schema';
|
|
3
|
+
export declare function updateAngularJson(host: Tree, options: any): void;
|
|
4
|
+
export declare function createWebpackConfig(host: Tree): void;
|
|
5
|
+
export default function (options: SchemaOptions): Rule;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateAngularJson = updateAngularJson;
|
|
4
|
+
exports.createWebpackConfig = createWebpackConfig;
|
|
5
|
+
exports.default = default_1;
|
|
6
|
+
const node_child_process_1 = require("node:child_process");
|
|
7
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
8
|
+
const config_1 = require("@angular/cli/src/utilities/config");
|
|
9
|
+
const rxjs_1 = require("rxjs");
|
|
10
|
+
const schematics_core_1 = require("../../schematics-core");
|
|
11
|
+
async function installKeysManager() {
|
|
12
|
+
const packageManager = await (0, config_1.getConfiguredPackageManager)();
|
|
13
|
+
console.log('Installing packages for tooling...');
|
|
14
|
+
if (packageManager === 'yarn') {
|
|
15
|
+
(0, node_child_process_1.execSync)('yarn add --dev @jsverse/transloco-keys-manager ngx-build-plus');
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
(0, node_child_process_1.execSync)('npm install --save-dev @jsverse/transloco-keys-manager ngx-build-plus');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function updateAngularJson(host, options) {
|
|
22
|
+
const angularJson = (0, schematics_core_1.getWorkspace)(host);
|
|
23
|
+
if (angularJson) {
|
|
24
|
+
const project = angularJson.projects[options.project];
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
26
|
+
// @ts-ignore - This is a custom builder type added after installing ngx-build-plus
|
|
27
|
+
project.architect.serve.builder = 'ngx-build-plus:dev-server';
|
|
28
|
+
}
|
|
29
|
+
(0, schematics_core_1.setWorkspace)(host, angularJson);
|
|
30
|
+
}
|
|
31
|
+
function createWebpackConfig(host) {
|
|
32
|
+
const webpackConfig = `const { TranslocoExtractKeysWebpackPlugin } = require('@jsverse/transloco-keys-manager');
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
plugins: [new TranslocoExtractKeysWebpackPlugin()]
|
|
36
|
+
};
|
|
37
|
+
`;
|
|
38
|
+
host.create('webpack-dev.config.js', webpackConfig);
|
|
39
|
+
}
|
|
40
|
+
function addKeysDetectiveScript(host, strategy) {
|
|
41
|
+
if (strategy === 'Both') {
|
|
42
|
+
(0, schematics_core_1.addScriptToPackageJson)(host, 'start', 'ng serve --extra-webpack-config webpack-dev.config.js');
|
|
43
|
+
(0, schematics_core_1.addScriptToPackageJson)(host, 'i18n:extract', 'transloco-keys-manager extract');
|
|
44
|
+
}
|
|
45
|
+
if (strategy === 'CLI') {
|
|
46
|
+
(0, schematics_core_1.addScriptToPackageJson)(host, 'i18n:extract', 'transloco-keys-manager extract');
|
|
47
|
+
}
|
|
48
|
+
if (strategy === 'Webpack Plugin') {
|
|
49
|
+
(0, schematics_core_1.addScriptToPackageJson)(host, 'start', 'ng serve --extra-webpack-config webpack-dev.config.js');
|
|
50
|
+
}
|
|
51
|
+
(0, schematics_core_1.addScriptToPackageJson)(host, 'i18n:find', 'transloco-keys-manager find');
|
|
52
|
+
}
|
|
53
|
+
function updateTranslocoConfig(host, options) {
|
|
54
|
+
const config = (0, schematics_core_1.getGlobalConfig)() || {};
|
|
55
|
+
let shouldUpdate = false;
|
|
56
|
+
if (!config.rootTranslationsPath) {
|
|
57
|
+
if (!options.translationPath) {
|
|
58
|
+
throw new schematics_1.SchematicsException('Please provide the translation root path by using the --translation-path flag');
|
|
59
|
+
}
|
|
60
|
+
config.rootTranslationsPath = options.translationPath;
|
|
61
|
+
shouldUpdate = true;
|
|
62
|
+
}
|
|
63
|
+
if (!config.langs) {
|
|
64
|
+
if (!options.langs) {
|
|
65
|
+
throw new schematics_1.SchematicsException('Please provide the available languages either by using --langs or through the "langs" property in transloco.config.ts file');
|
|
66
|
+
}
|
|
67
|
+
config.langs = options.langs.split(',').map((l) => l.trim());
|
|
68
|
+
shouldUpdate = true;
|
|
69
|
+
}
|
|
70
|
+
if (!config.keysManager) {
|
|
71
|
+
config.keysManager = {};
|
|
72
|
+
shouldUpdate = true;
|
|
73
|
+
}
|
|
74
|
+
if (shouldUpdate) {
|
|
75
|
+
(0, schematics_core_1.updateGlobalConfig)(host, config);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function default_1(options) {
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
return (host) => {
|
|
81
|
+
// First install dependencies via command line to get the latest versions.
|
|
82
|
+
return (0, rxjs_1.from)(installKeysManager()).pipe((0, rxjs_1.map)(() => {
|
|
83
|
+
updateTranslocoConfig(host, options);
|
|
84
|
+
if (['Webpack Plugin', 'Both'].includes(options.strategy)) {
|
|
85
|
+
createWebpackConfig(host);
|
|
86
|
+
updateAngularJson(host, options);
|
|
87
|
+
}
|
|
88
|
+
addKeysDetectiveScript(host, options.strategy);
|
|
89
|
+
return host;
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/keys-manager/index.ts"],"names":[],"mappings":";;AA6BA,8CAUC;AAED,kDAQC;AAmED,4BAmBC;AAvID,2DAA8C;AAE9C,2DAA6E;AAC7E,8DAAgF;AAEhF,+BAAiC;AAEjC,2DAM+B;AAI/B,KAAK,UAAU,kBAAkB;IAC/B,MAAM,cAAc,GAAG,MAAM,IAAA,oCAA2B,GAAE,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;QAC9B,IAAA,6BAAQ,EAAC,+DAA+D,CAAC,CAAC;IAC5E,CAAC;SAAM,CAAC;QACN,IAAA,6BAAQ,EACN,uEAAuE,CACxE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,IAAU,EAAE,OAAO;IACnD,MAAM,WAAW,GAAG,IAAA,8BAAY,EAAC,IAAI,CAAC,CAAC;IACvC,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,6DAA6D;QAC7D,mFAAmF;QACnF,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG,2BAA2B,CAAC;IAChE,CAAC;IAED,IAAA,8BAAY,EAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,mBAAmB,CAAC,IAAU;IAC5C,MAAM,aAAa,GAAG;;;;;CAKvB,CAAC;IACA,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAU,EAAE,QAAgB;IAC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IAAI,EAAE,CAAC,CAAC;QAC7D,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACxB,MAAM,CAAC,WAAW,GAAG,EAAE,CAAC;QACxB,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACjB,IAAA,oCAAkB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,mBAAyB,OAAsB;IAC7C,aAAa;IACb,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,0EAA0E;QAC1E,OAAO,IAAA,WAAI,EAAC,kBAAkB,EAAE,CAAC,CAAC,IAAI,CACpC,IAAA,UAAG,EAAC,GAAG,EAAE;YACP,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAErC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC1D,mBAAmB,CAAC,IAAI,CAAC,CAAC;gBAC1B,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACnC,CAAC;YAED,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;YAE/C,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema } from '@schematics/angular/module/schema';
|
|
2
|
+
export interface SchemaOptions extends Schema {
|
|
3
|
+
/**
|
|
4
|
+
* The strategy which will be used to work with the CLI.
|
|
5
|
+
*/
|
|
6
|
+
strategy: string;
|
|
7
|
+
/**
|
|
8
|
+
* The folder that contain the root translation files.
|
|
9
|
+
*/
|
|
10
|
+
translationPath: string;
|
|
11
|
+
/**
|
|
12
|
+
* The languages that being used in the project.
|
|
13
|
+
*/
|
|
14
|
+
langs: string;
|
|
15
|
+
/**
|
|
16
|
+
* The root project name.
|
|
17
|
+
*/
|
|
18
|
+
project: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/keys-manager/schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "SchematicsTranslocoKeysManager",
|
|
4
|
+
"title": "Adds Transloco Keys Manager to a project",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"strategy": {
|
|
8
|
+
"description": "The strategy which will be used to work with the CLI.",
|
|
9
|
+
"x-prompt": "Which strategy do you want to use?",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"default": "both",
|
|
12
|
+
"enum": ["CLI", "Webpack Plugin", "Both"]
|
|
13
|
+
},
|
|
14
|
+
"langs": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "The languages of the project."
|
|
17
|
+
},
|
|
18
|
+
"translationPath": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The folder that contain the root translation files.",
|
|
21
|
+
"default": "src/assets/i18n/",
|
|
22
|
+
"alias": "root"
|
|
23
|
+
},
|
|
24
|
+
"project": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "The root project name.",
|
|
27
|
+
"$default": {
|
|
28
|
+
"$source": "projectName"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"required": []
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const process_1 = require("process");
|
|
5
|
+
const ng_migrate_1 = require("./ng-migrate");
|
|
6
|
+
function default_1(options) {
|
|
7
|
+
return () => {
|
|
8
|
+
const langs = options.langs.split(',').map((l) => l.trim());
|
|
9
|
+
(0, ng_migrate_1.run)({ input: options.path, output: options.translationFilesPath, langs });
|
|
10
|
+
// prevent "nothing to be done".
|
|
11
|
+
(0, process_1.exit)();
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/ng-migrate/index.ts"],"names":[],"mappings":";;AAOA,4BAOC;AAdD,qCAA+B;AAI/B,6CAAmC;AAGnC,mBAAyB,OAAsB;IAC7C,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5D,IAAA,gBAAG,EAAC,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1E,gCAAgC;QAChC,IAAA,cAAI,GAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = run;
|
|
4
|
+
const glob_1 = require("glob");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const strings_1 = require("@angular-devkit/core/src/utils/strings");
|
|
7
|
+
const regex = /<([\w-]*)\s*(?=[^>]*i18n)[^>]*i18n(?:(?:=("|')(?<attrValue>[^>]*?)\2)|(?:-(?<propName>[\w-]*)[^>]*\4=("|')(?<propValue>[^>]*?)\5))?[^>]*(?:>(?<innerText>[^]*?)<\/\1)?/g;
|
|
8
|
+
function run({ input, output, langs }) {
|
|
9
|
+
const files = (0, glob_1.sync)(`${process.cwd()}/${input}/**/*.html`);
|
|
10
|
+
let translation = {};
|
|
11
|
+
for (const filePath of files) {
|
|
12
|
+
const tpl = (0, fs_extra_1.readFileSync)(filePath, { encoding: 'utf-8' });
|
|
13
|
+
translation = { ...translation, ...getTranslation(tpl) };
|
|
14
|
+
const newTpl = getNewTemplate(tpl);
|
|
15
|
+
(0, fs_extra_1.outputFileSync)(filePath, newTpl);
|
|
16
|
+
}
|
|
17
|
+
for (const lang of langs) {
|
|
18
|
+
const sorted = Object.keys(translation)
|
|
19
|
+
.sort()
|
|
20
|
+
.reduce((acc, key) => {
|
|
21
|
+
acc[key] = translation[key];
|
|
22
|
+
return acc;
|
|
23
|
+
}, {});
|
|
24
|
+
(0, fs_extra_1.outputJsonSync)(`${process.cwd()}/${output}/${lang}.json`, sorted, {
|
|
25
|
+
spaces: 2,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
console.log('\n 🌵 Done! 🌵');
|
|
29
|
+
console.log('Welcome to a better translation experience 🌐');
|
|
30
|
+
console.log('\nFor more information about this script please visit 👉 https://jsverse.github.io/transloco/docs/migration/angular\n');
|
|
31
|
+
}
|
|
32
|
+
function resolveKey(attrValue, value) {
|
|
33
|
+
let key = value;
|
|
34
|
+
if (!attrValue) {
|
|
35
|
+
return (0, strings_1.dasherize)(value);
|
|
36
|
+
}
|
|
37
|
+
if (attrValue) {
|
|
38
|
+
const splitCustomId = attrValue.split('@@');
|
|
39
|
+
const hasCustomId = splitCustomId.length === 2;
|
|
40
|
+
key = hasCustomId ? splitCustomId[1] : key;
|
|
41
|
+
}
|
|
42
|
+
key = (0, strings_1.dasherize)(key);
|
|
43
|
+
return key;
|
|
44
|
+
}
|
|
45
|
+
function getTranslation(template) {
|
|
46
|
+
let result = regex.exec(template);
|
|
47
|
+
const translation = {};
|
|
48
|
+
while (result) {
|
|
49
|
+
const { attrValue, innerText, propValue } = result.groups;
|
|
50
|
+
let context;
|
|
51
|
+
let comment;
|
|
52
|
+
let keyValue = propValue ? propValue : innerText;
|
|
53
|
+
let key = keyValue;
|
|
54
|
+
if (attrValue) {
|
|
55
|
+
const splitCustomId = attrValue.split('@@');
|
|
56
|
+
const hasCustomId = splitCustomId.length === 2;
|
|
57
|
+
key = hasCustomId ? splitCustomId[1] : key;
|
|
58
|
+
const splitContextDescription = attrValue.split('|');
|
|
59
|
+
// we have context
|
|
60
|
+
if (splitContextDescription.length === 2) {
|
|
61
|
+
context = splitContextDescription[0];
|
|
62
|
+
comment = splitContextDescription[1].split('@@')[0];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (splitContextDescription[0].startsWith('@@') === false) {
|
|
66
|
+
comment = attrValue.split('@@')[0];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
key = (0, strings_1.dasherize)(key);
|
|
71
|
+
keyValue = keyValue.trim().replace(/(\r\n|\n|\r)/gm, '');
|
|
72
|
+
if (context) {
|
|
73
|
+
translation[context] = translation[context] || {};
|
|
74
|
+
translation[context][key] = keyValue;
|
|
75
|
+
if (comment) {
|
|
76
|
+
translation[context][`${key}.comment`] = comment;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
translation[key] = keyValue;
|
|
81
|
+
if (comment) {
|
|
82
|
+
translation[`${key}.comment`] = comment;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
result = regex.exec(template);
|
|
86
|
+
}
|
|
87
|
+
return translation;
|
|
88
|
+
}
|
|
89
|
+
function getNewTemplate(template) {
|
|
90
|
+
return template.replace(regex, function (match, tag, mark, attrValue, propName, propMark, propValue, innerText) {
|
|
91
|
+
let replace = ' i18n';
|
|
92
|
+
const key = resolveKey(attrValue, propValue || innerText);
|
|
93
|
+
let value = innerText;
|
|
94
|
+
const newValue = `{{ '${key}' | transloco }}`;
|
|
95
|
+
if (attrValue) {
|
|
96
|
+
replace = ` i18n=${mark}${attrValue}${mark}`;
|
|
97
|
+
}
|
|
98
|
+
if (propName) {
|
|
99
|
+
replace = ` i18n-${propName}`;
|
|
100
|
+
value = propValue;
|
|
101
|
+
}
|
|
102
|
+
return match.replace(replace, '').replace(value, newValue);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=ng-migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ng-migrate.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/ng-migrate/ng-migrate.ts"],"names":[],"mappings":";;AAOA,kBA4BC;AAnCD,+BAAwC;AACxC,uCAAwE;AACxE,oEAAmE;AAEnE,MAAM,KAAK,GACT,yKAAyK,CAAC;AAE5K,SAAgB,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;IAC1C,MAAM,KAAK,GAAG,IAAA,WAAQ,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,KAAK,YAAY,CAAC,CAAC;IAC9D,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAA,uBAAY,EAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1D,WAAW,GAAG,EAAE,GAAG,WAAW,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QAEzD,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACnC,IAAA,yBAAc,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;aACpC,IAAI,EAAE;aACN,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACnB,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;YAC5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*/
|
|
5
|
+
path: string;
|
|
6
|
+
/**
|
|
7
|
+
* The location of the translation files.
|
|
8
|
+
*/
|
|
9
|
+
translationFilesPath: string;
|
|
10
|
+
/**
|
|
11
|
+
* The languages of the project.
|
|
12
|
+
*/
|
|
13
|
+
langs: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/ng-migrate/schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "SchematicsTranslocoNgMigrate",
|
|
4
|
+
"title": "Migrate from Angular i18n to Transloco",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"langs": {
|
|
8
|
+
"description": "The languages of the project.",
|
|
9
|
+
"x-prompt": "Which languages do you use?",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"default": "en, es"
|
|
12
|
+
},
|
|
13
|
+
"translationFilesPath": {
|
|
14
|
+
"description": "The location of the translation files.",
|
|
15
|
+
"x-prompt": "Which folder will contain the translation files?",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"default": "src/assets/i18n"
|
|
18
|
+
},
|
|
19
|
+
"path": {
|
|
20
|
+
"description": "The path to the source root directory.",
|
|
21
|
+
"x-prompt": "Which folder will contain the translation files?",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"default": "./src/app"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": []
|
|
27
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
exports.run = run;
|
|
5
|
+
const nodePath = require("node:path");
|
|
6
|
+
const fs = require("node:fs/promises");
|
|
7
|
+
const glob = require("glob");
|
|
8
|
+
const migration_matchers_1 = require("./migration-matchers");
|
|
9
|
+
function default_1(options) {
|
|
10
|
+
return () => run(options);
|
|
11
|
+
}
|
|
12
|
+
async function run(options) {
|
|
13
|
+
console.log('\x1b[4m%s\x1b[0m', '\nStarting migration script');
|
|
14
|
+
const dir = nodePath.resolve(process.cwd());
|
|
15
|
+
const path = nodePath.join(dir, options.path, '/**/*');
|
|
16
|
+
const { tsReplacements, htmlReplacements } = (0, migration_matchers_1.generateMatchers)(path);
|
|
17
|
+
async function migrate(matchersArr, filesType) {
|
|
18
|
+
console.log(`\nMigrating ${filesType} files 📜`);
|
|
19
|
+
const isWindows = process.platform === 'win32';
|
|
20
|
+
for (let i = 0; i < matchersArr.length; i++) {
|
|
21
|
+
const { step, matchers } = matchersArr[i];
|
|
22
|
+
const msg = `Step ${i + 1}/${matchersArr.length}: Migrating ${step}`;
|
|
23
|
+
console.log(`⏳ ${msg}`);
|
|
24
|
+
const noFilesFound = [];
|
|
25
|
+
for (const matcher of matchers) {
|
|
26
|
+
try {
|
|
27
|
+
// Find files matching the pattern
|
|
28
|
+
const files = glob.sync(matcher.files, {
|
|
29
|
+
windowsPathsNoEscape: isWindows,
|
|
30
|
+
nodir: true,
|
|
31
|
+
});
|
|
32
|
+
if (files.length === 0) {
|
|
33
|
+
noFilesFound.push(`No files match the pattern: ${matcher.files}`);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// Process each file
|
|
37
|
+
for (const file of files) {
|
|
38
|
+
const content = await fs.readFile(file, 'utf8');
|
|
39
|
+
// Apply all replacements
|
|
40
|
+
let lastIndex = 0;
|
|
41
|
+
let result;
|
|
42
|
+
let newContent = '';
|
|
43
|
+
while ((result = matcher.from.exec(content)) !== null) {
|
|
44
|
+
// Add the text from last match to current match
|
|
45
|
+
newContent += content.slice(lastIndex, result.index);
|
|
46
|
+
// Generate replacement text
|
|
47
|
+
const replacement = typeof matcher.to === 'function'
|
|
48
|
+
? matcher.to(result[0], ...result.slice(1))
|
|
49
|
+
: matcher.to;
|
|
50
|
+
newContent += replacement;
|
|
51
|
+
lastIndex = matcher.from.lastIndex;
|
|
52
|
+
}
|
|
53
|
+
// Add remaining content after last match
|
|
54
|
+
newContent += content.slice(lastIndex);
|
|
55
|
+
// Write the modified content back to the file
|
|
56
|
+
await fs.writeFile(file, newContent, 'utf8');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
if (e.message.includes('No files match the pattern')) {
|
|
61
|
+
noFilesFound.push(e.message);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
console.log(`✅ ${msg}`);
|
|
69
|
+
noFilesFound.forEach((pattern) => console.log('\x1b[33m%s\x1b[0m', `⚠️ ${pattern}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
await migrate(htmlReplacements, 'HTML');
|
|
73
|
+
await migrate(tsReplacements, 'TS');
|
|
74
|
+
console.log('\n 🌵 Done! 🌵');
|
|
75
|
+
console.log('Welcome to a better translation experience 🌐');
|
|
76
|
+
console.log('\nFor more information about this script please visit 👉 https://jsverse.github.io/transloco/docs/migration/ngx\n');
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/ngx-migrate/index.ts"],"names":[],"mappings":";;AASA,4BAEC;AAED,kBAiFC;AA9FD,sCAAsC;AACtC,uCAAuC;AAEvC,6BAA6B;AAI7B,6DAAiE;AAEjE,mBAAyB,OAAsB;IAC7C,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC5B,CAAC;AAEM,KAAK,UAAU,GAAG,CAAC,OAAsB;IAC9C,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,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;YACH,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;YACxB,YAAY,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC/B,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,MAAM,OAAO,EAAE,CAAC,CAClD,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAEpC,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CACT,mHAAmH,CACpH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const PIPE_REGEX = "{{\\s*([^}\\r\\n]*?\\|)\\s*(translate)[^\\r\\n]*?}}";
|
|
2
|
+
export declare const PIPE_IN_BINDING_REGEX = "\\]=('|\")\\s*([^}\\r\\n]*?\\|)\\s*(translate)[^\\r\\n]*?\\1";
|
|
3
|
+
export interface MatcherDef {
|
|
4
|
+
files: string;
|
|
5
|
+
from: RegExp;
|
|
6
|
+
to: string | ((match: string, ...args: string[]) => string);
|
|
7
|
+
}
|
|
8
|
+
export interface Matcher {
|
|
9
|
+
matchers: MatcherDef[];
|
|
10
|
+
step: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function generateMatchers(path: string): {
|
|
13
|
+
htmlReplacements: Matcher[];
|
|
14
|
+
tsReplacements: Matcher[];
|
|
15
|
+
};
|