@nizza/devkit 0.1.0-alpha.1 → 0.1.0-alpha.11

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 (191) hide show
  1. package/dist/cjs/executors/deploy/helpers.cjs +26 -0
  2. package/dist/cjs/executors/deploy/index.cjs +22 -0
  3. package/dist/cjs/executors/environments/helpers.cjs +62 -0
  4. package/dist/cjs/executors/environments/index.cjs +60 -0
  5. package/dist/cjs/executors/publish/helpers.cjs +51 -0
  6. package/dist/cjs/executors/publish/index.cjs +53 -0
  7. package/dist/cjs/executors/shared/utils.cjs +67 -0
  8. package/dist/cjs/executors/update-executors-file/helpers.cjs +64 -0
  9. package/dist/cjs/executors/update-executors-file/index.cjs +38 -0
  10. package/dist/cjs/executors/vtex-link/constants.cjs +9 -0
  11. package/dist/cjs/executors/vtex-link/helpers.cjs +206 -0
  12. package/dist/cjs/executors/vtex-link/index.cjs +30 -0
  13. package/dist/cjs/index.cjs +56 -0
  14. package/dist/cjs/scripts/changeset-pre-mode.cjs +41 -0
  15. package/dist/cjs/scripts/index.cjs +7 -0
  16. package/dist/cjs/shared/logger.cjs +98 -0
  17. package/dist/cjs/shared/utils.cjs +36 -0
  18. package/dist/cjs/vite-utils/config-builder/configs/app.cjs +13 -0
  19. package/dist/cjs/vite-utils/config-builder/configs/base.cjs +58 -0
  20. package/dist/cjs/vite-utils/config-builder/configs/index.cjs +36 -0
  21. package/dist/cjs/vite-utils/config-builder/configs/lib.cjs +57 -0
  22. package/dist/cjs/vite-utils/config-builder/configs/script.cjs +46 -0
  23. package/dist/cjs/vite-utils/config-builder/main.cjs +42 -0
  24. package/dist/cjs/vite-utils/config-builder/plugins.cjs +93 -0
  25. package/dist/cjs/vite-utils/config-builder/shared/types.cjs +33 -0
  26. package/dist/cjs/vite-utils/config-builder/shared/utils/helpers.cjs +115 -0
  27. package/dist/cjs/vite-utils/config-builder/shared/utils/projectConfig.cjs +114 -0
  28. package/dist/cjs/vite-utils/config-builder/shared/utils/viteCommand.cjs +59 -0
  29. package/dist/{src/vite/plugins/shadow-dom-inject-css/index.js → cjs/vite-utils/plugins/shadow-dom-inject-css/index.cjs} +4 -19
  30. package/dist/{src/vite/plugins/third-party-css-inject/main.js → cjs/vite-utils/plugins/third-party-css-inject/main.cjs} +13 -14
  31. package/dist/{src/vite/plugins/third-party-css-inject/utils.js → cjs/vite-utils/plugins/third-party-css-inject/utils.cjs} +9 -21
  32. package/dist/esm/executors/deploy/helpers.mjs +22 -0
  33. package/dist/esm/executors/deploy/index.mjs +20 -0
  34. package/dist/esm/executors/deploy/schema.json +41 -0
  35. package/dist/esm/executors/environments/helpers.mjs +58 -0
  36. package/dist/esm/executors/environments/index.mjs +58 -0
  37. package/dist/esm/executors/environments/schema.json +9 -0
  38. package/dist/esm/executors/publish/helpers.mjs +48 -0
  39. package/dist/esm/executors/publish/index.mjs +51 -0
  40. package/dist/esm/executors/publish/schema.json +19 -0
  41. package/dist/esm/executors/shared/utils.mjs +62 -0
  42. package/dist/esm/executors/update-executors-file/helpers.mjs +59 -0
  43. package/dist/esm/executors/update-executors-file/index.mjs +36 -0
  44. package/dist/esm/executors/update-executors-file/schema.json +9 -0
  45. package/dist/esm/executors/vtex-link/constants.mjs +5 -0
  46. package/dist/esm/executors/vtex-link/helpers.mjs +192 -0
  47. package/dist/esm/executors/vtex-link/index.mjs +28 -0
  48. package/dist/esm/executors/vtex-link/schema.json +25 -0
  49. package/dist/esm/index.mjs +12 -0
  50. package/dist/esm/scripts/changeset-pre-mode.mjs +39 -0
  51. package/dist/esm/scripts/index.mjs +1 -0
  52. package/dist/{src/logger.js → esm/shared/logger.mjs} +28 -39
  53. package/dist/esm/shared/utils.mjs +33 -0
  54. package/dist/esm/vite-utils/config-builder/configs/app.mjs +11 -0
  55. package/dist/{src/vite/config-builder/configs/base.js → esm/vite-utils/config-builder/configs/base.mjs} +23 -22
  56. package/dist/esm/vite-utils/config-builder/configs/index.mjs +30 -0
  57. package/dist/{src/vite/config-builder/configs/lib.js → esm/vite-utils/config-builder/configs/lib.mjs} +16 -18
  58. package/dist/esm/vite-utils/config-builder/configs/script.mjs +44 -0
  59. package/dist/esm/vite-utils/config-builder/main.mjs +40 -0
  60. package/dist/esm/vite-utils/config-builder/plugins.mjs +87 -0
  61. package/dist/{src/vite/config-builder/shared/types.js → esm/vite-utils/config-builder/shared/types.mjs} +2 -27
  62. package/dist/{src/vite/config-builder/shared/utils/helpers.d.ts → esm/vite-utils/config-builder/shared/utils/helpers.mjs} +33 -24
  63. package/dist/esm/vite-utils/config-builder/shared/utils/projectConfig.mjs +109 -0
  64. package/dist/esm/vite-utils/config-builder/shared/utils/viteCommand.mjs +56 -0
  65. package/dist/esm/vite-utils/plugins/shadow-dom-inject-css/index.mjs +27 -0
  66. package/dist/esm/vite-utils/plugins/third-party-css-inject/main.mjs +45 -0
  67. package/dist/esm/vite-utils/plugins/third-party-css-inject/utils.mjs +97 -0
  68. package/dist/index.d.ts +367 -0
  69. package/executors.json +29 -0
  70. package/package.json +52 -6
  71. package/dist/package.json +0 -13
  72. package/dist/src/executors/deploy/executor.d.ts +0 -11
  73. package/dist/src/executors/deploy/executor.d.ts.map +0 -1
  74. package/dist/src/executors/deploy/executor.js +0 -27
  75. package/dist/src/executors/deploy/helpers.d.ts +0 -4
  76. package/dist/src/executors/deploy/helpers.d.ts.map +0 -1
  77. package/dist/src/executors/deploy/helpers.js +0 -40
  78. package/dist/src/executors/environments/executor.d.ts +0 -16
  79. package/dist/src/executors/environments/executor.d.ts.map +0 -1
  80. package/dist/src/executors/environments/executor.js +0 -59
  81. package/dist/src/executors/environments/helpers.d.ts +0 -21
  82. package/dist/src/executors/environments/helpers.d.ts.map +0 -1
  83. package/dist/src/executors/environments/helpers.js +0 -63
  84. package/dist/src/executors/publish/executor.d.ts +0 -12
  85. package/dist/src/executors/publish/executor.d.ts.map +0 -1
  86. package/dist/src/executors/publish/executor.js +0 -58
  87. package/dist/src/executors/publish/helpers.d.ts +0 -19
  88. package/dist/src/executors/publish/helpers.d.ts.map +0 -1
  89. package/dist/src/executors/publish/helpers.js +0 -52
  90. package/dist/src/executors/shared/index.d.ts +0 -3
  91. package/dist/src/executors/shared/index.d.ts.map +0 -1
  92. package/dist/src/executors/shared/index.js +0 -7
  93. package/dist/src/executors/shared/types.d.ts +0 -4
  94. package/dist/src/executors/shared/types.d.ts.map +0 -1
  95. package/dist/src/executors/shared/types.js +0 -4
  96. package/dist/src/executors/shared/utils.d.ts +0 -34
  97. package/dist/src/executors/shared/utils.d.ts.map +0 -1
  98. package/dist/src/executors/shared/utils.js +0 -74
  99. package/dist/src/executors/update-executors-file/executor.d.ts +0 -12
  100. package/dist/src/executors/update-executors-file/executor.d.ts.map +0 -1
  101. package/dist/src/executors/update-executors-file/executor.js +0 -46
  102. package/dist/src/executors/update-executors-file/helpers.d.ts +0 -24
  103. package/dist/src/executors/update-executors-file/helpers.d.ts.map +0 -1
  104. package/dist/src/executors/update-executors-file/helpers.js +0 -70
  105. package/dist/src/executors/update-executors-file/types.d.ts +0 -14
  106. package/dist/src/executors/update-executors-file/types.d.ts.map +0 -1
  107. package/dist/src/executors/update-executors-file/types.js +0 -4
  108. package/dist/src/executors/vtex-link/constants.d.ts +0 -4
  109. package/dist/src/executors/vtex-link/constants.d.ts.map +0 -1
  110. package/dist/src/executors/vtex-link/constants.js +0 -24
  111. package/dist/src/executors/vtex-link/executor.d.ts +0 -5
  112. package/dist/src/executors/vtex-link/executor.d.ts.map +0 -1
  113. package/dist/src/executors/vtex-link/executor.js +0 -35
  114. package/dist/src/executors/vtex-link/helpers.d.ts +0 -77
  115. package/dist/src/executors/vtex-link/helpers.d.ts.map +0 -1
  116. package/dist/src/executors/vtex-link/helpers.js +0 -187
  117. package/dist/src/executors/vtex-link/types.d.ts +0 -12
  118. package/dist/src/executors/vtex-link/types.d.ts.map +0 -1
  119. package/dist/src/executors/vtex-link/types.js +0 -4
  120. package/dist/src/index.d.ts +0 -2
  121. package/dist/src/index.d.ts.map +0 -1
  122. package/dist/src/index.js +0 -6
  123. package/dist/src/logger.d.ts +0 -34
  124. package/dist/src/logger.d.ts.map +0 -1
  125. package/dist/src/scripts/changeset-pre-mode.d.ts +0 -2
  126. package/dist/src/scripts/changeset-pre-mode.d.ts.map +0 -1
  127. package/dist/src/scripts/changeset-pre-mode.js +0 -41
  128. package/dist/src/shared/index.d.ts +0 -2
  129. package/dist/src/shared/index.d.ts.map +0 -1
  130. package/dist/src/shared/index.js +0 -6
  131. package/dist/src/shared/utils.d.ts +0 -11
  132. package/dist/src/shared/utils.d.ts.map +0 -1
  133. package/dist/src/shared/utils.js +0 -22
  134. package/dist/src/vite/config-builder/configs/app.d.ts +0 -4
  135. package/dist/src/vite/config-builder/configs/app.d.ts.map +0 -1
  136. package/dist/src/vite/config-builder/configs/app.js +0 -19
  137. package/dist/src/vite/config-builder/configs/base.d.ts +0 -4
  138. package/dist/src/vite/config-builder/configs/base.d.ts.map +0 -1
  139. package/dist/src/vite/config-builder/configs/index.d.ts +0 -7
  140. package/dist/src/vite/config-builder/configs/index.d.ts.map +0 -1
  141. package/dist/src/vite/config-builder/configs/index.js +0 -28
  142. package/dist/src/vite/config-builder/configs/lib.d.ts +0 -4
  143. package/dist/src/vite/config-builder/configs/lib.d.ts.map +0 -1
  144. package/dist/src/vite/config-builder/configs/script.d.ts +0 -4
  145. package/dist/src/vite/config-builder/configs/script.d.ts.map +0 -1
  146. package/dist/src/vite/config-builder/configs/script.js +0 -42
  147. package/dist/src/vite/config-builder/index.d.ts +0 -3
  148. package/dist/src/vite/config-builder/index.d.ts.map +0 -1
  149. package/dist/src/vite/config-builder/index.js +0 -7
  150. package/dist/src/vite/config-builder/main.d.ts +0 -10
  151. package/dist/src/vite/config-builder/main.d.ts.map +0 -1
  152. package/dist/src/vite/config-builder/main.js +0 -37
  153. package/dist/src/vite/config-builder/plugins.d.ts +0 -30
  154. package/dist/src/vite/config-builder/plugins.d.ts.map +0 -1
  155. package/dist/src/vite/config-builder/plugins.js +0 -88
  156. package/dist/src/vite/config-builder/shared/index.d.ts +0 -3
  157. package/dist/src/vite/config-builder/shared/index.d.ts.map +0 -1
  158. package/dist/src/vite/config-builder/shared/index.js +0 -7
  159. package/dist/src/vite/config-builder/shared/types.d.ts +0 -155
  160. package/dist/src/vite/config-builder/shared/types.d.ts.map +0 -1
  161. package/dist/src/vite/config-builder/shared/utils/helpers.d.ts.map +0 -1
  162. package/dist/src/vite/config-builder/shared/utils/helpers.js +0 -61
  163. package/dist/src/vite/config-builder/shared/utils/index.d.ts +0 -4
  164. package/dist/src/vite/config-builder/shared/utils/index.d.ts.map +0 -1
  165. package/dist/src/vite/config-builder/shared/utils/index.js +0 -8
  166. package/dist/src/vite/config-builder/shared/utils/projectConfig.d.ts +0 -60
  167. package/dist/src/vite/config-builder/shared/utils/projectConfig.d.ts.map +0 -1
  168. package/dist/src/vite/config-builder/shared/utils/projectConfig.js +0 -85
  169. package/dist/src/vite/config-builder/shared/utils/viteCommand.d.ts +0 -24
  170. package/dist/src/vite/config-builder/shared/utils/viteCommand.d.ts.map +0 -1
  171. package/dist/src/vite/config-builder/shared/utils/viteCommand.js +0 -54
  172. package/dist/src/vite/index.d.ts +0 -3
  173. package/dist/src/vite/index.d.ts.map +0 -1
  174. package/dist/src/vite/index.js +0 -7
  175. package/dist/src/vite/plugins/index.d.ts +0 -3
  176. package/dist/src/vite/plugins/index.d.ts.map +0 -1
  177. package/dist/src/vite/plugins/index.js +0 -7
  178. package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts +0 -8
  179. package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts.map +0 -1
  180. package/dist/src/vite/plugins/third-party-css-inject/index.d.ts +0 -4
  181. package/dist/src/vite/plugins/third-party-css-inject/index.d.ts.map +0 -1
  182. package/dist/src/vite/plugins/third-party-css-inject/index.js +0 -13
  183. package/dist/src/vite/plugins/third-party-css-inject/main.d.ts +0 -17
  184. package/dist/src/vite/plugins/third-party-css-inject/main.d.ts.map +0 -1
  185. package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts +0 -5
  186. package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts.map +0 -1
  187. /package/dist/{src → cjs}/executors/deploy/schema.json +0 -0
  188. /package/dist/{src → cjs}/executors/environments/schema.json +0 -0
  189. /package/dist/{src → cjs}/executors/publish/schema.json +0 -0
  190. /package/dist/{src → cjs}/executors/update-executors-file/schema.json +0 -0
  191. /package/dist/{src → cjs}/executors/vtex-link/schema.json +0 -0
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ var devkit = require('@nx/devkit');
4
+ var path = require('path');
5
+ var R = require('ramda');
6
+ require('../../../../shared/logger.cjs');
7
+ var utils = require('../../../../shared/utils.cjs');
8
+
9
+ function _interopNamespaceDefault(e) {
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
27
+
28
+ /**
29
+ * Deeply merges two objects, combining their properties.
30
+ *
31
+ * @param {Record<string, any>} v1 - The first object.
32
+ * @param {Record<string, any>} v2 - The second object.
33
+ * @returns {Record<string, any>} - The merged object.
34
+ *
35
+ * @example
36
+ * const obj1 = { a: 1, b: { c: 2 } };
37
+ * const obj2 = { b: { d: 3 } };
38
+ * const merged = deepMerge(obj1, obj2); // Outputs: { a: 1, b: { c: 2, d: 3 } }
39
+ */ function deepMerge(v1, v2) {
40
+ if (Array.isArray(v1) && Array.isArray(v2)) {
41
+ return R__namespace.uniq(R__namespace.concat(v1, v2));
42
+ } else if (typeof v1 === 'object' && typeof v2 === 'object' && !R__namespace.isNil(v1) && !R__namespace.isNil(v2)) {
43
+ return R__namespace.mergeWith(deepMerge, v1, v2);
44
+ } else {
45
+ return v2;
46
+ }
47
+ }
48
+ /**
49
+ * Generates a name for js files.
50
+ *
51
+ * @param {string} [prefix] - An optional prefix for the chunk name.
52
+ * @returns - A function that takes an item and generates a chunk name.
53
+ *
54
+ * @example
55
+ * const generateChunkName = chunkName('prefix');
56
+ * const name = generateChunkName({ name: 'example' }); // Outputs: "prefix-example-Aj3_Dk7_2j.js"
57
+ */ const chunkName = (prefix)=>(x)=>{
58
+ const nameWithoutUnderscore = x.name.replace(/_/g, '');
59
+ const pre = prefix ? `${prefix}-` : '';
60
+ return `${pre}${nameWithoutUnderscore}-${utils.shortId(8)}.js`;
61
+ };
62
+ /**
63
+ * Returns the given object if the condition is true, otherwise returns null.
64
+ *
65
+ * @param {any} condition - The condition to evaluate.
66
+ * @param {Record<string, any>} obj - The object to return if the condition is true.
67
+ * @returns {Record<string, any> | null} - The object or null based on the condition.
68
+ *
69
+ * @example
70
+ * const obj = { a: 1 };
71
+ * const result = when(true, obj); // Outputs: { a: 1 }
72
+ * const result2 = when(false, obj); // Outputs: {}
73
+ */ const when = (condition, obj)=>condition ? obj : {};
74
+ /**
75
+ * Filters and generates plugin configurations based on conditions and the provided context.
76
+ *
77
+ * @param {Context} ctx - The main configuration object.
78
+ * @returns {any[]} - An array of generated plugin configurations.
79
+ */ const getPlugins = (ctx, ...pluginConfigs)=>pluginConfigs// Filters the plugins based on conditions
80
+ .filter((p)=>!p.condition || p.condition(ctx))// Generates the configuration of each plugin and flattens the resulting array
81
+ .flatMap((p)=>p.generate(ctx));
82
+ /**
83
+ * Gets the paths to the tsconfig files for all relevant projects.
84
+ *
85
+ * @returns {string[]} - An array containing paths to tsconfig files for both app and lib projects.
86
+ *
87
+ * @example
88
+ * const projects = {
89
+ * 'my-app': {
90
+ * type: 'app',
91
+ * data: { root: 'apps/my-app' }
92
+ * },
93
+ * 'my-lib': {
94
+ * type: 'lib',
95
+ * data: { root: 'libs/my-lib' }
96
+ * }
97
+ * };
98
+ *
99
+ * const tsConfigPaths = getTsConfigPaths(projects);
100
+ * console.log(tsConfigPaths);
101
+ * // Output:
102
+ * // ['apps/my-app/tsconfig.app.json', 'libs/my-lib/tsconfig.lib.json']
103
+ */ const getNxTsConfigPaths = ()=>{
104
+ const isValid = (p)=>p.data.root.startsWith('apps/') || p.data.root.startsWith('libs/');
105
+ const getTsConfigPath = (p)=>path.resolve(p.data.root, `tsconfig.${p.type === 'app' ? 'app' : 'lib'}.json`);
106
+ const graph = devkit.readCachedProjectGraph();
107
+ const projects = graph.nodes;
108
+ return Object.values(projects).filter(isValid).map(getTsConfigPath);
109
+ };
110
+
111
+ exports.chunkName = chunkName;
112
+ exports.deepMerge = deepMerge;
113
+ exports.getNxTsConfigPaths = getNxTsConfigPaths;
114
+ exports.getPlugins = getPlugins;
115
+ exports.when = when;
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+
3
+ var minimatch = require('minimatch');
4
+ var logger = require('../../../../shared/logger.cjs');
5
+ var utils = require('../../../../shared/utils.cjs');
6
+ var types = require('../types.cjs');
7
+ var helpers = require('./helpers.cjs');
8
+ var viteCommand = require('./viteCommand.cjs');
9
+
10
+ /**
11
+ * Initializes the project configuration with default values.
12
+ *
13
+ * @example
14
+ * const config = { type: ProjectType.APP, path: '/path/to/project', viteEnv: { mode: ViteMode.DEV } };
15
+ * const initializedConfig = initializeConfig(config);
16
+ */ const initializeConfig = (ccfg, pcfg, localPkgJson)=>{
17
+ const { envPrefix } = ccfg;
18
+ const localPkgName = localPkgJson['name'];
19
+ const { name = localPkgName, overrides = {}, shadowDom = false, chunkPrefix = getInitials(localPkgName), resolveEnvs = {
20
+ default: true,
21
+ local: true
22
+ }, fileName = `${envPrefix}-${chunkPrefix}-index`, externalizeLibs = {
23
+ default: true,
24
+ glob: []
25
+ } } = pcfg;
26
+ const viteCmd = viteCommand.getViteCommand(pcfg.viteEnv.mode);
27
+ const isVerbose = Object.keys(viteCmd.flags).some((x)=>[
28
+ types.Flag.VERBOSE,
29
+ types.Flag.VERBOSE_ALIAS
30
+ ].includes(x));
31
+ const logLevel = isVerbose ? logger.LogLevel.DEBUG : pcfg.logLevel ?? logger.LogLevel.INFO;
32
+ logger.setLogLevel(logLevel);
33
+ return {
34
+ viteCmd,
35
+ cfg: {
36
+ ...pcfg,
37
+ name,
38
+ fileName,
39
+ logLevel,
40
+ overrides,
41
+ chunkPrefix,
42
+ shadowDom,
43
+ resolveEnvs,
44
+ externalizeLibs: externalizeLibs
45
+ }
46
+ };
47
+ };
48
+ /**
49
+ * Handles merging configurations and logs any errors.
50
+ *
51
+ * @param {UserConfig} defaultConfig - The default configuration.
52
+ * @param {UserConfig} overrides - The overrides configuration.
53
+ * @returns {UserConfig} - The merged configuration.
54
+ */ const mergeConfigs = (defaultConfig, overrides)=>{
55
+ try {
56
+ return helpers.deepMerge(defaultConfig, overrides);
57
+ } catch (err) {
58
+ logger.logger.error('Error merging vite configs: ', err);
59
+ return defaultConfig;
60
+ }
61
+ };
62
+ /**
63
+ * Resolves glob patterns to actual package names found in package.json dependencies.
64
+ * This function is used to determine which packages should be treated as external
65
+ * in a Rollup or Vite build configuration.
66
+ *
67
+ * @param {string} path - The base path where package.json is located.
68
+ * @param {string | string[]} globs - A glob pattern or an array of glob patterns to match dependencies against.
69
+ * @returns {string[]} An array of package names that match the given glob patterns.
70
+ *
71
+ * @example
72
+ * // Example of using `getExternalDependencies` to find all dependencies starting with "my-lib" and "lodash"
73
+ * const projectPath = '/path/to/project';
74
+ * const globs = ['my-lib*', 'lodash'];
75
+ * const externalDependencies = getExternalDependencies(projectPath, globs);
76
+ * console.log(externalDependencies);
77
+ * // Output might be: ['my-lib/utils', 'my-lib/core', 'lodash']
78
+ */ const getExternalDependencies = (path, globs = [])=>{
79
+ const pkgJson = utils.getPkgJson(path); // Assumes getLocalPkgJson is a function that reads and parses package.json
80
+ const dependencies = Object.keys(pkgJson.dependencies || {});
81
+ const globPatterns = Array.isArray(globs) ? globs : [
82
+ globs
83
+ ];
84
+ return dependencies.filter((dep)=>globPatterns.some((pattern)=>minimatch.minimatch(dep, pattern)));
85
+ };
86
+ /**
87
+ * Generates a string of initials based on the input string,
88
+ * following certain rules:
89
+ * 1. A word is considered as a sequence of characters
90
+ * separated by hyphens.
91
+ * 2. If the string contains '@', any characters before
92
+ * and including the next '/' are ignored.
93
+ * 3. The first character of each word is taken to form
94
+ * the initials.
95
+ *
96
+ * @param {string} input - The input string from which to generate the initials.
97
+ * @returns {string} The initials formed by taking the first character
98
+ * of each word, after applying the specified rules.
99
+ *
100
+ * @example
101
+ * getInitials("player-script"); // returns "ps"
102
+ * getInitials("ssv-admin"); // returns "sa"
103
+ * getInitials("@nizza/customize-live"); // returns "cl"
104
+ */ function getInitials(input) {
105
+ const cleanedInput = input.includes('@') ? input.split('/')[1] : input;
106
+ const words = cleanedInput?.split('-');
107
+ const initials = words?.map((word)=>word.charAt(0)).join('');
108
+ return initials ?? '';
109
+ }
110
+
111
+ exports.getExternalDependencies = getExternalDependencies;
112
+ exports.getInitials = getInitials;
113
+ exports.initializeConfig = initializeConfig;
114
+ exports.mergeConfigs = mergeConfigs;
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ var chalk = require('chalk');
4
+ var argv = require('mri');
5
+ var vite = require('vite');
6
+ var types = require('../types.cjs');
7
+
8
+ /**
9
+ * Retrieves the Vite command details.
10
+ *
11
+ * @param {ViteMode} mode - The Vite mode.
12
+ * @returns {ViteCommand} - The command details.
13
+ *
14
+ * @example
15
+ * const command = getViteCommand(ViteMode.PROD);
16
+ * // Outputs: { stage: Stage.PROD, target: 'build', flags: {} }
17
+ */ function getViteCommand(mode) {
18
+ const nxEnv = vite.loadEnv(mode, process.cwd(), 'NX');
19
+ const nxCommandString = process?.env?.['npm_package_scripts_nx'];
20
+ const modeIsProd = mode === types.ViteMode.PROD;
21
+ const stage = (nxEnv?.['NX_TASK_TARGET_CONFIGURATION']) ?? (modeIsProd ? types.Stage.PROD : types.Stage.DEV);
22
+ const target = nxEnv?.['NX_TASK_TARGET_TARGET'] ?? types.Target.BUILD;
23
+ const flags = getViteCmdFlags(nxCommandString);
24
+ const showIn = {
25
+ prod: (...args)=>modeIsProd && console.log(...args),
26
+ dev: (...args)=>!modeIsProd && console.log(...args)
27
+ };
28
+ try {
29
+ showIn.prod(chalk.cyan('Build Stage:'), chalk.green(stage));
30
+ showIn.dev(chalk.green(' ➜ '), chalk.bold.white(`Stage: `), chalk.cyan(stage));
31
+ } catch {
32
+ showIn.prod(console.log('Build Stage:', stage));
33
+ showIn.dev(console.log(` ➜ Stage: `, stage));
34
+ }
35
+ return {
36
+ stage,
37
+ target,
38
+ flags
39
+ };
40
+ }
41
+ /**
42
+ * Parses the command string to extract flags.
43
+ *
44
+ * @param {string | undefined} commandString - The command string.
45
+ * @returns {Record<string, string>} - The flags extracted from the command string.
46
+ *
47
+ * @example
48
+ * const flags = getViteCmdFlags('nx run core:build --source-maps');
49
+ * // Outputs: { 'source-maps: 'true' }
50
+ */ function getViteCmdFlags(commandString) {
51
+ if (!commandString) return {};
52
+ const cleanedCommandString = commandString.replace(/"/g, '');
53
+ const args = argv(cleanedCommandString.split(' '));
54
+ delete args['_'];
55
+ return args;
56
+ }
57
+
58
+ exports.getViteCmdFlags = getViteCmdFlags;
59
+ exports.getViteCommand = getViteCommand;
@@ -1,21 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- default: function() {
13
- return _default;
14
- },
15
- injectCssIntoShadowDom: function() {
16
- return injectCssIntoShadowDom;
17
- }
18
- });
1
+ 'use strict';
2
+
19
3
  function injectCssIntoShadowDom() {
20
4
  const fileRegex = /\.(css)$/;
21
5
  let server;
@@ -41,4 +25,5 @@ function injectCssIntoShadowDom() {
41
25
  }
42
26
  };
