@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,124 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var devkit = require('@nx/devkit');
|
|
4
|
+
var nanoid = require('nanoid');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var R = require('ramda');
|
|
7
|
+
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generates a short ID string.
|
|
29
|
+
*
|
|
30
|
+
* @param {number} length - The length of the ID to generate.
|
|
31
|
+
* @returns {string} - The generated ID.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const id = shortId(10); // Outputs: "Aj3_Dk7_2j"
|
|
35
|
+
*/ const shortId = (length)=>nanoid.nanoid(length);
|
|
36
|
+
/**
|
|
37
|
+
* Deeply merges two objects, combining their properties.
|
|
38
|
+
*
|
|
39
|
+
* @param {Record<string, any>} v1 - The first object.
|
|
40
|
+
* @param {Record<string, any>} v2 - The second object.
|
|
41
|
+
* @returns {Record<string, any>} - The merged object.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const obj1 = { a: 1, b: { c: 2 } };
|
|
45
|
+
* const obj2 = { b: { d: 3 } };
|
|
46
|
+
* const merged = deepMerge(obj1, obj2); // Outputs: { a: 1, b: { c: 2, d: 3 } }
|
|
47
|
+
*/ function deepMerge(v1, v2) {
|
|
48
|
+
if (Array.isArray(v1) && Array.isArray(v2)) {
|
|
49
|
+
return R__namespace.uniq(R__namespace.concat(v1, v2));
|
|
50
|
+
} else if (typeof v1 === 'object' && typeof v2 === 'object' && !R__namespace.isNil(v1) && !R__namespace.isNil(v2)) {
|
|
51
|
+
return R__namespace.mergeWith(deepMerge, v1, v2);
|
|
52
|
+
} else {
|
|
53
|
+
return v2;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generates a name for js files.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} [prefix] - An optional prefix for the chunk name.
|
|
60
|
+
* @returns - A function that takes an item and generates a chunk name.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* const generateChunkName = chunkName('prefix');
|
|
64
|
+
* const name = generateChunkName({ name: 'example' }); // Outputs: "prefix-example-Aj3_Dk7_2j.js"
|
|
65
|
+
*/ const chunkName = (prefix)=>(x)=>{
|
|
66
|
+
const nameWithoutUnderscore = x.name.replace(/_/g, '');
|
|
67
|
+
const pre = prefix ? `${prefix}-` : '';
|
|
68
|
+
return `${pre}${nameWithoutUnderscore}-${shortId(8)}.js`;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Returns the given object if the condition is true, otherwise returns null.
|
|
72
|
+
*
|
|
73
|
+
* @param {any} condition - The condition to evaluate.
|
|
74
|
+
* @param {Record<string, any>} obj - The object to return if the condition is true.
|
|
75
|
+
* @returns {Record<string, any> | null} - The object or null based on the condition.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const obj = { a: 1 };
|
|
79
|
+
* const result = when(true, obj); // Outputs: { a: 1 }
|
|
80
|
+
* const result2 = when(false, obj); // Outputs: {}
|
|
81
|
+
*/ const when = (condition, obj)=>condition ? obj : {};
|
|
82
|
+
/**
|
|
83
|
+
* Filters and generates plugin configurations based on conditions and the provided context.
|
|
84
|
+
*
|
|
85
|
+
* @param {Context} ctx - The main configuration object.
|
|
86
|
+
* @returns {any[]} - An array of generated plugin configurations.
|
|
87
|
+
*/ const getPlugins = (ctx, ...pluginConfigs)=>pluginConfigs // Filters the plugins based on conditions
|
|
88
|
+
.filter((p)=>!p.condition || p.condition(ctx)) // Generates the configuration of each plugin and flattens the resulting array
|
|
89
|
+
.flatMap((p)=>p.generate(ctx));
|
|
90
|
+
/**
|
|
91
|
+
* Gets the paths to the tsconfig files for all relevant projects.
|
|
92
|
+
*
|
|
93
|
+
* @returns {string[]} - An array containing paths to tsconfig files for both app and lib projects.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const projects = {
|
|
97
|
+
* 'my-app': {
|
|
98
|
+
* type: 'app',
|
|
99
|
+
* data: { root: 'apps/my-app' }
|
|
100
|
+
* },
|
|
101
|
+
* 'my-lib': {
|
|
102
|
+
* type: 'lib',
|
|
103
|
+
* data: { root: 'libs/my-lib' }
|
|
104
|
+
* }
|
|
105
|
+
* };
|
|
106
|
+
*
|
|
107
|
+
* const tsConfigPaths = getTsConfigPaths(projects);
|
|
108
|
+
* console.log(tsConfigPaths);
|
|
109
|
+
* // Output:
|
|
110
|
+
* // ['apps/my-app/tsconfig.app.json', 'libs/my-lib/tsconfig.lib.json']
|
|
111
|
+
*/ const getNxTsConfigPaths = ()=>{
|
|
112
|
+
const isValid = (p)=>p.data.root.startsWith('apps/') || p.data.root.startsWith('libs/');
|
|
113
|
+
const getTsConfigPath = (p)=>path.resolve(p.data.root, `tsconfig.${p.type === 'app' ? 'app' : 'lib'}.json`);
|
|
114
|
+
const graph = devkit.readCachedProjectGraph();
|
|
115
|
+
const projects = graph.nodes;
|
|
116
|
+
return Object.values(projects).filter(isValid).map(getTsConfigPath);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
exports.chunkName = chunkName;
|
|
120
|
+
exports.deepMerge = deepMerge;
|
|
121
|
+
exports.getNxTsConfigPaths = getNxTsConfigPaths;
|
|
122
|
+
exports.getPlugins = getPlugins;
|
|
123
|
+
exports.shortId = shortId;
|
|
124
|
+
exports.when = when;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { UserConfig } from 'vite';
|
|
2
|
+
import { CommonProjectConfig, ProjectConfig, ProjectConfigInitialized } from "../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Initializes the project configuration with default values.
|
|
5
5
|
*
|
|
@@ -7,8 +7,8 @@ import { type CommonProjectConfig, type ProjectConfig, type ProjectConfigInitial
|
|
|
7
7
|
* const config = { type: ProjectType.APP, path: '/path/to/project', viteEnv: { mode: ViteMode.DEV } };
|
|
8
8
|
* const initializedConfig = initializeConfig(config);
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
viteCmd: import("../types").ViteCommand;
|
|
10
|
+
declare const initializeConfig: (ccfg: CommonProjectConfig, pcfg: ProjectConfig, localPkgJson: Record<string, any>) => {
|
|
11
|
+
viteCmd: import("../types.js").ViteCommand;
|
|
12
12
|
cfg: ProjectConfigInitialized;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
@@ -18,7 +18,7 @@ export declare const initializeConfig: (ccfg: CommonProjectConfig, pcfg: Project
|
|
|
18
18
|
* @param {UserConfig} overrides - The overrides configuration.
|
|
19
19
|
* @returns {UserConfig} - The merged configuration.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
declare const mergeConfigs: (defaultConfig: UserConfig, overrides: UserConfig) => UserConfig;
|
|
22
22
|
/**
|
|
23
23
|
* Resolves glob patterns to actual package names found in package.json dependencies.
|
|
24
24
|
* This function is used to determine which packages should be treated as external
|
|
@@ -36,7 +36,7 @@ export declare const mergeConfigs: (defaultConfig: UserConfig, overrides: UserCo
|
|
|
36
36
|
* console.log(externalDependencies);
|
|
37
37
|
* // Output might be: ['my-lib/utils', 'my-lib/core', 'lodash']
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
declare const getExternalDependencies: (path: string, globs?: string | string[]) => string[];
|
|
40
40
|
/**
|
|
41
41
|
* Generates a string of initials based on the input string,
|
|
42
42
|
* following certain rules:
|
|
@@ -56,5 +56,5 @@ export declare const getExternalDependencies: (path: string, globs?: string | st
|
|
|
56
56
|
* getInitials("ssv-admin"); // returns "sa"
|
|
57
57
|
* getInitials("@nizza/customize-live"); // returns "cl"
|
|
58
58
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
declare function getInitials(input: string): string;
|
|
60
|
+
export { initializeConfig, mergeConfigs, getExternalDependencies, getInitials };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var minimatch = require('minimatch');
|
|
4
|
+
var logger = require('../../../../shared/logger.js');
|
|
5
|
+
var utils = require('../../../../shared/utils.js');
|
|
6
|
+
var types = require('../types.js');
|
|
7
|
+
var helpers = require('./helpers.js');
|
|
8
|
+
var viteCommand = require('./viteCommand.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the project configuration with default values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const config = { type: ProjectType.APP, path: '/path/to/project', viteEnv: { mode: ViteMode.DEV } };
|
|
15
|
+
* const initializedConfig = initializeConfig(config);
|
|
16
|
+
*/ const initializeConfig = (ccfg, pcfg, localPkgJson)=>{
|
|
17
|
+
const { envPrefix } = ccfg;
|
|
18
|
+
const localPkgName = localPkgJson['name'];
|
|
19
|
+
const { name = localPkgName, overrides = {}, shadowDom = false, chunkPrefix = getInitials(localPkgName), resolveEnvs = {
|
|
20
|
+
default: true,
|
|
21
|
+
local: true
|
|
22
|
+
}, fileName = `${envPrefix}-${chunkPrefix}-index`, externalizeLibs = {
|
|
23
|
+
default: true,
|
|
24
|
+
glob: []
|
|
25
|
+
} } = pcfg;
|
|
26
|
+
const viteCmd = viteCommand.getViteCommand(pcfg.viteEnv.mode);
|
|
27
|
+
const isVerbose = Object.keys(viteCmd.flags).some((x)=>[
|
|
28
|
+
types.Flag.VERBOSE,
|
|
29
|
+
types.Flag.VERBOSE_ALIAS
|
|
30
|
+
].includes(x));
|
|
31
|
+
const logLevel = isVerbose ? logger.LogLevel.DEBUG : pcfg.logLevel ?? logger.LogLevel.INFO;
|
|
32
|
+
logger.setLogLevel(logLevel);
|
|
33
|
+
return {
|
|
34
|
+
viteCmd,
|
|
35
|
+
cfg: {
|
|
36
|
+
...pcfg,
|
|
37
|
+
name,
|
|
38
|
+
fileName,
|
|
39
|
+
logLevel,
|
|
40
|
+
overrides,
|
|
41
|
+
chunkPrefix,
|
|
42
|
+
shadowDom,
|
|
43
|
+
resolveEnvs,
|
|
44
|
+
externalizeLibs: externalizeLibs
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Handles merging configurations and logs any errors.
|
|
50
|
+
*
|
|
51
|
+
* @param {UserConfig} defaultConfig - The default configuration.
|
|
52
|
+
* @param {UserConfig} overrides - The overrides configuration.
|
|
53
|
+
* @returns {UserConfig} - The merged configuration.
|
|
54
|
+
*/ const mergeConfigs = (defaultConfig, overrides)=>{
|
|
55
|
+
try {
|
|
56
|
+
return helpers.deepMerge(defaultConfig, overrides);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
logger.logger.error('Error merging vite configs: ', err);
|
|
59
|
+
return defaultConfig;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Resolves glob patterns to actual package names found in package.json dependencies.
|
|
64
|
+
* This function is used to determine which packages should be treated as external
|
|
65
|
+
* in a Rollup or Vite build configuration.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} path - The base path where package.json is located.
|
|
68
|
+
* @param {string | string[]} globs - A glob pattern or an array of glob patterns to match dependencies against.
|
|
69
|
+
* @returns {string[]} An array of package names that match the given glob patterns.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Example of using `getExternalDependencies` to find all dependencies starting with "my-lib" and "lodash"
|
|
73
|
+
* const projectPath = '/path/to/project';
|
|
74
|
+
* const globs = ['my-lib*', 'lodash'];
|
|
75
|
+
* const externalDependencies = getExternalDependencies(projectPath, globs);
|
|
76
|
+
* console.log(externalDependencies);
|
|
77
|
+
* // Output might be: ['my-lib/utils', 'my-lib/core', 'lodash']
|
|
78
|
+
*/ const getExternalDependencies = (path, globs = [])=>{
|
|
79
|
+
const pkgJson = utils.getPkgJson(path); // Assumes getLocalPkgJson is a function that reads and parses package.json
|
|
80
|
+
const dependencies = Object.keys(pkgJson.dependencies || {});
|
|
81
|
+
const globPatterns = Array.isArray(globs) ? globs : [
|
|
82
|
+
globs
|
|
83
|
+
];
|
|
84
|
+
return dependencies.filter((dep)=>globPatterns.some((pattern)=>minimatch.minimatch(dep, pattern)));
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Generates a string of initials based on the input string,
|
|
88
|
+
* following certain rules:
|
|
89
|
+
* 1. A word is considered as a sequence of characters
|
|
90
|
+
* separated by hyphens.
|
|
91
|
+
* 2. If the string contains '@', any characters before
|
|
92
|
+
* and including the next '/' are ignored.
|
|
93
|
+
* 3. The first character of each word is taken to form
|
|
94
|
+
* the initials.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} input - The input string from which to generate the initials.
|
|
97
|
+
* @returns {string} The initials formed by taking the first character
|
|
98
|
+
* of each word, after applying the specified rules.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* getInitials("player-script"); // returns "ps"
|
|
102
|
+
* getInitials("ssv-admin"); // returns "sa"
|
|
103
|
+
* getInitials("@nizza/customize-live"); // returns "cl"
|
|
104
|
+
*/ function getInitials(input) {
|
|
105
|
+
const cleanedInput = input.includes('@') ? input.split('/')[1] : input;
|
|
106
|
+
const words = cleanedInput?.split('-');
|
|
107
|
+
const initials = words?.map((word)=>word.charAt(0)).join('');
|
|
108
|
+
return initials ?? '';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.getExternalDependencies = getExternalDependencies;
|
|
112
|
+
exports.getInitials = getInitials;
|
|
113
|
+
exports.initializeConfig = initializeConfig;
|
|
114
|
+
exports.mergeConfigs = mergeConfigs;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ViteMode,
|
|
1
|
+
import { ViteMode, ViteCommand } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the Vite command details.
|
|
4
4
|
*
|
|
@@ -9,7 +9,7 @@ import { ViteMode, type ViteCommand } from '../types';
|
|
|
9
9
|
* const command = getViteCommand(ViteMode.PROD);
|
|
10
10
|
* // Outputs: { stage: Stage.PROD, target: 'build', flags: {} }
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
declare function getViteCommand(mode: ViteMode): ViteCommand;
|
|
13
13
|
/**
|
|
14
14
|
* Parses the command string to extract flags.
|
|
15
15
|
*
|
|
@@ -20,5 +20,5 @@ export declare function getViteCommand(mode: ViteMode): ViteCommand;
|
|
|
20
20
|
* const flags = getViteCmdFlags('nx run core:build --source-maps');
|
|
21
21
|
* // Outputs: { 'source-maps: 'true' }
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
declare function getViteCmdFlags(commandString: string | undefined): Record<string, string>;
|
|
24
|
+
export { getViteCommand, getViteCmdFlags };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chalk = require('chalk');
|
|
4
|
+
var argv = require('mri');
|
|
5
|
+
var vite = require('vite');
|
|
6
|
+
var types = require('../types.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the Vite command details.
|
|
10
|
+
*
|
|
11
|
+
* @param {ViteMode} mode - The Vite mode.
|
|
12
|
+
* @returns {ViteCommand} - The command details.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const command = getViteCommand(ViteMode.PROD);
|
|
16
|
+
* // Outputs: { stage: Stage.PROD, target: 'build', flags: {} }
|
|
17
|
+
*/ function getViteCommand(mode) {
|
|
18
|
+
const nxEnv = vite.loadEnv(mode, process.cwd(), 'NX');
|
|
19
|
+
const nxCommandString = process?.env?.['npm_package_scripts_nx'];
|
|
20
|
+
const modeIsProd = mode === types.ViteMode.PROD;
|
|
21
|
+
const stage = (nxEnv?.['NX_TASK_TARGET_CONFIGURATION']) ?? (modeIsProd ? types.Stage.PROD : types.Stage.DEV);
|
|
22
|
+
const target = nxEnv?.['NX_TASK_TARGET_TARGET'] ?? types.Target.BUILD;
|
|
23
|
+
const flags = getViteCmdFlags(nxCommandString);
|
|
24
|
+
const showIn = {
|
|
25
|
+
prod: (...args)=>modeIsProd && console.log(...args),
|
|
26
|
+
dev: (...args)=>!modeIsProd && console.log(...args)
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
showIn.prod(chalk.cyan('Build Stage:'), chalk.green(stage));
|
|
30
|
+
showIn.dev(chalk.green(' ➜ '), chalk.bold.white(`Stage: `), chalk.cyan(stage));
|
|
31
|
+
} catch {
|
|
32
|
+
showIn.prod(console.log('Build Stage:', stage));
|
|
33
|
+
showIn.dev(console.log(` ➜ Stage: `, stage));
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
stage,
|
|
37
|
+
target,
|
|
38
|
+
flags
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parses the command string to extract flags.
|
|
43
|
+
*
|
|
44
|
+
* @param {string | undefined} commandString - The command string.
|
|
45
|
+
* @returns {Record<string, string>} - The flags extracted from the command string.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const flags = getViteCmdFlags('nx run core:build --source-maps');
|
|
49
|
+
* // Outputs: { 'source-maps: 'true' }
|
|
50
|
+
*/ function getViteCmdFlags(commandString) {
|
|
51
|
+
if (!commandString) return {};
|
|
52
|
+
const cleanedCommandString = commandString.replace(/"/g, '');
|
|
53
|
+
const args = argv(cleanedCommandString.split(' '));
|
|
54
|
+
delete args['_'];
|
|
55
|
+
return args;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.getViteCmdFlags = getViteCmdFlags;
|
|
59
|
+
exports.getViteCommand = getViteCommand;
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
default: function() {
|
|
13
|
-
return _default;
|
|
14
|
-
},
|
|
15
|
-
injectCssIntoShadowDom: function() {
|
|
16
|
-
return injectCssIntoShadowDom;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
19
3
|
function injectCssIntoShadowDom() {
|
|
20
4
|
const fileRegex = /\.(css)$/;
|
|
21
5
|
let server;
|
|
@@ -41,4 +25,5 @@ function injectCssIntoShadowDom() {
|
|
|
41
25
|
}
|
|
42
26
|
};
|
|
43
27
|
}
|
|
44
|
-
|
|
28
|
+
|
|
29
|
+
exports.injectCssIntoShadowDom = injectCssIntoShadowDom;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
interface Execute {
|
|
3
|
+
function: (data?: string) => void;
|
|
4
|
+
listen: string;
|
|
5
|
+
observer: string;
|
|
6
|
+
}
|
|
7
|
+
interface ThirdPartyCssInjectPlugin {
|
|
8
|
+
topExecutionPriority?: boolean;
|
|
9
|
+
execute?: Execute[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Inject the CSS compiled with JS.
|
|
13
|
+
*
|
|
14
|
+
* @return {Plugin}
|
|
15
|
+
*/
|
|
16
|
+
declare function thirdPartyCssInjectPlugin({ topExecutionPriority, execute }?: ThirdPartyCssInjectPlugin | undefined): Plugin;
|
|
17
|
+
export { Execute, ThirdPartyCssInjectPlugin, thirdPartyCssInjectPlugin };
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
const _utils = require("./utils");
|
|
12
|
-
function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Inject the CSS compiled with JS.
|
|
7
|
+
*
|
|
8
|
+
* @return {Plugin}
|
|
9
|
+
*/ function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
|
|
13
10
|
topExecutionPriority: true,
|
|
14
11
|
execute: []
|
|
15
12
|
}) {
|
|
@@ -33,12 +30,12 @@ function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
|
|
|
33
30
|
const htmlChunk = bundle[name];
|
|
34
31
|
let replacedHtml = htmlChunk.source;
|
|
35
32
|
cssAssets.forEach((cssName)=>{
|
|
36
|
-
replacedHtml =
|
|
33
|
+
replacedHtml = utils.removeLinkStyleSheets(replacedHtml, cssName);
|
|
37
34
|
htmlChunk.source = replacedHtml;
|
|
38
35
|
});
|
|
39
36
|
}
|
|
40
37
|
const jsAsset = bundle[jsAssets[0]];
|
|
41
|
-
const cssInjectionCode = await
|
|
38
|
+
const cssInjectionCode = await utils.buildCSSInjectionCode(execute);
|
|
42
39
|
const appCode = jsAsset.code;
|
|
43
40
|
jsAsset.code = topExecutionPriority ? '' : appCode;
|
|
44
41
|
jsAsset.code += cssInjectionCode ? cssInjectionCode.code : '';
|
|
@@ -46,3 +43,5 @@ function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
|
|
|
46
43
|
}
|
|
47
44
|
};
|
|
48
45
|
}
|
|
46
|
+
|
|
47
|
+
exports.thirdPartyCssInjectPlugin = thirdPartyCssInjectPlugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OutputChunk } from 'rollup';
|
|
2
|
+
import { Execute } from "../../../index-3080371d.js";
|
|
3
|
+
declare function buildCSSInjectionCode(execute?: Execute[]): Promise<OutputChunk | null | any>;
|
|
4
|
+
declare function removeLinkStyleSheets(html: string, cssFileName: string): string;
|
|
5
|
+
export { buildCSSInjectionCode, removeLinkStyleSheets };
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
buildCSSInjectionCode: function() {
|
|
13
|
-
return buildCSSInjectionCode;
|
|
14
|
-
},
|
|
15
|
-
removeLinkStyleSheets: function() {
|
|
16
|
-
return removeLinkStyleSheets;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _vite = require("vite");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vite = require('vite');
|
|
4
|
+
|
|
20
5
|
const cssInjectedByJsId = '\0vite/all-css';
|
|
21
6
|
const waitForElement = (selector, observerElementName = 'body')=>{
|
|
22
7
|
const getElement = (selector)=>document.querySelector(selector);
|
|
@@ -47,7 +32,7 @@ const waitForElement = (selector, observerElementName = 'body')=>{
|
|
|
47
32
|
});
|
|
48
33
|
};
|
|
49
34
|
async function buildCSSInjectionCode(execute) {
|
|
50
|
-
const res = await
|
|
35
|
+
const res = await vite.build({
|
|
51
36
|
root: '',
|
|
52
37
|
configFile: false,
|
|
53
38
|
logLevel: 'error',
|
|
@@ -110,3 +95,6 @@ function removeLinkStyleSheets(html, cssFileName) {
|
|
|
110
95
|
const removeCSS = new RegExp(`<link rel=".*"[^>]*?href=".*/?${cssFileName}"[^>]*?>`);
|
|
111
96
|
return html.replace(removeCSS, '');
|
|
112
97
|
}
|
|
98
|
+
|
|
99
|
+
exports.buildCSSInjectionCode = buildCSSInjectionCode;
|
|
100
|
+
exports.removeLinkStyleSheets = removeLinkStyleSheets;
|
|
@@ -0,0 +1,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
|
+
import { logger } from '@nx/devkit';
|
|
2
|
+
import { runCommand } from '../shared/utils.js';
|
|
3
|
+
|
|
4
|
+
async function cleanS3Bucket(s3BucketPath) {
|
|
5
|
+
logger.info('🧹 Cleaning S3 bucket...');
|
|
6
|
+
await runCommand(`aws s3 rm ${s3BucketPath} --recursive`);
|
|
7
|
+
logger.info('✅ S3 bucket cleared.');
|
|
8
|
+
}
|
|
9
|
+
async function copyAssetsToS3(s3BucketPath, projectRoot) {
|
|
10
|
+
logger.info('📦 Copying assets to S3 bucket...');
|
|
11
|
+
await runCommand(`aws s3 cp ${projectRoot}/dist ${s3BucketPath} --recursive`);
|
|
12
|
+
logger.info('🚚 Assets files copied.');
|
|
13
|
+
}
|
|
14
|
+
async function createCloudFrontInvalidation(distributionId, invalidationPaths) {
|
|
15
|
+
const pathsString = invalidationPaths.map((path)=>`"${path}"`).join(' ');
|
|
16
|
+
const command = `aws cloudfront create-invalidation --distribution-id ${distributionId} --paths ${pathsString}`;
|
|
17
|
+
logger.info('🔃 Creating invalidation for CloudFront...');
|
|
18
|
+
await runCommand(command);
|
|
19
|
+
logger.info('🔄 CloudFront invalidation created.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { cleanS3Bucket, copyAssetsToS3, createCloudFrontInvalidation };
|
|
@@ -0,0 +1,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,20 @@
|
|
|
1
|
+
import { getProjectConfig, runCommand, ok, err } from '../shared/utils.js';
|
|
2
|
+
import { cleanS3Bucket, copyAssetsToS3, createCloudFrontInvalidation } from './helpers.js';
|
|
3
|
+
|
|
4
|
+
async function deployExecutor(opts, ctx) {
|
|
5
|
+
try {
|
|
6
|
+
const { root, name } = getProjectConfig(ctx);
|
|
7
|
+
const { s3BucketPath, cloudFrontDistributionId, cloudFrontInvalidationPaths, skipBuild = false } = opts;
|
|
8
|
+
const buildTarget = `${name}:${opts.buildTarget}`;
|
|
9
|
+
if (!skipBuild) await runCommand(`nx run ${buildTarget}`);
|
|
10
|
+
await cleanS3Bucket(s3BucketPath);
|
|
11
|
+
await copyAssetsToS3(s3BucketPath, root);
|
|
12
|
+
await createCloudFrontInvalidation(cloudFrontDistributionId, cloudFrontInvalidationPaths);
|
|
13
|
+
const now = new Date().toLocaleString();
|
|
14
|
+
return ok(`✨ Build completed successfully on ${now}`);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return err(error, '❌ Error when executing deploy command');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { deployExecutor as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Deploy executor",
|
|
5
|
+
"description": "",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"s3BucketPath": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "S3 BUCKET ROUTE"
|
|
11
|
+
},
|
|
12
|
+
"cloudFrontDistributionId": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Cloudfront distribution id for cache invalidation"
|
|
15
|
+
},
|
|
16
|
+
"cloudFrontInvalidationPaths": {
|
|
17
|
+
"type": "array",
|
|
18
|
+
"description": "Cloudfront path list that must be invalidated in the cache",
|
|
19
|
+
"items": {
|
|
20
|
+
"type": "string"
|
|
21
|
+
},
|
|
22
|
+
"uniqueItems": true,
|
|
23
|
+
"minItems": 1
|
|
24
|
+
},
|
|
25
|
+
"buildTarget": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Build command relative to the project and without the name of the project because it is not necessary"
|
|
28
|
+
},
|
|
29
|
+
"skipBuild": {
|
|
30
|
+
"type": "boolean",
|
|
31
|
+
"description": "It allows to omit the Build process and assumes that it was already done",
|
|
32
|
+
"default": false
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"required": [
|
|
36
|
+
"s3BucketPath",
|
|
37
|
+
"cloudFrontDistributionId",
|
|
38
|
+
"cloudFrontInvalidationPaths",
|
|
39
|
+
"buildTarget"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the content for an environment file based on the core environment path.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} coreEnvPath - The path to the core environment file.
|
|
5
|
+
* @returns {string} The content of the environment file.
|
|
6
|
+
*/
|
|
7
|
+
declare function createEnvironmentFileContent(coreEnvPath: string): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Ensures that the given directory exists, creating it if it does not.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} dir - The path to the directory to check/create.
|
|
12
|
+
*/
|
|
13
|
+
declare function ensureDirectoryExists(dir: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Writes environment files to the given base path if they do not already exist.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} basePath - The base directory where the files should be written.
|
|
18
|
+
* @param {Record<string, string>} files - An object containing filenames and their respective content.
|
|
19
|
+
*/
|
|
20
|
+
declare function writeFilesIfNotExist(basePath: string, files: Record<string, string>): Promise<void>;
|
|
21
|
+
export { createEnvironmentFileContent, ensureDirectoryExists, writeFilesIfNotExist };
|