aiot-toolkit 1.0.18-aspect-beta.21 → 1.0.18-aspect-beta.23
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/bin/index.js +1 -0
- package/lib/commands/compile.js +388 -1
- package/lib/commands/debug.js +673 -1
- package/lib/commands/init.js +255 -1
- package/lib/commands/packages.js +86 -1
- package/lib/commands/preview.js +19 -1
- package/lib/commands/report.js +60 -1
- package/lib/commands/resign.js +88 -1
- package/lib/commands/transform.js +223 -1
- package/lib/commands/update.js +358 -1
- package/lib/commands/utils.js +523 -1
- package/lib/index.js +85 -1
- package/lib/plugins/manifest-watch-plugin.js +123 -1
- package/lib/utils.js +110 -1
- package/package.json +9 -9
|
@@ -1,2 +1,124 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
colorconsole,
|
|
7
|
+
readJson,
|
|
8
|
+
logger,
|
|
9
|
+
mergeJsonFile
|
|
10
|
+
} = require('@aiot-toolkit/shared-utils');
|
|
11
|
+
|
|
12
|
+
const eventBus = require('@aiot-toolkit/shared-utils/event-bus');
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
resolveEntries
|
|
16
|
+
} = require('../utils');
|
|
17
|
+
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
PACKAGER_WATCH_START
|
|
22
|
+
} = eventBus;
|
|
23
|
+
|
|
24
|
+
function sort(list) {
|
|
25
|
+
return list.sort((a, b) => a.localeCompare(b));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = class ManifestWatchPlugin {
|
|
29
|
+
/**
|
|
30
|
+
* @param {Object} options - 配置参数
|
|
31
|
+
* @param {String} options.root - 应用根目录
|
|
32
|
+
*/
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.appRoot = options.appRoot;
|
|
35
|
+
this.root = options.root;
|
|
36
|
+
this.manifestFile = path.resolve(this.root, 'manifest.json');
|
|
37
|
+
this.isMinaH5 = options.isMinaH5;
|
|
38
|
+
let entries = {};
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
/** @readonly */
|
|
42
|
+
const manifest = readJson(this.manifestFile);
|
|
43
|
+
entries = resolveEntries(manifest, this.root, this.appRoot);
|
|
44
|
+
} catch (_) {}
|
|
45
|
+
|
|
46
|
+
this.list = Object.keys(entries);
|
|
47
|
+
this.list = sort(this.list);
|
|
48
|
+
this.mergeRootManifest();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
hasChanged(newList) {
|
|
52
|
+
const sorted = sort(newList);
|
|
53
|
+
const changed = JSON.stringify(sorted) !== JSON.stringify(this.list);
|
|
54
|
+
|
|
55
|
+
if (changed) {
|
|
56
|
+
this.list = sorted;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return changed;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
apply(compiler) {
|
|
63
|
+
// watch静态资源
|
|
64
|
+
compiler.hooks.compilation.tap('compilation', compilation => {
|
|
65
|
+
const rootManifest = this.getRootManifest(); // minh5项目需要监听.src外层的manifest文件变化
|
|
66
|
+
|
|
67
|
+
if (this.isMinaH5 && fs.existsSync(rootManifest)) {
|
|
68
|
+
compilation.fileDependencies.add(rootManifest);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
compiler.hooks.watchRun.tapAsync('watch', (compiler, callback) => {
|
|
72
|
+
eventBus.emit(PACKAGER_WATCH_START);
|
|
73
|
+
logger.clear();
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const modifiedFiles = compiler.modifiedFiles; // 当发生变化的文件是 app.json,且 list 列表有增/删时,更新入口文件
|
|
77
|
+
// TODO 页面减少时不会移除 entry
|
|
78
|
+
// https://stackoverflow.com/a/39401288/1087831
|
|
79
|
+
|
|
80
|
+
if (modifiedFiles) {
|
|
81
|
+
if (modifiedFiles.has(this.manifestFile)) {
|
|
82
|
+
/** @readonly */
|
|
83
|
+
const manifest = readJson(this.manifestFile);
|
|
84
|
+
const entries = resolveEntries(manifest, this.root, this.appRoot);
|
|
85
|
+
const newList = Object.keys(entries);
|
|
86
|
+
|
|
87
|
+
if (this.hasChanged(newList)) {
|
|
88
|
+
// 增删页面要修改 webpack entries
|
|
89
|
+
this.list = newList;
|
|
90
|
+
compiler.options.entry = entries;
|
|
91
|
+
}
|
|
92
|
+
} // 当是minah5且根目录的mainfest.json变化时,同步到.src下
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
const rootManifest = this.getRootManifest();
|
|
96
|
+
|
|
97
|
+
if (modifiedFiles.has(rootManifest)) {
|
|
98
|
+
this.mergeRootManifest();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
// 需要将错误显示出来,watch时修改才有显示
|
|
103
|
+
colorconsole.error(err.message);
|
|
104
|
+
logger.add(err.message);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
callback();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
mergeRootManifest() {
|
|
112
|
+
const rootManifest = this.getRootManifest(); // 把manifest.json合并到.src/manifest.json
|
|
113
|
+
|
|
114
|
+
if (this.isMinaH5 && fs.existsSync(rootManifest) && fs.existsSync(this.manifestFile)) {
|
|
115
|
+
mergeJsonFile(rootManifest, this.manifestFile);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getRootManifest() {
|
|
120
|
+
return path.resolve(this.root, '../manifest.json');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
};
|
|
2
124
|
//# sourceMappingURL=manifest-watch-plugin.js.map
|
package/lib/utils.js
CHANGED
|
@@ -1,2 +1,111 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
colorconsole
|
|
7
|
+
} = require('@aiot-toolkit/shared-utils');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
ENTRY_TYPE
|
|
11
|
+
} = require('@aiot-toolkit/packager/lib/common/utils');
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
resolveFile
|
|
15
|
+
} = require('@aiot-toolkit/packager/lib/common/info');
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
isEmptyObject
|
|
19
|
+
} = require('@aiot-toolkit/compiler/lib/utils');
|
|
20
|
+
|
|
21
|
+
const globalConfig = require('@aiot-toolkit/shared-utils/config');
|
|
22
|
+
/**
|
|
23
|
+
* 提取其中的应用,页面,worker,services, floatingWindows的脚本文件
|
|
24
|
+
* @return {Array}
|
|
25
|
+
* 以 basedir 为基本目录,获取 manifest 的配置的入口页面
|
|
26
|
+
*
|
|
27
|
+
* @param {ManifestObject} manifest - manifest
|
|
28
|
+
* @param {String} basedir - 扫描目录
|
|
29
|
+
* @param {String} cwd - 工作目录
|
|
30
|
+
* @returns {Array<Object>}
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
exports.resolveEntries = function resolveEntries(manifest, basedir, cwd) {
|
|
35
|
+
if (!manifest.router) {
|
|
36
|
+
throw Error('No routing configured in manifest.json!');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const entries = {};
|
|
40
|
+
const pagesConf = manifest.router.pages || {};
|
|
41
|
+
const widgetsConf = manifest.router.widgets || {};
|
|
42
|
+
const floatingWindowsConf = manifest.router.floatingWindows || {};
|
|
43
|
+
const confsList = [{
|
|
44
|
+
confs: floatingWindowsConf,
|
|
45
|
+
type: ENTRY_TYPE.FLOAT
|
|
46
|
+
}, {
|
|
47
|
+
confs: widgetsConf,
|
|
48
|
+
type: ENTRY_TYPE.CARD
|
|
49
|
+
}];
|
|
50
|
+
confsList.unshift({
|
|
51
|
+
confs: pagesConf,
|
|
52
|
+
type: ENTRY_TYPE.PAGE
|
|
53
|
+
});
|
|
54
|
+
let baseName = 'app';
|
|
55
|
+
|
|
56
|
+
if (globalConfig.aspectTemplate.isAspect && !globalConfig.aspectTemplate.isApp) {
|
|
57
|
+
baseName = 'aspect';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const appFile = resolveFile(path.join(basedir, baseName));
|
|
61
|
+
|
|
62
|
+
if (!appFile) {
|
|
63
|
+
colorconsole.error(`${baseName} file does not exist`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
entries[baseName] = './' + path.relative(cwd, appFile) + `?uxType=${ENTRY_TYPE.APP}`;
|
|
68
|
+
confsList.forEach(({
|
|
69
|
+
confs,
|
|
70
|
+
type
|
|
71
|
+
}) => {
|
|
72
|
+
Object.keys(confs).forEach(routePath => {
|
|
73
|
+
const conf = confs[routePath];
|
|
74
|
+
const entryKey = path.join(routePath, conf.component);
|
|
75
|
+
let filepath = resolveFile(path.join(basedir, entryKey));
|
|
76
|
+
|
|
77
|
+
if (!filepath) {
|
|
78
|
+
colorconsole.throw(`Compilation failed: please confirm that the file path ${entryKey} configured in manifest.json exists`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (/^\//.test(routePath)) {
|
|
82
|
+
colorconsole.throw(`Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let sourceFile = path.relative(cwd, filepath);
|
|
86
|
+
sourceFile = './' + sourceFile + `?uxType=${type}`;
|
|
87
|
+
sourceFile = sourceFile.replace(/\\/g, '/');
|
|
88
|
+
entries[entryKey] = sourceFile;
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
const workers = manifest.workers;
|
|
92
|
+
|
|
93
|
+
if (workers && workers.entries && workers.entries instanceof Array) {
|
|
94
|
+
workers.entries.filter(worker => worker.file).forEach(worker => {
|
|
95
|
+
entries[worker.file.replace(/\.js$/, '')] = './src/' + worker.file;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const services = manifest.services;
|
|
100
|
+
|
|
101
|
+
if (!isEmptyObject(services)) {
|
|
102
|
+
for (const key in services) {
|
|
103
|
+
if (Object.hasOwnProperty.call(services, key)) {
|
|
104
|
+
entries['services/' + key] = './src/' + services[key].path + `?uxType=${ENTRY_TYPE.APP}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return entries;
|
|
110
|
+
};
|
|
2
111
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiot-toolkit",
|
|
3
|
-
"version": "1.0.18-aspect-beta.
|
|
3
|
+
"version": "1.0.18-aspect-beta.23",
|
|
4
4
|
"description": "A command line toolkit for developing Aiot Quick Apps.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@aiot-toolkit/compiler": "1.0.18-aspect-beta.
|
|
10
|
-
"@aiot-toolkit/debugger": "1.0.18-aspect-beta.
|
|
11
|
-
"@aiot-toolkit/dsl-vue": "1.0.18-aspect-beta.
|
|
12
|
-
"@aiot-toolkit/dsl-xvm": "1.0.18-aspect-beta.
|
|
13
|
-
"@aiot-toolkit/packager": "1.0.18-aspect-beta.
|
|
14
|
-
"@aiot-toolkit/server": "1.0.18-aspect-beta.
|
|
15
|
-
"@aiot-toolkit/shared-utils": "1.0.18-aspect-beta.
|
|
9
|
+
"@aiot-toolkit/compiler": "1.0.18-aspect-beta.23",
|
|
10
|
+
"@aiot-toolkit/debugger": "1.0.18-aspect-beta.23",
|
|
11
|
+
"@aiot-toolkit/dsl-vue": "1.0.18-aspect-beta.23",
|
|
12
|
+
"@aiot-toolkit/dsl-xvm": "1.0.18-aspect-beta.23",
|
|
13
|
+
"@aiot-toolkit/packager": "1.0.18-aspect-beta.23",
|
|
14
|
+
"@aiot-toolkit/server": "1.0.18-aspect-beta.23",
|
|
15
|
+
"@aiot-toolkit/shared-utils": "1.0.18-aspect-beta.23",
|
|
16
16
|
"@babel/core": "^7.9.6",
|
|
17
17
|
"@babel/plugin-syntax-jsx": "^7.8.3",
|
|
18
18
|
"@babel/preset-env": "^7.9.6",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"supertest": "^3.3.0",
|
|
52
52
|
"webpack-cli": "^4.3.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "7a50d5a6f6a312386cc8864c9ed9b50f888bff7c"
|
|
55
55
|
}
|