43
27
  }
44
- const _default = injectCssIntoShadowDom;
28
+
29
+ exports.injectCssIntoShadowDom = injectCssIntoShadowDom;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "thirdPartyCssInjectPlugin", {
6
- enumerable: true,
7
- get: function() {
8
- return thirdPartyCssInjectPlugin;
9
- }
10
- });
11
- const _utils = require("./utils");
12
- function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
1
+ 'use strict';
2
+
3
+ var utils = require('./utils.cjs');
4
+
5
+ /**
6
+ * Inject the CSS compiled with JS.
7
+ *
8
+ * @return {Plugin}
9
+ */ function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
13
10
  topExecutionPriority: true,
14
11
  execute: []
15
12
  }) {
@@ -33,12 +30,12 @@ function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
33
30
  const htmlChunk = bundle[name];
34
31
  let replacedHtml = htmlChunk.source;
35
32
  cssAssets.forEach((cssName)=>{
36
- replacedHtml = (0, _utils.removeLinkStyleSheets)(replacedHtml, cssName);
33
+ replacedHtml = utils.removeLinkStyleSheets(replacedHtml, cssName);
37
34
  htmlChunk.source = replacedHtml;
38
35
  });
39
36
  }
40
37
  const jsAsset = bundle[jsAssets[0]];
