@nizza/devkit 0.1.0-alpha.1 → 0.1.0-alpha.10
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.cjs +26 -0
- package/dist/cjs/executors/deploy/helpers.d.cts +4 -0
- package/dist/cjs/executors/deploy/index.cjs +22 -0
- package/dist/cjs/executors/deploy/index.d.cts +11 -0
- package/dist/cjs/executors/environments/helpers.cjs +62 -0
- package/dist/{src/executors/environments/helpers.d.ts → cjs/executors/environments/helpers.d.cts} +9 -5
- package/dist/cjs/executors/environments/index.cjs +60 -0
- package/dist/{src/executors/environments/executor.d.ts → cjs/executors/environments/index.d.cts} +5 -5
- package/dist/cjs/executors/publish/helpers.cjs +51 -0
- package/dist/{src/executors/publish/helpers.d.ts → cjs/executors/publish/helpers.d.cts} +3 -3
- package/dist/cjs/executors/publish/index.cjs +53 -0
- package/dist/cjs/executors/publish/index.d.cts +12 -0
- package/dist/cjs/executors/shared/utils.cjs +67 -0
- package/dist/cjs/executors/shared/utils.d.cts +27 -0
- package/dist/cjs/executors/update-executors-file/helpers.cjs +64 -0
- package/dist/cjs/executors/update-executors-file/helpers.d.cts +17 -0
- package/dist/cjs/executors/update-executors-file/index.cjs +38 -0
- package/dist/{src/executors/update-executors-file/executor.d.ts → cjs/executors/update-executors-file/index.d.cts} +5 -5
- package/dist/cjs/executors/vtex-link/constants.cjs +9 -0
- package/dist/cjs/executors/vtex-link/constants.d.cts +4 -0
- package/dist/cjs/executors/vtex-link/helpers.cjs +206 -0
- package/dist/{src/executors/vtex-link/helpers.d.ts → cjs/executors/vtex-link/helpers.d.cts} +15 -15
- package/dist/cjs/executors/vtex-link/index.cjs +30 -0
- package/dist/cjs/executors/vtex-link/index.d.cts +5 -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.cjs +71 -0
- package/dist/cjs/index.d.cts +10 -0
- package/dist/cjs/index.d.cts.map +1 -0
- package/dist/cjs/scripts/changeset-pre-mode.cjs +41 -0
- package/dist/cjs/scripts/changeset-pre-mode.d.cts +2 -0
- package/dist/cjs/scripts/index.cjs +7 -0
- package/dist/cjs/scripts/index.d.cts +1 -0
- package/dist/cjs/shared/logger.cjs +98 -0
- package/dist/{src/logger.d.ts → cjs/shared/logger.d.cts} +5 -6
- package/dist/cjs/shared/utils.cjs +64 -0
- package/dist/cjs/shared/utils.d.cts +19 -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.cjs +13 -0
- package/dist/cjs/vite/config-builder/configs/app.d.cts +4 -0
- package/dist/cjs/vite/config-builder/configs/base.cjs +58 -0
- package/dist/cjs/vite/config-builder/configs/base.d.cts +4 -0
- package/dist/cjs/vite/config-builder/configs/index.cjs +36 -0
- package/dist/cjs/vite/config-builder/configs/index.d.cts +7 -0
- package/dist/cjs/vite/config-builder/configs/lib.cjs +57 -0
- package/dist/cjs/vite/config-builder/configs/lib.d.cts +4 -0
- package/dist/cjs/vite/config-builder/configs/script.cjs +46 -0
- package/dist/cjs/vite/config-builder/configs/script.d.cts +4 -0
- package/dist/cjs/vite/config-builder/main.cjs +42 -0
- package/dist/cjs/vite/config-builder/main.d.cts +10 -0
- package/dist/cjs/vite/config-builder/plugins.cjs +93 -0
- package/dist/{src/vite/config-builder/plugins.d.ts → cjs/vite/config-builder/plugins.d.cts} +7 -7
- package/dist/cjs/vite/config-builder/shared/types.cjs +33 -0
- package/dist/{src/vite/config-builder/shared/types.d.ts → cjs/vite/config-builder/shared/types.d.cts} +17 -17
- package/dist/cjs/vite/config-builder/shared/utils/helpers.cjs +115 -0
- package/dist/{src/vite/config-builder/shared/utils/helpers.d.ts → cjs/vite/config-builder/shared/utils/helpers.d.cts} +9 -19
- package/dist/cjs/vite/config-builder/shared/utils/projectConfig.cjs +114 -0
- package/dist/{src/vite/config-builder/shared/utils/projectConfig.d.ts → cjs/vite/config-builder/shared/utils/projectConfig.d.cts} +8 -8
- package/dist/cjs/vite/config-builder/shared/utils/viteCommand.cjs +59 -0
- package/dist/{src/vite/config-builder/shared/utils/viteCommand.d.ts → cjs/vite/config-builder/shared/utils/viteCommand.d.cts} +4 -4
- package/dist/{src/vite/plugins/shadow-dom-inject-css/index.js → cjs/vite/plugins/shadow-dom-inject-css/index.cjs} +4 -19
- package/dist/cjs/vite/plugins/shadow-dom-inject-css/index.d.cts +7 -0
- package/dist/{src/vite/plugins/third-party-css-inject/main.js → cjs/vite/plugins/third-party-css-inject/main.cjs} +13 -14
- package/dist/cjs/vite/plugins/third-party-css-inject/main.d.cts +17 -0
- package/dist/{src/vite/plugins/third-party-css-inject/utils.js → cjs/vite/plugins/third-party-css-inject/utils.cjs} +8 -20
- package/dist/cjs/vite/plugins/third-party-css-inject/utils.d.cts +5 -0
- package/dist/esm/executors/deploy/helpers.d.mts +4 -0
- package/dist/esm/executors/deploy/helpers.mjs +22 -0
- package/dist/esm/executors/deploy/index.d.mts +11 -0
- package/dist/esm/executors/deploy/index.mjs +20 -0
- package/dist/esm/executors/deploy/schema.json +41 -0
- package/dist/esm/executors/environments/helpers.d.mts +25 -0
- package/dist/esm/executors/environments/helpers.mjs +58 -0
- package/dist/esm/executors/environments/index.d.mts +16 -0
- package/dist/esm/executors/environments/index.mjs +58 -0
- package/dist/esm/executors/environments/schema.json +9 -0
- package/dist/esm/executors/publish/helpers.d.mts +19 -0
- package/dist/esm/executors/publish/helpers.mjs +48 -0
- package/dist/esm/executors/publish/index.d.mts +12 -0
- package/dist/esm/executors/publish/index.mjs +51 -0
- package/dist/esm/executors/publish/schema.json +19 -0
- package/dist/esm/executors/shared/utils.d.mts +27 -0
- package/dist/esm/executors/shared/utils.mjs +62 -0
- package/dist/esm/executors/update-executors-file/helpers.d.mts +17 -0
- package/dist/esm/executors/update-executors-file/helpers.mjs +59 -0
- package/dist/esm/executors/update-executors-file/index.d.mts +12 -0
- package/dist/esm/executors/update-executors-file/index.mjs +36 -0
- package/dist/esm/executors/update-executors-file/schema.json +9 -0
- package/dist/esm/executors/vtex-link/constants.d.mts +4 -0
- package/dist/esm/executors/vtex-link/constants.mjs +5 -0
- package/dist/esm/executors/vtex-link/helpers.d.mts +77 -0
- package/dist/esm/executors/vtex-link/helpers.mjs +192 -0
- package/dist/esm/executors/vtex-link/index.d.mts +5 -0
- package/dist/esm/executors/vtex-link/index.mjs +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.mts +10 -0
- package/dist/esm/index.d.mts.map +1 -0
- package/dist/esm/index.mjs +14 -0
- package/dist/esm/scripts/changeset-pre-mode.d.mts +2 -0
- package/dist/esm/scripts/changeset-pre-mode.mjs +39 -0
- package/dist/esm/scripts/index.d.mts +1 -0
- package/dist/esm/scripts/index.mjs +1 -0
- package/dist/esm/shared/logger.d.mts +33 -0
- package/dist/{src/logger.js → esm/shared/logger.mjs} +28 -39
- package/dist/esm/shared/utils.d.mts +19 -0
- package/dist/esm/shared/utils.mjs +60 -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.mts +4 -0
- package/dist/esm/vite/config-builder/configs/app.mjs +11 -0
- package/dist/esm/vite/config-builder/configs/base.d.mts +4 -0
- package/dist/{src/vite/config-builder/configs/base.js → esm/vite/config-builder/configs/base.mjs} +23 -22
- package/dist/esm/vite/config-builder/configs/index.d.mts +7 -0
- package/dist/esm/vite/config-builder/configs/index.mjs +30 -0
- package/dist/esm/vite/config-builder/configs/lib.d.mts +4 -0
- package/dist/{src/vite/config-builder/configs/lib.js → esm/vite/config-builder/configs/lib.mjs} +16 -18
- package/dist/esm/vite/config-builder/configs/script.d.mts +4 -0
- package/dist/esm/vite/config-builder/configs/script.mjs +44 -0
- package/dist/esm/vite/config-builder/main.d.mts +10 -0
- package/dist/esm/vite/config-builder/main.mjs +40 -0
- package/dist/esm/vite/config-builder/plugins.d.mts +30 -0
- package/dist/esm/vite/config-builder/plugins.mjs +87 -0
- package/dist/esm/vite/config-builder/shared/types.d.mts +155 -0
- package/dist/{src/vite/config-builder/shared/types.js → esm/vite/config-builder/shared/types.mjs} +2 -27
- package/dist/esm/vite/config-builder/shared/utils/helpers.d.mts +71 -0
- package/dist/esm/vite/config-builder/shared/utils/helpers.mjs +90 -0
- package/dist/esm/vite/config-builder/shared/utils/projectConfig.d.mts +60 -0
- package/dist/esm/vite/config-builder/shared/utils/projectConfig.mjs +109 -0
- package/dist/esm/vite/config-builder/shared/utils/viteCommand.d.mts +24 -0
- package/dist/esm/vite/config-builder/shared/utils/viteCommand.mjs +56 -0
- package/dist/esm/vite/plugins/shadow-dom-inject-css/index.d.mts +7 -0
- package/dist/esm/vite/plugins/shadow-dom-inject-css/index.mjs +27 -0
- package/dist/esm/vite/plugins/third-party-css-inject/main.d.mts +17 -0
- package/dist/esm/vite/plugins/third-party-css-inject/main.mjs +45 -0
- package/dist/esm/vite/plugins/third-party-css-inject/utils.d.mts +5 -0
- package/dist/esm/vite/plugins/third-party-css-inject/utils.mjs +97 -0
- package/dist/executors.json +29 -0
- package/executors.json +29 -0
- package/package.json +52 -6
- 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/executor.js +0 -59
- 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 -74
- 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 +0 -24
- 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 +0 -11
- 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,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var devkit = require('@nx/devkit');
|
|
4
|
+
var utils = require('../shared/utils.cjs');
|
|
5
|
+
|
|
6
|
+
async function cleanS3Bucket(s3BucketPath) {
|
|
7
|
+
devkit.logger.info('🧹 Cleaning S3 bucket...');
|
|
8
|
+
await utils.runCommand(`aws s3 rm ${s3BucketPath} --recursive`);
|
|
9
|
+
devkit.logger.info('✅ S3 bucket cleared.');
|
|
10
|
+
}
|
|
11
|
+
async function copyAssetsToS3(s3BucketPath, projectRoot) {
|
|
12
|
+
devkit.logger.info('📦 Copying assets to S3 bucket...');
|
|
13
|
+
await utils.runCommand(`aws s3 cp ${projectRoot}/dist ${s3BucketPath} --recursive`);
|
|
14
|
+
devkit.logger.info('🚚 Assets files copied.');
|
|
15
|
+
}
|
|
16
|
+
async function createCloudFrontInvalidation(distributionId, invalidationPaths) {
|
|
17
|
+
const pathsString = invalidationPaths.map((path)=>`"${path}"`).join(' ');
|
|
18
|
+
const command = `aws cloudfront create-invalidation --distribution-id ${distributionId} --paths ${pathsString}`;
|
|
19
|
+
devkit.logger.info('🔃 Creating invalidation for CloudFront...');
|
|
20
|
+
await utils.runCommand(command);
|
|
21
|
+
devkit.logger.info('🔄 CloudFront invalidation created.');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.cleanS3Bucket = cleanS3Bucket;
|
|
25
|
+
exports.copyAssetsToS3 = copyAssetsToS3;
|
|
26
|
+
exports.createCloudFrontInvalidation = createCloudFrontInvalidation;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare function cleanS3Bucket(s3BucketPath: string): Promise<void>;
|
|
2
|
+
declare function copyAssetsToS3(s3BucketPath: string, projectRoot: string): Promise<void>;
|
|
3
|
+
declare function createCloudFrontInvalidation(distributionId: string, invalidationPaths: string[]): Promise<void>;
|
|
4
|
+
export { cleanS3Bucket, copyAssetsToS3, createCloudFrontInvalidation };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('../shared/utils.cjs');
|
|
4
|
+
var helpers = require('./helpers.cjs');
|
|
5
|
+
|
|
6
|
+
async function deployExecutor(opts, ctx) {
|
|
7
|
+
try {
|
|
8
|
+
const { root, name } = utils.getProjectConfig(ctx);
|
|
9
|
+
const { s3BucketPath, cloudFrontDistributionId, cloudFrontInvalidationPaths, skipBuild = false } = opts;
|
|
10
|
+
const buildTarget = `${name}:${opts.buildTarget}`;
|
|
11
|
+
if (!skipBuild) await utils.runCommand(`nx run ${buildTarget}`);
|
|
12
|
+
await helpers.cleanS3Bucket(s3BucketPath);
|
|
13
|
+
await helpers.copyAssetsToS3(s3BucketPath, root);
|
|
14
|
+
await helpers.createCloudFrontInvalidation(cloudFrontDistributionId, cloudFrontInvalidationPaths);
|
|
15
|
+
const now = new Date().toLocaleString();
|
|
16
|
+
return utils.ok(`✨ Build completed successfully on ${now}`);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return utils.err(error, '❌ Error when executing deploy command');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = deployExecutor;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { ExecutorResponse } from "../../index-f6330edc.js";
|
|
3
|
+
interface ExecutorOptions {
|
|
4
|
+
s3BucketPath: string;
|
|
5
|
+
cloudFrontDistributionId: string;
|
|
6
|
+
cloudFrontInvalidationPaths: string[];
|
|
7
|
+
buildTarget: string;
|
|
8
|
+
skipBuild?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function deployExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
|
|
11
|
+
export { ExecutorOptions, deployExecutor as default };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var devkit = require('@nx/devkit');
|
|
6
|
+
|
|
7
|
+
const { mkdir, writeFile, access } = fs.promises;
|
|
8
|
+
/**
|
|
9
|
+
* Creates the content for an environment file based on the core environment path.
|
|
10
|
+
*
|
|
11
|
+
* @param {CreateEnvironmentData} data - Values to replace in template.
|
|
12
|
+
* @returns {string} The content of the environment file.
|
|
13
|
+
*/ async function createEnvironmentFileContent({ coreEnvFile, projectOrg }) {
|
|
14
|
+
return `import { Environment } from '@${projectOrg}/core';
|
|
15
|
+
import coreEnvs from '@${projectOrg}/core/envs/${coreEnvFile}';
|
|
16
|
+
|
|
17
|
+
const config = {
|
|
18
|
+
...coreEnvs,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const environment: Environment<typeof config> = config;
|
|
22
|
+
export default environment;
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Ensures that the given directory exists, creating it if it does not.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} dir - The path to the directory to check/create.
|
|
29
|
+
*/ async function ensureDirectoryExists(dir) {
|
|
30
|
+
try {
|
|
31
|
+
await access(dir);
|
|
32
|
+
devkit.logger.info('✅ Directory exists.');
|
|
33
|
+
} catch {
|
|
34
|
+
devkit.logger.info('📁 Directory does not exist. Creating...');
|
|
35
|
+
await mkdir(dir, {
|
|
36
|
+
recursive: true
|
|
37
|
+
});
|
|
38
|
+
devkit.logger.info('📁 Directory created.');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Writes environment files to the given base path if they do not already exist.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} basePath - The base directory where the files should be written.
|
|
45
|
+
* @param {Record<string, string>} files - An object containing filenames and their respective content.
|
|
46
|
+
*/ async function writeFilesIfNotExist(basePath, files) {
|
|
47
|
+
await Promise.all(Object.entries(files).map(async ([filename, content])=>{
|
|
48
|
+
const filePath = path.join(basePath, filename);
|
|
49
|
+
try {
|
|
50
|
+
await access(filePath);
|
|
51
|
+
devkit.logger.info(`✅ The file "${filename}" already exists.`);
|
|
52
|
+
} catch {
|
|
53
|
+
devkit.logger.warn(`📝 The file "${filename}" does not exist. Creating...`);
|
|
54
|
+
await writeFile(filePath, content);
|
|
55
|
+
devkit.logger.info(`🎉 The file "${filename}" has been created.`);
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.createEnvironmentFileContent = createEnvironmentFileContent;
|
|
61
|
+
exports.ensureDirectoryExists = ensureDirectoryExists;
|
|
62
|
+
exports.writeFilesIfNotExist = writeFilesIfNotExist;
|
package/dist/{src/executors/environments/helpers.d.ts → cjs/executors/environments/helpers.d.cts}
RENAMED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
+
interface CreateEnvironmentData {
|
|
2
|
+
projectOrg: string;
|
|
3
|
+
coreEnvFile: string;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* Creates the content for an environment file based on the core environment path.
|
|
3
7
|
*
|
|
4
|
-
* @param {
|
|
8
|
+
* @param {CreateEnvironmentData} data - Values to replace in template.
|
|
5
9
|
* @returns {string} The content of the environment file.
|
|
6
10
|
*/
|
|
7
|
-
|
|
11
|
+
declare function createEnvironmentFileContent({ coreEnvFile, projectOrg, }: CreateEnvironmentData): Promise<string>;
|
|
8
12
|
/**
|
|
9
13
|
* Ensures that the given directory exists, creating it if it does not.
|
|
10
14
|
*
|
|
11
15
|
* @param {string} dir - The path to the directory to check/create.
|
|
12
16
|
*/
|
|
13
|
-
|
|
17
|
+
declare function ensureDirectoryExists(dir: string): Promise<void>;
|
|
14
18
|
/**
|
|
15
19
|
* Writes environment files to the given base path if they do not already exist.
|
|
16
20
|
*
|
|
17
21
|
* @param {string} basePath - The base directory where the files should be written.
|
|
18
22
|
* @param {Record<string, string>} files - An object containing filenames and their respective content.
|
|
19
23
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
declare function writeFilesIfNotExist(basePath: string, files: Record<string, string>): Promise<void>;
|
|
25
|
+
export { createEnvironmentFileContent, ensureDirectoryExists, writeFilesIfNotExist };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var utils = require('../shared/utils.cjs');
|
|
5
|
+
var helpers = require('./helpers.cjs');
|
|
6
|
+
require('../../shared/logger.cjs');
|
|
7
|
+
var utils$1 = require('../../shared/utils.cjs');
|
|
8
|
+
|
|
9
|
+
const ENV_DIR = 'src/environments';
|
|
10
|
+
const ENV_DEV_FILE = 'environment.ts';
|
|
11
|
+
const ENV_LOCAL_FILE = 'environment.local.ts';
|
|
12
|
+
const ENV_PROD_FILE = 'environment.prod.ts';
|
|
13
|
+
const ENV_STAGING_FILE = 'environment.staging.ts';
|
|
14
|
+
const environmentFiles = [
|
|
15
|
+
ENV_DEV_FILE,
|
|
16
|
+
ENV_LOCAL_FILE,
|
|
17
|
+
ENV_PROD_FILE,
|
|
18
|
+
ENV_STAGING_FILE
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* The executor function to create environment files.
|
|
22
|
+
* Ensures that the directory for the environment files exists and creates the files
|
|
23
|
+
* if they do not exist already. Files created are 'environment.ts', 'environment.prod.ts',
|
|
24
|
+
* and 'environment.staging.ts'.
|
|
25
|
+
*
|
|
26
|
+
* @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
|
|
27
|
+
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
28
|
+
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
29
|
+
*/ async function runExecutor(_opts, ctx) {
|
|
30
|
+
try {
|
|
31
|
+
const projectConfig = utils.getProjectConfig(ctx);
|
|
32
|
+
const environmentsDir = path.join(projectConfig.root, ENV_DIR);
|
|
33
|
+
const mainPkgJson = utils$1.getPkgJson(ctx.root);
|
|
34
|
+
const getEnvPath = (fileName)=>{
|
|
35
|
+
const isLocal = fileName.includes('.local');
|
|
36
|
+
const coreEnvFile = (isLocal ? ENV_DEV_FILE : fileName).replace('.ts', '');
|
|
37
|
+
const key = isLocal ? ENV_LOCAL_FILE : fileName;
|
|
38
|
+
return {
|
|
39
|
+
key,
|
|
40
|
+
coreEnvFile
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
await helpers.ensureDirectoryExists(environmentsDir);
|
|
44
|
+
for (const envFileName of environmentFiles){
|
|
45
|
+
const { key, coreEnvFile } = getEnvPath(envFileName);
|
|
46
|
+
const content = await helpers.createEnvironmentFileContent({
|
|
47
|
+
coreEnvFile,
|
|
48
|
+
projectOrg: mainPkgJson.name
|
|
49
|
+
});
|
|
50
|
+
await helpers.writeFilesIfNotExist(environmentsDir, {
|
|
51
|
+
[key]: content
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return utils.ok();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return utils.err(error, `Failed to create environment files:`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = runExecutor;
|
package/dist/{src/executors/environments/executor.d.ts → cjs/executors/environments/index.d.cts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { ExecutorResponse } from "../../index-f6330edc.js";
|
|
3
|
+
interface ExecutorOptions {
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* The executor function to create environment files.
|
|
@@ -12,5 +12,5 @@ export interface ExecutorOptions {
|
|
|
12
12
|
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
13
13
|
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
|
|
16
|
+
export { ExecutorOptions, runExecutor as default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var devkit = require('@nx/devkit');
|
|
4
|
+
var child_process = require('child_process');
|
|
5
|
+
var util = require('util');
|
|
6
|
+
|
|
7
|
+
const execAsync = util.promisify(child_process.exec);
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the version of a published package with a given name and tag.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} packageName The name of the package to retrieve the version for.
|
|
12
|
+
* @param {string} tag The tag to retrieve the version for.
|
|
13
|
+
* @returns The version of the package as a string or an object containing versions for each tag.
|
|
14
|
+
*/ async function getPublishedPackageVersion(packageName, tag) {
|
|
15
|
+
const withTag = tag ? `.${tag}` : ' --json';
|
|
16
|
+
const command = `npm view ${packageName} dist-tags${withTag}`;
|
|
17
|
+
const { stdout, stderr } = await execAsync(command);
|
|
18
|
+
if (stderr) {
|
|
19
|
+
devkit.logger.error(stderr.trim());
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
const published = stdout.trim();
|
|
23
|
+
return tag ? published : JSON.parse(published);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a package with the given name is already published and returns its version.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} packageName The name of the package to check for.
|
|
29
|
+
* @returns An object containing the published versions of the package and a flag indicating if it is the first version.
|
|
30
|
+
*/ async function checkPublishedVersion(packageName) {
|
|
31
|
+
let publishedVersion;
|
|
32
|
+
let isFirstVersion = false;
|
|
33
|
+
try {
|
|
34
|
+
publishedVersion = await getPublishedPackageVersion(packageName);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
if (err?.message.includes('code E404')) {
|
|
37
|
+
isFirstVersion = true;
|
|
38
|
+
devkit.logger.info(`🏁 This is the first version of "${packageName}" package. \n`);
|
|
39
|
+
} else {
|
|
40
|
+
devkit.logger.error('❌ Error when checking the last published versions \n');
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
publishedVersion,
|
|
46
|
+
isFirstVersion
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.checkPublishedVersion = checkPublishedVersion;
|
|
51
|
+
exports.getPublishedPackageVersion = getPublishedPackageVersion;
|
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
* @param {string} tag The tag to retrieve the version for.
|
|
6
6
|
* @returns The version of the package as a string or an object containing versions for each tag.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
declare function getPublishedPackageVersion(packageName: string, tag?: string): Promise<any>;
|
|
9
9
|
/**
|
|
10
10
|
* Checks if a package with the given name is already published and returns its version.
|
|
11
11
|
*
|
|
12
12
|
* @param {string} packageName The name of the package to check for.
|
|
13
13
|
* @returns An object containing the published versions of the package and a flag indicating if it is the first version.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
declare function checkPublishedVersion(packageName: string): Promise<{
|
|
16
16
|
publishedVersion: any;
|
|
17
17
|
isFirstVersion: boolean;
|
|
18
18
|
}>;
|
|
19
|
-
|
|
19
|
+
export { getPublishedPackageVersion, checkPublishedVersion };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var devkit = require('@nx/devkit');
|
|
4
|
+
var semver = require('semver');
|
|
5
|
+
require('../../shared/logger.cjs');
|
|
6
|
+
var utils$1 = require('../../shared/utils.cjs');
|
|
7
|
+
var utils = require('../shared/utils.cjs');
|
|
8
|
+
var helpers = require('./helpers.cjs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This is a minimal script to publish package to "npm".
|
|
12
|
+
* Need to authenticate with NPM before running this script.
|
|
13
|
+
*/ async function runExecutor(opts, ctx) {
|
|
14
|
+
try {
|
|
15
|
+
const { tag, dryRun: isDryRun } = opts;
|
|
16
|
+
const { root: projectRoot } = utils.getProjectConfig(ctx);
|
|
17
|
+
// Read the package.json file and extract the name and version.
|
|
18
|
+
const packageJson = utils$1.getPkgJson(projectRoot);
|
|
19
|
+
const { name: packageName, version: packageVersion } = packageJson;
|
|
20
|
+
// Check if the package has been previously published and get the published version.
|
|
21
|
+
const { publishedVersion, isFirstVersion } = await helpers.checkPublishedVersion(packageName);
|
|
22
|
+
let greaterThanTagVersion, greaterThanLatestVersion;
|
|
23
|
+
if (!isFirstVersion) {
|
|
24
|
+
// Check if the package version is greater than the latest published version for the specified tag.
|
|
25
|
+
greaterThanTagVersion = publishedVersion?.[tag] ? semver.gt(packageVersion, publishedVersion?.[tag]) : true;
|
|
26
|
+
// Check if the package version is greater than the latest published version.
|
|
27
|
+
greaterThanLatestVersion = semver.gt(packageVersion, publishedVersion.latest);
|
|
28
|
+
console.log(`🔎 package.json version: ${packageVersion}`);
|
|
29
|
+
console.log('🔺 published versions:');
|
|
30
|
+
Object.entries(publishedVersion).forEach(([k, v])=>console.log(` * ${k}: ${v}`));
|
|
31
|
+
console.log('\n');
|
|
32
|
+
}
|
|
33
|
+
// Publish the package if it's the first version or if it's a new version.
|
|
34
|
+
const needsPublish = isFirstVersion || greaterThanLatestVersion && greaterThanTagVersion;
|
|
35
|
+
if (needsPublish) {
|
|
36
|
+
const dryRun = isDryRun ? '--dry-run' : '';
|
|
37
|
+
const commandToPublish = `pnpm publish --access public --tag ${tag} --no-git-checks ${dryRun}`;
|
|
38
|
+
isDryRun && devkit.logger.info('👀 Skip publish (dry run) \n');
|
|
39
|
+
devkit.logger.info(`${commandToPublish} \n`);
|
|
40
|
+
// Execute the command to publish the package.
|
|
41
|
+
// process.chdir(projectRoot);
|
|
42
|
+
await utils.runCommand(commandToPublish, projectRoot);
|
|
43
|
+
devkit.logger.info(`\n🚀 Successfully published ${packageName}@${packageVersion}`);
|
|
44
|
+
} else {
|
|
45
|
+
devkit.logger.warn(`👻 Package version "${packageVersion}" is invalid.`);
|
|
46
|
+
}
|
|
47
|
+
return utils.ok();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return utils.err(error, '❌ Error when publishing the package');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = runExecutor;
|
|
@@ -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,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var devkit = require('@nx/devkit');
|
|
4
|
+
var child_process = require('child_process');
|
|
5
|
+
var util = require('util');
|
|
6
|
+
|
|
7
|
+
const execAsync = util.promisify(child_process.exec);
|
|
8
|
+
/**
|
|
9
|
+
* Indicates a successful executor operation.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} message - Optional message to log for the success case.
|
|
12
|
+
* @returns {ExecutorResponse} - An object representing a successful operation.
|
|
13
|
+
*/ function ok(message) {
|
|
14
|
+
message && devkit.logger.info(message);
|
|
15
|
+
return {
|
|
16
|
+
success: true
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Indicates a failed executor operation.
|
|
21
|
+
*
|
|
22
|
+
* @param {string | Error | unknown} err - An optional error object or message indicating the nature of the failure.
|
|
23
|
+
* @param {string} message - An optional message to log for the error case. If not provided, a default error message is logged.
|
|
24
|
+
* @returns {ExecutorResponse} - An object representing a failed operation.
|
|
25
|
+
*/ function err(err, message) {
|
|
26
|
+
if (message) {
|
|
27
|
+
devkit.logger.error(message);
|
|
28
|
+
} else {
|
|
29
|
+
devkit.logger.error(`❌ an error occurred:`);
|
|
30
|
+
}
|
|
31
|
+
if (err) devkit.logger.error(err);
|
|
32
|
+
return {
|
|
33
|
+
success: false
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the project configuration for the current execution context.
|
|
38
|
+
*
|
|
39
|
+
* @param {ExecutorContext} ctx - The execution context containing project information.
|
|
40
|
+
* @returns {ProjectConfiguration} - The configuration object for the current project.
|
|
41
|
+
* @throws {Error} If the project configuration is invalid or not found.
|
|
42
|
+
*/ function getProjectConfig(ctx) {
|
|
43
|
+
const projectName = ctx.projectName || '';
|
|
44
|
+
const projectConfig = ctx.projectsConfigurations?.projects?.[projectName];
|
|
45
|
+
if (!projectConfig) throw new Error('Invalid project configuration.');
|
|
46
|
+
return projectConfig;
|
|
47
|
+
}
|
|
48
|
+
async function runCommand(command, cwd) {
|
|
49
|
+
try {
|
|
50
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
51
|
+
...cwd && {
|
|
52
|
+
cwd
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
devkit.logger.info(stdout);
|
|
56
|
+
devkit.logger.info(stderr);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
devkit.logger.error(`Unexpected error running command:`);
|
|
59
|
+
devkit.logger.error(error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.err = err;
|
|
65
|
+
exports.getProjectConfig = getProjectConfig;
|
|
66
|
+
exports.ok = ok;
|
|
67
|
+
exports.runCommand = runCommand;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
* Retrieves the project configuration for the current execution context.
|
|
20
|
+
*
|
|
21
|
+
* @param {ExecutorContext} ctx - The execution context containing project information.
|
|
22
|
+
* @returns {ProjectConfiguration} - The configuration object for the current project.
|
|
23
|
+
* @throws {Error} If the project configuration is invalid or not found.
|
|
24
|
+
*/
|
|
25
|
+
declare function getProjectConfig(ctx: ExecutorContext): ProjectConfiguration;
|
|
26
|
+
declare function runCommand(command: string, cwd?: string | URL): Promise<void>;
|
|
27
|
+
export { ok, err, getProjectConfig, runCommand };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var devkit = require('@nx/devkit');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var R = require('ramda');
|
|
6
|
+
|
|
7
|
+
const { writeFile } = fs.promises;
|
|
8
|
+
const transformPathToRoot = (path)=>{
|
|
9
|
+
const distPrefix = './dist/cjs/';
|
|
10
|
+
const srcRegex = /^\.\/src\//;
|
|
11
|
+
const executorTsRegex = /executor\.ts$/;
|
|
12
|
+
const jsonFileRegex = /\.json$/;
|
|
13
|
+
const isJson = jsonFileRegex.test(path);
|
|
14
|
+
const changeSrcPath = (p)=>p.replace(srcRegex, distPrefix);
|
|
15
|
+
const changeFileName = (p)=>isJson ? p : p.replace(executorTsRegex, 'index.cjs');
|
|
16
|
+
return R.pipe(changeSrcPath, changeFileName)(path);
|
|
17
|
+
};
|
|
18
|
+
const transformPathToDist = (path)=>{
|
|
19
|
+
const cjsPrefix = './cjs/';
|
|
20
|
+
const distRegex = /^\.\/dist\/cjs\//;
|
|
21
|
+
return path.replace(distRegex, cjsPrefix);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Updates the executor paths for the provided executors object.
|
|
25
|
+
* @param {Executors} executors - The executors object from executors.json.
|
|
26
|
+
* @param {boolean} toDist - Flag to determine if './dist' should be removed from paths.
|
|
27
|
+
* @returns - The updated executors object with transformed paths.
|
|
28
|
+
*/ const updateExecutorPaths = (executors, toDist)=>{
|
|
29
|
+
const transform = R.cond([
|
|
30
|
+
[
|
|
31
|
+
R.always(toDist),
|
|
32
|
+
transformPathToDist
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
R.T,
|
|
36
|
+
transformPathToRoot
|
|
37
|
+
]
|
|
38
|
+
]);
|
|
39
|
+
return Object.entries(executors).reduce((updatedExecutors, [key, executor])=>{
|
|
40
|
+
updatedExecutors[key] = {
|
|
41
|
+
...executor,
|
|
42
|
+
implementation: transform(executor.implementation),
|
|
43
|
+
schema: transform(executor.schema)
|
|
44
|
+
};
|
|
45
|
+
return updatedExecutors;
|
|
46
|
+
}, {});
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Writes a JSON file asynchronously.
|
|
50
|
+
* @param {string} path - The file path where to write the JSON data.
|
|
51
|
+
* @param {any} data - The data to be written to the file.
|
|
52
|
+
*/ const writeJsonFileAsync = async (path, data)=>{
|
|
53
|
+
try {
|
|
54
|
+
await writeFile(path, JSON.stringify(data, null, 2));
|
|
55
|
+
devkit.logger.info(`✅ Updated: ${path}`);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
devkit.logger.error(`❌ Error writing file ${path}: ${error}`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
exports.transformPathToDist = transformPathToDist;
|
|
62
|
+
exports.transformPathToRoot = transformPathToRoot;
|
|
63
|
+
exports.updateExecutorPaths = updateExecutorPaths;
|
|
64
|
+
exports.writeJsonFileAsync = writeJsonFileAsync;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Executors } from "../../types-763439e4.js";
|
|
2
|
+
declare const transformPathToRoot: (path: string) => string;
|
|
3
|
+
declare const transformPathToDist: (path: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Updates the executor paths for the provided executors object.
|
|
6
|
+
* @param {Executors} executors - The executors object from executors.json.
|
|
7
|
+
* @param {boolean} toDist - Flag to determine if './dist' should be removed from paths.
|
|
8
|
+
* @returns - The updated executors object with transformed paths.
|
|
9
|
+
*/
|
|
10
|
+
declare const updateExecutorPaths: (executors: Executors, toDist: boolean) => Executors;
|
|
11
|
+
/**
|
|
12
|
+
* Writes a JSON file asynchronously.
|
|
13
|
+
* @param {string} path - The file path where to write the JSON data.
|
|
14
|
+
* @param {any} data - The data to be written to the file.
|
|
15
|
+
*/
|
|
16
|
+
declare const writeJsonFileAsync: (path: string, data: any) => Promise<void>;
|
|
17
|
+
export { transformPathToRoot, transformPathToDist, updateExecutorPaths, writeJsonFileAsync };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var utils = require('../shared/utils.cjs');
|
|
6
|
+
var helpers = require('./helpers.cjs');
|
|
7
|
+
|
|
8
|
+
const { readFile } = fs.promises;
|
|
9
|
+
/**
|
|
10
|
+
* Executor function to update paths in the executors.json file.
|
|
11
|
+
*
|
|
12
|
+
* @param {ExecutorOptions} _opts - Executor options, currently not used but provided for future extensibility.
|
|
13
|
+
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
14
|
+
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
15
|
+
*/ async function runExecutor(_opts, ctx) {
|
|
16
|
+
try {
|
|
17
|
+
const projectConfig = utils.getProjectConfig(ctx);
|
|
18
|
+
const rootDir = projectConfig.root;
|
|
19
|
+
const executorsFilePath = path.join(rootDir, 'executors.json');
|
|
20
|
+
const distExecutorsFilePath = path.join(rootDir, 'dist', 'executors.json');
|
|
21
|
+
const originalContent = JSON.parse(await readFile(executorsFilePath, 'utf8'));
|
|
22
|
+
// Update paths to point to './dist/' and add '.js'
|
|
23
|
+
const updatedExecutors = helpers.updateExecutorPaths(originalContent.executors, false);
|
|
24
|
+
// Prepare the version for the dist folder by removing './dist/' from paths
|
|
25
|
+
// const distExecutors = updateExecutorPaths(updatedExecutors, true);
|
|
26
|
+
// Write both files asynchronously and in parallel
|
|
27
|
+
await Promise.all([
|
|
28
|
+
helpers.writeJsonFileAsync(executorsFilePath, {
|
|
29
|
+
executors: updatedExecutors
|
|
30
|
+
})
|
|
31
|
+
]);
|
|
32
|
+
return utils.ok(`🚀 Executors updated successfully.`);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return utils.err(error, `❌ Error processing file: ${error}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = runExecutor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { ExecutorResponse } from "../../index-f6330edc.js";
|
|
3
|
+
import { ExecutorOptions } from "../../types-763439e4.js";
|
|
4
4
|
/**
|
|
5
5
|
* Executor function to update paths in the executors.json file.
|
|
6
6
|
*
|
|
@@ -8,5 +8,5 @@ import type { ExecutorOptions } from './types';
|
|
|
8
8
|
* @param {ExecutorContext} ctx - The executor context, providing access to the project configuration.
|
|
9
9
|
* @returns {Promise<ExecutorResponse>} The result object with a success or error status.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
|
|
12
|
+
export { runExecutor as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const VTEX_PROJECT_PATH = process.env.NZ_VTEX_PROJECT;
|
|
4
|
+
const ERROR_LINKING_FLAG = '[31merror[39m: App build failed';
|
|
5
|
+
const SUCCESS_LINKING_FLAG = '[32minfo[39m: App running';
|
|
6
|
+
|
|
7
|
+
exports.ERROR_LINKING_FLAG = ERROR_LINKING_FLAG;
|
|
8
|
+
exports.SUCCESS_LINKING_FLAG = SUCCESS_LINKING_FLAG;
|
|
9
|
+
exports.VTEX_PROJECT_PATH = VTEX_PROJECT_PATH;
|
|
@@ -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 };
|