@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,33 @@
1
+ import { logger } from '@nx/devkit';
2
+ import { randomBytes } from 'crypto';
3
+ import { readFileSync } from 'fs';
4
+ import { resolve } from 'path';
5
+
6
+ /**
7
+ * Reads and parses the package.json file from the given project path.
8
+ *
9
+ * @param {string} projectPath - The path to the project.
10
+ * @returns {Record<string, any>} - The parsed package.json data.
11
+ *
12
+ * @example
13
+ * const pkgJsonData = getPkgJson('/path/to/project');
14
+ */ const getPkgJson = (projectPath)=>{
15
+ try {
16
+ const data = readFileSync(resolve(projectPath, './package.json'), 'utf-8');
17
+ return JSON.parse(data);
18
+ } catch (err) {
19
+ logger.error('Error reading or parsing package.json');
20
+ throw err;
21
+ }
22
+ };
23
+ /**
24
+ * Generates a random alphanumeric identifier of a specified length.
25
+ *
26
+ * @param {number} [length=8] - The length of the identifier to generate. Defaults to 8 if not specified.
27
+ * @returns {string} - A string representing a unique identifier.
28
+ */ function shortId(length = 8) {
29
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
30
+ return Array.from(randomBytes(length), (b)=>chars[b % chars.length]).join('');
31
+ }
32
+
33
+ export { getPkgJson, shortId };
@@ -0,0 +1,11 @@
1
+ const getAppConfig = (ctx)=>{
2
+ const { port } = ctx.projectConfig;
3
+ return {
4
+ server: {
5
+ port,
6
+ host: true
7
+ }
8
+ };
9
+ };
10
+
11
+ export { getAppConfig };
@@ -1,40 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "getBaseConfig", {
6
- enumerable: true,
7
- get: function() {
8
- return getBaseConfig;
9
- }
10
- });
11
- const _plugins = require("../plugins");
12
- const _shared = require("../shared");
13
- const _fs = require("fs");
14
- const _path = require("path");
1
+ import { bundleAnalysisPlugin, basePlugins } from '../plugins.mjs';
2
+ import { Target, ViteMode, Flag, Stage } from '../shared/types.mjs';
3
+ import { getPlugins, when } from '../shared/utils/helpers.mjs';
4
+ import 'minimatch';
5
+ import '../../../shared/logger.mjs';
6
+ import '@nx/devkit';
7
+ import 'crypto';
8
+ import { existsSync } from 'fs';
9
+ import { resolve } from 'path';
10
+ import 'chalk';
11
+ import 'mri';
12
+ import 'vite';
13
+
15
14
  const getBaseConfig = (ctx)=>{
16
15
  const { commonConfig, projectConfig, viteCmd } = ctx;
17
16
  const { resolveEnvs, path } = projectConfig;
18
17
  const { stage, target, flags: cmdOverrides } = viteCmd;
19
- const NODE_ENV = target === _shared.Target.BUILD ? _shared.ViteMode.PROD : _shared.ViteMode.DEV;
20
- const sourcemap = cmdOverrides?.[_shared.Flag.SOURCEMAP] ?? stage !== _shared.Stage.PROD;
18
+ const NODE_ENV = target === Target.BUILD ? ViteMode.PROD : ViteMode.DEV;
19
+ const sourcemap = cmdOverrides?.[Flag.SOURCEMAP] ?? stage !== Stage.PROD;
21
20
  const envPrefix = `${commonConfig.envPrefix.toUpperCase()}_`;
22
21
  const omittedStages = resolveEnvs.local ? [
23
- _shared.Stage.DEV
22
+ Stage.DEV
24
23
  ] : [
25
- _shared.Stage.DEV,
26
- _shared.Stage.LOCAL
24
+ Stage.DEV,
25
+ Stage.LOCAL
27
26
  ];
28
27
  const envPath = `environments/environment.${stage}.ts`;
29
28
  const fallbackEnvPath = `environments/environment.ts`;
30
29
  // Verify if the local Environment file is present
31
- const envFilePath = (0, _fs.existsSync)((0, _path.resolve)(path, 'src', envPath)) ? envPath : fallbackEnvPath;
30
+ const envFilePath = existsSync(resolve(path, 'src', envPath)) ? envPath : fallbackEnvPath;
32
31
  return {
33
32
  envPrefix,
34
- plugins: (0, _shared.getPlugins)(ctx, _plugins.basePlugins, _plugins.bundleAnalysisPlugin),
33
+ plugins: getPlugins(ctx, basePlugins, bundleAnalysisPlugin),
35
34
  resolve: {
36
35
  alias: {
37
- ...(0, _shared.when)(resolveEnvs.default && !omittedStages.includes(stage), {
36
+ ...when(resolveEnvs.default && !omittedStages.includes(stage), {
38
37
  '~env': envFilePath
39
38
  })
40
39
  }
@@ -53,3 +52,5 @@ const getBaseConfig = (ctx)=>{
53
52
  }
54
53
  };
55
54
  };
55
+
56
+ export { getBaseConfig };
@@ -0,0 +1,30 @@
1
+ import { ProjectType } from '../shared/types.mjs';
2
+ import '@nx/devkit';
3
+ import 'path';
4
+ import 'ramda';
5
+ import '../../../shared/logger.mjs';
6
+ import 'crypto';
7
+ import 'fs';
8
+ import 'minimatch';
9
+ import 'chalk';
10
+ import 'mri';
11
+ import 'vite';
12
+ import { getAppConfig } from './app.mjs';
13
+ import { getBaseConfig } from './base.mjs';
14
+ import { getLibConfig } from './lib.mjs';
15
+ import { getScriptConfig } from './script.mjs';
16
+
17
+ const getConfig = (ctx, type = null)=>{
18
+ switch(type){
19
+ case ProjectType.APP:
20
+ return getAppConfig(ctx);
21
+ case ProjectType.LIB:
22
+ return getLibConfig(ctx);
23
+ case ProjectType.SCRIPT:
24
+ return getScriptConfig(ctx);
25
+ default:
26
+ return getBaseConfig(ctx);
27
+ }
28
+ };
29
+
30
+ export { getAppConfig, getBaseConfig, getConfig, getLibConfig, getScriptConfig };
@@ -1,34 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "getLibConfig", {
6
- enumerable: true,
7
- get: function() {
8
- return getLibConfig;
9
- }
10
- });
11
- const _path = require("path");
12
- const _plugins = require("../plugins");
13
- const _shared = require("../shared");
1
+ import { resolve } from 'path';
2
+ import { dtsPlugin } from '../plugins.mjs';
3
+ import '../shared/types.mjs';
4
+ import { when, getPlugins } from '../shared/utils/helpers.mjs';
5
+ import { getExternalDependencies } from '../shared/utils/projectConfig.mjs';
6
+ import 'chalk';
7
+ import 'mri';
8
+ import 'vite';
9
+
14
10
  const getLibConfig = (ctx)=>{
15
11
  const { projectConfig, commonConfig } = ctx;
16
12
  const { externalizeLibGlob = [] } = commonConfig;
17
13
  const { name, path, externalizeLibs } = projectConfig;
18
- const entry = (0, _path.resolve)(path, projectConfig.entry ?? 'src/index.ts');
14
+ const entry = resolve(path, projectConfig.entry ?? 'src/index.ts');
19
15
  const defaultExternals = {
20
16
  react: true,
21
17
  'react-dom': true,
22
18
  'react/jsx-runtime': true
23
19
  };
24
20
  // Get external dependencies based on glob patterns
25
- const externalDeps = (0, _shared.getExternalDependencies)(path, [
21
+ const externalDeps = getExternalDependencies(path, [
26
22
  ...externalizeLibGlob,
27
23
  ...externalizeLibs.glob
28
24
  ]);
29
25
  const rollupExternal = [
30
26
  ...externalDeps,
31
- ...Object.keys((0, _shared.when)(externalizeLibs.default, defaultExternals))
27
+ ...Object.keys(when(externalizeLibs.default, defaultExternals))
32
28
  ];
33
29
  const rollupGlobals = {
34
30
  react: 'React',
@@ -36,7 +32,7 @@ const getLibConfig = (ctx)=>{
36
32
  'react/jsx-runtime': 'ReactJsxRuntime'
37
33
  };
38
34
  return {
39
- plugins: (0, _shared.getPlugins)(ctx, _plugins.dtsPlugin),
35
+ plugins: getPlugins(ctx, dtsPlugin),
40
36
  build: {
41
37
  lib: {
42
38
  name,
@@ -49,9 +45,11 @@ const getLibConfig = (ctx)=>{
49
45
  rollupOptions: {
50
46
  external: rollupExternal,
51
47
  output: {
52
- globals: (0, _shared.when)(externalizeLibs.default, rollupGlobals)
48
+ globals: when(externalizeLibs.default, rollupGlobals)
53
49
  }
54
50
  }
55
51
  }
56
52
  };
57
53
  };
54
+
55
+ export { getLibConfig };
@@ -0,0 +1,44 @@
1
+ import { resolve } from 'path';
2
+ import { injectCssByJsPlugin, injectCssIntoShadowDomPlugin } from '../plugins.mjs';
3
+ import '../shared/types.mjs';
4
+ import { getPlugins, chunkName } from '../shared/utils/helpers.mjs';
5
+ import 'minimatch';
6
+ import '../../../shared/logger.mjs';
7
+ import '@nx/devkit';
8
+ import 'crypto';
9
+ import 'fs';
10
+ import 'chalk';
11
+ import 'mri';
12
+ import 'vite';
13
+
14
+ const getScriptConfig = (ctx)=>{
15
+ const { commonConfig, projectConfig } = ctx;
16
+ const { envPrefix } = commonConfig;
17
+ const { port } = projectConfig;
18
+ const { name, path, fileName, chunkPrefix } = projectConfig;
19
+ const entry = resolve(path, projectConfig.entry ?? 'src/main');
20
+ return {
21
+ plugins: getPlugins(ctx, injectCssIntoShadowDomPlugin, injectCssByJsPlugin),
22
+ server: {
23
+ port,
24
+ host: true
25
+ },
26
+ build: {
27
+ lib: {
28
+ name,
29
+ entry,
30
+ fileName,
31
+ formats: [
32
+ 'es'
33
+ ]
34
+ },
35
+ rollupOptions: {
36
+ output: {
37
+ chunkFileNames: chunkName(`${envPrefix}-${chunkPrefix}`)
38
+ }
39
+ }
40
+ }
41
+ };
42
+ };
43
+
44
+ export { getScriptConfig };
@@ -0,0 +1,40 @@
1
+ import { defineConfig } from 'vite';
2
+ import { currentLogLevel, LogLevel, logger } from '../../shared/logger.mjs';
3
+ import { getPkgJson } from '../../shared/utils.mjs';
4
+ import { getConfig } from './configs/index.mjs';
5
+ import './shared/types.mjs';
6
+ import '@nx/devkit';
7
+ import 'path';
8
+ import 'ramda';
9
+ import { initializeConfig, mergeConfigs } from './shared/utils/projectConfig.mjs';
10
+ import 'chalk';
11
+ import 'mri';
12
+
13
+ /**
14
+ * Builds the configuration based on common and project-specific configurations.
15
+ *
16
+ * @param {CommonProjectConfig} commonConfig - The common configuration.
17
+ * @returns - Returns a function that accepts a project configuration and returns the Vite configuration.
18
+ */ const createConfigBuilder = (commonConfig)=>(projectConfig)=>{
19
+ try {
20
+ const localPkgJson = getPkgJson(projectConfig.path);
21
+ const { cfg, viteCmd } = initializeConfig(commonConfig, projectConfig, localPkgJson);
22
+ const isDebug = currentLogLevel === LogLevel.DEBUG;
23
+ const { type, overrides } = cfg;
24
+ const ctx = {
25
+ viteCmd,
26
+ localPkgJson,
27
+ commonConfig,
28
+ projectConfig: cfg
29
+ };
30
+ const defaultConfig = mergeConfigs(getConfig(ctx), getConfig(ctx, type));
31
+ const config = mergeConfigs(defaultConfig, overrides);
32
+ if (isDebug) logger.debug('Generated config:', config);
33
+ return defineConfig(config);
34
+ } catch (err) {
35
+ logger.error('buildConfig unexpected error:');
36
+ throw err;
37
+ }
38
+ };
39
+
40
+ export { createConfigBuilder };
@@ -0,0 +1,87 @@
1
+ import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
2
+ import graphql from '@rollup/plugin-graphql';
3
+ import react from '@vitejs/plugin-react-swc';
4
+ import { resolve } from 'path';
5
+ import { visualizer } from 'rollup-plugin-visualizer';
6
+ import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
7
+ import dts from 'vite-plugin-dts';
8
+ import tsconfigPaths from 'vite-tsconfig-paths';
9
+ import 'vite';
10
+ import { injectCssIntoShadowDom } from '../plugins/shadow-dom-inject-css/index.mjs';
11
+ import { Stage, Flag } from './shared/types.mjs';
12
+ import { getNxTsConfigPaths } from './shared/utils/helpers.mjs';
13
+ import 'minimatch';
14
+ import '../../shared/logger.mjs';
15
+ import '@nx/devkit';
16
+ import 'crypto';
17
+ import 'fs';
18
+ import 'chalk';
19
+ import 'mri';
20
+
21
+ /**
22
+ * Base plugins configuration for apps and libs.
23
+ *
24
+ * Plugins configured:
25
+ * - vite-tsconfig-paths
26
+ * - @originjs/vite-plugin-commonjs
27
+ * - @rollup/plugin-graphql
28
+ * - @vitejs/plugin-react-swc
29
+ */ const basePlugins = {
30
+ generate: ()=>{
31
+ const projects = getNxTsConfigPaths();
32
+ return [
33
+ tsconfigPaths({
34
+ projects
35
+ }),
36
+ viteCommonjs(),
37
+ graphql(),
38
+ react({
39
+ tsDecorators: true
40
+ })
41
+ ];
42
+ }
43
+ };
44
+ /**
45
+ * Plugin configuration for generating type declarations using vite-plugin-dts.
46
+ */ const dtsPlugin = {
47
+ generate: ({ projectConfig })=>[
48
+ dts({
49
+ tsconfigPath: resolve(projectConfig.path, 'tsconfig.lib.json'),
50
+ outDir: resolve(projectConfig.path, 'dist'),
51
+ entryRoot: resolve(projectConfig.path, 'src')
52
+ })
53
+ ],
54
+ condition: ({ projectConfig, viteCmd })=>viteCmd.stage !== Stage.LOCAL && projectConfig.dts == null ? true : !!projectConfig.dts
55
+ };
56
+ /**
57
+ * Plugin configuration for bundle analysis using rollup-plugin-visualizer.
58
+ */ const bundleAnalysisPlugin = {
59
+ generate: ({ projectConfig })=>[
60
+ visualizer({
61
+ emitFile: true,
62
+ projectRoot: resolve(projectConfig.path, 'dist'),
63
+ filename: 'bundle-analysis.html'
64
+ })
65
+ ],
66
+ condition: ({ viteCmd })=>viteCmd.flags?.[Flag.ANALYZE] === 'true'
67
+ };
68
+ /**
69
+ * Plugin configuration for injecting CSS into JS files
70
+ * using vite-plugin-css-injected-by-js.
71
+ */ const injectCssByJsPlugin = {
72
+ generate: (_)=>[
73
+ cssInjectedByJsPlugin()
74
+ ],
75
+ condition: ({ projectConfig })=>!projectConfig.shadowDom
76
+ };
77
+ /**
78
+ * Plugin configuration for injecting CSS into Shadow Dom.
79
+ * using local plugin.
80
+ */ const injectCssIntoShadowDomPlugin = {
81
+ generate: (_)=>[
82
+ injectCssIntoShadowDom()
83
+ ],
84
+ condition: ({ projectConfig })=>projectConfig.shadowDom
85
+ };
86
+
87
+ export { basePlugins, bundleAnalysisPlugin, dtsPlugin, injectCssByJsPlugin, injectCssIntoShadowDomPlugin };
@@ -1,30 +1,3 @@
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
- Flag: function() {
13
- return Flag;
14
- },
15
- ProjectType: function() {
16
- return ProjectType;
17
- },
18
- Stage: function() {
19
- return Stage;
20
- },
21
- Target: function() {
22
- return Target;
23
- },
24
- ViteMode: function() {
25
- return ViteMode;
26
- }
27
- });
28
1
  var ViteMode;
29
2
  (function(ViteMode) {
30
3
  ViteMode["PROD"] = "production";
@@ -56,3 +29,5 @@ var Target;
56
29
  Target["PREVIEW"] = "preview";
57
30
  Target["SERVE"] = "serve";
58
31
  })(Target || (Target = {}));
32
+
33
+ export { Flag, ProjectType, Stage, Target, ViteMode };
@@ -1,16 +1,9 @@
1
- import type { PreRenderedChunk } from 'rollup';
2
- import type { PluginOption } from 'vite';
3
- import type { Context, PluginConfig } from '../types';
4
- /**
5
- * Generates a short ID string.
6
- *
7
- * @param {number} length - The length of the ID to generate.
8
- * @returns {string} - The generated ID.
9
- *
10
- * @example
11
- * const id = shortId(10); // Outputs: "Aj3_Dk7_2j"
12
- */
13
- export declare const shortId: (length: number) => string;
1
+ import { readCachedProjectGraph } from '@nx/devkit';
2
+ import { resolve } from 'path';
3
+ import * as R from 'ramda';
4
+ import '../../../../shared/logger.mjs';
5
+ import { shortId } from '../../../../shared/utils.mjs';
6
+
14
7
  /**
15
8
  * Deeply merges two objects, combining their properties.
16
9
  *
@@ -22,8 +15,15 @@ export declare const shortId: (length: number) => string;
22
15
  * const obj1 = { a: 1, b: { c: 2 } };
23
16
  * const obj2 = { b: { d: 3 } };
24
17
  * const merged = deepMerge(obj1, obj2); // Outputs: { a: 1, b: { c: 2, d: 3 } }
25
- */
26
- export declare function deepMerge(v1: Record<string, any>, v2: Record<string, any>): Record<string, any>;
18
+ */ function deepMerge(v1, v2) {
19
+ if (Array.isArray(v1) && Array.isArray(v2)) {
20
+ return R.uniq(R.concat(v1, v2));
21
+ } else if (typeof v1 === 'object' && typeof v2 === 'object' && !R.isNil(v1) && !R.isNil(v2)) {
22
+ return R.mergeWith(deepMerge, v1, v2);
23
+ } else {
24
+ return v2;
25
+ }
26
+ }
27
27
  /**
28
28
  * Generates a name for js files.
29
29
  *
@@ -33,8 +33,11 @@ export declare function deepMerge(v1: Record<string, any>, v2: Record<string, an
33
33
  * @example
34
34
  * const generateChunkName = chunkName('prefix');
35
35
  * const name = generateChunkName({ name: 'example' }); // Outputs: "prefix-example-Aj3_Dk7_2j.js"
36
- */
37
- export declare const chunkName: (prefix?: string) => (x: PreRenderedChunk) => string;
36
+ */ const chunkName = (prefix)=>(x)=>{
37
+ const nameWithoutUnderscore = x.name.replace(/_/g, '');
38
+ const pre = prefix ? `${prefix}-` : '';
39
+ return `${pre}${nameWithoutUnderscore}-${shortId(8)}.js`;
40
+ };
38
41
  /**
39
42
  * Returns the given object if the condition is true, otherwise returns null.
40
43
  *
@@ -46,15 +49,15 @@ export declare const chunkName: (prefix?: string) => (x: PreRenderedChunk) => st
46
49
  * const obj = { a: 1 };
47
50
  * const result = when(true, obj); // Outputs: { a: 1 }
48
51
  * const result2 = when(false, obj); // Outputs: {}
49
- */
50
- export declare const when: (condition: any, obj: Record<string, any>) => Record<string, any>;
52
+ */ const when = (condition, obj)=>condition ? obj : {};
51
53
  /**
52
54
  * Filters and generates plugin configurations based on conditions and the provided context.
53
55
  *
54
56
  * @param {Context} ctx - The main configuration object.
55
57
  * @returns {any[]} - An array of generated plugin configurations.
56
- */
57
- export declare const getPlugins: (ctx: Context, ...pluginConfigs: PluginConfig[]) => PluginOption[];
58
+ */ const getPlugins = (ctx, ...pluginConfigs)=>pluginConfigs// Filters the plugins based on conditions
59
+ .filter((p)=>!p.condition || p.condition(ctx))// Generates the configuration of each plugin and flattens the resulting array
60
+ .flatMap((p)=>p.generate(ctx));
58
61
  /**
59
62
  * Gets the paths to the tsconfig files for all relevant projects.
60
63
  *
@@ -76,6 +79,12 @@ export declare const getPlugins: (ctx: Context, ...pluginConfigs: PluginConfig[]
76
79
  * console.log(tsConfigPaths);
77
80
  * // Output:
78
81
  * // ['apps/my-app/tsconfig.app.json', 'libs/my-lib/tsconfig.lib.json']
79
- */
80
- export declare const getNxTsConfigPaths: () => string[];
81
- //# sourceMappingURL=helpers.d.ts.map
82
+ */ const getNxTsConfigPaths = ()=>{
83
+ const isValid = (p)=>p.data.root.startsWith('apps/') || p.data.root.startsWith('libs/');
84
+ const getTsConfigPath = (p)=>resolve(p.data.root, `tsconfig.${p.type === 'app' ? 'app' : 'lib'}.json`);
85
+ const graph = readCachedProjectGraph();
86
+ const projects = graph.nodes;
87
+ return Object.values(projects).filter(isValid).map(getTsConfigPath);
88
+ };
89
+
90
+ export { chunkName, deepMerge, getNxTsConfigPaths, getPlugins, when };
@@ -0,0 +1,109 @@
1
+ import { minimatch } from 'minimatch';
2
+ import { LogLevel, logger, setLogLevel } from '../../../../shared/logger.mjs';
3
+ import { getPkgJson } from '../../../../shared/utils.mjs';
4
+ import { Flag } from '../types.mjs';
5
+ import { deepMerge } from './helpers.mjs';
6
+ import { getViteCommand } from './viteCommand.mjs';
7
+
8
+ /**
9
+ * Initializes the project configuration with default values.
10
+ *
11
+ * @example
12
+ * const config = { type: ProjectType.APP, path: '/path/to/project', viteEnv: { mode: ViteMode.DEV } };
13
+ * const initializedConfig = initializeConfig(config);
14
+ */ const initializeConfig = (ccfg, pcfg, localPkgJson)=>{
15
+ const { envPrefix } = ccfg;
16
+ const localPkgName = localPkgJson['name'];
17
+ const { name = localPkgName, overrides = {}, shadowDom = false, chunkPrefix = getInitials(localPkgName), resolveEnvs = {
18
+ default: true,
19
+ local: true
20
+ }, fileName = `${envPrefix}-${chunkPrefix}-index`, externalizeLibs = {
21
+ default: true,
22
+ glob: []
23
+ } } = pcfg;
24
+ const viteCmd = getViteCommand(pcfg.viteEnv.mode);
25
+ const isVerbose = Object.keys(viteCmd.flags).some((x)=>[
26
+ Flag.VERBOSE,
27
+ Flag.VERBOSE_ALIAS
28
+ ].includes(x));
29
+ const logLevel = isVerbose ? LogLevel.DEBUG : pcfg.logLevel ?? LogLevel.INFO;
30
+ setLogLevel(logLevel);
31
+ return {
32
+ viteCmd,
33
+ cfg: {
34
+ ...pcfg,
35
+ name,
36
+ fileName,
37
+ logLevel,
38
+ overrides,
39
+ chunkPrefix,
40
+ shadowDom,
41
+ resolveEnvs,
42
+ externalizeLibs: externalizeLibs
43
+ }
44
+ };
45
+ };
46
+ /**
47
+ * Handles merging configurations and logs any errors.
48
+ *
49
+ * @param {UserConfig} defaultConfig - The default configuration.
50
+ * @param {UserConfig} overrides - The overrides configuration.
51
+ * @returns {UserConfig} - The merged configuration.
52
+ */ const mergeConfigs = (defaultConfig, overrides)=>{
53
+ try {
54
+ return deepMerge(defaultConfig, overrides);
55
+ } catch (err) {
56
+ logger.error('Error merging vite configs: ', err);
57
+ return defaultConfig;
58
+ }
59
+ };
60
+ /**
61
+ * Resolves glob patterns to actual package names found in package.json dependencies.
62
+ * This function is used to determine which packages should be treated as external
63
+ * in a Rollup or Vite build configuration.
64
+ *
65
+ * @param {string} path - The base path where package.json is located.
66
+ * @param {string | string[]} globs - A glob pattern or an array of glob patterns to match dependencies against.
67
+ * @returns {string[]} An array of package names that match the given glob patterns.
68
+ *
69
+ * @example
70
+ * // Example of using `getExternalDependencies` to find all dependencies starting with "my-lib" and "lodash"
71
+ * const projectPath = '/path/to/project';
72
+ * const globs = ['my-lib*', 'lodash'];
73
+ * const externalDependencies = getExternalDependencies(projectPath, globs);
74
+ * console.log(externalDependencies);
75
+ * // Output might be: ['my-lib/utils', 'my-lib/core', 'lodash']
76
+ */ const getExternalDependencies = (path, globs = [])=>{
77
+ const pkgJson = getPkgJson(path); // Assumes getLocalPkgJson is a function that reads and parses package.json
78
+ const dependencies = Object.keys(pkgJson.dependencies || {});
79
+ const globPatterns = Array.isArray(globs) ? globs : [
80
+ globs
81
+ ];
82
+ return dependencies.filter((dep)=>globPatterns.some((pattern)=>minimatch(dep, pattern)));
83
+ };
84
+ /**
85
+ * Generates a string of initials based on the input string,
86
+ * following certain rules:
87
+ * 1. A word is considered as a sequence of characters
88
+ * separated by hyphens.
89
+ * 2. If the string contains '@', any characters before
90
+ * and including the next '/' are ignored.
91
+ * 3. The first character of each word is taken to form
92
+ * the initials.
93
+ *
94
+ * @param {string} input - The input string from which to generate the initials.
95
+ * @returns {string} The initials formed by taking the first character
96
+ * of each word, after applying the specified rules.
97
+ *
98
+ * @example
99
+ * getInitials("player-script"); // returns "ps"
100
+ * getInitials("ssv-admin"); // returns "sa"
101
+ * getInitials("@nizza/customize-live"); // returns "cl"
102
+ */ function getInitials(input) {
103
+ const cleanedInput = input.includes('@') ? input.split('/')[1] : input;
104
+ const words = cleanedInput?.split('-');
105
+ const initials = words?.map((word)=>word.charAt(0)).join('');
106
+ return initials ?? '';
107
+ }
108
+
109
+ export { getExternalDependencies, getInitials, initializeConfig, mergeConfigs };