@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,43 @@
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
+ }
@@ -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,97 @@
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
@@ -0,0 +1 @@
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,EAAE,WAAW,CAAC,CAAC;AAClC,CAAC;AAVD,8CAUC;AAED,SAAgB,mBAAmB,CAAC,IAAU;IAC5C,MAAM,aAAa,GAAG;;;;;CAKvB,CAAC;IACA,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC;AACtD,CAAC;AARD,kDAQC;AAED,SAAS,sBAAsB,CAA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;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"}
@@ -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,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/keys-manager/schema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
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
+ }
@@ -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,21 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
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 declare function run(path: any): Promise<void>;
@@ -0,0 +1,169 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngx-translate-migration.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/migrate/ngx-translate-migration.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAE/B,2BAA2B;AAC3B,qDAAgD;AAEhD,MAAM,kBAAkB,GAAG,iDAAiD,CAAC;AAChE,QAAA,UAAU,GAAG,KAAK,kBAAkB,IAAI,CAAC;AACzC,QAAA,qBAAqB,GAAG,YAAY,kBAAkB,KAAK,CAAC;AAEzE,kCAAkC;AAClC,SAAgB,GAAG,CAAC,IAAI;IACtB,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAErC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,SAAS,EAAE,KAAK,EAAE,GAAG,IAAI,KAAK,EAAE,CAAC;IACtE,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC,GAAG;QACvC,sDAAsD;QACtD,IAAI,MAAM,CAAC,kBAAU,EAAE,IAAI,CAAC;QAC5B,IAAI,MAAM,CAAC,6BAAqB,EAAE,IAAI,CAAC;KACxC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAChB,KAAK,EAAE,GAAG,IAAI,OAAO;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C;SACH;IACH,CAAC;IAED,OAAO,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC;SACrC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;SACzC,IAAI,CAAC,GAAG,EAAE;QACT,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;QAC7D,OAAO,CAAC,GAAG,CACT,mHAAmH,CACpH,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC;AAtLD,kBAsLC"}
@@ -0,0 +1,10 @@
1
+ export interface SchemaOptions {
2
+ /**
3
+ * The path to the source root directory.
4
+ */
5
+ path: string;
6
+ /**
7
+ * Where is the migration from.
8
+ */
9
+ from: 'Angular' | 'NgxTranslate';
10
+ }
@@ -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/migrate/schema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "transloco-migrate",
4
+ "title": "Run a migration script from @ngx-translate.",
5
+ "type": "object",
6
+ "properties": {
7
+ "from": {
8
+ "description": "Where is the migration from",
9
+ "x-prompt": "✍ Which library did you use?",
10
+ "enum": ["NgxTranslate", "Angular"],
11
+ "default": "NgxTranslate",
12
+ "type": "string"
13
+ },
14
+ "path": {
15
+ "description": "The path to the source root directory.",
16
+ "x-prompt": "✍ Which folder will contain the translation files?",
17
+ "type": "string",
18
+ "default": "./src/app",
19
+ "alias": "p"
20
+ }
21
+ },
22
+ "required": []
23
+ }
@@ -0,0 +1,12 @@
1
+ import { inject, Injectable } from "@angular/core";
2
+ import { Translation, TranslocoLoader } from "@jsverse/transloco";
3
+ import { HttpClient } from "@angular/common/http";
4
+
5
+ @Injectable({ providedIn: 'root' })
6
+ export class TranslocoHttpLoader implements TranslocoLoader {
7
+ private http = inject(HttpClient);
8
+
9
+ getTranslation(lang: string) {
10
+ return this.http.get<Translation>(`<%= loaderPrefix %>/assets/i18n/${lang}.json`);
11
+ }
12
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ provideTransloco,
3
+ TranslocoModule
4
+ } from '@jsverse/transloco';
5
+ import { <% if (!importEnv) {%>isDevMode, <% } %>NgModule } from '@angular/core';
6
+ import { TranslocoHttpLoader } from './transloco-loader';
7
+ <% if (importEnv) {%>import { environment } from '<%= envPath %>';<% } %>
8
+
9
+ @NgModule({
10
+ exports: [ TranslocoModule ],
11
+ providers: [
12
+ provideTransloco({
13
+ config: {
14
+ availableLangs: [<%=stringifyList(langs)%>],
15
+ defaultLang: '<%=langs[0]%>',
16
+ // Remove this option if your application doesn't support changing language in runtime.
17
+ reRenderOnLangChange: true,
18
+ prodMode: <%=prodMode%>,
19
+ },
20
+ loader: TranslocoHttpLoader
21
+ }),
22
+ ],
23
+ })
24
+ export class TranslocoRootModule {}
@@ -0,0 +1,4 @@
1
+ export declare function createLoaderFile({ ssr, loaderPath }: {
2
+ ssr: any;
3
+ loaderPath: any;
4
+ }): import("@angular-devkit/schematics").Source;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLoaderFile = void 0;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ function createLoaderFile({ ssr, loaderPath }) {
6
+ return (0, schematics_1.apply)((0, schematics_1.url)(`./files/transloco-loader`), [
7
+ (0, schematics_1.template)({
8
+ ts: 'ts',
9
+ loaderPrefix: ssr ? '${environment.baseUrl}' : '',
10
+ }),
11
+ (0, schematics_1.move)('/', loaderPath),
12
+ ]);
13
+ }
14
+ exports.createLoaderFile = createLoaderFile;
15
+ //# sourceMappingURL=http-loader.gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-loader.gen.js","sourceRoot":"","sources":["../../../../../../../libs/transloco-schematics/src/ng-add/generators/http-loader.gen.ts"],"names":[],"mappings":";;;AAAA,2DAAwE;AAExE,SAAgB,gBAAgB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE;IAClD,OAAO,IAAA,kBAAK,EAAC,IAAA,gBAAG,EAAC,0BAA0B,CAAC,EAAE;QAC5C,IAAA,qBAAQ,EAAC;YACP,EAAE,EAAE,IAAI;YACR,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE;SAClD,CAAC;QACF,IAAA,iBAAI,EAAC,GAAG,EAAE,UAAU,CAAC;KACtB,CAAC,CAAC;AACL,CAAC;AARD,4CAQC"}
@@ -0,0 +1,9 @@
1
+ import { Source, Tree } from '@angular-devkit/schematics';
2
+ export declare function createTranslocoModule({ isLib, ssr, langs, modulePath, sourceRoot, host, }: {
3
+ isLib: boolean;
4
+ ssr: boolean;
5
+ langs: string[];
6
+ modulePath: string;
7
+ sourceRoot: string;
8
+ host: Tree;
9
+ }): Source;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTranslocoModule = void 0;
4
+ const path = require("node:path");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ const array_1 = require("../../utils/array");
7
+ function createTranslocoModule({ isLib, ssr, langs, modulePath, sourceRoot, host, }) {
8
+ const envPath = path
9
+ .relative(modulePath, `${sourceRoot}/environments/environment`)
10
+ .split(path.sep)
11
+ .join('/');
12
+ const envFileExists = host.exists(`${sourceRoot}/environments/environment.ts`);
13
+ let prodMode = envFileExists ? 'environment.production' : '!isDevMode()';
14
+ if (isLib) {
15
+ prodMode = 'false';
16
+ }
17
+ return (0, schematics_1.apply)((0, schematics_1.url)(`./files/transloco-module`), [
18
+ (0, schematics_1.template)({
19
+ ts: 'ts',
20
+ stringifyList: array_1.stringifyList,
21
+ isLib,
22
+ langs,
23
+ importEnv: ssr || envFileExists,
24
+ envPath,
25
+ prodMode,
26
+ }),
27
+ (0, schematics_1.move)('/', modulePath),
28
+ ]);
29
+ }
30
+ exports.createTranslocoModule = createTranslocoModule;
31
+ //# sourceMappingURL=root-module.gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-module.gen.js","sourceRoot":"","sources":["../../../../../../../libs/transloco-schematics/src/ng-add/generators/root-module.gen.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAElC,2DAOoC;AAEpC,6CAAkD;AAElD,SAAgB,qBAAqB,CAAC,EACpC,KAAK,EACL,GAAG,EACH,KAAK,EACL,UAAU,EACV,UAAU,EACV,IAAI,GAQL;IACC,MAAM,OAAO,GAAG,IAAI;SACjB,QAAQ,CAAC,UAAU,EAAE,GAAG,UAAU,2BAA2B,CAAC;SAC9D,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;SACf,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAC/B,GAAG,UAAU,8BAA8B,CAC5C,CAAC;IACF,IAAI,QAAQ,GAAG,aAAa,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,cAAc,CAAC;IAEzE,IAAI,KAAK,EAAE;QACT,QAAQ,GAAG,OAAO,CAAC;KACpB;IAED,OAAO,IAAA,kBAAK,EAAC,IAAA,gBAAG,EAAC,0BAA0B,CAAC,EAAE;QAC5C,IAAA,qBAAQ,EAAC;YACP,EAAE,EAAE,IAAI;YACR,aAAa,EAAb,qBAAa;YACb,KAAK;YACL,KAAK;YACL,SAAS,EAAE,GAAG,IAAI,aAAa;YAC/B,OAAO;YACP,QAAQ;SACT,CAAC;QACF,IAAA,iBAAI,EAAC,GAAG,EAAE,UAAU,CAAC;KACtB,CAAC,CAAC;AACL,CAAC;AAxCD,sDAwCC"}
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@angular-devkit/schematics';
2
+ export declare function typescriptTranslationFileCreator(source: Tree, lang: string): void;
3
+ export declare function jsonTranslationFileCreator(source: Tree, lang: string): void;
4
+ export declare function createTranslateFiles(langs: string[], creator: (source: Tree, lang: string) => void, path: any): import("@angular-devkit/schematics").Source;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTranslateFiles = exports.jsonTranslationFileCreator = exports.typescriptTranslationFileCreator = void 0;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ function typescriptTranslationFileCreator(source, lang) {
6
+ source.create(`${lang}.ts`, `export default {};
7
+ `);
8
+ }
9
+ exports.typescriptTranslationFileCreator = typescriptTranslationFileCreator;
10
+ function jsonTranslationFileCreator(source, lang) {
11
+ source.create(`${lang}.json`, `{}
12
+ `);
13
+ }
14
+ exports.jsonTranslationFileCreator = jsonTranslationFileCreator;
15
+ function createTranslateFiles(langs, creator, path) {
16
+ const treeSource = new schematics_1.EmptyTree();
17
+ langs.forEach((lang) => {
18
+ creator(treeSource, lang);
19
+ });
20
+ return (0, schematics_1.apply)((0, schematics_1.source)(treeSource), [(0, schematics_1.move)('/', path)]);
21
+ }
22
+ exports.createTranslateFiles = createTranslateFiles;
23
+ //# sourceMappingURL=translation-files.gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translation-files.gen.js","sourceRoot":"","sources":["../../../../../../../libs/transloco-schematics/src/ng-add/generators/translation-files.gen.ts"],"names":[],"mappings":";;;AAAA,2DAMoC;AAEpC,SAAgB,gCAAgC,CAAC,MAAY,EAAE,IAAY;IACzE,MAAM,CAAC,MAAM,CACX,GAAG,IAAI,KAAK,EACZ;CACH,CACE,CAAC;AACJ,CAAC;AAND,4EAMC;AAED,SAAgB,0BAA0B,CAAC,MAAY,EAAE,IAAY;IACnE,MAAM,CAAC,MAAM,CACX,GAAG,IAAI,OAAO,EACd;CACH,CACE,CAAC;AACJ,CAAC;AAND,gEAMC;AAED,SAAgB,oBAAoB,CAClC,KAAe,EACf,OAA6C,EAC7C,IAAI;IAEJ,MAAM,UAAU,GAAG,IAAI,sBAAS,EAAE,CAAC;IACnC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,OAAO,IAAA,kBAAK,EAAC,IAAA,mBAAM,EAAC,UAAU,CAAC,EAAE,CAAC,IAAA,iBAAI,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAXD,oDAWC"}
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { SchemaOptions } from './schema';
3
+ export default function (options: SchemaOptions): Rule;