@nizza/devkit 0.1.0-alpha.2 → 0.1.0-alpha.3
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.
- package/dist/cjs/executors/deploy/helpers.d.ts +4 -0
- package/dist/cjs/executors/deploy/helpers.js +26 -0
- package/dist/cjs/executors/deploy/index.d.ts +11 -0
- package/dist/cjs/executors/deploy/index.js +22 -0
- package/dist/{src → cjs}/executors/environments/helpers.d.ts +4 -4
- package/dist/cjs/executors/environments/helpers.js +63 -0
- package/dist/{src/executors/environments/executor.d.ts → cjs/executors/environments/index.d.ts} +5 -5
- package/dist/cjs/executors/environments/index.js +54 -0
- package/dist/{src → cjs}/executors/publish/helpers.d.ts +3 -3
- package/dist/cjs/executors/publish/helpers.js +51 -0
- package/dist/cjs/executors/publish/index.d.ts +12 -0
- package/dist/cjs/executors/publish/index.js +53 -0
- package/dist/cjs/executors/shared/utils.d.ts +34 -0
- package/dist/cjs/executors/shared/utils.js +78 -0
- package/dist/{src → cjs}/executors/update-executors-file/helpers.d.ts +7 -6
- package/dist/cjs/executors/update-executors-file/helpers.js +76 -0
- package/dist/{src/executors/update-executors-file/executor.d.ts → cjs/executors/update-executors-file/index.d.ts} +5 -5
- package/dist/cjs/executors/update-executors-file/index.js +41 -0
- package/dist/cjs/executors/vtex-link/constants.d.ts +4 -0
- package/dist/cjs/executors/vtex-link/constants.js +9 -0
- package/dist/{src → cjs}/executors/vtex-link/helpers.d.ts +15 -15
- package/dist/cjs/executors/vtex-link/helpers.js +206 -0
- package/dist/cjs/executors/vtex-link/index.d.ts +5 -0
- package/dist/cjs/executors/vtex-link/index.js +30 -0
- package/dist/cjs/index-0ce2daf7.d.ts +2 -0
- package/dist/cjs/index-17143e35.d.ts +2 -0
- package/dist/cjs/index-3080371d.d.ts +3 -0
- package/dist/cjs/index-f6330edc.d.ts +2 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +59 -0
- package/dist/cjs/scripts/changeset-pre-mode.d.ts +2 -0
- package/dist/cjs/scripts/changeset-pre-mode.js +41 -0
- package/dist/{src → cjs/shared}/logger.d.ts +5 -6
- package/dist/cjs/shared/logger.js +98 -0
- package/dist/{src → cjs}/shared/utils.d.ts +2 -2
- package/dist/cjs/shared/utils.js +25 -0
- package/dist/{src/executors/vtex-link/types.d.ts → cjs/types-1282e639.d.ts} +3 -3
- package/dist/cjs/types-7377dcc9.d.ts +4 -0
- package/dist/cjs/types-763439e4.d.ts +14 -0
- package/dist/cjs/vite/config-builder/configs/app.d.ts +4 -0
- package/dist/cjs/vite/config-builder/configs/app.js +13 -0
- package/dist/cjs/vite/config-builder/configs/base.d.ts +4 -0
- package/dist/cjs/vite/config-builder/configs/base.js +57 -0
- package/dist/cjs/vite/config-builder/configs/index.d.ts +7 -0
- package/dist/cjs/vite/config-builder/configs/index.js +36 -0
- package/dist/cjs/vite/config-builder/configs/lib.d.ts +4 -0
- package/dist/cjs/vite/config-builder/configs/lib.js +57 -0
- package/dist/cjs/vite/config-builder/configs/script.d.ts +4 -0
- package/dist/cjs/vite/config-builder/configs/script.js +45 -0
- package/dist/cjs/vite/config-builder/main.d.ts +10 -0
- package/dist/cjs/vite/config-builder/main.js +43 -0
- package/dist/{src → cjs}/vite/config-builder/plugins.d.ts +7 -7
- package/dist/cjs/vite/config-builder/plugins.js +95 -0
- package/dist/{src → cjs}/vite/config-builder/shared/types.d.ts +17 -17
- package/dist/cjs/vite/config-builder/shared/types.js +33 -0
- package/dist/{src → cjs}/vite/config-builder/shared/utils/helpers.d.ts +10 -10
- package/dist/cjs/vite/config-builder/shared/utils/helpers.js +124 -0
- package/dist/{src → cjs}/vite/config-builder/shared/utils/projectConfig.d.ts +8 -8
- package/dist/cjs/vite/config-builder/shared/utils/projectConfig.js +114 -0
- package/dist/{src → cjs}/vite/config-builder/shared/utils/viteCommand.d.ts +4 -4
- package/dist/cjs/vite/config-builder/shared/utils/viteCommand.js +59 -0
- package/dist/cjs/vite/plugins/shadow-dom-inject-css/index.d.ts +7 -0
- package/dist/{src → cjs}/vite/plugins/shadow-dom-inject-css/index.js +4 -19
- package/dist/cjs/vite/plugins/third-party-css-inject/main.d.ts +17 -0
- package/dist/{src → cjs}/vite/plugins/third-party-css-inject/main.js +13 -14
- package/dist/cjs/vite/plugins/third-party-css-inject/utils.d.ts +5 -0
- package/dist/{src → cjs}/vite/plugins/third-party-css-inject/utils.js +8 -20
- package/dist/esm/executors/deploy/helpers.d.ts +4 -0
- package/dist/esm/executors/deploy/helpers.js +22 -0
- package/dist/esm/executors/deploy/index.d.ts +11 -0
- package/dist/esm/executors/deploy/index.js +20 -0
- package/dist/esm/executors/deploy/schema.json +41 -0
- package/dist/esm/executors/environments/helpers.d.ts +21 -0
- package/dist/esm/executors/environments/helpers.js +59 -0
- package/dist/esm/executors/environments/index.d.ts +16 -0
- package/dist/{src/executors/environments/executor.js → esm/executors/environments/index.js} +23 -30
- package/dist/esm/executors/environments/schema.json +9 -0
- package/dist/esm/executors/publish/helpers.d.ts +19 -0
- package/dist/esm/executors/publish/helpers.js +48 -0
- package/dist/esm/executors/publish/index.d.ts +12 -0
- package/dist/esm/executors/publish/index.js +51 -0
- package/dist/esm/executors/publish/schema.json +19 -0
- package/dist/esm/executors/shared/utils.d.ts +34 -0
- package/dist/esm/executors/shared/utils.js +72 -0
- package/dist/esm/executors/update-executors-file/helpers.d.ts +25 -0
- package/dist/esm/executors/update-executors-file/helpers.js +71 -0
- package/dist/esm/executors/update-executors-file/index.d.ts +12 -0
- package/dist/esm/executors/update-executors-file/index.js +39 -0
- package/dist/esm/executors/update-executors-file/schema.json +9 -0
- package/dist/esm/executors/vtex-link/constants.d.ts +4 -0
- package/dist/esm/executors/vtex-link/constants.js +5 -0
- package/dist/esm/executors/vtex-link/helpers.d.ts +77 -0
- package/dist/esm/executors/vtex-link/helpers.js +192 -0
- package/dist/esm/executors/vtex-link/index.d.ts +5 -0
- package/dist/esm/executors/vtex-link/index.js +28 -0
- package/dist/esm/executors/vtex-link/schema.json +25 -0
- package/dist/esm/index-0ce2daf7.d.ts +2 -0
- package/dist/esm/index-17143e35.d.ts +2 -0
- package/dist/esm/index-3080371d.d.ts +3 -0
- package/dist/esm/index-f6330edc.d.ts +2 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/scripts/changeset-pre-mode.d.ts +2 -0
- package/dist/esm/scripts/changeset-pre-mode.js +39 -0
- package/dist/esm/shared/logger.d.ts +33 -0
- package/dist/{src → esm/shared}/logger.js +28 -39
- package/dist/esm/shared/utils.d.ts +11 -0
- package/dist/esm/shared/utils.js +23 -0
- package/dist/esm/types-1282e639.d.ts +12 -0
- package/dist/esm/types-7377dcc9.d.ts +4 -0
- package/dist/esm/types-763439e4.d.ts +14 -0
- package/dist/esm/vite/config-builder/configs/app.d.ts +4 -0
- package/dist/esm/vite/config-builder/configs/app.js +11 -0
- package/dist/esm/vite/config-builder/configs/base.d.ts +4 -0
- package/dist/{src → esm}/vite/config-builder/configs/base.js +22 -22
- package/dist/esm/vite/config-builder/configs/index.d.ts +7 -0
- package/dist/esm/vite/config-builder/configs/index.js +30 -0
- package/dist/esm/vite/config-builder/configs/lib.d.ts +4 -0
- package/dist/{src → esm}/vite/config-builder/configs/lib.js +16 -18
- package/dist/esm/vite/config-builder/configs/script.d.ts +4 -0
- package/dist/esm/vite/config-builder/configs/script.js +43 -0
- package/dist/esm/vite/config-builder/main.d.ts +10 -0
- package/dist/esm/vite/config-builder/main.js +41 -0
- package/dist/esm/vite/config-builder/plugins.d.ts +30 -0
- package/dist/esm/vite/config-builder/plugins.js +89 -0
- package/dist/esm/vite/config-builder/shared/types.d.ts +155 -0
- package/dist/{src → esm}/vite/config-builder/shared/types.js +2 -27
- package/dist/esm/vite/config-builder/shared/utils/helpers.d.ts +81 -0
- package/dist/esm/vite/config-builder/shared/utils/helpers.js +98 -0
- package/dist/esm/vite/config-builder/shared/utils/projectConfig.d.ts +60 -0
- package/dist/esm/vite/config-builder/shared/utils/projectConfig.js +109 -0
- package/dist/esm/vite/config-builder/shared/utils/viteCommand.d.ts +24 -0
- package/dist/esm/vite/config-builder/shared/utils/viteCommand.js +56 -0
- package/dist/esm/vite/plugins/shadow-dom-inject-css/index.d.ts +7 -0
- package/dist/esm/vite/plugins/shadow-dom-inject-css/index.js +27 -0
- package/dist/esm/vite/plugins/third-party-css-inject/main.d.ts +17 -0
- package/dist/esm/vite/plugins/third-party-css-inject/main.js +45 -0
- package/dist/esm/vite/plugins/third-party-css-inject/utils.d.ts +5 -0
- package/dist/esm/vite/plugins/third-party-css-inject/utils.js +97 -0
- package/dist/executors.json +29 -0
- package/package.json +36 -5
- package/dist/package.json +0 -13
- package/dist/src/executors/deploy/executor.d.ts +0 -11
- package/dist/src/executors/deploy/executor.d.ts.map +0 -1
- package/dist/src/executors/deploy/executor.js +0 -27
- package/dist/src/executors/deploy/helpers.d.ts +0 -4
- package/dist/src/executors/deploy/helpers.d.ts.map +0 -1
- package/dist/src/executors/deploy/helpers.js +0 -40
- package/dist/src/executors/environments/executor.d.ts.map +0 -1
- package/dist/src/executors/environments/helpers.d.ts.map +0 -1
- package/dist/src/executors/environments/helpers.js +0 -63
- package/dist/src/executors/publish/executor.d.ts +0 -12
- package/dist/src/executors/publish/executor.d.ts.map +0 -1
- package/dist/src/executors/publish/executor.js +0 -58
- package/dist/src/executors/publish/helpers.d.ts.map +0 -1
- package/dist/src/executors/publish/helpers.js +0 -52
- package/dist/src/executors/shared/index.d.ts +0 -3
- package/dist/src/executors/shared/index.d.ts.map +0 -1
- package/dist/src/executors/shared/index.js +0 -7
- package/dist/src/executors/shared/types.d.ts +0 -4
- package/dist/src/executors/shared/types.d.ts.map +0 -1
- package/dist/src/executors/shared/types.js +0 -4
- package/dist/src/executors/shared/utils.d.ts +0 -34
- package/dist/src/executors/shared/utils.d.ts.map +0 -1
- package/dist/src/executors/shared/utils.js +0 -78
- package/dist/src/executors/update-executors-file/executor.d.ts.map +0 -1
- package/dist/src/executors/update-executors-file/executor.js +0 -46
- package/dist/src/executors/update-executors-file/helpers.d.ts.map +0 -1
- package/dist/src/executors/update-executors-file/helpers.js +0 -70
- package/dist/src/executors/update-executors-file/types.d.ts +0 -14
- package/dist/src/executors/update-executors-file/types.d.ts.map +0 -1
- package/dist/src/executors/update-executors-file/types.js +0 -4
- package/dist/src/executors/vtex-link/constants.d.ts +0 -4
- package/dist/src/executors/vtex-link/constants.d.ts.map +0 -1
- package/dist/src/executors/vtex-link/constants.js +0 -24
- package/dist/src/executors/vtex-link/executor.d.ts +0 -5
- package/dist/src/executors/vtex-link/executor.d.ts.map +0 -1
- package/dist/src/executors/vtex-link/executor.js +0 -35
- package/dist/src/executors/vtex-link/helpers.d.ts.map +0 -1
- package/dist/src/executors/vtex-link/helpers.js +0 -187
- package/dist/src/executors/vtex-link/types.d.ts.map +0 -1
- package/dist/src/executors/vtex-link/types.js +0 -4
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -6
- package/dist/src/logger.d.ts.map +0 -1
- package/dist/src/scripts/changeset-pre-mode.d.ts +0 -2
- package/dist/src/scripts/changeset-pre-mode.d.ts.map +0 -1
- package/dist/src/scripts/changeset-pre-mode.js +0 -41
- package/dist/src/shared/index.d.ts +0 -2
- package/dist/src/shared/index.d.ts.map +0 -1
- package/dist/src/shared/index.js +0 -6
- package/dist/src/shared/utils.d.ts.map +0 -1
- package/dist/src/shared/utils.js +0 -22
- package/dist/src/vite/config-builder/configs/app.d.ts +0 -4
- package/dist/src/vite/config-builder/configs/app.d.ts.map +0 -1
- package/dist/src/vite/config-builder/configs/app.js +0 -19
- package/dist/src/vite/config-builder/configs/base.d.ts +0 -4
- package/dist/src/vite/config-builder/configs/base.d.ts.map +0 -1
- package/dist/src/vite/config-builder/configs/index.d.ts +0 -7
- package/dist/src/vite/config-builder/configs/index.d.ts.map +0 -1
- package/dist/src/vite/config-builder/configs/index.js +0 -28
- package/dist/src/vite/config-builder/configs/lib.d.ts +0 -4
- package/dist/src/vite/config-builder/configs/lib.d.ts.map +0 -1
- package/dist/src/vite/config-builder/configs/script.d.ts +0 -4
- package/dist/src/vite/config-builder/configs/script.d.ts.map +0 -1
- package/dist/src/vite/config-builder/configs/script.js +0 -42
- package/dist/src/vite/config-builder/index.d.ts +0 -3
- package/dist/src/vite/config-builder/index.d.ts.map +0 -1
- package/dist/src/vite/config-builder/index.js +0 -7
- package/dist/src/vite/config-builder/main.d.ts +0 -10
- package/dist/src/vite/config-builder/main.d.ts.map +0 -1
- package/dist/src/vite/config-builder/main.js +0 -37
- package/dist/src/vite/config-builder/plugins.d.ts.map +0 -1
- package/dist/src/vite/config-builder/plugins.js +0 -88
- package/dist/src/vite/config-builder/shared/index.d.ts +0 -3
- package/dist/src/vite/config-builder/shared/index.d.ts.map +0 -1
- package/dist/src/vite/config-builder/shared/index.js +0 -7
- package/dist/src/vite/config-builder/shared/types.d.ts.map +0 -1
- package/dist/src/vite/config-builder/shared/utils/helpers.d.ts.map +0 -1
- package/dist/src/vite/config-builder/shared/utils/helpers.js +0 -61
- package/dist/src/vite/config-builder/shared/utils/index.d.ts +0 -4
- package/dist/src/vite/config-builder/shared/utils/index.d.ts.map +0 -1
- package/dist/src/vite/config-builder/shared/utils/index.js +0 -8
- package/dist/src/vite/config-builder/shared/utils/projectConfig.d.ts.map +0 -1
- package/dist/src/vite/config-builder/shared/utils/projectConfig.js +0 -85
- package/dist/src/vite/config-builder/shared/utils/viteCommand.d.ts.map +0 -1
- package/dist/src/vite/config-builder/shared/utils/viteCommand.js +0 -54
- package/dist/src/vite/index.d.ts +0 -3
- package/dist/src/vite/index.d.ts.map +0 -1
- package/dist/src/vite/index.js +0 -7
- package/dist/src/vite/plugins/index.d.ts +0 -3
- package/dist/src/vite/plugins/index.d.ts.map +0 -1
- package/dist/src/vite/plugins/index.js +0 -7
- package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts +0 -8
- package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts.map +0 -1
- package/dist/src/vite/plugins/third-party-css-inject/index.d.ts +0 -4
- package/dist/src/vite/plugins/third-party-css-inject/index.d.ts.map +0 -1
- package/dist/src/vite/plugins/third-party-css-inject/index.js +0 -13
- package/dist/src/vite/plugins/third-party-css-inject/main.d.ts +0 -17
- package/dist/src/vite/plugins/third-party-css-inject/main.d.ts.map +0 -1
- package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts +0 -5
- package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts.map +0 -1
- /package/dist/{src → cjs}/executors/deploy/schema.json +0 -0
- /package/dist/{src → cjs}/executors/environments/schema.json +0 -0
- /package/dist/{src → cjs}/executors/publish/schema.json +0 -0
- /package/dist/{src → cjs}/executors/update-executors-file/schema.json +0 -0
- /package/dist/{src → cjs}/executors/vtex-link/schema.json +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
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 {string} coreEnvPath - The path to the core environment file.
|
|
10
|
+
* @returns {string} The content of the environment file.
|
|
11
|
+
*/ async function createEnvironmentFileContent(coreEnvPath) {
|
|
12
|
+
return `
|
|
13
|
+
import { Environment } from '@nizza/core';
|
|
14
|
+
import coreEnvs from '${coreEnvPath}';
|
|
15
|
+
|
|
16
|
+
const config = {
|
|
17
|
+
...coreEnvs,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const environment: Environment<typeof config> = config;
|
|
21
|
+
export default environment;
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Ensures that the given directory exists, creating it if it does not.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} dir - The path to the directory to check/create.
|
|
28
|
+
*/ async function ensureDirectoryExists(dir) {
|
|
29
|
+
try {
|
|
30
|
+
await access(dir);
|
|
31
|
+
logger.info('✅ Directory exists.');
|
|
32
|
+
} catch {
|
|
33
|
+
logger.info('📁 Directory does not exist. Creating...');
|
|
34
|
+
await mkdir(dir, {
|
|
35
|
+
recursive: true
|
|
36
|
+
});
|
|
37
|
+
logger.info('📁 Directory created.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Writes environment files to the given base path if they do not already exist.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} basePath - The base directory where the files should be written.
|
|
44
|
+
* @param {Record<string, string>} files - An object containing filenames and their respective content.
|
|
45
|
+
*/ async function writeFilesIfNotExist(basePath, files) {
|
|
46
|
+
await Promise.all(Object.entries(files).map(async ([filename, content])=>{
|
|
47
|
+
const filePath = join(basePath, filename);
|
|
48
|
+
try {
|
|
49
|
+
await access(filePath);
|
|
50
|
+
logger.info(`✅ The file "${filename}" already exists.`);
|
|
51
|
+
} catch {
|
|
52
|
+
logger.warn(`📝 The file "${filename}" does not exist. Creating...`);
|
|
53
|
+
await writeFile(filePath, content);
|
|
54
|
+
logger.info(`🎉 The file "${filename}" has been created.`);
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { createEnvironmentFileContent, ensureDirectoryExists, writeFilesIfNotExist };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { ExecutorResponse } from "../../index-f6330edc.js";
|
|
3
|
+
interface ExecutorOptions {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The executor function to create environment files.
|
|
7
|
+
* Ensures that the directory for the environment files exists and creates the files
|
|
8
|
+
* if they do not exist already. Files created are 'environment.ts', 'environment.prod.ts',
|
|
9
|
+
* and 'environment.staging.ts'.
|
|
10
|
+
*
|
|
11
|
+
* @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
|
|
12
|
+
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
13
|
+
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
14
|
+
*/
|
|
15
|
+
declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
|
|
16
|
+
export { ExecutorOptions, runExecutor as default };
|
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, /**
|
|
6
|
-
* The executor function to create environment files.
|
|
7
|
-
* Ensures that the directory for the environment files exists and creates the files
|
|
8
|
-
* if they do not exist already. Files created are 'environment.ts', 'environment.prod.ts',
|
|
9
|
-
* and 'environment.staging.ts'.
|
|
10
|
-
*
|
|
11
|
-
* @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
|
|
12
|
-
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
13
|
-
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
14
|
-
*/ "default", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function() {
|
|
17
|
-
return runExecutor;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
const _path = require("path");
|
|
21
|
-
const _shared = require("../shared");
|
|
22
|
-
const _helpers = require("./helpers");
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { getProjectConfig, ok, err } from '../shared/utils.js';
|
|
3
|
+
import { ensureDirectoryExists, createEnvironmentFileContent, writeFilesIfNotExist } from './helpers.js';
|
|
4
|
+
|
|
23
5
|
const ENV_DIR = 'src/environments';
|
|
24
6
|
const ENV_DEV_FILE = 'environment.ts';
|
|
25
7
|
const ENV_LOCAL_FILE = 'environment.local.ts';
|
|
@@ -31,21 +13,30 @@ const environmentFiles = [
|
|
|
31
13
|
ENV_PROD_FILE,
|
|
32
14
|
ENV_STAGING_FILE
|
|
33
15
|
];
|
|
34
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The executor function to create environment files.
|
|
18
|
+
* Ensures that the directory for the environment files exists and creates the files
|
|
19
|
+
* if they do not exist already. Files created are 'environment.ts', 'environment.prod.ts',
|
|
20
|
+
* and 'environment.staging.ts'.
|
|
21
|
+
*
|
|
22
|
+
* @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
|
|
23
|
+
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
24
|
+
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
25
|
+
*/ async function runExecutor(_opts, ctx) {
|
|
35
26
|
try {
|
|
36
|
-
const projectConfig =
|
|
37
|
-
const environmentsDir =
|
|
38
|
-
await
|
|
27
|
+
const projectConfig = getProjectConfig(ctx);
|
|
28
|
+
const environmentsDir = join(projectConfig.root, ENV_DIR);
|
|
29
|
+
await ensureDirectoryExists(environmentsDir);
|
|
39
30
|
for (const envFileName of environmentFiles){
|
|
40
31
|
const { key, path } = getEnvPath(envFileName);
|
|
41
|
-
const content = await
|
|
42
|
-
await
|
|
32
|
+
const content = await createEnvironmentFileContent(path);
|
|
33
|
+
await writeFilesIfNotExist(environmentsDir, {
|
|
43
34
|
[key]: content
|
|
44
35
|
});
|
|
45
36
|
}
|
|
46
|
-
return
|
|
37
|
+
return ok();
|
|
47
38
|
} catch (error) {
|
|
48
|
-
return
|
|
39
|
+
return err(error, `Failed to create environment files:`);
|
|
49
40
|
}
|
|
50
41
|
}
|
|
51
42
|
function getEnvPath(fileName) {
|
|
@@ -57,3 +48,5 @@ function getEnvPath(fileName) {
|
|
|
57
48
|
path: `@nizza/core/envs/${baseFileName.replace('.ts', '')}`
|
|
58
49
|
};
|
|
59
50
|
}
|
|
51
|
+
|
|
52
|
+
export { runExecutor as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the version of a published package with a given name and tag.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} packageName The name of the package to retrieve the version for.
|
|
5
|
+
* @param {string} tag The tag to retrieve the version for.
|
|
6
|
+
* @returns The version of the package as a string or an object containing versions for each tag.
|
|
7
|
+
*/
|
|
8
|
+
declare function getPublishedPackageVersion(packageName: string, tag?: string): Promise<any>;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a package with the given name is already published and returns its version.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} packageName The name of the package to check for.
|
|
13
|
+
* @returns An object containing the published versions of the package and a flag indicating if it is the first version.
|
|
14
|
+
*/
|
|
15
|
+
declare function checkPublishedVersion(packageName: string): Promise<{
|
|
16
|
+
publishedVersion: any;
|
|
17
|
+
isFirstVersion: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
export { getPublishedPackageVersion, checkPublishedVersion };
|
|
@@ -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 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { ExecutorResponse } from "../../index-f6330edc.js";
|
|
3
|
+
interface ExecutorOptions {
|
|
4
|
+
tag: string;
|
|
5
|
+
dryRun?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* This is a minimal script to publish package to "npm".
|
|
9
|
+
* Need to authenticate with NPM before running this script.
|
|
10
|
+
*/
|
|
11
|
+
declare function runExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
|
|
12
|
+
export { ExecutorOptions, runExecutor as default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { logger } from '@nx/devkit';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import '../../shared/logger.js';
|
|
4
|
+
import { getPkgJson } from '../../shared/utils.js';
|
|
5
|
+
import { getProjectConfig, runCommand, ok, err } from '../shared/utils.js';
|
|
6
|
+
import { checkPublishedVersion } from './helpers.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This is a minimal script to publish package to "npm".
|
|
10
|
+
* Need to authenticate with NPM before running this script.
|
|
11
|
+
*/ async function runExecutor(opts, ctx) {
|
|
12
|
+
try {
|
|
13
|
+
const { tag, dryRun: isDryRun } = opts;
|
|
14
|
+
const { root: projectRoot } = getProjectConfig(ctx);
|
|
15
|
+
// Read the package.json file and extract the name and version.
|
|
16
|
+
const packageJson = getPkgJson(projectRoot);
|
|
17
|
+
const { name: packageName, version: packageVersion } = packageJson;
|
|
18
|
+
// Check if the package has been previously published and get the published version.
|
|
19
|
+
const { publishedVersion, isFirstVersion } = await checkPublishedVersion(packageName);
|
|
20
|
+
let greaterThanTagVersion, greaterThanLatestVersion;
|
|
21
|
+
if (!isFirstVersion) {
|
|
22
|
+
// Check if the package version is greater than the latest published version for the specified tag.
|
|
23
|
+
greaterThanTagVersion = publishedVersion?.[tag] ? semver.gt(packageVersion, publishedVersion?.[tag]) : true;
|
|
24
|
+
// Check if the package version is greater than the latest published version.
|
|
25
|
+
greaterThanLatestVersion = semver.gt(packageVersion, publishedVersion.latest);
|
|
26
|
+
console.log(`🔎 package.json version: ${packageVersion}`);
|
|
27
|
+
console.log('🔺 published versions:');
|
|
28
|
+
Object.entries(publishedVersion).forEach(([k, v])=>console.log(` * ${k}: ${v}`));
|
|
29
|
+
console.log('\n');
|
|
30
|
+
}
|
|
31
|
+
// Publish the package if it's the first version or if it's a new version.
|
|
32
|
+
const needsPublish = isFirstVersion || greaterThanLatestVersion && greaterThanTagVersion;
|
|
33
|
+
if (needsPublish) {
|
|
34
|
+
const dryRun = isDryRun ? '--dry-run' : '';
|
|
35
|
+
const commandToPublish = `pnpm publish --access public --tag ${tag} --no-git-checks ${dryRun}`;
|
|
36
|
+
isDryRun && logger.info('👀 Skip publish (dry run) \n');
|
|
37
|
+
logger.info(`${commandToPublish} \n`);
|
|
38
|
+
// Execute the command to publish the package.
|
|
39
|
+
// process.chdir(projectRoot);
|
|
40
|
+
await runCommand(commandToPublish, projectRoot);
|
|
41
|
+
logger.info(`\n🚀 Successfully published ${packageName}@${packageVersion}`);
|
|
42
|
+
} else {
|
|
43
|
+
logger.warn(`👻 Package version "${packageVersion}" is invalid.`);
|
|
44
|
+
}
|
|
45
|
+
return ok();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return err(error, '❌ Error when publishing the package');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { runExecutor as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Publish executor",
|
|
5
|
+
"description": "",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"tag": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Tag name to publish"
|
|
11
|
+
},
|
|
12
|
+
"dryRun": {
|
|
13
|
+
"type": "boolean",
|
|
14
|
+
"description": "Indicates whether a test execution should be done without really publishing",
|
|
15
|
+
"default": false
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"required": ["tag"]
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ExecutorContext, ProjectConfiguration } from '@nx/devkit';
|
|
2
|
+
import { ExecutorResponse } from "../../types-7377dcc9.js";
|
|
3
|
+
/**
|
|
4
|
+
* Indicates a successful executor operation.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} message - Optional message to log for the success case.
|
|
7
|
+
* @returns {ExecutorResponse} - An object representing a successful operation.
|
|
8
|
+
*/
|
|
9
|
+
declare function ok(message?: string): ExecutorResponse;
|
|
10
|
+
/**
|
|
11
|
+
* Indicates a failed executor operation.
|
|
12
|
+
*
|
|
13
|
+
* @param {string | Error | unknown} err - An optional error object or message indicating the nature of the failure.
|
|
14
|
+
* @param {string} message - An optional message to log for the error case. If not provided, a default error message is logged.
|
|
15
|
+
* @returns {ExecutorResponse} - An object representing a failed operation.
|
|
16
|
+
*/
|
|
17
|
+
declare function err(err?: string | Error | unknown, message?: string): ExecutorResponse;
|
|
18
|
+
/**
|
|
19
|
+
* Generates a random alphanumeric identifier of a specified length.
|
|
20
|
+
*
|
|
21
|
+
* @param {number} [length=8] - The length of the identifier to generate. Defaults to 8 if not specified.
|
|
22
|
+
* @returns {string} - A string representing a unique identifier.
|
|
23
|
+
*/
|
|
24
|
+
declare function shortId(length?: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the project configuration for the current execution context.
|
|
27
|
+
*
|
|
28
|
+
* @param {ExecutorContext} ctx - The execution context containing project information.
|
|
29
|
+
* @returns {ProjectConfiguration} - The configuration object for the current project.
|
|
30
|
+
* @throws {Error} If the project configuration is invalid or not found.
|
|
31
|
+
*/
|
|
32
|
+
declare function getProjectConfig(ctx: ExecutorContext): ProjectConfiguration;
|
|
33
|
+
declare function runCommand(command: string, cwd?: string | URL): Promise<void>;
|
|
34
|
+
export { ok, err, shortId, getProjectConfig, runCommand };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { logger } from '@nx/devkit';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
3
|
+
import { exec } from 'child_process';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
|
|
6
|
+
const execAsync = promisify(exec);
|
|
7
|
+
/**
|
|
8
|
+
* Indicates a successful executor operation.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} message - Optional message to log for the success case.
|
|
11
|
+
* @returns {ExecutorResponse} - An object representing a successful operation.
|
|
12
|
+
*/ function ok(message) {
|
|
13
|
+
message && logger.info(message);
|
|
14
|
+
return {
|
|
15
|
+
success: true
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Indicates a failed executor operation.
|
|
20
|
+
*
|
|
21
|
+
* @param {string | Error | unknown} err - An optional error object or message indicating the nature of the failure.
|
|
22
|
+
* @param {string} message - An optional message to log for the error case. If not provided, a default error message is logged.
|
|
23
|
+
* @returns {ExecutorResponse} - An object representing a failed operation.
|
|
24
|
+
*/ function err(err, message) {
|
|
25
|
+
if (message) {
|
|
26
|
+
logger.error(message);
|
|
27
|
+
} else {
|
|
28
|
+
logger.error(`❌ an error occurred:`);
|
|
29
|
+
}
|
|
30
|
+
if (err) logger.error(err);
|
|
31
|
+
return {
|
|
32
|
+
success: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generates a random alphanumeric identifier of a specified length.
|
|
37
|
+
*
|
|
38
|
+
* @param {number} [length=8] - The length of the identifier to generate. Defaults to 8 if not specified.
|
|
39
|
+
* @returns {string} - A string representing a unique identifier.
|
|
40
|
+
*/ function shortId(length = 8) {
|
|
41
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
42
|
+
return Array.from(randomBytes(length), (b)=>chars[b % chars.length]).join('');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves the project configuration for the current execution context.
|
|
46
|
+
*
|
|
47
|
+
* @param {ExecutorContext} ctx - The execution context containing project information.
|
|
48
|
+
* @returns {ProjectConfiguration} - The configuration object for the current project.
|
|
49
|
+
* @throws {Error} If the project configuration is invalid or not found.
|
|
50
|
+
*/ function getProjectConfig(ctx) {
|
|
51
|
+
const projectName = ctx.projectName || '';
|
|
52
|
+
const projectConfig = ctx.projectsConfigurations?.projects?.[projectName];
|
|
53
|
+
if (!projectConfig) throw new Error('Invalid project configuration.');
|
|
54
|
+
return projectConfig;
|
|
55
|
+
}
|
|
56
|
+
async function runCommand(command, cwd) {
|
|
57
|
+
try {
|
|
58
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
59
|
+
...cwd && {
|
|
60
|
+
cwd
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
logger.info(stdout);
|
|
64
|
+
logger.info(stderr);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
logger.error(`Unexpected error running command:`);
|
|
67
|
+
logger.error(error);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { err, getProjectConfig, ok, runCommand, shortId };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Executors } from "../../types-763439e4.js";
|
|
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
|
+
declare const transformPathToRoot: (path: string) => string;
|
|
11
|
+
declare const transformPathToDist: (path: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Updates the executor paths for the provided executors object.
|
|
14
|
+
* @param {Executors} executors - The executors object from executors.json.
|
|
15
|
+
* @param {boolean} toDist - Flag to determine if './dist' should be removed from paths.
|
|
16
|
+
* @returns - The updated executors object with transformed paths.
|
|
17
|
+
*/
|
|
18
|
+
declare const updateExecutorPaths: (executors: Executors, toDist: boolean) => Executors;
|
|
19
|
+
/**
|
|
20
|
+
* Writes a JSON file asynchronously.
|
|
21
|
+
* @param {string} path - The file path where to write the JSON data.
|
|
22
|
+
* @param {any} data - The data to be written to the file.
|
|
23
|
+
*/
|
|
24
|
+
declare const writeJsonFileAsync: (path: string, data: any) => Promise<void>;
|
|
25
|
+
export { transformPathToRoot, transformPathToDist, updateExecutorPaths, writeJsonFileAsync };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { logger } from '@nx/devkit';
|
|
2
|
+
import { promises } from 'fs';
|
|
3
|
+
import { cond, always, T, endsWith, test, pipe } from 'ramda';
|
|
4
|
+
|
|
5
|
+
const { writeFile } = promises;
|
|
6
|
+
/**
|
|
7
|
+
* Transforms the given path by adding or removing the './dist/' prefix
|
|
8
|
+
* and ensuring that it has the '.js' extension if it's not a JSON file.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} path - The original file path to transform.
|
|
11
|
+
* @param {boolean} removeDist - Flag to determine if './dist/' should be removed.
|
|
12
|
+
* @returns {string} The transformed file path.
|
|
13
|
+
*/ const transformPathToRoot = (path)=>{
|
|
14
|
+
const distPrefix = './dist/cjs/';
|
|
15
|
+
const srcRegex = /^\.\/src\//;
|
|
16
|
+
const distRegex = /^\.\/dist\//;
|
|
17
|
+
const jsExt = '.js';
|
|
18
|
+
endsWith(jsExt, path);
|
|
19
|
+
const isJson = endsWith('.json', path);
|
|
20
|
+
test(distRegex, path);
|
|
21
|
+
// Adds './dist/' prefix to the path if it's not already present.
|
|
22
|
+
const changeSrcPath = (p)=>p.replace(srcRegex, distPrefix);
|
|
23
|
+
// Adds '.js' extension to the path if it's not a JSON file and doesn't have the extension already.
|
|
24
|
+
const changeFileName = (p)=>isJson ? p : p.replace(/executor\.ts$/, 'index.js');
|
|
25
|
+
return pipe(changeSrcPath, changeFileName)(path);
|
|
26
|
+
};
|
|
27
|
+
const transformPathToDist = (path)=>{
|
|
28
|
+
const cjsPrefix = './cjs/';
|
|
29
|
+
const distRegex = /^\.\/dist\/cjs\//;
|
|
30
|
+
const changeDistPath = (p)=>p.replace(distRegex, cjsPrefix);
|
|
31
|
+
return changeDistPath(path);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Updates the executor paths for the provided executors object.
|
|
35
|
+
* @param {Executors} executors - The executors object from executors.json.
|
|
36
|
+
* @param {boolean} toDist - Flag to determine if './dist' should be removed from paths.
|
|
37
|
+
* @returns - The updated executors object with transformed paths.
|
|
38
|
+
*/ const updateExecutorPaths = (executors, toDist)=>{
|
|
39
|
+
const transform = cond([
|
|
40
|
+
[
|
|
41
|
+
always(toDist),
|
|
42
|
+
transformPathToDist
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
T,
|
|
46
|
+
transformPathToRoot
|
|
47
|
+
]
|
|
48
|
+
]);
|
|
49
|
+
return Object.entries(executors).reduce((updatedExecutors, [key, executor])=>{
|
|
50
|
+
updatedExecutors[key] = {
|
|
51
|
+
...executor,
|
|
52
|
+
implementation: transform(executor.implementation),
|
|
53
|
+
schema: transform(executor.schema)
|
|
54
|
+
};
|
|
55
|
+
return updatedExecutors;
|
|
56
|
+
}, {});
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Writes a JSON file asynchronously.
|
|
60
|
+
* @param {string} path - The file path where to write the JSON data.
|
|
61
|
+
* @param {any} data - The data to be written to the file.
|
|
62
|
+
*/ const writeJsonFileAsync = async (path, data)=>{
|
|
63
|
+
try {
|
|
64
|
+
await writeFile(path, JSON.stringify(data, null, 2));
|
|
65
|
+
logger.info(`✅ Updated: ${path}`);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
logger.error(`❌ Error writing file ${path}: ${error}`);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { transformPathToDist, transformPathToRoot, updateExecutorPaths, writeJsonFileAsync };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { ExecutorResponse } from "../../index-f6330edc.js";
|
|
3
|
+
import { ExecutorOptions } from "../../types-763439e4.js";
|
|
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
|
+
declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
|
|
12
|
+
export { runExecutor as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { promises } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { getProjectConfig, ok, err } from '../shared/utils.js';
|
|
4
|
+
import { updateExecutorPaths, writeJsonFileAsync } from './helpers.js';
|
|
5
|
+
|
|
6
|
+
const { readFile } = promises;
|
|
7
|
+
/**
|
|
8
|
+
* Executor function to update paths in the executors.json file.
|
|
9
|
+
*
|
|
10
|
+
* @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
|
|
11
|
+
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
12
|
+
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
13
|
+
*/ async function runExecutor(_opts, ctx) {
|
|
14
|
+
try {
|
|
15
|
+
const projectConfig = getProjectConfig(ctx);
|
|
16
|
+
const rootDir = projectConfig.root;
|
|
17
|
+
const executorsFilePath = join(rootDir, 'executors.json');
|
|
18
|
+
const distExecutorsFilePath = join(rootDir, 'dist', 'executors.json');
|
|
19
|
+
const originalContent = JSON.parse(await readFile(executorsFilePath, 'utf8'));
|
|
20
|
+
// Update paths to point to './dist/' and add '.js'
|
|
21
|
+
const updatedExecutors = updateExecutorPaths(originalContent.executors, false);
|
|
22
|
+
// Prepare the version for the dist folder by removing './dist/' from paths
|
|
23
|
+
const distExecutors = updateExecutorPaths(updatedExecutors, true);
|
|
24
|
+
// Write both files asynchronously and in parallel
|
|
25
|
+
await Promise.all([
|
|
26
|
+
writeJsonFileAsync(executorsFilePath, {
|
|
27
|
+
executors: updatedExecutors
|
|
28
|
+
}),
|
|
29
|
+
writeJsonFileAsync(distExecutorsFilePath, {
|
|
30
|
+
executors: distExecutors
|
|
31
|
+
})
|
|
32
|
+
]);
|
|
33
|
+
return ok(`🚀 Executors updated successfully.`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return err(error, `❌ Error processing file: ${error}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { runExecutor as default };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const VTEX_PROJECT_PATH: string | undefined;
|
|
2
|
+
declare const ERROR_LINKING_FLAG = "[31merror\u001B[39m: App build failed";
|
|
3
|
+
declare const SUCCESS_LINKING_FLAG = "[32minfo\u001B[39m: App running";
|
|
4
|
+
export { VTEX_PROJECT_PATH, ERROR_LINKING_FLAG, SUCCESS_LINKING_FLAG };
|