aiot-toolkit 1.0.17-binary-beta.2 → 1.0.17-binary-beta.4

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