@jsverse/transloco 7.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.
Files changed (167) hide show
  1. package/CHANGELOG.md +1005 -0
  2. package/LICENSE +22 -0
  3. package/README.md +44 -0
  4. package/esm2022/index.mjs +20 -0
  5. package/esm2022/jsverse-transloco.mjs +5 -0
  6. package/esm2022/lib/browser-lang.mjs +28 -0
  7. package/esm2022/lib/get-fallbacks-loaders.mjs +13 -0
  8. package/esm2022/lib/helpers.mjs +104 -0
  9. package/esm2022/lib/lang-resolver.mjs +54 -0
  10. package/esm2022/lib/loader-component.component.mjs +21 -0
  11. package/esm2022/lib/resolve-loader.mjs +13 -0
  12. package/esm2022/lib/scope-resolver.mjs +24 -0
  13. package/esm2022/lib/shared.mjs +73 -0
  14. package/esm2022/lib/template-handler.mjs +28 -0
  15. package/esm2022/lib/transloco-fallback-strategy.mjs +26 -0
  16. package/esm2022/lib/transloco-lang.mjs +3 -0
  17. package/esm2022/lib/transloco-loading-template.mjs +3 -0
  18. package/esm2022/lib/transloco-missing-handler.mjs +18 -0
  19. package/esm2022/lib/transloco-scope.mjs +3 -0
  20. package/esm2022/lib/transloco-testing.module.mjs +76 -0
  21. package/esm2022/lib/transloco.config.mjs +37 -0
  22. package/esm2022/lib/transloco.directive.mjs +169 -0
  23. package/esm2022/lib/transloco.interceptor.mjs +17 -0
  24. package/esm2022/lib/transloco.loader.mjs +13 -0
  25. package/esm2022/lib/transloco.module.mjs +18 -0
  26. package/esm2022/lib/transloco.pipe.mjs +97 -0
  27. package/esm2022/lib/transloco.providers.mjs +92 -0
  28. package/esm2022/lib/transloco.service.mjs +579 -0
  29. package/esm2022/lib/transloco.transpiler.mjs +145 -0
  30. package/esm2022/lib/types.mjs +2 -0
  31. package/fesm2022/jsverse-transloco.mjs +1580 -0
  32. package/fesm2022/jsverse-transloco.mjs.map +1 -0
  33. package/index.d.ts +19 -0
  34. package/lib/browser-lang.d.ts +8 -0
  35. package/lib/get-fallbacks-loaders.d.ts +14 -0
  36. package/lib/helpers.d.ts +21 -0
  37. package/lib/lang-resolver.d.ts +32 -0
  38. package/lib/loader-component.component.d.ts +6 -0
  39. package/lib/resolve-loader.d.ts +10 -0
  40. package/lib/scope-resolver.d.ts +12 -0
  41. package/lib/shared.d.ts +17 -0
  42. package/lib/template-handler.d.ts +9 -0
  43. package/lib/transloco-fallback-strategy.d.ts +14 -0
  44. package/lib/transloco-lang.d.ts +2 -0
  45. package/lib/transloco-loading-template.d.ts +3 -0
  46. package/lib/transloco-missing-handler.d.ts +16 -0
  47. package/lib/transloco-scope.d.ts +3 -0
  48. package/lib/transloco-testing.module.d.ts +27 -0
  49. package/lib/transloco.config.d.ts +27 -0
  50. package/lib/transloco.directive.d.ts +50 -0
  51. package/lib/transloco.interceptor.d.ts +14 -0
  52. package/lib/transloco.loader.d.ts +15 -0
  53. package/lib/transloco.module.d.ts +8 -0
  54. package/lib/transloco.pipe.d.ts +23 -0
  55. package/lib/transloco.providers.d.ts +30 -0
  56. package/lib/transloco.service.d.ts +199 -0
  57. package/lib/transloco.transpiler.d.ts +58 -0
  58. package/lib/types.d.ts +45 -0
  59. package/package.json +54 -0
  60. package/schematics/src/assets/i18n/en.json +1 -0
  61. package/schematics/src/collection.json +59 -0
  62. package/schematics/src/component/index.d.ts +2 -0
  63. package/schematics/src/component/index.js +21 -0
  64. package/schematics/src/component/index.js.map +1 -0
  65. package/schematics/src/join/index.d.ts +3 -0
  66. package/schematics/src/join/index.js +79 -0
  67. package/schematics/src/join/index.js.map +1 -0
  68. package/schematics/src/join/schema.d.ts +28 -0
  69. package/schematics/src/join/schema.js +3 -0
  70. package/schematics/src/join/schema.js.map +1 -0
  71. package/schematics/src/join/schema.json +43 -0
  72. package/schematics/src/keys-manager/index.d.ts +5 -0
  73. package/schematics/src/keys-manager/index.js +97 -0
  74. package/schematics/src/keys-manager/index.js.map +1 -0
  75. package/schematics/src/keys-manager/schema.d.ts +19 -0
  76. package/schematics/src/keys-manager/schema.js +3 -0
  77. package/schematics/src/keys-manager/schema.js.map +1 -0
  78. package/schematics/src/keys-manager/schema.json +33 -0
  79. package/schematics/src/migrate/index.d.ts +3 -0
  80. package/schematics/src/migrate/index.js +21 -0
  81. package/schematics/src/migrate/index.js.map +1 -0
  82. package/schematics/src/migrate/ngx-translate-migration.d.ts +3 -0
  83. package/schematics/src/migrate/ngx-translate-migration.js +169 -0
  84. package/schematics/src/migrate/ngx-translate-migration.js.map +1 -0
  85. package/schematics/src/migrate/schema.d.ts +10 -0
  86. package/schematics/src/migrate/schema.js +3 -0
  87. package/schematics/src/migrate/schema.js.map +1 -0
  88. package/schematics/src/migrate/schema.json +23 -0
  89. package/schematics/src/ng-add/files/transloco-loader/transloco-loader.__ts__ +12 -0
  90. package/schematics/src/ng-add/files/transloco-module/transloco-root.module.__ts__ +24 -0
  91. package/schematics/src/ng-add/generators/http-loader.gen.d.ts +4 -0
  92. package/schematics/src/ng-add/generators/http-loader.gen.js +15 -0
  93. package/schematics/src/ng-add/generators/http-loader.gen.js.map +1 -0
  94. package/schematics/src/ng-add/generators/root-module.gen.d.ts +9 -0
  95. package/schematics/src/ng-add/generators/root-module.gen.js +31 -0
  96. package/schematics/src/ng-add/generators/root-module.gen.js.map +1 -0
  97. package/schematics/src/ng-add/generators/translation-files.gen.d.ts +4 -0
  98. package/schematics/src/ng-add/generators/translation-files.gen.js +23 -0
  99. package/schematics/src/ng-add/generators/translation-files.gen.js.map +1 -0
  100. package/schematics/src/ng-add/index.d.ts +3 -0
  101. package/schematics/src/ng-add/index.js +103 -0
  102. package/schematics/src/ng-add/index.js.map +1 -0
  103. package/schematics/src/ng-add/schema.d.ts +42 -0
  104. package/schematics/src/ng-add/schema.js +14 -0
  105. package/schematics/src/ng-add/schema.js.map +1 -0
  106. package/schematics/src/ng-add/schema.json +53 -0
  107. package/schematics/src/ng-migrate/index.d.ts +3 -0
  108. package/schematics/src/ng-migrate/index.js +14 -0
  109. package/schematics/src/ng-migrate/index.js.map +1 -0
  110. package/schematics/src/ng-migrate/ng-migrate.d.ts +5 -0
  111. package/schematics/src/ng-migrate/ng-migrate.js +106 -0
  112. package/schematics/src/ng-migrate/ng-migrate.js.map +1 -0
  113. package/schematics/src/ng-migrate/schema.d.ts +14 -0
  114. package/schematics/src/ng-migrate/schema.js +3 -0
  115. package/schematics/src/ng-migrate/schema.js.map +1 -0
  116. package/schematics/src/ng-migrate/schema.json +27 -0
  117. package/schematics/src/schematics.consts.d.ts +4 -0
  118. package/schematics/src/schematics.consts.js +8 -0
  119. package/schematics/src/schematics.consts.js.map +1 -0
  120. package/schematics/src/scope/index.d.ts +3 -0
  121. package/schematics/src/scope/index.js +101 -0
  122. package/schematics/src/scope/index.js.map +1 -0
  123. package/schematics/src/scope/schema.d.ts +28 -0
  124. package/schematics/src/scope/schema.js +3 -0
  125. package/schematics/src/scope/schema.js.map +1 -0
  126. package/schematics/src/scope/schema.json +84 -0
  127. package/schematics/src/split/index.d.ts +3 -0
  128. package/schematics/src/split/index.js +66 -0
  129. package/schematics/src/split/index.js.map +1 -0
  130. package/schematics/src/split/schema.d.ts +20 -0
  131. package/schematics/src/split/schema.js +3 -0
  132. package/schematics/src/split/schema.js.map +1 -0
  133. package/schematics/src/split/schema.json +35 -0
  134. package/schematics/src/types.d.ts +5 -0
  135. package/schematics/src/types.js +10 -0
  136. package/schematics/src/types.js.map +1 -0
  137. package/schematics/src/upgrade/index.d.ts +3 -0
  138. package/schematics/src/upgrade/index.js +19 -0
  139. package/schematics/src/upgrade/index.js.map +1 -0
  140. package/schematics/src/upgrade/schema.d.ts +6 -0
  141. package/schematics/src/upgrade/schema.js +3 -0
  142. package/schematics/src/upgrade/schema.js.map +1 -0
  143. package/schematics/src/upgrade/schema.json +16 -0
  144. package/schematics/src/upgrade/v2.d.ts +1 -0
  145. package/schematics/src/upgrade/v2.js +89 -0
  146. package/schematics/src/upgrade/v2.js.map +1 -0
  147. package/schematics/src/utils/array.d.ts +3 -0
  148. package/schematics/src/utils/array.js +12 -0
  149. package/schematics/src/utils/array.js.map +1 -0
  150. package/schematics/src/utils/config.d.ts +2 -0
  151. package/schematics/src/utils/config.js +13 -0
  152. package/schematics/src/utils/config.js.map +1 -0
  153. package/schematics/src/utils/find-module.d.ts +23 -0
  154. package/schematics/src/utils/find-module.js +110 -0
  155. package/schematics/src/utils/find-module.js.map +1 -0
  156. package/schematics/src/utils/package.d.ts +5 -0
  157. package/schematics/src/utils/package.js +19 -0
  158. package/schematics/src/utils/package.js.map +1 -0
  159. package/schematics/src/utils/projects.d.ts +8 -0
  160. package/schematics/src/utils/projects.js +56 -0
  161. package/schematics/src/utils/projects.js.map +1 -0
  162. package/schematics/src/utils/translations.d.ts +7 -0
  163. package/schematics/src/utils/translations.js +31 -0
  164. package/schematics/src/utils/translations.js.map +1 -0
  165. package/schematics/src/utils/transloco.d.ts +24 -0
  166. package/schematics/src/utils/transloco.js +93 -0
  167. package/schematics/src/utils/transloco.js.map +1 -0
