aiot-toolkit 1.0.20 → 1.0.21-beta.1

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/lib/index.js CHANGED
@@ -1,86 +1,2 @@
1
- "use strict";
2
-
3
- /**
4
- * Copyright (C) 2017, hapjs.org. All rights reserved.
5
- */
6
- const BuildModeManager = require('@aiot-toolkit/shared-utils/lib/buildMode/BuildModeManager');
7
-
8
- const {
9
- launchServer,
10
- stopServer
11
- } = require('@aiot-toolkit/server');
12
-
13
- const {
14
- compile,
15
- stopWatch
16
- } = require('./commands/compile');
17
- /**
18
- * 关闭开发服务及停止webpack watching
19
- *
20
- * @module stopAll
21
- * @returns {Promise} - 返回成功与否的信息
22
- */
23
-
24
-
25
- function stopAll() {
26
- return Promise.all([stopServer(), stopWatch()]).then(([stopServerData, stopWatchData]) => {
27
- const data = Object.assign({}, stopServerData, stopWatchData); // 得出布尔值
28
-
29
- data.error = !!(stopServerData.stopServerError || stopWatchData.stopWatchError);
30
- return data;
31
- });
32
- }
33
- /**
34
- * 启动开发服务及开启webpack watching
35
- *
36
- * @module launchWithWatch
37
- * @param {Object} options - 参数配置项
38
- * @param {String|Number} [options.port] - 服务端口
39
- * @param {Array<debugger|packager>} [options.modules] - 加载其他模块
40
- * @param {String} [options.chromePath] - 指定 chrome 的启动路径
41
- * @param {String} [options.disableADB] - 是否禁止启用adb
42
- * @param {String} [options.cwd] - 要运行的项目路径
43
- * @param {String} [options.openDebugger] - 是否打开调试窗口
44
- * @param {String} [options.webVersion] - 启用预览的 web.js 版本
45
- * @param {Writable} [options.log] - 日志输出流
46
- * @param {Function} [options.onerror] - compile 的错误回调函数
47
- * @param {requestCallback} [options.callback] - 回调函数,用以传递回一些数据给调用方
48
- * @returns {Promise} - 返回成功与否的信息
49
- */
50
-
51
- /**
52
- * launchWithWatch 传进来的回调函数
53
- * @callback requestCallback
54
- * @param {string} action - toolkit进行到的操作
55
- * @param {string} url - 调试页面的地址
56
- */
57
-
58
-
59
- function launchWithWatch(options) {
60
- const {
61
- cwd,
62
- log,
63
- onerror
64
- } = options;
65
- return Promise.all([launchServer(options), compile('native', 'dev', true, {
66
- cwd,
67
- log,
68
- onerror
69
- })]).then(([launchData, compileData]) => {
70
- const data = Object.assign({}, launchData, compileData); // 得出布尔值
71
-
72
- data.error = !!(launchData.launchError || compileData.compileError);
73
- return data;
74
- });
75
- }
76
-
77
- module.exports = {
78
- compile,
79
- stopWatch,
80
- launchServer,
81
- stopServer,
82
- launchWithWatch,
83
- stopAll,
84
- BuildModeManager
85
- };
1
+ "use strict";const BuildModeManager=require("@aiot-toolkit/shared-utils/lib/buildMode/BuildModeManager"),{launchServer:launchServer,stopServer:stopServer}=require("@aiot-toolkit/server"),{compile:compile,stopWatch:stopWatch}=require("./commands/compile");function stopAll(){return Promise.all([stopServer(),stopWatch()]).then((([r,e])=>{const o=Object.assign({},r,e);return o.error=!(!r.stopServerError&&!e.stopWatchError),o}))}function launchWithWatch(r){const{cwd:e,log:o,onerror:t}=r;return Promise.all([launchServer(r),compile("native","dev",!0,{cwd:e,log:o,onerror:t})]).then((([r,e])=>{const o=Object.assign({},r,e);return o.error=!(!r.launchError&&!e.compileError),o}))}module.exports={compile:compile,stopWatch:stopWatch,launchServer:launchServer,stopServer:stopServer,launchWithWatch:launchWithWatch,stopAll:stopAll,BuildModeManager:BuildModeManager};
86
2
  //# sourceMappingURL=index.js.map
@@ -1,124 +1,2 @@
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
- };
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")}};
124
2
  //# sourceMappingURL=manifest-watch-plugin.js.map
