@nizza/devkit 0.1.0-alpha.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 (131) hide show
  1. package/README.md +7 -0
  2. package/dist/package.json +13 -0
  3. package/dist/src/executors/deploy/executor.d.ts +11 -0
  4. package/dist/src/executors/deploy/executor.d.ts.map +1 -0
  5. package/dist/src/executors/deploy/executor.js +27 -0
  6. package/dist/src/executors/deploy/helpers.d.ts +4 -0
  7. package/dist/src/executors/deploy/helpers.d.ts.map +1 -0
  8. package/dist/src/executors/deploy/helpers.js +40 -0
  9. package/dist/src/executors/deploy/schema.json +41 -0
  10. package/dist/src/executors/environments/executor.d.ts +16 -0
  11. package/dist/src/executors/environments/executor.d.ts.map +1 -0
  12. package/dist/src/executors/environments/executor.js +59 -0
  13. package/dist/src/executors/environments/helpers.d.ts +21 -0
  14. package/dist/src/executors/environments/helpers.d.ts.map +1 -0
  15. package/dist/src/executors/environments/helpers.js +63 -0
  16. package/dist/src/executors/environments/schema.json +9 -0
  17. package/dist/src/executors/publish/executor.d.ts +12 -0
  18. package/dist/src/executors/publish/executor.d.ts.map +1 -0
  19. package/dist/src/executors/publish/executor.js +57 -0
  20. package/dist/src/executors/publish/helpers.d.ts +19 -0
  21. package/dist/src/executors/publish/helpers.d.ts.map +1 -0
  22. package/dist/src/executors/publish/helpers.js +52 -0
  23. package/dist/src/executors/publish/schema.json +19 -0
  24. package/dist/src/executors/shared/index.d.ts +3 -0
  25. package/dist/src/executors/shared/index.d.ts.map +1 -0
  26. package/dist/src/executors/shared/index.js +7 -0
  27. package/dist/src/executors/shared/types.d.ts +4 -0
  28. package/dist/src/executors/shared/types.d.ts.map +1 -0
  29. package/dist/src/executors/shared/types.js +4 -0
  30. package/dist/src/executors/shared/utils.d.ts +34 -0
  31. package/dist/src/executors/shared/utils.d.ts.map +1 -0
  32. package/dist/src/executors/shared/utils.js +74 -0
  33. package/dist/src/executors/update-executors-file/executor.d.ts +12 -0
  34. package/dist/src/executors/update-executors-file/executor.d.ts.map +1 -0
  35. package/dist/src/executors/update-executors-file/executor.js +46 -0
  36. package/dist/src/executors/update-executors-file/helpers.d.ts +24 -0
  37. package/dist/src/executors/update-executors-file/helpers.d.ts.map +1 -0
  38. package/dist/src/executors/update-executors-file/helpers.js +70 -0
  39. package/dist/src/executors/update-executors-file/schema.json +9 -0
  40. package/dist/src/executors/update-executors-file/types.d.ts +14 -0
  41. package/dist/src/executors/update-executors-file/types.d.ts.map +1 -0
  42. package/dist/src/executors/update-executors-file/types.js +4 -0
  43. package/dist/src/executors/vtex-link/constants.d.ts +4 -0
  44. package/dist/src/executors/vtex-link/constants.d.ts.map +1 -0
  45. package/dist/src/executors/vtex-link/constants.js +24 -0
  46. package/dist/src/executors/vtex-link/executor.d.ts +5 -0
  47. package/dist/src/executors/vtex-link/executor.d.ts.map +1 -0
  48. package/dist/src/executors/vtex-link/executor.js +35 -0
  49. package/dist/src/executors/vtex-link/helpers.d.ts +77 -0
  50. package/dist/src/executors/vtex-link/helpers.d.ts.map +1 -0
  51. package/dist/src/executors/vtex-link/helpers.js +187 -0
  52. package/dist/src/executors/vtex-link/schema.json +25 -0
  53. package/dist/src/executors/vtex-link/types.d.ts +12 -0
  54. package/dist/src/executors/vtex-link/types.d.ts.map +1 -0
  55. package/dist/src/executors/vtex-link/types.js +4 -0
  56. package/dist/src/index.d.ts +2 -0
  57. package/dist/src/index.d.ts.map +1 -0
  58. package/dist/src/index.js +6 -0
  59. package/dist/src/logger.d.ts +34 -0
  60. package/dist/src/logger.d.ts.map +1 -0
  61. package/dist/src/logger.js +106 -0
  62. package/dist/src/scripts/changeset-pre-mode.d.ts +2 -0
  63. package/dist/src/scripts/changeset-pre-mode.d.ts.map +1 -0
  64. package/dist/src/scripts/changeset-pre-mode.js +41 -0
  65. package/dist/src/shared/index.d.ts +2 -0
  66. package/dist/src/shared/index.d.ts.map +1 -0
  67. package/dist/src/shared/index.js +6 -0
  68. package/dist/src/shared/utils.d.ts +11 -0
  69. package/dist/src/shared/utils.d.ts.map +1 -0
  70. package/dist/src/shared/utils.js +22 -0
  71. package/dist/src/vite/config-builder/configs/app.d.ts +4 -0
  72. package/dist/src/vite/config-builder/configs/app.d.ts.map +1 -0
  73. package/dist/src/vite/config-builder/configs/app.js +19 -0
  74. package/dist/src/vite/config-builder/configs/base.d.ts +4 -0
  75. package/dist/src/vite/config-builder/configs/base.d.ts.map +1 -0
  76. package/dist/src/vite/config-builder/configs/base.js +55 -0
  77. package/dist/src/vite/config-builder/configs/index.d.ts +7 -0
  78. package/dist/src/vite/config-builder/configs/index.d.ts.map +1 -0
  79. package/dist/src/vite/config-builder/configs/index.js +28 -0
  80. package/dist/src/vite/config-builder/configs/lib.d.ts +4 -0
  81. package/dist/src/vite/config-builder/configs/lib.d.ts.map +1 -0
  82. package/dist/src/vite/config-builder/configs/lib.js +57 -0
  83. package/dist/src/vite/config-builder/configs/script.d.ts +4 -0
  84. package/dist/src/vite/config-builder/configs/script.d.ts.map +1 -0
  85. package/dist/src/vite/config-builder/configs/script.js +42 -0
  86. package/dist/src/vite/config-builder/index.d.ts +3 -0
  87. package/dist/src/vite/config-builder/index.d.ts.map +1 -0
  88. package/dist/src/vite/config-builder/index.js +7 -0
  89. package/dist/src/vite/config-builder/main.d.ts +10 -0
  90. package/dist/src/vite/config-builder/main.d.ts.map +1 -0
  91. package/dist/src/vite/config-builder/main.js +37 -0
  92. package/dist/src/vite/config-builder/plugins.d.ts +30 -0
  93. package/dist/src/vite/config-builder/plugins.d.ts.map +1 -0
  94. package/dist/src/vite/config-builder/plugins.js +88 -0
  95. package/dist/src/vite/config-builder/shared/index.d.ts +3 -0
  96. package/dist/src/vite/config-builder/shared/index.d.ts.map +1 -0
  97. package/dist/src/vite/config-builder/shared/index.js +7 -0
  98. package/dist/src/vite/config-builder/shared/types.d.ts +155 -0
  99. package/dist/src/vite/config-builder/shared/types.d.ts.map +1 -0
  100. package/dist/src/vite/config-builder/shared/types.js +58 -0
  101. package/dist/src/vite/config-builder/shared/utils/helpers.d.ts +81 -0
  102. package/dist/src/vite/config-builder/shared/utils/helpers.d.ts.map +1 -0
  103. package/dist/src/vite/config-builder/shared/utils/helpers.js +61 -0
  104. package/dist/src/vite/config-builder/shared/utils/index.d.ts +4 -0
  105. package/dist/src/vite/config-builder/shared/utils/index.d.ts.map +1 -0
  106. package/dist/src/vite/config-builder/shared/utils/index.js +8 -0
  107. package/dist/src/vite/config-builder/shared/utils/projectConfig.d.ts +60 -0
  108. package/dist/src/vite/config-builder/shared/utils/projectConfig.d.ts.map +1 -0
  109. package/dist/src/vite/config-builder/shared/utils/projectConfig.js +85 -0
  110. package/dist/src/vite/config-builder/shared/utils/viteCommand.d.ts +24 -0
  111. package/dist/src/vite/config-builder/shared/utils/viteCommand.d.ts.map +1 -0
  112. package/dist/src/vite/config-builder/shared/utils/viteCommand.js +54 -0
  113. package/dist/src/vite/index.d.ts +3 -0
  114. package/dist/src/vite/index.d.ts.map +1 -0
  115. package/dist/src/vite/index.js +7 -0
  116. package/dist/src/vite/plugins/index.d.ts +3 -0
  117. package/dist/src/vite/plugins/index.d.ts.map +1 -0
  118. package/dist/src/vite/plugins/index.js +7 -0
  119. package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts +8 -0
  120. package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts.map +1 -0
  121. package/dist/src/vite/plugins/shadow-dom-inject-css/index.js +44 -0
  122. package/dist/src/vite/plugins/third-party-css-inject/index.d.ts +4 -0
  123. package/dist/src/vite/plugins/third-party-css-inject/index.d.ts.map +1 -0
  124. package/dist/src/vite/plugins/third-party-css-inject/index.js +13 -0
  125. package/dist/src/vite/plugins/third-party-css-inject/main.d.ts +17 -0
  126. package/dist/src/vite/plugins/third-party-css-inject/main.d.ts.map +1 -0
  127. package/dist/src/vite/plugins/third-party-css-inject/main.js +48 -0
  128. package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts +5 -0
  129. package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts.map +1 -0
  130. package/dist/src/vite/plugins/third-party-css-inject/utils.js +112 -0
  131. package/package.json +12 -0