41
- const cssInjectionCode = await (0, _utils.buildCSSInjectionCode)(execute);
38
+ const cssInjectionCode = await utils.buildCSSInjectionCode(execute);
42
39
  const appCode = jsAsset.code;
43
40
  jsAsset.code = topExecutionPriority ? '' : appCode;
44
41
  jsAsset.code += cssInjectionCode ? cssInjectionCode.code : '';
@@ -46,3 +43,5 @@ function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
46
43
  }
47
44
  };
48
45
  }
46
+
47
+ exports.thirdPartyCssInjectPlugin = thirdPartyCssInjectPlugin;
@@ -1,22 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- buildCSSInjectionCode: function() {
13
- return buildCSSInjectionCode;
14
- },
15
- removeLinkStyleSheets: function() {
16
- return removeLinkStyleSheets;
17
- }
18
- });
19
- const _vite = require("vite");
1
+ 'use strict';
2
+
3
+ var vite = require('vite');
4
+
20
5
  const cssInjectedByJsId = '\0vite/all-css';
21
6
  const waitForElement = (selector, observerElementName = 'body')=>{
22
7
  const getElement = (selector)=>document.querySelector(selector);
@@ -47,7 +32,7 @@ const waitForElement = (selector, observerElementName = 'body')=>{
47
32
  });