package/lib/utils.js CHANGED
@@ -1,118 +1,2 @@
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
- * 提取其中的应用,页面,worker,services, floatingWindows的脚本文件
22
- * @return {Array}
23
- * 以 basedir 为基本目录,获取 manifest 的配置的入口页面
24
- *
25
- * @param {ManifestObject} manifest - manifest
26
- * @param {String} basedir - 扫描目录
27
- * @param {String} cwd - 工作目录
28
- * @returns {Array<Object>}
29
- */
30
-
31
-
32
- exports.resolveEntries = function resolveEntries(manifest, basedir, cwd) {
33
- if (!manifest.router) {
34
- throw Error('No routing configured in manifest.json!');
35
- }
36
-
37
- const entries = {};
38
- const pagesConf = manifest.router.pages || {};
39
- const widgetsConf = manifest.router.widgets || {};
40
- const floatingWindowsConf = manifest.router.floatingWindows || {};
41
- const confsList = [{
42
- confs: floatingWindowsConf,
43
- type: ENTRY_TYPE.FLOAT
44
- }, {
45
- confs: widgetsConf,
46
- type: ENTRY_TYPE.CARD
47
- }];
48
- confsList.unshift({
49
- confs: pagesConf,
50
- type: ENTRY_TYPE.PAGE
51
- });
52
- const appFile = resolveFile(path.join(basedir, 'app'));
53
-
54
- if (!appFile) {
55
- colorconsole.error('app file does not exist');
56
- process.exit(1);
57
- }
58
-
59
- entries['app'] = './' + path.relative(cwd, appFile) + `?uxType=${ENTRY_TYPE.APP}`;
60
- confsList.forEach(({
61
- confs,
62
- type
63
- }) => {
64
- Object.keys(confs).forEach(routePath => {
65
- const conf = confs[routePath];
66
- const entryKey = path.join(routePath, conf.component);
67
- const filepath = resolveFile(path.join(basedir, entryKey));
68
-
69
- if (!filepath) {
70
- colorconsole.throw(`Compilation failed: please confirm that the file path ${entryKey} configured in manifest.json exists`);
71
- }
72
-
73
- if (/^\//.test(routePath)) {
74
- colorconsole.throw(`Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`);
75
- }
76
-
77
- let sourceFile = path.relative(cwd, filepath);
78
- sourceFile = './' + sourceFile + `?uxType=${type}`;
79
- sourceFile = sourceFile.replace(/\\/g, '/');
80
- entries[entryKey] = sourceFile;
81
- });
82
- });
83
- const workers = manifest.workers;
84
-
85
- if (workers && workers.entries && workers.entries instanceof Array) {
86
- workers.entries.filter(worker => worker.file).forEach(worker => {
87
- entries[worker.file.replace(/\.js$/, '')] = './src/' + worker.file;
88
- });
89
- }
90
-
91
- const services = manifest.services;
92
-
93
- if (!isEmptyObject(services)) {
94
- // 数组格式
95
- if (Array.isArray(services)) {
96
- services.forEach(item => {
97
- const {
98
- name,
99
- path
100
- } = item;
101
-
102
- if (name && path) {
103
- entries['services/' + name] = './src/' + path + `?uxType=${ENTRY_TYPE.APP}`;
104
- }
105
- });
106
- } // 字典格式
107
- else {
108
- for (const key in services) {
109
- if (Object.hasOwnProperty.call(services, key)) {
110
- entries['services/' + key] = './src/' + services[key].path + `?uxType=${ENTRY_TYPE.APP}`;
111
- }
112
- }
113
- }
114
- }
115
-
116
- return entries;
117
- };
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=e.router.widgets||{},n=[{confs:e.router.floatingWindows||{},type:ENTRY_TYPE.FLOAT},{confs:s,type:ENTRY_TYPE.CARD}];n.unshift({confs:i,type:ENTRY_TYPE.PAGE});const c=resolveFile(path.join(o,"app"));c||(colorconsole.error("app file does not exist"),process.exit(1)),r.app="./"+path.relative(t,c)+`?uxType=${ENTRY_TYPE.APP}`,n.forEach((({confs:e,type:i})=>{Object.keys(e).forEach((s=>{const n=e[s],c=path.join(s,n.component),a=resolveFile(path.join(o,c));a||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 l=path.relative(t,a);l="./"+l+`?uxType=${i}`,l=l.replace(/\\/g,"/"),r[c]=l}))}));const a=e.workers;a&&a.entries&&a.entries instanceof Array&&a.entries.filter((e=>e.file)).forEach((e=>{r[e.file.replace(/\.js$/,"")]="./src/"+e.file}));const l=e.services;if(!isEmptyObject(l))if(Array.isArray(l))l.forEach((e=>{const{name:o,path:t}=e;o&&t&&(r["services/"+o]="./src/"+t+`?uxType=${ENTRY_TYPE.APP}`)}));else for(const e in l)Object.hasOwnProperty.call(l,e)&&(r["services/"+e]="./src/"+l[e].path+`?uxType=${ENTRY_TYPE.APP}`);return r};
118
2
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "aiot-toolkit",
3
- "version": "1.0.20",
3
+ "version": "1.0.21-beta.1",
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.20",
10
- "@aiot-toolkit/debugger": "1.0.20",
11
- "@aiot-toolkit/dsl-vue": "1.0.20",
12
- "@aiot-toolkit/dsl-xvm": "1.0.20",
13
- "@aiot-toolkit/packager": "1.0.20",
14
- "@aiot-toolkit/server": "1.0.20",
15
- "@aiot-toolkit/shared-utils": "1.0.20",
9
+ "@aiot-toolkit/compiler": "1.0.21-beta.1",
10
+ "@aiot-toolkit/debugger": "1.0.21-beta.1",
11
+ "@aiot-toolkit/dsl-vue": "1.0.21-beta.1",
12
+ "@aiot-toolkit/dsl-xvm": "1.0.21-beta.1",
13
+ "@aiot-toolkit/packager": "1.0.21-beta.1",
14
+ "@aiot-toolkit/server": "1.0.21-beta.1",
15
+ "@aiot-toolkit/shared-utils": "1.0.21-beta.1",
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": "42608b697b5f44aca7d8ad563e2ab264776b3f5f"
55
+ "gitHead": "f6835e57a6f164b944fce02e79874cbd772a9be9"
56
56
  }