@@ -0,0 +1,74 @@
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
+ err: function() {
13
+ return err;
14
+ },
15
+ getProjectConfig: function() {
16
+ return getProjectConfig;
17
+ },
18
+ ok: function() {
19
+ return ok;
20
+ },
21
+ runCommand: function() {
22
+ return runCommand;
23
+ },
24
+ shortId: function() {
25
+ return shortId;
26
+ }
27
+ });
28
+ const _devkit = require("@nx/devkit");
29
+ const _crypto = require("crypto");
30
+ const _child_process = require("child_process");
31
+ const _util = require("util");
32
+ const execAsync = (0, _util.promisify)(_child_process.exec);
33
+ function ok(message) {
34
+ message && _devkit.logger.info(message);
35
+ return {
36
+ success: true
37
+ };
38
+ }
39
+ function err(err, message) {
40
+ if (message) {
41
+ _devkit.logger.error(message);
42
+ } else {
43
+ _devkit.logger.error(`❌ an error occurred:`);
44
+ }
45
+ if (err) _devkit.logger.error(err);
46
+ return {
47
+ success: false
48
+ };
49
+ }
50
+ function shortId(length = 8) {
51
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
52
+ return Array.from((0, _crypto.randomBytes)(length), (b)=>chars[b % chars.length]).join('');
53
+ }
54
+ function getProjectConfig(ctx) {
55
+ const projectName = ctx.projectName || '';
56
+ const projectConfig = ctx.projectsConfigurations?.projects?.[projectName];
57
+ if (!projectConfig) throw new Error('Invalid project configuration.');
58
+ return projectConfig;
59
+ }
60
+ async function runCommand(command) {
61
+ try {
62
+ const { stdout, stderr } = await execAsync(command);
63
+ if (stderr) {
64
+ _devkit.logger.error(`Error running command:`);
65
+ _devkit.logger.error(stderr);
66
+ throw new Error(stderr);
67
+ }
68
+ _devkit.logger.info(stdout);
69
+ } catch (error) {
70
+ _devkit.logger.error(`Unexpected error running command:`);
71
+ _devkit.logger.error(error);
72
+ throw error;
73
+ }
74
+ }
@@ -0,0 +1,12 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import { type ExecutorResponse } from '../shared';
3
+ import type { ExecutorOptions } from './types';
4
+ /**
5
+ * Executor function to update paths in the executors.json file.
6
+ *
7
+ * @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
8
+ * @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
9
+ * @returns {Promise<ExecutorResponse>} The result object with a success or error status.
10
+ */
11
+ export default function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
12
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../../src/executors/update-executors-file/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAAW,KAAK,gBAAgB,EAAoB,MAAM,WAAW,CAAC;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,SAAS,CAAC;AAI9D;;;;;;GAMG;AACH,wBAA8B,WAAW,CACvC,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,eAAe,GACnB,OAAO,CAAC,gBAAgB,CAAC,CA8B3B"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, /**
6
+ * Executor function to update paths in the executors.json file.
7
+ *
8
+ * @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
9
+ * @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
10
+ * @returns {Promise<ExecutorResponse>} The result object with a success or error status.
11
+ */ "default", {
12
+ enumerable: true,
13
+ get: function() {
14
+ return runExecutor;
15
+ }
16
+ });
17
+ const _fs = require("fs");
18
+ const _path = require("path");
19
+ const _shared = require("../shared");
20
+ const _helpers = require("./helpers");
21
+ const { readFile } = _fs.promises;
22
+ async function runExecutor(_opts, ctx) {
23
+ try {
24
+ const projectConfig = (0, _shared.getProjectConfig)(ctx);
25
+ const rootDir = projectConfig.root;
26
+ const executorsFilePath = (0, _path.join)(rootDir, 'executors.json');
27
+ const distExecutorsFilePath = (0, _path.join)(rootDir, 'dist', 'executors.json');
28
+ const originalContent = JSON.parse(await readFile(executorsFilePath, 'utf8'));
29
+ // Update paths to point to './dist/' and add '.js'
30
+ const updatedExecutors = (0, _helpers.updateExecutorPaths)(originalContent.executors, false);
31
+ // Prepare the version for the dist folder by removing './dist/' from paths
32
+ const distExecutors = (0, _helpers.updateExecutorPaths)(updatedExecutors, true);
33
+ // Write both files asynchronously and in parallel
34
+ await Promise.all([
35
+ (0, _helpers.writeJsonFileAsync)(executorsFilePath, {
36
+ executors: updatedExecutors
37
+ }),
38
+ (0, _helpers.writeJsonFileAsync)(distExecutorsFilePath, {
39
+ executors: distExecutors
40
+ })
41
+ ]);
42
+ return (0, _shared.ok)(`🚀 Executors updated successfully.`);
43
+ } catch (error) {
44
+ return (0, _shared.err)(error, `❌ Error processing file: ${error}`);
45
+ }
46
+ }
@@ -0,0 +1,24 @@
1
+ import type { Executors } from './types';
2
+ /**
3
+ * Transforms the given path by adding or removing the './dist/' prefix
4
+ * and ensuring that it has the '.js' extension if it's not a JSON file.
5
+ *
6
+ * @param {string} path - The original file path to transform.
7
+ * @param {boolean} removeDist - Flag to determine if './dist/' should be removed.
8
+ * @returns {string} The transformed file path.
9
+ */
10
+ export declare const transformPath: (path: string, removeDist: boolean) => string;
11
+ /**
12
+ * Updates the executor paths for the provided executors object.
13
+ * @param {Executors} executors - The executors object from executors.json.
14
+ * @param {boolean} removeDist - Flag to determine if './dist' should be removed from paths.
15
+ * @returns - The updated executors object with transformed paths.
16
+ */
17
+ export declare const updateExecutorPaths: (executors: Executors, removeDist: boolean) => Executors;
18
+ /**
19
+ * Writes a JSON file asynchronously.
20
+ * @param {string} path - The file path where to write the JSON data.
21
+ * @param {any} data - The data to be written to the file.
22
+ */
23
+ export declare const writeJsonFileAsync: (path: string, data: any) => Promise<void>;
24
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/executors/update-executors-file/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,SAAU,MAAM,cAAc,OAAO,KAAG,MAuBjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,cACnB,SAAS,cACR,OAAO,cAapB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,SAAgB,MAAM,QAAQ,GAAG,kBAO/D,CAAC"}
@@ -0,0 +1,70 @@
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
+ transformPath: function() {
13
+ return transformPath;
14
+ },
15
+ updateExecutorPaths: function() {
16
+ return updateExecutorPaths;
17
+ },
18
+ writeJsonFileAsync: function() {
19
+ return writeJsonFileAsync;
20
+ }
21
+ });
22
+ const _devkit = require("@nx/devkit");
23
+ const _fs = require("fs");
24
+ const _ramda = require("ramda");
25
+ const { writeFile } = _fs.promises;
26
+ const transformPath = (path, removeDist)=>{
27
+ const distPrefix = './dist/';
28
+ const distRegex = /^\.\/dist\//;
29
+ const jsExt = '.js';
30
+ const isJs = (0, _ramda.endsWith)(jsExt, path);
31
+ const isJson = (0, _ramda.endsWith)('.json', path);
32
+ const hasDist = (0, _ramda.test)(distRegex, path);
33
+ // Adds './dist/' prefix to the path if it's not already present.
34
+ const addDist = (p)=>hasDist ? p : `${distPrefix}${p}`;
35
+ // Removes './dist/' prefix from the path if present.
36
+ const stripDist = (p)=>(0, _ramda.replace)(distRegex, './', p);
37
+ // Adds '.js' extension to the path if it's not a JSON file and doesn't have the extension already.
38
+ const addJs = (p)=>isJs || isJson ? p : `${p}${jsExt}`;
39
+ // Cleans up any occurrences of '/./' within the path.
40
+ const clean = (p)=>(0, _ramda.replace)(/\/\.\//g, '/', p);
41
+ const transform = (0, _ramda.cond)([
42
+ [
43
+ (0, _ramda.always)(removeDist),
44
+ (0, _ramda.pipe)(stripDist, addJs, clean)
45
+ ],
46
+ [
47
+ _ramda.T,
48
+ (0, _ramda.pipe)(addDist, addJs, clean)
49
+ ]
50
+ ]);
51
+ return transform(path);
52
+ };
53
+ const updateExecutorPaths = (executors, removeDist)=>{
54
+ return Object.entries(executors).reduce((updatedExecutors, [key, executor])=>{
55
+ updatedExecutors[key] = {
56
+ ...executor,
57
+ implementation: transformPath(executor.implementation, removeDist),
58
+ schema: transformPath(executor.schema, removeDist)
59
+ };
60
+ return updatedExecutors;
61
+ }, {});
62
+ };
63
+ const writeJsonFileAsync = async (path, data)=>{
64
+ try {
65
+ await writeFile(path, JSON.stringify(data, null, 2));
66
+ _devkit.logger.info(`✅ Updated: ${path}`);
67
+ } catch (error) {
68
+ _devkit.logger.error(`❌ Error writing file ${path}: ${error}`);
69
+ }
70
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "version": 2,
4
+ "title": "UpdateExecutorsFile executor",
5
+ "description": "",
6
+ "type": "object",
7
+ "properties": {},
8
+ "required": []
9
+ }
@@ -0,0 +1,14 @@
1
+ export interface ExecutorOptions {
2
+ }
3
+ export interface ExecutorConfig {
4
+ implementation: string;
5
+ schema: string;
6
+ description: string;
7
+ }
8
+ export interface Executors {
9
+ [executorName: string]: ExecutorConfig;
10
+ }
11
+ export interface ExecutorsFile {
12
+ executors: Executors;
13
+ }
14
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/executors/update-executors-file/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;CAAG;AAGnC,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAID,MAAM,WAAW,SAAS;IACxB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAAC;CACxC;AAGD,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,SAAS,CAAC;CACtB"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,4 @@
1
+ export declare const VTEX_PROJECT_PATH: string | undefined;
2
+ export declare const ERROR_LINKING_FLAG = "[31merror\u001B[39m: App build failed";
3
+ export declare const SUCCESS_LINKING_FLAG = "[32minfo\u001B[39m: App running";
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/executors/vtex-link/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,oBAA8B,CAAC;AAC7D,eAAO,MAAM,kBAAkB,0CAAqC,CAAC;AACrE,eAAO,MAAM,oBAAoB,oCAA+B,CAAC"}
@@ -0,0 +1,24 @@
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
+ ERROR_LINKING_FLAG: function() {
13
+ return ERROR_LINKING_FLAG;
14
+ },
15
+ SUCCESS_LINKING_FLAG: function() {
16
+ return SUCCESS_LINKING_FLAG;
17
+ },
18
+ VTEX_PROJECT_PATH: function() {
19
+ return VTEX_PROJECT_PATH;
20
+ }
21
+ });
22
+ const VTEX_PROJECT_PATH = process.env.NZ_VTEX_PROJECT;
23
+ const ERROR_LINKING_FLAG = '[31merror: App build failed';
24
+ const SUCCESS_LINKING_FLAG = '[32minfo: App running';
@@ -0,0 +1,5 @@
1
+ import { type ExecutorContext } from '@nx/devkit';
2
+ import { type ExecutorResponse } from '../shared';
3
+ import type { ExecutorOptions } from './types';
4
+ export default function runExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
5
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../../src/executors/vtex-link/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAA6B,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7E,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,SAAS,CAAC;AAI9D,wBAA8B,WAAW,CACvC,IAAI,EAAE,eAAe,EACrB,GAAG,EAAE,eAAe,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAwB3B"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return runExecutor;
9
+ }
10
+ });
11
+ const _path = require("path");
12
+ const _shared = require("../shared");
13
+ const _helpers = require("./helpers");
14
+ const VTEX_PROJECT_PATH = process.env.NZ_VTEX_PROJECT;
15
+ async function runExecutor(opts, ctx) {
16
+ try {
17
+ const { rollback, skipLink, packageOrg } = opts;
18
+ const projectName = ctx.projectName || '';
19
+ (0, _helpers.validateEnvironment)();
20
+ const projectConfig = (0, _shared.getProjectConfig)(ctx);
21
+ const projectRoot = projectConfig.root;
22
+ const vtexProjectPath = (0, _path.resolve)(VTEX_PROJECT_PATH, 'react');
23
+ const sharedContext = {
24
+ packageOrg,
25
+ projectRoot,
26
+ projectName,
27
+ vtexProjectPath
28
+ };
29
+ if (rollback) return await (0, _helpers.performRollback)(sharedContext);
30
+ await (0, _helpers.buildAndLink)(sharedContext, skipLink);
31
+ return (0, _shared.ok)();
32
+ } catch (error) {
33
+ return (0, _shared.err)(error);
34
+ }
35
+ }
@@ -0,0 +1,77 @@
1
+ import type { SharedContext } from './types';
2
+ /**
3
+ * Links the local package to the VTEX environment.
4
+ *
5
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
6
+ * @returns {Promise<void>} A promise that resolves when the package is linked or rejects on error.
7
+ */
8
+ export declare function vtexLink(ctx: SharedContext): Promise<void>;
9
+ /**
10
+ * Updates the package.json file within the VTEX project to use the local version of the package.
11
+ *
12
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
13
+ * @param {string} packageName - The name of the package to link.
14
+ * @returns {Promise<void>} A promise that resolves when the package.json is updated.
15
+ */
16
+ export declare function changePackageJsonFromVtexProject(ctx: SharedContext, packageName: string): Promise<void>;
17
+ /**
18
+ * Restores the original package.json from the backup created before modifications.
19
+ *
20
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
21
+ * @returns {Promise<void>} A promise that resolves when the package.json is restored.
22
+ */
23
+ export declare function restorePackageJsonFromVtexProject(ctx: SharedContext): Promise<void>;
24
+ /**
25
+ * Renames the generated package file with a unique identifier.
26
+ *
27
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
28
+ * @returns {Promise<string>} A promise that resolves with the new name of the package.
29
+ */
30
+ export declare function renamePackage(ctx: SharedContext): Promise<string>;
31
+ /**
32
+ * Creates a pnpm package for uploading to VTEX.
33
+ *
34
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
35
+ * @returns {Promise<string>} A promise that resolves with the name of the created package.
36
+ */
37
+ export declare function createPackage(ctx: SharedContext): Promise<string>;
38
+ /**
39
+ * Searches for and lists all outdated packages in the VTEX project directory.
40
+ *
41
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
42
+ * @returns {Promise<string[]>} A promise that resolves with a list of deprecated package names.
43
+ */
44
+ export declare function findLastPackages(ctx: SharedContext): Promise<string[]>;
45
+ /**
46
+ * Removes all outdated packages in the VTEX project directory.
47
+ *
48
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
49
+ * @returns {Promise<void>} A promise that resolves when the old packages are removed.
50
+ */
51
+ export declare function removeOldPackages(ctx: SharedContext): Promise<void>;
52
+ /**
53
+ * Moves a package to the VTEX project directory.
54
+ *
55
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
56
+ * @param {string} packageName - The name of the package to move.
57
+ * @returns {Promise<void>} A promise that resolves when the package is moved successfully.
58
+ */
59
+ export declare function movePackage(ctx: SharedContext, packageName: string): Promise<void>;
60
+ /**
61
+ * Builds the package, moves it to the VTEX project, and updates the project's package.json.
62
+ *
63
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
64
+ * @returns {Promise<void>} A promise that resolves when the build is complete.
65
+ */
66
+ export declare function buildPackage(ctx: SharedContext): Promise<void>;
67
+ /**
68
+ * Cleans the VTEX project by removing old packages and restoring the original package.json.
69
+ *
70
+ * @param {SharedContext} ctx - The shared context containing paths and configurations.
71
+ * @returns {Promise<void>} A promise that resolves when the clean-up is complete.
72
+ */
73
+ export declare function clean(ctx: SharedContext): Promise<void>;
74
+ export declare function validateEnvironment(): void;
75
+ export declare function performRollback(sharedContext: SharedContext): Promise<import("../shared").ExecutorResponse>;
76
+ export declare function buildAndLink(sharedContext: SharedContext, skipLink?: boolean): Promise<void>;
77
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/executors/vtex-link/helpers.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAO7C;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAgC1D;AAED;;;;;;GAMG;AACH,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,aAAa,EAClB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;GAKG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,aAAa,GACjB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBvE;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAQvE;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAe5E;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzE;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,aAAa,EAClB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAOpE;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAK7D;AAED,wBAAgB,mBAAmB,SAKlC;AAED,wBAAsB,eAAe,CAAC,aAAa,EAAE,aAAa,iDAGjE;AAED,wBAAsB,YAAY,CAChC,aAAa,EAAE,aAAa,EAC5B,QAAQ,UAAQ,iBAKjB"}
@@ -0,0 +1,187 @@
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
+ buildAndLink: function() {
13
+ return buildAndLink;
14
+ },
15
+ buildPackage: function() {
16
+ return buildPackage;
17
+ },
18
+ changePackageJsonFromVtexProject: function() {
19
+ return changePackageJsonFromVtexProject;
20
+ },
21
+ clean: function() {
22
+ return clean;
23
+ },
24
+ createPackage: function() {
25
+ return createPackage;
26
+ },
27
+ findLastPackages: function() {
28
+ return findLastPackages;
29
+ },
30
+ movePackage: function() {
31
+ return movePackage;
32
+ },
33
+ performRollback: function() {
34
+ return performRollback;
35
+ },
36
+ removeOldPackages: function() {
37
+ return removeOldPackages;
38
+ },
39
+ renamePackage: function() {
40
+ return renamePackage;
41
+ },
42
+ restorePackageJsonFromVtexProject: function() {
43
+ return restorePackageJsonFromVtexProject;
44
+ },
45
+ validateEnvironment: function() {
46
+ return validateEnvironment;
47
+ },
48
+ vtexLink: function() {
49
+ return vtexLink;
50
+ }
51
+ });
52
+ const _devkit = require("@nx/devkit");
53
+ const _child_process = require("child_process");
54
+ const _fs = require("fs");
55
+ const _path = require("path");
56
+ const _util = require("util");
57
+ const _shared = require("../../shared");
58
+ const _shared1 = require("../shared");
59
+ const _constants = require("./constants");
60
+ const execAsync = (0, _util.promisify)(_child_process.exec);
61
+ const getPkgJsonPath = (vtexProjectPath)=>(0, _path.resolve)(vtexProjectPath, 'package.json');
62
+ function vtexLink(ctx) {
63
+ const { vtexProjectPath } = ctx;
64
+ return new Promise((resolve, reject)=>{
65
+ _devkit.logger.info('🔗 Linking package to VTEX...');
66
+ const link = (0, _child_process.spawn)('vtex', [
67
+ 'link',
68
+ '-u'
69
+ ], {
70
+ cwd: vtexProjectPath,
71
+ detached: true
72
+ });
73
+ link.stdout.on('data', (chunk)=>{
74
+ const data = chunk.toString('utf8');
75
+ if (data.includes(_constants.ERROR_LINKING_FLAG)) {
76
+ reject('could not link package in VTEX');
77
+ }
78
+ if (data.includes(_constants.SUCCESS_LINKING_FLAG)) {
79
+ link.pid && process.kill(-link.pid);
80
+ setTimeout(()=>{
81
+ link.kill();
82
+ _devkit.logger.info('✅ Successfully linked package to VTEX.');
83
+ }, 200);
84
+ resolve();
85
+ }
86
+ _devkit.logger.info(data);
87
+ });
88
+ link.on('error', (error)=>reject(error.message));
89
+ });
90
+ }
91
+ async function changePackageJsonFromVtexProject(ctx, packageName) {
92
+ const { vtexProjectPath, projectName, packageOrg } = ctx;
93
+ const pkgJsonPath = getPkgJsonPath(vtexProjectPath);
94
+ // Make backup of package.json
95
+ await _fs.promises.copyFile(pkgJsonPath, (0, _path.join)(vtexProjectPath, 'package.json.nxback'));
96
+ _devkit.logger.info('🔃 Created package.json backup.');
97
+ // Find and edit value "@${packageOrg}/${projectName}" dependency
98
+ const packageJson = (0, _shared.getPkgJson)(vtexProjectPath);
99
+ const newPackageJson = {
100
+ ...packageJson,
101
+ dependencies: {
102
+ ...packageJson.dependencies,
103
+ [`@${packageOrg}/${projectName}`]: `file:./${packageName}`
104
+ }
105
+ };
106
+ await _fs.promises.unlink(pkgJsonPath);
107
+ await _fs.promises.writeFile(pkgJsonPath, JSON.stringify(newPackageJson, null, 2));
108
+ _devkit.logger.info('📝 Updated package.json in VTEX project.');
109
+ }
110
+ async function restorePackageJsonFromVtexProject(ctx) {
111
+ const { vtexProjectPath } = ctx;
112
+ const pkgJsonPath = getPkgJsonPath(vtexProjectPath);
113
+ const backupFile = (0, _path.resolve)(vtexProjectPath, 'package.json.nxback');
114
+ if (!(0, _fs.existsSync)(backupFile)) return;
115
+ await _fs.promises.unlink(pkgJsonPath);
116
+ await _fs.promises.copyFile(backupFile, pkgJsonPath);
117
+ await _fs.promises.unlink(backupFile);
118
+ _devkit.logger.info('🔄 Restored package.json in VTEX project.');
119
+ }
120
+ async function renamePackage(ctx) {
121
+ const { projectRoot, projectName, packageOrg } = ctx;
122
+ const packageJson = (0, _shared.getPkgJson)('./');
123
+ const oldName = `${packageOrg}-${projectName}-${packageJson.version}.tgz`;
124
+ const oldPath = (0, _path.join)(projectRoot, oldName);
125
+ const newName = `${packageOrg}-${projectName}-${packageJson.version}-${(0, _shared1.shortId)(8)}.tgz`;
126
+ const newPath = (0, _path.join)(projectRoot, newName);
127
+ await _fs.promises.rename(oldPath, newPath);
128
+ _devkit.logger.info(`🏷️ New package name: ${newName}`);
129
+ return newName;
130
+ }
131
+ async function createPackage(ctx) {
132
+ const command = 'pnpm pack';
133
+ const { stderr } = await execAsync(command);
134
+ if (stderr) _devkit.logger.error(stderr);
135
+ _devkit.logger.info('📦 Package generated successfully.');
136
+ return renamePackage(ctx);
137
+ }
138
+ async function findLastPackages(ctx) {
139
+ const { vtexProjectPath, projectName, packageOrg } = ctx;
140
+ const matchedFiles = [];
141
+ const files = await _fs.promises.readdir(vtexProjectPath);
142
+ for (const file of files){
143
+ const regex = new RegExp(`^${packageOrg}-${projectName}-.*$`);
144
+ if (regex.test(file)) {
145
+ matchedFiles.push(file);
146
+ _devkit.logger.info(`🔍 Found deprecated package: ${file}`);
147
+ }
148
+ }
149
+ return matchedFiles;
150
+ }
151
+ async function removeOldPackages(ctx) {
152
+ const { vtexProjectPath } = ctx;
153
+ const files = await findLastPackages(ctx);
154
+ const toRemove = files.map((x)=>_fs.promises.unlink((0, _path.resolve)(vtexProjectPath, x)));
155
+ await Promise.all(toRemove);
156
+ _devkit.logger.info('🗑️ Removed old packages in VTEX project.');
157
+ }
158
+ async function movePackage(ctx, packageName) {
159
+ const { vtexProjectPath } = ctx;
160
+ await _fs.promises.rename((0, _path.resolve)(packageName), (0, _path.join)(vtexProjectPath, packageName));
161
+ _devkit.logger.info(`🚚 Moved package "${packageName}" to VTEX project.`);
162
+ }
163
+ async function buildPackage(ctx) {
164
+ const packageName = await createPackage(ctx);
165
+ await Promise.all([
166
+ movePackage(ctx, packageName),
167
+ changePackageJsonFromVtexProject(ctx, packageName)
168
+ ]);
169
+ }
170
+ async function clean(ctx) {
171
+ await Promise.all([
172
+ removeOldPackages(ctx),
173
+ restorePackageJsonFromVtexProject(ctx)
174
+ ]);
175
+ }
176
+ function validateEnvironment() {
177
+ if (!_constants.VTEX_PROJECT_PATH) throw new Error('The NZ_VTEX_PROJECT environment variable is missing. Set it in the project root in a .env.local file.');
178
+ }
179
+ async function performRollback(sharedContext) {
180
+ await clean(sharedContext);
181
+ return (0, _shared1.ok)();
182
+ }
183
+ async function buildAndLink(sharedContext, skipLink = false) {
184
+ await clean(sharedContext);
185
+ await buildPackage(sharedContext);
186
+ if (!skipLink) await vtexLink(sharedContext);
187
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "version": 2,
4
+ "title": "VtexLink executor",
5
+ "description": "",
6
+ "type": "object",
7
+ "properties": {
8
+ "packageOrg": {
9
+ "type": "string",
10
+ "description": "Name of the npm organization in which the packages are published"
11
+ },
12
+ "rollback": {
13
+ "type": "boolean",
14
+ "description": "Perform a rollback.",
15
+ "default": false
16
+ },
17
+ "skipLink": {
18
+ "type": "boolean",
19
+ "description": "Skip the linking step.",
20
+ "default": false
21
+ }
22
+ },
23
+ "required": [],
24
+ "additionalProperties": true
25
+ }
@@ -0,0 +1,12 @@
1
+ export interface SharedContext {
2
+ vtexProjectPath: string;
3
+ projectRoot: string;
4
+ projectName: string;
5
+ packageOrg: string;
6
+ }
7
+ export interface ExecutorOptions {
8
+ packageOrg: string;
9
+ rollback?: boolean;
10
+ skipLink?: boolean;
11
+ }
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/executors/vtex-link/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}