@jsverse/transloco 7.1.0 → 7.2.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/CHANGELOG.md +6 -0
- package/esm2022/lib/transloco.providers.mjs +4 -4
- package/fesm2022/jsverse-transloco.mjs +3 -3
- package/fesm2022/jsverse-transloco.mjs.map +1 -1
- package/lib/resolve-loader.d.ts +1 -1
- package/lib/transloco.providers.d.ts +2 -2
- package/package.json +1 -1
- package/schematics/src/assets/i18n/en.json +0 -1
- package/schematics/src/collection.json +0 -59
- package/schematics/src/component/index.d.ts +0 -2
- package/schematics/src/component/index.js +0 -21
- package/schematics/src/component/index.js.map +0 -1
- package/schematics/src/join/index.d.ts +0 -3
- package/schematics/src/join/index.js +0 -79
- package/schematics/src/join/index.js.map +0 -1
- package/schematics/src/join/schema.d.ts +0 -28
- package/schematics/src/join/schema.js +0 -3
- package/schematics/src/join/schema.js.map +0 -1
- package/schematics/src/join/schema.json +0 -43
- package/schematics/src/keys-manager/index.d.ts +0 -5
- package/schematics/src/keys-manager/index.js +0 -97
- package/schematics/src/keys-manager/index.js.map +0 -1
- package/schematics/src/keys-manager/schema.d.ts +0 -19
- package/schematics/src/keys-manager/schema.js +0 -3
- package/schematics/src/keys-manager/schema.js.map +0 -1
- package/schematics/src/keys-manager/schema.json +0 -33
- package/schematics/src/migrate/index.d.ts +0 -3
- package/schematics/src/migrate/index.js +0 -21
- package/schematics/src/migrate/index.js.map +0 -1
- package/schematics/src/migrate/ngx-translate-migration.d.ts +0 -3
- package/schematics/src/migrate/ngx-translate-migration.js +0 -169
- package/schematics/src/migrate/ngx-translate-migration.js.map +0 -1
- package/schematics/src/migrate/schema.d.ts +0 -10
- package/schematics/src/migrate/schema.js +0 -3
- package/schematics/src/migrate/schema.js.map +0 -1
- package/schematics/src/migrate/schema.json +0 -23
- package/schematics/src/ng-add/files/transloco-loader/transloco-loader.__ts__ +0 -12
- package/schematics/src/ng-add/files/transloco-module/transloco-root.module.__ts__ +0 -24
- package/schematics/src/ng-add/generators/http-loader.gen.d.ts +0 -4
- package/schematics/src/ng-add/generators/http-loader.gen.js +0 -15
- package/schematics/src/ng-add/generators/http-loader.gen.js.map +0 -1
- package/schematics/src/ng-add/generators/root-module.gen.d.ts +0 -9
- package/schematics/src/ng-add/generators/root-module.gen.js +0 -31
- package/schematics/src/ng-add/generators/root-module.gen.js.map +0 -1
- package/schematics/src/ng-add/generators/translation-files.gen.d.ts +0 -4
- package/schematics/src/ng-add/generators/translation-files.gen.js +0 -23
- package/schematics/src/ng-add/generators/translation-files.gen.js.map +0 -1
- package/schematics/src/ng-add/index.d.ts +0 -3
- package/schematics/src/ng-add/index.js +0 -103
- package/schematics/src/ng-add/index.js.map +0 -1
- package/schematics/src/ng-add/schema.d.ts +0 -42
- package/schematics/src/ng-add/schema.js +0 -14
- package/schematics/src/ng-add/schema.js.map +0 -1
- package/schematics/src/ng-add/schema.json +0 -53
- package/schematics/src/ng-migrate/index.d.ts +0 -3
- package/schematics/src/ng-migrate/index.js +0 -14
- package/schematics/src/ng-migrate/index.js.map +0 -1
- package/schematics/src/ng-migrate/ng-migrate.d.ts +0 -5
- package/schematics/src/ng-migrate/ng-migrate.js +0 -106
- package/schematics/src/ng-migrate/ng-migrate.js.map +0 -1
- package/schematics/src/ng-migrate/schema.d.ts +0 -14
- package/schematics/src/ng-migrate/schema.js +0 -3
- package/schematics/src/ng-migrate/schema.js.map +0 -1
- package/schematics/src/ng-migrate/schema.json +0 -27
- package/schematics/src/schematics.consts.d.ts +0 -4
- package/schematics/src/schematics.consts.js +0 -8
- package/schematics/src/schematics.consts.js.map +0 -1
- package/schematics/src/scope/index.d.ts +0 -3
- package/schematics/src/scope/index.js +0 -101
- package/schematics/src/scope/index.js.map +0 -1
- package/schematics/src/scope/schema.d.ts +0 -28
- package/schematics/src/scope/schema.js +0 -3
- package/schematics/src/scope/schema.js.map +0 -1
- package/schematics/src/scope/schema.json +0 -84
- package/schematics/src/split/index.d.ts +0 -3
- package/schematics/src/split/index.js +0 -66
- package/schematics/src/split/index.js.map +0 -1
- package/schematics/src/split/schema.d.ts +0 -20
- package/schematics/src/split/schema.js +0 -3
- package/schematics/src/split/schema.js.map +0 -1
- package/schematics/src/split/schema.json +0 -35
- package/schematics/src/types.d.ts +0 -5
- package/schematics/src/types.js +0 -10
- package/schematics/src/types.js.map +0 -1
- package/schematics/src/upgrade/index.d.ts +0 -3
- package/schematics/src/upgrade/index.js +0 -19
- package/schematics/src/upgrade/index.js.map +0 -1
- package/schematics/src/upgrade/schema.d.ts +0 -6
- package/schematics/src/upgrade/schema.js +0 -3
- package/schematics/src/upgrade/schema.js.map +0 -1
- package/schematics/src/upgrade/schema.json +0 -16
- package/schematics/src/upgrade/v2.d.ts +0 -1
- package/schematics/src/upgrade/v2.js +0 -89
- package/schematics/src/upgrade/v2.js.map +0 -1
- package/schematics/src/utils/array.d.ts +0 -3
- package/schematics/src/utils/array.js +0 -12
- package/schematics/src/utils/array.js.map +0 -1
- package/schematics/src/utils/config.d.ts +0 -2
- package/schematics/src/utils/config.js +0 -13
- package/schematics/src/utils/config.js.map +0 -1
- package/schematics/src/utils/find-module.d.ts +0 -23
- package/schematics/src/utils/find-module.js +0 -110
- package/schematics/src/utils/find-module.js.map +0 -1
- package/schematics/src/utils/package.d.ts +0 -5
- package/schematics/src/utils/package.js +0 -19
- package/schematics/src/utils/package.js.map +0 -1
- package/schematics/src/utils/projects.d.ts +0 -8
- package/schematics/src/utils/projects.js +0 -56
- package/schematics/src/utils/projects.js.map +0 -1
- package/schematics/src/utils/translations.d.ts +0 -7
- package/schematics/src/utils/translations.js +0 -31
- package/schematics/src/utils/translations.js.map +0 -1
- package/schematics/src/utils/transloco.d.ts +0 -24
- package/schematics/src/utils/transloco.js +0 -93
- package/schematics/src/utils/transloco.js.map +0 -1
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["@schematics/angular"],
|
|
3
|
-
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
4
|
-
"schematics": {
|
|
5
|
-
"ng-add": {
|
|
6
|
-
"aliases": ["init"],
|
|
7
|
-
"factory": "./ng-add/index",
|
|
8
|
-
"schema": "./ng-add/schema.json",
|
|
9
|
-
"description": "Add transloco configuration for root module."
|
|
10
|
-
},
|
|
11
|
-
"component": {
|
|
12
|
-
"aliases": ["c"],
|
|
13
|
-
"factory": "./component/index",
|
|
14
|
-
"schema": "../../../../@schematics/angular/component/schema.json",
|
|
15
|
-
"description": "Add component with translation."
|
|
16
|
-
},
|
|
17
|
-
"migrate": {
|
|
18
|
-
"aliases": ["m"],
|
|
19
|
-
"factory": "./migrate/index",
|
|
20
|
-
"schema": "./migrate/schema.json",
|
|
21
|
-
"description": "Run a migration script from @ngx-translate."
|
|
22
|
-
},
|
|
23
|
-
"scope": {
|
|
24
|
-
"aliases": ["s"],
|
|
25
|
-
"factory": "./scope/index",
|
|
26
|
-
"schema": "./scope/schema.json",
|
|
27
|
-
"description": "Add transloco scope."
|
|
28
|
-
},
|
|
29
|
-
"upgrade": {
|
|
30
|
-
"aliases": ["up"],
|
|
31
|
-
"factory": "./upgrade/index",
|
|
32
|
-
"schema": "./upgrade/schema.json",
|
|
33
|
-
"description": "Run an upgrade script."
|
|
34
|
-
},
|
|
35
|
-
"keys-manager": {
|
|
36
|
-
"aliases": ["km"],
|
|
37
|
-
"factory": "./keys-manager/index",
|
|
38
|
-
"schema": "./keys-manager/schema.json",
|
|
39
|
-
"description": "Add Transloco Keys Manager plugin to your project."
|
|
40
|
-
},
|
|
41
|
-
"join": {
|
|
42
|
-
"aliases": ["build"],
|
|
43
|
-
"factory": "./join/index",
|
|
44
|
-
"schema": "./join/schema.json",
|
|
45
|
-
"description": "Join the translation files into one."
|
|
46
|
-
},
|
|
47
|
-
"split": {
|
|
48
|
-
"aliases": ["sp"],
|
|
49
|
-
"factory": "./split/index",
|
|
50
|
-
"schema": "./split/schema.json",
|
|
51
|
-
"description": "split the translated files over the project's translation files."
|
|
52
|
-
},
|
|
53
|
-
"ng-migrate": {
|
|
54
|
-
"factory": "./ng-migrate/index",
|
|
55
|
-
"schema": "./ng-migrate/schema.json",
|
|
56
|
-
"description": "split the translated files over the project's translation files."
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
4
|
-
const operators_1 = require("rxjs/operators");
|
|
5
|
-
function default_1(options) {
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
return (host, context) => {
|
|
8
|
-
const template = `<ng-template transloco let-t>
|
|
9
|
-
<h1> {{ t('title') }} </h1>
|
|
10
|
-
</ng-template>
|
|
11
|
-
`;
|
|
12
|
-
const cmpRule = (0, schematics_1.externalSchematic)('@schematics/angular', 'component', options);
|
|
13
|
-
const tree$ = cmpRule(host, context).pipe((0, operators_1.tap)((tree) => {
|
|
14
|
-
const templatePath = tree.actions.find((action) => !!action.path.match(/component.html/)).path;
|
|
15
|
-
tree.overwrite(templatePath, template);
|
|
16
|
-
}));
|
|
17
|
-
return tree$;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
exports.default = default_1;
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/component/index.ts"],"names":[],"mappings":";;AAAA,2DAKoC;AAEpC,8CAAqC;AAErC,mBAAyB,OAAO;IAC9B,aAAa;IACb,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAC/C,MAAM,QAAQ,GAAG;;;CAGpB,CAAC;QAEE,MAAM,OAAO,GAAG,IAAA,8BAAiB,EAC/B,qBAAqB,EACrB,WAAW,EACX,OAAO,CACR,CAAC;QACF,MAAM,KAAK,GAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAiC,CAAC,IAAI,CACxE,IAAA,eAAG,EAAC,CAAC,IAAI,EAAE,EAAE;YACX,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CACpC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAClD,CAAC,IAAI,CAAC;YACP,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACzC,CAAC,CAAC,CACH,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAxBD,4BAwBC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
4
|
-
const core_1 = require("@angular-devkit/core");
|
|
5
|
-
const fs_extra_1 = require("fs-extra");
|
|
6
|
-
const types_1 = require("../types");
|
|
7
|
-
const transloco_1 = require("../utils/transloco");
|
|
8
|
-
function reduceTranslations(host, dirPath, translationJson, lang, key = '') {
|
|
9
|
-
const dir = host.getDir(dirPath);
|
|
10
|
-
if (!(0, transloco_1.hasFiles)(dir) && !(0, transloco_1.hasSubdirs)(dir))
|
|
11
|
-
return translationJson;
|
|
12
|
-
dir.subfiles
|
|
13
|
-
.filter((fileName) => fileName.includes(`${lang}.json`))
|
|
14
|
-
.forEach((fileName) => {
|
|
15
|
-
if (translationJson[key]) {
|
|
16
|
-
throw new schematics_1.SchematicsException(`key: ${key} already exist in translation file, please rename it and rerun the command.`);
|
|
17
|
-
}
|
|
18
|
-
translationJson[key] = (0, transloco_1.getJsonFileContent)(fileName, dir);
|
|
19
|
-
});
|
|
20
|
-
if ((0, transloco_1.hasSubdirs)(dir)) {
|
|
21
|
-
dir.subdirs.forEach((subDirName) => {
|
|
22
|
-
const subDir = dir.dir(subDirName);
|
|
23
|
-
const nestedKey = (0, transloco_1.getTranslationKey)(key, subDirName);
|
|
24
|
-
reduceTranslations(host, (0, core_1.normalize)(subDir.path).substr(1), translationJson, lang, nestedKey);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return translationJson;
|
|
28
|
-
}
|
|
29
|
-
function deletePrevFiles(host, options) {
|
|
30
|
-
if ((0, fs_extra_1.existsSync)(options.outDir)) {
|
|
31
|
-
(0, fs_extra_1.removeSync)(options.outDir);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function jsonBuilder(tree, path, content) {
|
|
35
|
-
tree.create(`${path}.json`, JSON.stringify(content, null, 2));
|
|
36
|
-
}
|
|
37
|
-
function builderFactory(format) {
|
|
38
|
-
switch (format) {
|
|
39
|
-
case types_1.TranslationFileFormat.JSON:
|
|
40
|
-
return jsonBuilder;
|
|
41
|
-
case types_1.TranslationFileFormat.PO:
|
|
42
|
-
// TODO:
|
|
43
|
-
return jsonBuilder;
|
|
44
|
-
case types_1.TranslationFileFormat.XLIFF:
|
|
45
|
-
// TODO:
|
|
46
|
-
return jsonBuilder;
|
|
47
|
-
default:
|
|
48
|
-
return jsonBuilder;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function default_1(options) {
|
|
52
|
-
return (host) => {
|
|
53
|
-
deletePrevFiles(host, options);
|
|
54
|
-
const root = (0, transloco_1.getTranslationsRoot)(host, options);
|
|
55
|
-
const defaultLang = (0, transloco_1.getDefaultLang)(options);
|
|
56
|
-
if (options.includeDefaultLang && !defaultLang) {
|
|
57
|
-
throw new schematics_1.SchematicsException(`Please specify the default project's language using --default-Lang or in transloco.config.js file.`);
|
|
58
|
-
}
|
|
59
|
-
let rootTranslations = (0, transloco_1.getTranslationFiles)(host, root);
|
|
60
|
-
const translationEntryPaths = (0, transloco_1.getTranslationEntryPaths)(host, root);
|
|
61
|
-
if (!options.includeDefaultLang) {
|
|
62
|
-
rootTranslations = rootTranslations.filter((t) => t.lang !== defaultLang);
|
|
63
|
-
}
|
|
64
|
-
const output = rootTranslations.map((t) => ({
|
|
65
|
-
lang: t.lang,
|
|
66
|
-
translation: translationEntryPaths.reduce((acc, entryPath) => {
|
|
67
|
-
return reduceTranslations(host, entryPath.path, t.translation, t.lang, entryPath.scope);
|
|
68
|
-
}, t.translation),
|
|
69
|
-
}));
|
|
70
|
-
const treeSource = new schematics_1.EmptyTree();
|
|
71
|
-
const builder = builderFactory(options.format);
|
|
72
|
-
output.forEach((o) => {
|
|
73
|
-
builder(treeSource, `${options.outDir}/${o.lang}`, o.translation);
|
|
74
|
-
});
|
|
75
|
-
return treeSource;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
exports.default = default_1;
|
|
79
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/join/index.ts"],"names":[],"mappings":";;AAAA,2DAKoC;AACpC,+CAAiD;AACjD,uCAAkD;AAElD,oCAAiD;AACjD,kDAS4B;AAU5B,SAAS,kBAAkB,CACzB,IAAU,EACV,OAAe,EACf,eAAe,EACf,IAAY,EACZ,GAAG,GAAG,EAAE;IAER,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,CAAC,IAAA,oBAAQ,EAAC,GAAG,CAAC,IAAI,CAAC,IAAA,sBAAU,EAAC,GAAG,CAAC;QAAE,OAAO,eAAe,CAAC;IAC/D,GAAG,CAAC,QAAQ;SACT,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC;SACvD,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QACpB,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE;YACxB,MAAM,IAAI,gCAAmB,CAC3B,QAAQ,GAAG,6EAA6E,CACzF,CAAC;SACH;QAC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C/C,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACnB,OAAO,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAtCD,4BAsCC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@schematics/angular/module/schema';
|
|
2
|
-
import { TranslationFileFormat } from '../types';
|
|
3
|
-
export interface SchemaOptions extends Schema {
|
|
4
|
-
/**
|
|
5
|
-
* The folder that contain the root translation files.
|
|
6
|
-
*/
|
|
7
|
-
translationPath: string;
|
|
8
|
-
/**
|
|
9
|
-
* The default language of the project.
|
|
10
|
-
*/
|
|
11
|
-
defaultLang: string;
|
|
12
|
-
/**
|
|
13
|
-
* Determine rather join also the default language
|
|
14
|
-
*/
|
|
15
|
-
includeDefaultLang: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* The output directory.
|
|
18
|
-
*/
|
|
19
|
-
outDir: string;
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
format?: TranslationFileFormat;
|
|
24
|
-
/**
|
|
25
|
-
* The root project name.
|
|
26
|
-
*/
|
|
27
|
-
project: string;
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/join/schema.ts"],"names":[],"mappings":""}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema",
|
|
3
|
-
"$id": "transloco-join",
|
|
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
|
-
"format": {
|
|
28
|
-
"description": "The output translation files format.",
|
|
29
|
-
"type": "string",
|
|
30
|
-
"default": "JSON",
|
|
31
|
-
"enum": ["JSON", "xliff", "po"],
|
|
32
|
-
"alias": "f"
|
|
33
|
-
},
|
|
34
|
-
"project": {
|
|
35
|
-
"type": "string",
|
|
36
|
-
"description": "The root project name.",
|
|
37
|
-
"$default": {
|
|
38
|
-
"$source": "projectName"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"required": []
|
|
43
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createWebpackConfig = exports.updateAngularJson = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
|
-
const config_1 = require("@angular/cli/src/utilities/config");
|
|
7
|
-
const rxjs_1 = require("rxjs");
|
|
8
|
-
const package_1 = require("../utils/package");
|
|
9
|
-
const projects_1 = require("../utils/projects");
|
|
10
|
-
const transloco_1 = require("../utils/transloco");
|
|
11
|
-
const config_2 = require("../utils/config");
|
|
12
|
-
async function installKeysManager() {
|
|
13
|
-
const packageManager = await (0, config_1.getConfiguredPackageManager)();
|
|
14
|
-
console.log('Installing packages for tooling...');
|
|
15
|
-
if (packageManager === 'yarn') {
|
|
16
|
-
(0, child_process_1.execSync)('yarn add --dev @jsverse/transloco-keys-manager ngx-build-plus');
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
(0, child_process_1.execSync)('npm install --save-dev @jsverse/transloco-keys-manager ngx-build-plus');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function updateAngularJson(host, options) {
|
|
23
|
-
const angularJson = (0, projects_1.getWorkspace)(host);
|
|
24
|
-
if (angularJson) {
|
|
25
|
-
const project = angularJson.projects[options.project];
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
27
|
-
// @ts-ignore - This is a custom builder type added after installing ngx-build-plus
|
|
28
|
-
project.architect.serve.builder = 'ngx-build-plus:dev-server';
|
|
29
|
-
}
|
|
30
|
-
(0, projects_1.setWorkspace)(host, angularJson);
|
|
31
|
-
}
|
|
32
|
-
exports.updateAngularJson = updateAngularJson;
|
|
33
|
-
function createWebpackConfig(host) {
|
|
34
|
-
const webpackConfig = `const { TranslocoExtractKeysWebpackPlugin } = require('@jsverse/transloco-keys-manager');
|
|
35
|
-
|
|
36
|
-
module.exports = {
|
|
37
|
-
plugins: [new TranslocoExtractKeysWebpackPlugin()]
|
|
38
|
-
};
|
|
39
|
-
`;
|
|
40
|
-
host.create('webpack-dev.config.js', webpackConfig);
|
|
41
|
-
}
|
|
42
|
-
exports.createWebpackConfig = createWebpackConfig;
|
|
43
|
-
function addKeysDetectiveScript(host, strategy) {
|
|
44
|
-
if (strategy === 'Both') {
|
|
45
|
-
(0, package_1.addScriptToPackageJson)(host, 'start', 'ng serve --extra-webpack-config webpack-dev.config.js');
|
|
46
|
-
(0, package_1.addScriptToPackageJson)(host, 'i18n:extract', 'transloco-keys-manager extract');
|
|
47
|
-
}
|
|
48
|
-
if (strategy === 'CLI') {
|
|
49
|
-
(0, package_1.addScriptToPackageJson)(host, 'i18n:extract', 'transloco-keys-manager extract');
|
|
50
|
-
}
|
|
51
|
-
if (strategy === 'Webpack Plugin') {
|
|
52
|
-
(0, package_1.addScriptToPackageJson)(host, 'start', 'ng serve --extra-webpack-config webpack-dev.config.js');
|
|
53
|
-
}
|
|
54
|
-
(0, package_1.addScriptToPackageJson)(host, 'i18n:find', 'transloco-keys-manager find');
|
|
55
|
-
}
|
|
56
|
-
function updateTranslocoConfig(host, options) {
|
|
57
|
-
const config = (0, config_2.getConfig)() || {};
|
|
58
|
-
let shouldUpdate = false;
|
|
59
|
-
if (!config.rootTranslationsPath) {
|
|
60
|
-
if (!options.translationPath) {
|
|
61
|
-
throw new schematics_1.SchematicsException('Please provide the translation root path by using the --translation-path flag');
|
|
62
|
-
}
|
|
63
|
-
config.rootTranslationsPath = options.translationPath;
|
|
64
|
-
shouldUpdate = true;
|
|
65
|
-
}
|
|
66
|
-
if (!config.langs) {
|
|
67
|
-
if (!options.langs) {
|
|
68
|
-
throw new schematics_1.SchematicsException('Please provide the available languages either by using --langs or through the "langs" property in transloco.config.js file');
|
|
69
|
-
}
|
|
70
|
-
config.langs = options.langs.split(',').map((l) => l.trim());
|
|
71
|
-
shouldUpdate = true;
|
|
72
|
-
}
|
|
73
|
-
if (!config.keysManager) {
|
|
74
|
-
config.keysManager = {};
|
|
75
|
-
shouldUpdate = true;
|
|
76
|
-
}
|
|
77
|
-
if (shouldUpdate) {
|
|
78
|
-
(0, transloco_1.updateConfig)(host, config);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function default_1(options) {
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
return (host) => {
|
|
84
|
-
// First install dependencies via command line to get the latest versions.
|
|
85
|
-
return (0, rxjs_1.from)(installKeysManager()).pipe((0, rxjs_1.map)(() => {
|
|
86
|
-
updateTranslocoConfig(host, options);
|
|
87
|
-
if (['Webpack Plugin', 'Both'].includes(options.strategy)) {
|
|
88
|
-
createWebpackConfig(host);
|
|
89
|
-
updateAngularJson(host, options);
|
|
90
|
-
}
|
|
91
|
-
addKeysDetectiveScript(host, options.strategy);
|
|
92
|
-
return host;
|
|
93
|
-
}));
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
exports.default = default_1;
|
|
97
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/keys-manager/index.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAEzC,2DAA6E;AAC7E,8DAAgF;AAEhF,+BAAiC;AAEjC,8CAA0D;AAC1D,gDAA+D;AAC/D,kDAAkD;AAClD,4CAA4C;AAI5C,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;QAC7B,IAAA,wBAAQ,EAAC,+DAA+D,CAAC,CAAC;KAC3E;SAAM;QACL,IAAA,wBAAQ,EACN,uEAAuE,CACxE,CAAC;KACH;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,IAAU,EAAE,OAAO;IACnD,MAAM,WAAW,GAAG,IAAA,uBAAY,EAAC,IAAI,CAAC,CAAC;IACvC,IAAI,WAAW,EAAE;QACf,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;KAC/D;IAED,IAAA,uBAAY,EAAC,IAAI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mB,CAC3B,4HAA4H,CAC7H,CAAC;SACH;QAED,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7D,YAAY,GAAG,IAAI,CAAC;KACrB;IACD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;QACvB,MAAM,CAAC,WAAW,GAAG,EAAE,CAAC;QACxB,YAAY,GAAG,IAAI,CAAC;KACrB;IAED,IAAI,YAAY,EAAE;QAChB,IAAA,wBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;KAC5B;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;gBACzD,mBAAmB,CAAC,IAAI,CAAC,CAAC;gBAC1B,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;aAClC;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;AAnBD,4BAmBC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/keys-manager/schema.ts"],"names":[],"mappings":""}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema",
|
|
3
|
-
"$id": "transloco-keys-manager",
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
const ngx_translate_migration_1 = require("./ngx-translate-migration");
|
|
6
|
-
function default_1(options) {
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
return (tree) => {
|
|
9
|
-
if (!options.path) {
|
|
10
|
-
throw new schematics_1.SchematicsException(`
|
|
11
|
-
Please specify the root source of your project.
|
|
12
|
-
(e.g. --path ./src/app)
|
|
13
|
-
`);
|
|
14
|
-
}
|
|
15
|
-
return options.from === 'Angular'
|
|
16
|
-
? (0, schematics_1.schematic)('ng-migrate', options)
|
|
17
|
-
: (0, rxjs_1.from)((0, ngx_translate_migration_1.run)(options.path)).pipe((0, rxjs_1.map)(() => tree));
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
exports.default = default_1;
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/migrate/index.ts"],"names":[],"mappings":";;AAAA,2DAIoC;AACpC,+BAAiC;AAEjC,uEAAgD;AAGhD,mBAAyB,OAAsB;IAC7C,aAAa;IACb,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;YACjB,MAAM,IAAI,gCAAmB,CAAC;;;OAG7B,CAAC,CAAC;SACJ;QAED,OAAO,OAAO,CAAC,IAAI,KAAK,SAAS;YAC/B,CAAC,CAAC,IAAA,sBAAS,EAAC,YAAY,EAAE,OAAO,CAAC;YAClC,CAAC,CAAC,IAAA,WAAI,EAAC,IAAA,6BAAG,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAA,UAAG,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC;AAdD,4BAcC"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.run = exports.PIPE_IN_BINDING_REGEX = exports.PIPE_REGEX = void 0;
|
|
4
|
-
const p = require("node:path");
|
|
5
|
-
const ora = require("ora");
|
|
6
|
-
const replace_in_file_1 = require("replace-in-file");
|
|
7
|
-
const PIPE_CONTENT_REGEX = `\\s*([^}\\r\\n]*?\\|)\\s*(translate)[^\\r\\n]*?`;
|
|
8
|
-
exports.PIPE_REGEX = `{{${PIPE_CONTENT_REGEX}}}`;
|
|
9
|
-
exports.PIPE_IN_BINDING_REGEX = `\\]=('|")${PIPE_CONTENT_REGEX}\\1`;
|
|
10
|
-
// Example: `./src/ng2/**/*.html`;
|
|
11
|
-
function run(path) {
|
|
12
|
-
console.log('\x1b[4m%s\x1b[0m', '\nStarting migration script');
|
|
13
|
-
const dir = p.resolve(process.cwd());
|
|
14
|
-
path = p.join(dir, path, '/**/*');
|
|
15
|
-
const noSpecFiles = { ignore: `${path}spec.ts`, files: `${path}.ts` };
|
|
16
|
-
const [directive, pipe, pipeInBinding] = [
|
|
17
|
-
/(translate|\[translate(?:Params)?\])=("|')[^"']*\2/gm,
|
|
18
|
-
new RegExp(exports.PIPE_REGEX, 'gm'),
|
|
19
|
-
new RegExp(exports.PIPE_IN_BINDING_REGEX, 'gm'),
|
|
20
|
-
].map((regex) => ({
|
|
21
|
-
files: `${path}.html`,
|
|
22
|
-
from: regex,
|
|
23
|
-
to: (match) => match.replace(/translate/g, 'transloco'),
|
|
24
|
-
}));
|
|
25
|
-
const moduleMultiImport = {
|
|
26
|
-
files: `${path}.ts`,
|
|
27
|
-
from: /import\s*{((([^,}]*,)+\s*(TranslateModule)\s*(,[^}]*)*)|(([^,{}]*,)*\s*(TranslateModule)\s*,\s*[a-zA-Z0-9]+(,[^}]*)*))\s*}\s*from\s*('|").?ngx-translate(\/[^'"]+)?('|");?/g,
|
|
28
|
-
to: (match) => match
|
|
29
|
-
.replace('TranslateModule', '')
|
|
30
|
-
.replace(/,\s*,/, ',')
|
|
31
|
-
.replace(/{\s*,/, '{')
|
|
32
|
-
.replace(/,\s*}/, '}')
|
|
33
|
-
.concat(`\nimport { TranslocoModule } from '@jsverse/transloco';`),
|
|
34
|
-
};
|
|
35
|
-
const moduleSingleImport = {
|
|
36
|
-
files: `${path}.ts`,
|
|
37
|
-
from: /import\s*{\s*(TranslateModule),?\s*}\s*from\s*('|").?ngx-translate(\/[^'"]+)?('|");?/g,
|
|
38
|
-
to: `import { TranslocoModule } from '@jsverse/transloco';`,
|
|
39
|
-
};
|
|
40
|
-
const modules = {
|
|
41
|
-
files: `${path}.ts`,
|
|
42
|
-
from: /(?<![a-zA-Z])TranslateModule(?![^]*from)(\.(forRoot|forChild)\(({[^}]*})*[^)]*\))?/g,
|
|
43
|
-
to: 'TranslocoModule',
|
|
44
|
-
};
|
|
45
|
-
const serviceMultiImport = {
|
|
46
|
-
files: `${path}.ts`,
|
|
47
|
-
from: /import\s*{((([^,}]*,)+\s*(TranslateService)\s*(,[^}]*)*)|(([^,{}]*,)*\s*(TranslateService)\s*,\s*[a-zA-Z0-9]+(,[^}]*)*))\s*}\s*from\s*('|").?ngx-translate(\/[^'"]+)?('|");?/g,
|
|
48
|
-
to: (match) => match
|
|
49
|
-
.replace('TranslateService', '')
|
|
50
|
-
.replace(/,\s*,/, ',')
|
|
51
|
-
.replace(/{\s*,/, '{')
|
|
52
|
-
.replace(/,\s*}/, '}')
|
|
53
|
-
.concat(`\nimport { TranslocoService } from '@jsverse/transloco';`),
|
|
54
|
-
};
|
|
55
|
-
const [serviceSingleImport, pipeImport] = [
|
|
56
|
-
/import\s*{\s*(TranslateService),?\s*}\s*from\s*('|").?ngx-translate(\/[^'"]+)?('|");?/g,
|
|
57
|
-
/import\s*{\s*(TranslatePipe),?\s*}\s*from\s*('|")[^'"]+('|");?/g,
|
|
58
|
-
].map((regex) => ({
|
|
59
|
-
...noSpecFiles,
|
|
60
|
-
from: regex,
|
|
61
|
-
to: `import { TranslocoService } from '@jsverse/transloco';`,
|
|
62
|
-
}));
|
|
63
|
-
const constructorInjection = {
|
|
64
|
-
...noSpecFiles,
|
|
65
|
-
from: /(?:private|protected|public)\s+(.*?)\s*:\s*(?:TranslateService|TranslatePipe\s*(?:,|\)))/g,
|
|
66
|
-
to: (match) => match.replace(/TranslateService|TranslatePipe/g, 'TranslocoService'),
|
|
67
|
-
};
|
|
68
|
-
const serviceUsage = {
|
|
69
|
-
...noSpecFiles,
|
|
70
|
-
from: /(?=([^]+(?:private|protected|public)\s+([^,:()]+)\s*:\s*(?:TranslocoService\s*(?:,|\)))))\1[^]*/gm,
|
|
71
|
-
to: (match, _, serviceName) => {
|
|
72
|
-
const sanitizedName = serviceName
|
|
73
|
-
.split('')
|
|
74
|
-
.map((char) => (['$', '^'].includes(char) ? `\\${char}` : char))
|
|
75
|
-
.join('');
|
|
76
|
-
const functionsMap = {
|
|
77
|
-
instant: 'translate',
|
|
78
|
-
transform: 'translate',
|
|
79
|
-
get: 'selectTranslate',
|
|
80
|
-
stream: 'selectTranslate',
|
|
81
|
-
use: 'setActiveLang',
|
|
82
|
-
set: 'setTranslation',
|
|
83
|
-
};
|
|
84
|
-
const propsMap = {
|
|
85
|
-
currentLang: 'getActiveLang()',
|
|
86
|
-
onLangChange: 'langChanges$',
|
|
87
|
-
};
|
|
88
|
-
const serviceCallRgx = ({ map, func }) => new RegExp(`(?:(?:\\s*|this\\.)${sanitizedName})(?:\\s*\\t*\\r*\\n*)*\\.(?:\\s*\\t*\\r*\\n*)*(${getTarget(map)})[\\r\\t\\n\\s]*${func ? '\\(' : '(?!\\()'}`, 'g');
|
|
89
|
-
const getTarget = (t) => Object.keys(t).join('|');
|
|
90
|
-
return [
|
|
91
|
-
{ func: true, map: functionsMap },
|
|
92
|
-
{ func: false, map: propsMap },
|
|
93
|
-
].reduce((acc, curr) => {
|
|
94
|
-
return acc.replace(serviceCallRgx(curr), (str) => str.replace(new RegExp(getTarget(curr.map)), (func) => curr.map[func]));
|
|
95
|
-
}, match);
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
const specs = {
|
|
99
|
-
files: `${path}spec.ts`,
|
|
100
|
-
from: /TranslateService|TranslatePipe/g,
|
|
101
|
-
to: 'TranslocoService',
|
|
102
|
-
};
|
|
103
|
-
const htmlReplacements = [
|
|
104
|
-
{
|
|
105
|
-
matchers: [directive],
|
|
106
|
-
step: 'directives',
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
matchers: [pipe, pipeInBinding],
|
|
110
|
-
step: 'pipes',
|
|
111
|
-
},
|
|
112
|
-
];
|
|
113
|
-
const tsReplacements = [
|
|
114
|
-
{
|
|
115
|
-
matchers: [modules, moduleMultiImport, moduleSingleImport],
|
|
116
|
-
step: 'modules',
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
matchers: [serviceMultiImport, serviceSingleImport, pipeImport],
|
|
120
|
-
step: 'service imports',
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
matchers: [constructorInjection],
|
|
124
|
-
step: 'constructor injections',
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
matchers: [serviceUsage],
|
|
128
|
-
step: 'service usage',
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
matchers: [specs],
|
|
132
|
-
step: 'specs',
|
|
133
|
-
},
|
|
134
|
-
];
|
|
135
|
-
async function migrate(matchersArr, filesType) {
|
|
136
|
-
console.log(`\nMigrating ${filesType} files 📜`);
|
|
137
|
-
let spinner;
|
|
138
|
-
for (let i = 0; i < matchersArr.length; i++) {
|
|
139
|
-
const { step, matchers } = matchersArr[i];
|
|
140
|
-
const msg = `Step ${i + 1}/${matchersArr.length}: Migrating ${step}`;
|
|
141
|
-
spinner = ora().start(msg);
|
|
142
|
-
const noFilesFound = [];
|
|
143
|
-
for (const matcher of matchers) {
|
|
144
|
-
try {
|
|
145
|
-
await (0, replace_in_file_1.replaceInFile)(matcher);
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
if (e.message.includes('No files match the pattern')) {
|
|
149
|
-
noFilesFound.push(e.message);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
throw e;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
spinner.succeed(msg);
|
|
157
|
-
noFilesFound.forEach((pattern) => console.log('\x1b[33m%s\x1b[0m', `⚠️ ${pattern}`));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return migrate(htmlReplacements, 'HTML')
|
|
161
|
-
.then(() => migrate(tsReplacements, 'TS'))
|
|
162
|
-
.then(() => {
|
|
163
|
-
console.log('\n 🌵 Done! 🌵');
|
|
164
|
-
console.log('Welcome to a better translation experience 🌐');
|
|
165
|
-
console.log('\nFor more information about this script please visit 👉 https://jsverse.github.io/transloco/docs/migration/ngx\n');
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
exports.run = run;
|
|
169
|
-
//# sourceMappingURL=ngx-translate-migration.js.map
|