48
33
  };
49
34
  async function buildCSSInjectionCode(execute) {
50
- const res = await (0, _vite.build)({
35
+ const res = await vite.build({
51
36
  root: '',
52
37
  configFile: false,
53
38
  logLevel: 'error',
@@ -101,7 +86,7 @@ async function buildCSSInjectionCode(execute) {
101
86
  return `try{if(typeof document != 'undefined'){
102
87
  const waitForElement=${waitForElement.toString()};
103
88
  ${executeJs.join(' ')}
104
- }}catch(e){console.error('vite-third-party-css-inject-plugin', e);}`;
89
+ }}catch(e){console.error('vite'-third-party-css-inject-plugin', e);}`;
105
90
  }
106
91
  }
107
92
  };
@@ -110,3 +95,6 @@ function removeLinkStyleSheets(html, cssFileName) {
110
95
  const removeCSS = new RegExp(`<link rel=".*"[^>]*?href=".*/?${cssFileName}"[^>]*?>`);
111
96
  return html.replace(removeCSS, '');
112
97
  }
98
+
99
+ exports.buildCSSInjectionCode = buildCSSInjectionCode;
100
+ exports.removeLinkStyleSheets = removeLinkStyleSheets;
@@ -0,0 +1,22 @@
1
+ import { logger } from '@nx/devkit';
2
+ import { runCommand } from '../shared/utils.mjs';
3
+
4
+ async function cleanS3Bucket(s3BucketPath) {
5
+ logger.info('🧹 Cleaning S3 bucket...');
6
+ await runCommand(`aws s3 rm ${s3BucketPath} --recursive`);
7
+ logger.info('✅ S3 bucket cleared.');
8
+ }
9
+ async function copyAssetsToS3(s3BucketPath, projectRoot) {
10
+ logger.info('📦 Copying assets to S3 bucket...');
11
+ await runCommand(`aws s3 cp ${projectRoot}/dist ${s3BucketPath} --recursive`);
12
+ logger.info('🚚 Assets files copied.');
13
+ }
14
+ async function createCloudFrontInvalidation(distributionId, invalidationPaths) {
15
+ const pathsString = invalidationPaths.map((path)=>`"${path}"`).join(' ');
16
+ const command = `aws cloudfront create-invalidation --distribution-id ${distributionId} --paths ${pathsString}`;
17
+ logger.info('🔃 Creating invalidation for CloudFront...');
18
+ await runCommand(command);
19
+ logger.info('🔄 CloudFront invalidation created.');
20
+ }
21
+
22
+ export { cleanS3Bucket, copyAssetsToS3, createCloudFrontInvalidation };
@@ -0,0 +1,20 @@
1
+ import { getProjectConfig, runCommand, ok, err } from '../shared/utils.mjs';
2
+ import { cleanS3Bucket, copyAssetsToS3, createCloudFrontInvalidation } from './helpers.mjs';
3
+
4
+ async function deployExecutor(opts, ctx) {
5
+ try {
6
+ const { root, name } = getProjectConfig(ctx);
7
+ const { s3BucketPath, cloudFrontDistributionId, cloudFrontInvalidationPaths, skipBuild = false } = opts;
8
+ const buildTarget = `${name}:${opts.buildTarget}`;
9
+ if (!skipBuild) await runCommand(`nx run ${buildTarget}`);
10
+ await cleanS3Bucket(s3BucketPath);
11
+ await copyAssetsToS3(s3BucketPath, root);
12
+ await createCloudFrontInvalidation(cloudFrontDistributionId, cloudFrontInvalidationPaths);
13
+ const now = new Date().toLocaleString();
14
+ return ok(`✨ Build completed successfully on ${now}`);
15
+ } catch (error) {
16
+ return err(error, '❌ Error when executing deploy command');
17
+ }
18
+ }
19
+
20
+ export { deployExecutor as default };
@@ -0,0 +1,41 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "version": 2,
4
+ "title": "Deploy executor",
5
+ "description": "",
6
+ "type": "object",
7
+ "properties": {
8
+ "s3BucketPath": {
9
+ "type": "string",
10
+ "description": "S3 BUCKET ROUTE"
11
+ },
12
+ "cloudFrontDistributionId": {
13
+ "type": "string",
14
+ "description": "Cloudfront distribution id for cache invalidation"
15
+ },
16
+ "cloudFrontInvalidationPaths": {
17
+ "type": "array",
18
+ "description": "Cloudfront path list that must be invalidated in the cache",
19
+ "items": {
20
+ "type": "string"
21
+ },
22
+ "uniqueItems": true,
23
+ "minItems": 1
24
+ },
25
+ "buildTarget": {
26
+ "type": "string",
27
+ "description": "Build command relative to the project and without the name of the project because it is not necessary"
28
+ },
29
+ "skipBuild": {
30
+ "type": "boolean",
31
+ "description": "It allows to omit the Build process and assumes that it was already done",
32
+ "default": false
33
+ }
34
+ },
35
+ "required": [
36
+ "s3BucketPath",
37
+ "cloudFrontDistributionId",
38
+ "cloudFrontInvalidationPaths",
39
+ "buildTarget"
40
+ ]
41
+ }
@@ -0,0 +1,58 @@
1
+ import { promises } from 'fs';
2
+ import { join } from 'path';
3
+ import { logger } from '@nx/devkit';
4
+
5
+ const { mkdir, writeFile, access } = promises;
6
+ /**
7
+ * Creates the content for an environment file based on the core environment path.
8
+ *
9
+ * @param {CreateEnvironmentData} data - Values to replace in template.
10
+ * @returns {string} The content of the environment file.
11
+ */ async function createEnvironmentFileContent({ coreEnvFile, projectOrg }) {
12
+ return `import { Environment } from '@${projectOrg}/core';
13
+ import coreEnvs from '@${projectOrg}/core/envs/${coreEnvFile}';
14
+
15
+ const config = {
16
+ ...coreEnvs,
17
+ };
18
+
19
+ export const environment: Environment<typeof config> = config;
20
+ export default environment;
21
+ `;
22
+ }
23
+ /**
24
+ * Ensures that the given directory exists, creating it if it does not.
25
+ *
26
+ * @param {string} dir - The path to the directory to check/create.
27
+ */ async function ensureDirectoryExists(dir) {
28
+ try {
29
+ await access(dir);
30
+ logger.info('✅ Directory exists.');
31
+ } catch {
32
+ logger.info('📁 Directory does not exist. Creating...');
33
+ await mkdir(dir, {
34
+ recursive: true
35
+ });
36
+ logger.info('📁 Directory created.');
37
+ }
38
+ }
39
+ /**
40
+ * Writes environment files to the given base path if they do not already exist.
41
+ *
42
+ * @param {string} basePath - The base directory where the files should be written.
43
+ * @param {Record<string, string>} files - An object containing filenames and their respective content.
44
+ */ async function writeFilesIfNotExist(basePath, files) {
45
+ await Promise.all(Object.entries(files).map(async ([filename, content])=>{
46
+ const filePath = join(basePath, filename);
47
+ try {
48
+ await access(filePath);
49
+ logger.info(`✅ The file "${filename}" already exists.`);
50
+ } catch {
51
+ logger.warn(`📝 The file "${filename}" does not exist. Creating...`);
52
+ await writeFile(filePath, content);
53
+ logger.info(`🎉 The file "${filename}" has been created.`);
54
+ }
55
+ }));
56
+ }
57
+
58
+ export { createEnvironmentFileContent, ensureDirectoryExists, writeFilesIfNotExist };
@@ -0,0 +1,58 @@
1
+ import { join } from 'path';
2
+ import { getProjectConfig, ok, err } from '../shared/utils.mjs';
3
+ import { ensureDirectoryExists, createEnvironmentFileContent, writeFilesIfNotExist } from './helpers.mjs';
4
+ import '../../shared/logger.mjs';
5
+ import { getPkgJson } from '../../shared/utils.mjs';
6
+
7
+ const ENV_DIR = 'src/environments';
8
+ const ENV_DEV_FILE = 'environment.ts';
9
+ const ENV_LOCAL_FILE = 'environment.local.ts';
10
+ const ENV_PROD_FILE = 'environment.prod.ts';
11
+ const ENV_STAGING_FILE = 'environment.staging.ts';
12
+ const environmentFiles = [
13
+ ENV_DEV_FILE,
14
+ ENV_LOCAL_FILE,
15
+ ENV_PROD_FILE,
16
+ ENV_STAGING_FILE
17
+ ];
18
+ /**
19
+ * The executor function to create environment files.
20
+ * Ensures that the directory for the environment files exists and creates the files
21
+ * if they do not exist already. Files created are 'environment.ts', 'environment.prod.ts',
22
+ * and 'environment.staging.ts'.
23
+ *
24
+ * @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
25
+ * @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
26
+ * @returns {Promise<ExecutorResponse>} The result object with a success or error status.
27
+ */ async function runExecutor(_opts, ctx) {
28
+ try {
29
+ const projectConfig = getProjectConfig(ctx);
30
+ const environmentsDir = join(projectConfig.root, ENV_DIR);
31
+ const mainPkgJson = getPkgJson(ctx.root);
32
+ const getEnvPath = (fileName)=>{
33
+ const isLocal = fileName.includes('.local');
34
+ const coreEnvFile = (isLocal ? ENV_DEV_FILE : fileName).replace('.ts', '');
35
+ const key = isLocal ? ENV_LOCAL_FILE : fileName;
36
+ return {
37
+ key,
38
+ coreEnvFile
39
+ };
40
+ };
41
+ await ensureDirectoryExists(environmentsDir);
42
+ for (const envFileName of environmentFiles){
43
+ const { key, coreEnvFile } = getEnvPath(envFileName);
44
+ const content = await createEnvironmentFileContent({
45
+ coreEnvFile,
46
+ projectOrg: mainPkgJson.name
47
+ });
48
+ await writeFilesIfNotExist(environmentsDir, {
49
+ [key]: content
50
+ });
51
+ }
52
+ return ok();
53
+ } catch (error) {
54
+ return err(error, `Failed to create environment files:`);
55
+ }
56
+ }
57
+
58
+ export { runExecutor as default };
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "version": 2,
4
+ "title": "Environments executor",
5
+ "description": "",
6
+ "type": "object",
7
+ "properties": {},
8
+ "required": []
9
+ }
@@ -0,0 +1,48 @@
1
+ import { logger } from '@nx/devkit';
2
+ import { exec } from 'child_process';
3
+ import { promisify } from 'util';
4
+
5
+ const execAsync = promisify(exec);
6
+ /**
7
+ * Retrieves the version of a published package with a given name and tag.
8
+ *
9
+ * @param {string} packageName The name of the package to retrieve the version for.
10
+ * @param {string} tag The tag to retrieve the version for.
11
+ * @returns The version of the package as a string or an object containing versions for each tag.
12
+ */ async function getPublishedPackageVersion(packageName, tag) {
13
+ const withTag = tag ? `.${tag}` : ' --json';
14
+ const command = `npm view ${packageName} dist-tags${withTag}`;
15
+ const { stdout, stderr } = await execAsync(command);
16
+ if (stderr) {
17
+ logger.error(stderr.trim());
18
+ process.exit(1);
19
+ }
20
+ const published = stdout.trim();
21
+ return tag ? published : JSON.parse(published);
22
+ }
23
+ /**
24
+ * Checks if a package with the given name is already published and returns its version.
25
+ *
26
+ * @param {string} packageName The name of the package to check for.
27
+ * @returns An object containing the published versions of the package and a flag indicating if it is the first version.
28
+ */ async function checkPublishedVersion(packageName) {
29
+ let publishedVersion;
30
+ let isFirstVersion = false;
31
+ try {
32
+ publishedVersion = await getPublishedPackageVersion(packageName);
33
+ } catch (err) {
34
+ if (err?.message.includes('code E404')) {
35
+ isFirstVersion = true;
36
+ logger.info(`🏁 This is the first version of "${packageName}" package. \n`);
37
+ } else {
38
+ logger.error('❌ Error when checking the last published versions \n');
39
+ throw err;
40
+ }
41
+ }
42
+ return {
43
+ publishedVersion,
44
+ isFirstVersion
45
+ };
46
+ }
47
+
48
+ export { checkPublishedVersion, getPublishedPackageVersion };