@ixon-cdk/core 1.2.0-next.4 → 1.2.0-next.6
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/meta-files.js +55 -60
- package/package.json +2 -2
- package/utils.js +2 -1
package/meta-files.js
CHANGED
|
@@ -1,77 +1,73 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const fse = require('fs-extra');
|
|
2
3
|
const path = require('path');
|
|
4
|
+
const { watch } = require('chokidar');
|
|
3
5
|
const { globSync } = require('glob');
|
|
4
6
|
const { debounce, uniq } = require('lodash');
|
|
5
|
-
const
|
|
7
|
+
const { getRootDir } = require('./utils');
|
|
6
8
|
|
|
7
9
|
const ICON_FILE_NAME = 'icon.svg';
|
|
8
10
|
const MANIFEST_FILE_NAME = 'manifest.json';
|
|
9
11
|
const WATCH_OPTIONS = {
|
|
10
|
-
cwd:
|
|
12
|
+
cwd: getRootDir(),
|
|
11
13
|
usePolling: process.platform !== 'darwin',
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
module.exports = {
|
|
15
17
|
cleanDir(dir) {
|
|
16
|
-
|
|
17
|
-
rimraf.sync(dir);
|
|
18
|
-
}
|
|
19
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
18
|
+
fse.emptyDirSync(dir);
|
|
20
19
|
},
|
|
21
20
|
copyAssets(assets, inputDir, outputDir) {
|
|
22
|
-
const paths = uniq([MANIFEST_FILE_NAME, ICON_FILE_NAME, ...assets]).map(
|
|
23
|
-
path.join(inputDir, asset),
|
|
21
|
+
const paths = uniq([MANIFEST_FILE_NAME, ICON_FILE_NAME, ...assets]).map(
|
|
22
|
+
asset => path.join(inputDir, asset),
|
|
24
23
|
);
|
|
25
|
-
paths.forEach(
|
|
24
|
+
paths.forEach(_path => {
|
|
26
25
|
const globFilePath = _path.replaceAll('\\', '/');
|
|
27
26
|
globSync(globFilePath).forEach(file => {
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
const filePath = file.slice(inputDir.length + 1);
|
|
28
|
+
_copyFromToSync(filePath, inputDir, outputDir);
|
|
30
29
|
});
|
|
31
30
|
});
|
|
32
31
|
},
|
|
33
32
|
watchAssets(assets, inputDir, outputDir) {
|
|
34
|
-
const root =
|
|
35
|
-
return
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
33
|
+
const root = getRootDir();
|
|
34
|
+
return watch(
|
|
35
|
+
uniq([MANIFEST_FILE_NAME, ICON_FILE_NAME, ...assets]).map(asset =>
|
|
36
|
+
path.join(inputDir, asset),
|
|
37
|
+
),
|
|
38
|
+
WATCH_OPTIONS,
|
|
39
|
+
).on('all', (type, file) => {
|
|
40
|
+
const filePath = path.join(root, file).slice(inputDir.length + 1);
|
|
41
|
+
switch (type) {
|
|
42
|
+
case 'add':
|
|
43
|
+
case 'addDir':
|
|
44
|
+
case 'change':
|
|
45
|
+
case 'changeDir':
|
|
46
|
+
_copyFromToSync(filePath, inputDir, outputDir);
|
|
47
|
+
break;
|
|
48
|
+
case 'unlink':
|
|
49
|
+
case 'unlinkDir':
|
|
50
|
+
fse.removeSync(path.join(outputDir, filePath));
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
58
56
|
},
|
|
59
57
|
watchInputDir(dir, watchCallback) {
|
|
60
58
|
const _debouncedCallback = debounce(() => watchCallback(), 300);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
});
|
|
59
|
+
watch([`${dir}/**`], WATCH_OPTIONS).on('all', (_, _path) => {
|
|
60
|
+
if (
|
|
61
|
+
_path.endsWith(path.join(dir, MANIFEST_FILE_NAME)) ||
|
|
62
|
+
_path.endsWith(path.join(dir, ICON_FILE_NAME))
|
|
63
|
+
) {
|
|
64
|
+
watchCallback(true);
|
|
65
|
+
} else {
|
|
66
|
+
_debouncedCallback();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
73
69
|
},
|
|
74
|
-
writeDemoFile
|
|
70
|
+
writeDemoFile(tag, outputDir, outputFile) {
|
|
75
71
|
const demoFileContent = `<meta charset="utf-8">\n<title>${tag} demo</title>\n<script src="./${path.basename(
|
|
76
72
|
outputFile,
|
|
77
73
|
)}"></script>\n\n\n<${tag}></${tag}>\n\n`;
|
|
@@ -82,18 +78,17 @@ module.exports = {
|
|
|
82
78
|
},
|
|
83
79
|
};
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Copies an asset file or directory from the source directory to a destination directory.
|
|
83
|
+
*
|
|
84
|
+
* @param {String} filePath
|
|
85
|
+
* @param {String} sourceDir
|
|
86
|
+
* @param {String} destDir
|
|
87
|
+
*/
|
|
88
|
+
function _copyFromToSync(filePath, sourceDir, destDir) {
|
|
89
|
+
const sourceFile = path.join(sourceDir, filePath);
|
|
87
90
|
if (fs.existsSync(sourceFile)) {
|
|
88
|
-
const destFile = path.join(destDir,
|
|
89
|
-
|
|
90
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
91
|
-
}
|
|
92
|
-
if (!fs.existsSync(path.dirname(path.join(destDir, fileName)))) {
|
|
93
|
-
fs.mkdirSync(path.dirname(path.join(destDir, fileName)), {
|
|
94
|
-
recursive: true,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
fs.copyFileSync(sourceFile, destFile);
|
|
91
|
+
const destFile = path.join(destDir, filePath);
|
|
92
|
+
fse.copySync(sourceFile, destFile);
|
|
98
93
|
}
|
|
99
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ixon-cdk/core",
|
|
3
|
-
"version": "1.2.0-next.
|
|
3
|
+
"version": "1.2.0-next.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"cors": "^2.8.5",
|
|
15
15
|
"crypto-js": "^4.1.1",
|
|
16
16
|
"express": "^4.18.2",
|
|
17
|
+
"fs-extra": "^11.1.1",
|
|
17
18
|
"glob": "^9.2.1",
|
|
18
19
|
"livereload": "^0.9.3",
|
|
19
20
|
"lodash": "^4.17.21",
|
|
20
21
|
"opener": "^1.5.2",
|
|
21
22
|
"prompts": "^2.4.2",
|
|
22
|
-
"rimraf": "^4.3.1",
|
|
23
23
|
"yargs": "^17.7.1"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const fse = require('fs-extra');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const chalk = require('chalk');
|
|
4
5
|
const { globSync } = require('glob');
|
|
@@ -70,7 +71,7 @@ function zip(output, callback) {
|
|
|
70
71
|
const zipFile = path.join(`${outputDir}.zip`);
|
|
71
72
|
const stream = fs.createWriteStream(zipFile);
|
|
72
73
|
stream.on('close', () => {
|
|
73
|
-
|
|
74
|
+
fse.removeSync(outputDir);
|
|
74
75
|
callback(zipFile);
|
|
75
76
|
});
|
|
76
77
|
const archive = require('archiver')('zip', { zlib: { level: 9 } });
|