@@ -0,0 +1,84 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "transloco-scope",
4
+ "title": "Add new transloco scope module, along with translation files.",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The scope name.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What scope name would you like?"
15
+ },
16
+ "module": {
17
+ "type": "string",
18
+ "description": "The path at which module to add scope to, relative to the workspace root."
19
+ },
20
+ "inlineLoader": {
21
+ "description": "Should create scope with inline loader.",
22
+ "type": "boolean",
23
+ "alias": "il"
24
+ },
25
+ "langs": {
26
+ "description": "The languages of the project.",
27
+ "type": "string",
28
+ "alias": "la"
29
+ },
30
+ "skipCreation": {
31
+ "type": "boolean",
32
+ "description": "Skip the translation files creation."
33
+ },
34
+ "translationPath": {
35
+ "description": "The to the translation files, relative to the project's root.",
36
+ "type": "string"
37
+ },
38
+ "lintFix": {
39
+ "type": "boolean",
40
+ "default": false,
41
+ "description": "When true, applies lint fixes after generating the module."
42
+ },
43
+
44
+ "path": {
45
+ "type": "string",
46
+ "format": "path",
47
+ "$default": {
48
+ "$source": "workingDirectory"
49
+ },
50
+ "description": "The path at which to create the NgModule, relative to the workspace root.",
51
+ "visible": false
52
+ },
53
+ "project": {
54
+ "type": "string",
55
+ "description": "The name of the project.",
56
+ "$default": {
57
+ "$source": "projectName"
58
+ }
59
+ },
60
+ "routing": {
61
+ "type": "boolean",
62
+ "description": "Create a routing module.",
63
+ "default": false
64
+ },
65
+ "routingScope": {
66
+ "enum": ["Child", "Root"],
67
+ "type": "string",
68
+ "description": "The scope for the new routing module.",
69
+ "default": "Child"
70
+ },
71
+ "flat": {
72
+ "type": "boolean",
73
+ "description": "Create the new files at the top level of the current project root. ",
74
+ "default": false
75
+ },
76
+ "commonModule": {
77
+ "type": "boolean",
78
+ "description": "The new NgModule imports \"CommonModule\". ",
79
+ "default": true,
80
+ "visible": false
81
+ }
82
+ },
83
+ "required": []
84
+ }
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { SchemaOptions } from './schema';
3
+ export default function (options: SchemaOptions): Rule;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("../types");
4
+ const transloco_1 = require("../utils/transloco");
5
+ function reduceTranslations(host, dirPath, translationJson, lang, key = '') {
6
+ const dir = host.getDir(dirPath);
7
+ if (!(0, transloco_1.hasFiles)(dir))
8
+ return translationJson;
9
+ if ((0, transloco_1.hasSubdirs)(dir)) {
10
+ dir.subdirs.forEach((subDirName) => {
11
+ const subDir = dir.dir(subDirName);
12
+ const nestedKeyPath = (0, transloco_1.getTranslationKey)(key, subDirName);
13
+ const nestedKey = nestedKeyPath.split('.').at(-1);
14
+ const subTranslationJson = translationJson[key];
15
+ if (subTranslationJson) {
16
+ reduceTranslations(host, subDir.path, subTranslationJson, lang, nestedKey);
17
+ delete translationJson[key][nestedKey];
18
+ }
19
+ });
20
+ }
21
+ dir.subfiles
22
+ .filter((fileName) => fileName.includes(`${lang}.json`))
23
+ .forEach((fileName) => {
24
+ if (!translationJson[key]) {
25
+ return translationJson;
26
+ }
27
+ (0, transloco_1.setFileContent)(host, dir.path, fileName, translationJson[key]);
28
+ });
29
+ delete translationJson[key];
30
+ return translationJson;
31
+ }
32
+ function parserFactory(format) {
33
+ switch (format) {
34
+ case types_1.TranslationFileFormat.JSON:
35
+ return JSON.parse;
36
+ case types_1.TranslationFileFormat.PO:
37
+ // TODO:
38
+ return JSON.parse;
39
+ case types_1.TranslationFileFormat.XLIFF:
40
+ // TODO:
41
+ return JSON.parse;
42
+ default:
43
+ return JSON.parse;
44
+ }
45
+ }
46
+ function default_1(options) {
47
+ return (host) => {
48
+ const root = (0, transloco_1.getTranslationsRoot)(host, options);
49
+ const parser = parserFactory(options.format);
50
+ const translatedFiles = (0, transloco_1.getTranslationFiles)(host, options.source, parser);
51
+ const translationEntryPaths = (0, transloco_1.getTranslationEntryPaths)(host, root);
52
+ const newTranslation = {};
53
+ for (const { lang, translation } of translatedFiles) {
54
+ newTranslation[lang] = translationEntryPaths.reduce((acc, { scope, path }) => {
55
+ return reduceTranslations(host, path, translation, lang, scope);
56
+ }, translation);
57
+ }
58
+ host.getDir(root).subfiles.forEach((fileName) => {
59
+ const lang = fileName.split('.')[0];
60
+ (0, transloco_1.setFileContent)(host, root, fileName, newTranslation[lang]);
61
+ });
62
+ return host;
63
+ };
64
+ }
65
+ exports.default = default_1;
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/split/index.ts"],"names":[],"mappings":";;AAEA,oCAAiD;AACjD,kDAQ4B;AAM5B,SAAS,kBAAkB,CACzB,IAAU,EACV,OAAe,EACf,eAAe,EACf,IAAY,EACZ,GAAG,GAAG,EAAE;IAER,MAAM,GAAG,GAAG,IAA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AC,CAAC,CAAC,CAAC;YACpC,IAAA,0BAAc,EAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAzBD,4BAyBC"}
@@ -0,0 +1,20 @@
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 translated files format.
10
+ */
11
+ format: TranslationFileFormat;
12
+ /**
13
+ * The source directory that contain the translated files.
14
+ */
15
+ source: string;
16
+ /**
17
+ * The root project name.
18
+ */
19
+ project: string;
20
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/split/schema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "transloco-split",
4
+ "title": "Split translated files between the project's translation files.",
5
+ "type": "object",
6
+ "properties": {
7
+ "translationPath": {
8
+ "type": "string",
9
+ "description": "The folder that contain the root translation files.",
10
+ "default": "src/assets/i18n",
11
+ "alias": "root"
12
+ },
13
+ "source": {
14
+ "type": "string",
15
+ "description": "The path of the source directory that contain the translated files.",
16
+ "default": "dist-i18n",
17
+ "alias": "o"
18
+ },
19
+ "format": {
20
+ "description": "The translated files format.",
21
+ "type": "string",
22
+ "default": "JSON",
23
+ "enum": ["JSON", "xliff", "po"],
24
+ "alias": "f"
25
+ },
26
+ "project": {
27
+ "type": "string",
28
+ "description": "The root project name.",
29
+ "$default": {
30
+ "$source": "projectName"
31
+ }
32
+ }
33
+ },
34
+ "required": []
35
+ }
@@ -0,0 +1,5 @@
1
+ export declare enum TranslationFileFormat {
2
+ JSON = "JSON",
3
+ XLIFF = "xliff",
4
+ PO = "po"
5
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranslationFileFormat = void 0;
4
+ var TranslationFileFormat;
5
+ (function (TranslationFileFormat) {
6
+ TranslationFileFormat["JSON"] = "JSON";
7
+ TranslationFileFormat["XLIFF"] = "xliff";
8
+ TranslationFileFormat["PO"] = "po";
9
+ })(TranslationFileFormat || (exports.TranslationFileFormat = TranslationFileFormat = {}));
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,wCAAe,CAAA;IACf,kCAAS,CAAA;AACX,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC"}
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { SchemaOptions } from './schema';
3
+ export default function (options: SchemaOptions): Rule;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const process_1 = require("process");
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ const v2_1 = require("./v2");
6
+ function default_1(options) {
7
+ return () => {
8
+ if (!options.path) {
9
+ throw new schematics_1.SchematicsException(`
10
+ Please specify the root source of your project.
11
+ (e.g. --path ./src/app)
12
+ `);
13
+ }
14
+ (0, v2_1.run)(options.path);
15
+ (0, process_1.exit)();
16
+ };
17
+ }
18
+ exports.default = default_1;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/upgrade/index.ts"],"names":[],"mappings":";;AAAA,qCAA+B;AAE/B,2DAAuE;AAGvE,6BAA2B;AAE3B,mBAAyB,OAAsB;IAC7C,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;YACjB,MAAM,IAAI,gCAAmB,CAAC;;;OAG7B,CAAC,CAAC;SACJ;QAED,IAAA,QAAG,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,IAAA,cAAI,GAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC;AAZD,4BAYC"}
@@ -0,0 +1,6 @@
1
+ export interface SchemaOptions {
2
+ /**
3
+ * The entry path of the upgrade script.
4
+ */
5
+ path: string;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/upgrade/schema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "transloco-upgrade",
4
+ "title": "Run an upgrade script [Legacy and will be removed in v7]",
5
+ "type": "object",
6
+ "properties": {
7
+ "path": {
8
+ "description": "The entry path of the upgrade script.",
9
+ "x-prompt": "✍ Which folder should be the entry path for the script?",
10
+ "type": "string",
11
+ "default": "./src/app",
12
+ "alias": "p"
13
+ }
14
+ },
15
+ "required": []
16
+ }
@@ -0,0 +1 @@
1
+ export declare function run(path: any): void;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = void 0;
4
+ const p = require("node:path");
5
+ const fs = require("node:fs");
6
+ const glob_1 = require("glob");
7
+ function run(path) {
8
+ console.log('\x1b[4m%s\x1b[0m', '⬆️ Starting v2 upgrade script ⬆️');
9
+ const dir = p.resolve(process.cwd());
10
+ path = p.join(dir, path, '/**/*');
11
+ const htmlFiles = (0, glob_1.sync)(`${path}.html`);
12
+ const templateRegex = /<ng-template[^>]*transloco[^>]*>[^]+?<\/ng-template>/g;
13
+ const structuralRegex = /<([a-zA-Z-]*)[^*>]*\*transloco=('|")\s*let\s+(?<varName>\w*)[^>]*\2>[^]+?<\/\1\s*>/g;
14
+ const coreKeyRegex = (varName) => `(?<rawKey>${varName}(?:(?:\\[('|").+\\1\\])|(?:\\.\\w+))+)(?<param>[\\s\\w|:{}'"$&!?%@#^)(]*)`;
15
+ const bindingKey = (varName) => new RegExp(`("|')\\s*${coreKeyRegex(varName)}\\1`, 'g');
16
+ const templateKey = (varName) => new RegExp(`{{\\s*${coreKeyRegex(varName)}}}`, 'g');
17
+ for (const file of htmlFiles) {
18
+ let str = fs.readFileSync(file).toString('utf8');
19
+ if (!str.includes('transloco'))
20
+ continue;
21
+ [structuralRegex, templateRegex].forEach((rgx, index) => {
22
+ let containerSearch = rgx.exec(str);
23
+ while (containerSearch) {
24
+ const [matchedStr] = containerSearch;
25
+ const { varName } = index === 0
26
+ ? containerSearch.groups
27
+ : matchedStr.match(/let-(?<varName>\w*)/).groups;
28
+ let newStructuralStr = matchedStr;
29
+ let hasMatches;
30
+ [templateKey(varName), bindingKey(varName)].forEach((keyRegex) => {
31
+ let keySearch = keyRegex.exec(matchedStr);
32
+ hasMatches = hasMatches || !!keySearch;
33
+ while (keySearch) {
34
+ const { rawKey, param } = keySearch.groups;
35
+ /** The raw key may contain square braces we need to align it to '.' */
36
+ // eslint-disable-next-line prefer-const
37
+ let [key, ...inner] = rawKey
38
+ .trim()
39
+ .replace(/\[/g, '.')
40
+ .replace(/'|"|\]|\?/g, '')
41
+ .replace(`${varName}.`, '')
42
+ .split('.');
43
+ let callEnd = ')';
44
+ const pipes = (param && param.split('|')) || [];
45
+ const [paramsPipe] = pipes.filter((pipe) => pipe.includes('translocoParams'));
46
+ if (paramsPipe) {
47
+ const paramValue = paramsPipe.substring(paramsPipe.indexOf('{'), paramsPipe.lastIndexOf('}') + 1);
48
+ if (paramValue) {
49
+ callEnd = `, ${paramValue})`;
50
+ }
51
+ }
52
+ if (inner.length) {
53
+ key = `${key}.${inner.join('.')}`;
54
+ }
55
+ newStructuralStr = paramsPipe
56
+ ? newStructuralStr.replace(`${rawKey}${param}`, `${varName}('${key}'${callEnd} ${pipes
57
+ .filter((pipe) => !pipe.includes('translocoParams'))
58
+ .join('|')}`)
59
+ : newStructuralStr.replace(rawKey, `${varName}('${key}'${callEnd}`);
60
+ keySearch = keyRegex.exec(matchedStr);
61
+ }
62
+ });
63
+ if (hasMatches) {
64
+ str = str.replace(matchedStr, newStructuralStr);
65
+ }
66
+ containerSearch = rgx.exec(str);
67
+ }
68
+ });
69
+ fs.writeFileSync(file, str, { encoding: 'utf8' });
70
+ }
71
+ const modules = (0, glob_1.sync)(`${path}.module.ts`);
72
+ for (const file of modules) {
73
+ let str = fs.readFileSync(file).toString('utf8');
74
+ if (!str.includes('@jsverse/transloco'))
75
+ continue;
76
+ /** change listenToLangChange to renderOnce */
77
+ str = str.replace('listenToLangChange', 'reRenderOnLangChange');
78
+ /** Remove scopeStrategy */
79
+ str = str.replace(/\s*scopeStrategy:.*?,/, '');
80
+ /** Add availableLangs */
81
+ if (!str.includes('availableLangs')) {
82
+ str = str.replace(/((\s*)defaultLang:(.*?),)/, (str, g1, g2, g3) => `${g1}${g2}availableLangs: [${g3.trim()}],`);
83
+ }
84
+ fs.writeFileSync(file, str, { encoding: 'utf8' });
85
+ }
86
+ console.log(`Done! Welcome to Transloco v2 😎`);
87
+ }
88
+ exports.run = run;
89
+ //# sourceMappingURL=v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/upgrade/v2.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,8BAA8B;AAE9B,+BAAwC;AAExC,SAAgB,GAAG,CAAC,IAAI;IACtB,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,kCAAkC,CAAC,CA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AAC,oBAAoB,CAAC;YAAE,SAAS;QAClD,8CAA8C;QAC9C,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;QAChE,2BAA2B;QAC3B,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;QAC/C,yBAAyB;QACzB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE;YACnC,GAAG,GAAG,GAAG,CAAC,OAAO,CACf,2BAA2B,EAC3B,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAE,CAAC,IAAI,EAAE,IAAI,CACjE,CAAC;SACH;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;KACnD;IACD,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAClD,CAAC;AAjGD,kBAiGC"}
@@ -0,0 +1,3 @@
1
+ export declare function stringifyList<T>(list: T[], separator?: string): string;
2
+ export declare function coerceArray<T>(value: T | T[]): T[];
3
+ export declare function coerceArray<T>(value: T | readonly T[]): readonly T[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coerceArray = exports.stringifyList = void 0;
4
+ function stringifyList(list, separator = ', ') {
5
+ return list.map((item) => `'${item}'`).join(separator);
6
+ }
7
+ exports.stringifyList = stringifyList;
8
+ function coerceArray(value) {
9
+ return Array.isArray(value) ? value : [value];
10
+ }
11
+ exports.coerceArray = coerceArray;
12
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/utils/array.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa,CAAI,IAAS,EAAE,SAAS,GAAG,IAAI;IAC1D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACzD,CAAC;AAFD,sCAEC;AAID,SAAgB,WAAW,CAAI,KAAc;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAFD,kCAEC"}
@@ -0,0 +1,2 @@
1
+ import { TranslocoGlobalConfig } from '@jsverse/transloco-utils';
2
+ export declare function getConfig(): TranslocoGlobalConfig;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfig = void 0;
4
+ const transloco_utils_1 = require("@jsverse/transloco-utils");
5
+ let config;
6
+ function getConfig() {
7
+ if (config)
8
+ return config;
9
+ config = (0, transloco_utils_1.getGlobalConfig)();
10
+ return config;
11
+ }
12
+ exports.getConfig = getConfig;
13
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/utils/config.ts"],"names":[],"mappings":";;;AAAA,8DAGkC;AAElC,IAAI,MAA6B,CAAC;AAElC,SAAgB,SAAS;IACvB,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,MAAM,GAAG,IAAA,iCAAe,GAAE,CAAC;IAE3B,OAAO,MAAM,CAAC;AAChB,CAAC;AALD,8BAKC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Path } from '@angular-devkit/core';
9
+ import { Tree } from '@angular-devkit/schematics';
10
+ export declare const MODULE_EXT = ".module.ts";
11
+ export declare const ROUTING_MODULE_EXT = "-routing.module.ts";
12
+ /**
13
+ * Find the module referred by a set of options passed to the schematics.
14
+ */
15
+ export declare function findRootModule(host: Tree, module: string, rootPath?: string, skipImport?: boolean): string | undefined;
16
+ /**
17
+ * Find the module referred by a set of options passed to the schematics.
18
+ */
19
+ export declare function findModuleFromOptions(host: Tree, options: any, projectPath: any): Path | undefined;
20
+ /**
21
+ * Function to find the "closest" module to a generated file's path.
22
+ */
23
+ export declare function findModule(host: Tree, generateDir: string, moduleExt?: string, routingModuleExt?: string): Path;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findModule = exports.findModuleFromOptions = exports.findRootModule = exports.ROUTING_MODULE_EXT = exports.MODULE_EXT = void 0;
4
+ /**
5
+ * @license
6
+ * Copyright Google Inc. All Rights Reserved.
7
+ *
8
+ * Use of this source code is governed by an MIT-style license that can be
9
+ * found in the LICENSE file at https://angular.io/license
10
+ */
11
+ const core_1 = require("@angular-devkit/core");
12
+ exports.MODULE_EXT = '.module.ts';
13
+ exports.ROUTING_MODULE_EXT = '-routing.module.ts';
14
+ /**
15
+ * Find the module referred by a set of options passed to the schematics.
16
+ */
17
+ function findRootModule(host, module, rootPath = '', skipImport = false) {
18
+ if (skipImport || !module) {
19
+ return undefined;
20
+ }
21
+ const modulePath = (0, core_1.normalize)(`${rootPath}/${module}`);
22
+ const matchingExt = [
23
+ '',
24
+ '.ts',
25
+ exports.MODULE_EXT,
26
+ `/${module}${exports.MODULE_EXT}`,
27
+ `/${module}.ts`,
28
+ ].find((ext) => host.exists(modulePath + ext));
29
+ if (matchingExt) {
30
+ return (0, core_1.normalize)(modulePath + matchingExt);
31
+ }
32
+ throw new Error(`Specified module path ${modulePath} does not exist`);
33
+ }
34
+ exports.findRootModule = findRootModule;
35
+ /**
36
+ * Find the module referred by a set of options passed to the schematics.
37
+ */
38
+ function findModuleFromOptions(host, options, projectPath) {
39
+ if (Object.prototype.hasOwnProperty.call(options, 'skipImport') &&
40
+ options.skipImport) {
41
+ return undefined;
42
+ }
43
+ const moduleExt = options.moduleExt || exports.MODULE_EXT;
44
+ const routingModuleExt = options.routingModuleExt || exports.ROUTING_MODULE_EXT;
45
+ if (!options.module) {
46
+ const pathToCheck = (projectPath || '') + '/' + options.name;
47
+ const module = findModule(host, pathToCheck, moduleExt, routingModuleExt);
48
+ return module ? (0, core_1.normalize)(module) : null;
49
+ }
50
+ else {
51
+ const modulePath = (0, core_1.normalize)(`/${projectPath}/${options.module}`);
52
+ const componentPath = (0, core_1.normalize)(`/${projectPath}/${options.name}`);
53
+ const moduleBaseName = (0, core_1.normalize)(modulePath).split('/').pop();
54
+ const candidateSet = new Set([(0, core_1.normalize)(projectPath || '/')]);
55
+ for (let dir = modulePath; dir != core_1.NormalizedRoot; dir = (0, core_1.dirname)(dir)) {
56
+ candidateSet.add(dir);
57
+ }
58
+ for (let dir = componentPath; dir != core_1.NormalizedRoot; dir = (0, core_1.dirname)(dir)) {
59
+ candidateSet.add(dir);
60
+ }
61
+ const candidatesDirs = [...candidateSet].sort((a, b) => b.length - a.length);
62
+ for (const c of candidatesDirs) {
63
+ const candidateFiles = [
64
+ '',
65
+ `${moduleBaseName}.ts`,
66
+ `${moduleBaseName}${moduleExt}`,
67
+ ].map((x) => (0, core_1.join)(c, x));
68
+ for (const sc of candidateFiles) {
69
+ if (host.exists(sc)) {
70
+ return (0, core_1.normalize)(sc);
71
+ }
72
+ }
73
+ }
74
+ return null;
75
+ throw new Error(`Specified module '${options.module}' does not exist.\n` +
76
+ `Looked in the following directories:\n ${candidatesDirs.join('\n ')}`);
77
+ }
78
+ }
79
+ exports.findModuleFromOptions = findModuleFromOptions;
80
+ /**
81
+ * Function to find the "closest" module to a generated file's path.
82
+ */
83
+ function findModule(host, generateDir, moduleExt = exports.MODULE_EXT, routingModuleExt = exports.ROUTING_MODULE_EXT) {
84
+ let dir = host.getDir('/' + generateDir);
85
+ let foundRoutingModule = false;
86
+ while (dir) {
87
+ const allMatches = dir.subfiles.filter((p) => p.endsWith(moduleExt));
88
+ const filteredMatches = allMatches.filter((p) => !p.endsWith(routingModuleExt));
89
+ foundRoutingModule =
90
+ foundRoutingModule || allMatches.length !== filteredMatches.length;
91
+ if (filteredMatches.length == 1) {
92
+ return (0, core_1.join)(dir.path, filteredMatches[0]);
93
+ }
94
+ else if (filteredMatches.length > 1) {
95
+ return null;
96
+ throw new Error('More than one module matches. Use skip-import option to skip importing ' +
97
+ 'the component into the closest module.');
98
+ }
99
+ dir = dir.parent;
100
+ }
101
+ const errorMsg = foundRoutingModule
102
+ ? 'Could not find a non Routing NgModule.' +
103
+ `\nModules with suffix '${routingModuleExt}' are strictly reserved for routing.` +
104
+ '\nUse the skip-import option to skip importing in NgModule.'
105
+ : 'Could not find an NgModule. Use the skip-import option to skip importing in NgModule.';
106
+ return null;
107
+ throw new Error(errorMsg);
108
+ }
109
+ exports.findModule = findModule;
110
+ //# sourceMappingURL=find-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-module.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/utils/find-module.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+CAM8B;AAGjB,QAAA,UAAU,GAAG,YAAY,CAAC;AAC1B,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AAEvD;;GAEG;AACH,SAAgB,cAAc,CAC5B,IAAU,EACV,MAAc,EACd,QAAQ,GAAG,EAAE,EACb,UAAU,GAAG,KAAK;IAElB,IAAI,UAAU,IAAI,CAAC,MAAM,EAAE;QACzB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,UAAU,GAAG,IAAA,gBAAS,EAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG;QAClB,EAAE;QACF,KAAK;QACL,kBAAU;QACV,IAAI,MAAM,GAAG,kBAAU,EAAE;QACzB,IAAI,MAAM,KAAK;KAChB,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1,5 @@
1
+ import { Tree } from '@angular-devkit/schematics';
2
+ /**
3
+ * Adds a script to the package.json
4
+ */
5
+ export declare function addScriptToPackageJson(host: Tree, scriptName: string, script: string): Tree;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addScriptToPackageJson = void 0;
4
+ /**
5
+ * Adds a script to the package.json
6
+ */
7
+ function addScriptToPackageJson(host, scriptName, script) {
8
+ const packageFile = host.read('package.json');
9
+ if (packageFile !== null) {
10
+ const sourceText = packageFile.toString('utf-8');
11
+ const json = JSON.parse(sourceText);
12
+ json['scripts'] ??= {};
13
+ json['scripts'][scriptName] = script;
14
+ host.overwrite('package.json', JSON.stringify(json, null, 2));
15
+ }
16
+ return host;
17
+ }
18
+ exports.addScriptToPackageJson = addScriptToPackageJson;
19
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/utils/package.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,SAAgB,sBAAsB,CACpC,IAAU,EACV,UAAkB,EAClB,MAAc;IAEd,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC9C,IAAI,WAAW,KAAK,IAAI,EAAE;QACxB,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;QAErC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;KAC/D;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhBD,wDAgBC"}