@ixon-cdk/core 1.3.0-next.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/schema.d.ts +21 -4
- package/config/schema.json +35 -4
- package/meta-files.js +71 -32
- package/package.json +1 -1
package/config/schema.d.ts
CHANGED
|
@@ -36,14 +36,22 @@ export interface schema {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
interface component {
|
|
39
|
+
/**
|
|
40
|
+
* The component root path, relative to the workspace root. By default, the component root path
|
|
41
|
+
* is formed by concatenating the `newComponentRoot` and component name.
|
|
42
|
+
*/
|
|
43
|
+
root?: string;
|
|
39
44
|
runner: {
|
|
40
45
|
build: {
|
|
41
|
-
/** The builder package name and build command */
|
|
46
|
+
/** The builder package name and build command. */
|
|
42
47
|
builder: string;
|
|
43
|
-
/** The component input
|
|
48
|
+
/** The component input file, relative to the component root. */
|
|
44
49
|
input: string;
|
|
45
|
-
/**
|
|
46
|
-
|
|
50
|
+
/**
|
|
51
|
+
* List of static component assets. Can be passed as glob paths relative to the component
|
|
52
|
+
* root or as objects for more fine-tuned configuration.
|
|
53
|
+
*/
|
|
54
|
+
assets?: (string | asset)[];
|
|
47
55
|
};
|
|
48
56
|
deploy?: {
|
|
49
57
|
/** Company ID */
|
|
@@ -53,3 +61,12 @@ interface component {
|
|
|
53
61
|
};
|
|
54
62
|
};
|
|
55
63
|
}
|
|
64
|
+
|
|
65
|
+
interface asset {
|
|
66
|
+
/** A node-glob using input as base directory. */
|
|
67
|
+
glob: string;
|
|
68
|
+
/** A path relative to the workspace root. */
|
|
69
|
+
input?: string;
|
|
70
|
+
/** A path relative to the component output path (default is dist/component-name). */
|
|
71
|
+
output?: string;
|
|
72
|
+
}
|
package/config/schema.json
CHANGED
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"component": {
|
|
48
48
|
"type": "object",
|
|
49
49
|
"properties": {
|
|
50
|
+
"root": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"description": "The component root path, relative to the workspace root. By default, the component root path is formed by concatenating the `newComponentRoot` and component name."
|
|
53
|
+
},
|
|
50
54
|
"runner": {
|
|
51
55
|
"type": "object",
|
|
52
56
|
"properties": {
|
|
@@ -55,18 +59,25 @@
|
|
|
55
59
|
"properties": {
|
|
56
60
|
"builder": {
|
|
57
61
|
"type": "string",
|
|
58
|
-
"description": "The builder package name and build command"
|
|
62
|
+
"description": "The builder package name and build command."
|
|
59
63
|
},
|
|
60
64
|
"input": {
|
|
61
65
|
"type": "string",
|
|
62
|
-
"description": "The component input
|
|
66
|
+
"description": "The component input file, relative to the component root."
|
|
63
67
|
},
|
|
64
68
|
"assets": {
|
|
65
69
|
"type": "array",
|
|
66
70
|
"items": {
|
|
67
|
-
"
|
|
71
|
+
"anyOf": [
|
|
72
|
+
{
|
|
73
|
+
"type": "string"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"$ref": "#/definitions/asset"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
68
79
|
},
|
|
69
|
-
"description": "List of static component assets."
|
|
80
|
+
"description": "List of static component assets. Can be passed as glob paths relative to the component root or as objects for more fine-tuned configuration."
|
|
70
81
|
}
|
|
71
82
|
},
|
|
72
83
|
"required": [
|
|
@@ -100,6 +111,26 @@
|
|
|
100
111
|
"required": [
|
|
101
112
|
"runner"
|
|
102
113
|
]
|
|
114
|
+
},
|
|
115
|
+
"asset": {
|
|
116
|
+
"type": "object",
|
|
117
|
+
"properties": {
|
|
118
|
+
"glob": {
|
|
119
|
+
"type": "string",
|
|
120
|
+
"description": "A node-glob using input as base directory."
|
|
121
|
+
},
|
|
122
|
+
"input": {
|
|
123
|
+
"type": "string",
|
|
124
|
+
"description": "A path relative to the workspace root."
|
|
125
|
+
},
|
|
126
|
+
"output": {
|
|
127
|
+
"type": "string",
|
|
128
|
+
"description": "A path relative to the component output path (default is dist/component-name)."
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"required": [
|
|
132
|
+
"glob"
|
|
133
|
+
]
|
|
103
134
|
}
|
|
104
135
|
}
|
|
105
136
|
}
|
package/meta-files.js
CHANGED
|
@@ -3,7 +3,7 @@ const fse = require('fs-extra');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const { watch } = require('chokidar');
|
|
5
5
|
const { globSync } = require('glob');
|
|
6
|
-
const { debounce,
|
|
6
|
+
const { debounce, isEqual, uniqWith } = require('lodash');
|
|
7
7
|
const { getRootDir } = require('./utils');
|
|
8
8
|
|
|
9
9
|
const ICON_FILE_NAME = 'icon.svg';
|
|
@@ -13,46 +13,61 @@ const WATCH_OPTIONS = {
|
|
|
13
13
|
usePolling: process.platform !== 'darwin',
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} Asset
|
|
18
|
+
* @property {String} glob - A node-glob using input as base directory.
|
|
19
|
+
* @property {String} [input] - A path relative to the workspace root.
|
|
20
|
+
* @property {String} [output] - A path relative to outputPath (default is dist/component-name).
|
|
21
|
+
*/
|
|
22
|
+
|
|
16
23
|
module.exports = {
|
|
17
24
|
cleanDir(dir) {
|
|
18
25
|
fse.emptyDirSync(dir);
|
|
19
26
|
},
|
|
27
|
+
/**
|
|
28
|
+
* @param {Array<String | Asset>} assets
|
|
29
|
+
* @param {String} inputDir
|
|
30
|
+
* @param {String} outputDir
|
|
31
|
+
*/
|
|
20
32
|
copyAssets(assets, inputDir, outputDir) {
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
_getAssetSpecs(assets, inputDir, outputDir).forEach(
|
|
34
|
+
({ glob, input, output }) => {
|
|
35
|
+
const globFilePath = path.join(input, glob).replaceAll('\\', '/');
|
|
36
|
+
globSync(globFilePath).forEach(file => {
|
|
37
|
+
const filePath = file.slice(input.length + 1);
|
|
38
|
+
_copyFromToSync(filePath, input, output);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
23
41
|
);
|
|
24
|
-
paths.forEach(_path => {
|
|
25
|
-
const globFilePath = _path.replaceAll('\\', '/');
|
|
26
|
-
globSync(globFilePath).forEach(file => {
|
|
27
|
-
const filePath = file.slice(inputDir.length + 1);
|
|
28
|
-
_copyFromToSync(filePath, inputDir, outputDir);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
42
|
},
|
|
32
43
|
watchAssets(assets, inputDir, outputDir) {
|
|
33
44
|
const root = getRootDir();
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
path.join(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
return Promise.all(
|
|
46
|
+
_getAssetSpecs(assets, inputDir, outputDir).map(asset => {
|
|
47
|
+
return watch(path.join(asset.input, asset.glob), WATCH_OPTIONS).on(
|
|
48
|
+
'all',
|
|
49
|
+
(type, file) => {
|
|
50
|
+
const filePath = path
|
|
51
|
+
.join(root, file)
|
|
52
|
+
.slice(asset.input.length + 1);
|
|
53
|
+
switch (type) {
|
|
54
|
+
case 'add':
|
|
55
|
+
case 'addDir':
|
|
56
|
+
case 'change':
|
|
57
|
+
case 'changeDir':
|
|
58
|
+
_copyFromToSync(filePath, asset.input, asset.output);
|
|
59
|
+
break;
|
|
60
|
+
case 'unlink':
|
|
61
|
+
case 'unlinkDir':
|
|
62
|
+
fse.removeSync(path.join(asset.output, filePath));
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
56
71
|
},
|
|
57
72
|
watchInputDir(dir, watchCallback) {
|
|
58
73
|
const _debouncedCallback = debounce(() => watchCallback(), 300);
|
|
@@ -92,3 +107,27 @@ function _copyFromToSync(filePath, sourceDir, destDir) {
|
|
|
92
107
|
fse.copySync(sourceFile, destFile);
|
|
93
108
|
}
|
|
94
109
|
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {Array<String | Asset>} assets
|
|
113
|
+
* @param {String} inputDir
|
|
114
|
+
* @param {String} outputDir
|
|
115
|
+
* @returns {Required<Asset>[]}
|
|
116
|
+
*/
|
|
117
|
+
function _getAssetSpecs(assets, inputDir, outputDir) {
|
|
118
|
+
const rootDir = getRootDir();
|
|
119
|
+
return uniqWith([MANIFEST_FILE_NAME, ICON_FILE_NAME, ...assets], isEqual).map(
|
|
120
|
+
asset =>
|
|
121
|
+
typeof asset === 'string'
|
|
122
|
+
? {
|
|
123
|
+
glob: path.normalize(asset),
|
|
124
|
+
input: path.normalize(inputDir),
|
|
125
|
+
output: path.normalize(outputDir),
|
|
126
|
+
}
|
|
127
|
+
: {
|
|
128
|
+
glob: path.normalize(asset.glob),
|
|
129
|
+
input: path.join(rootDir, asset.input ?? inputDir),
|
|
130
|
+
output: path.join(outputDir, asset.output ?? '/'),
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
}
|