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/CHANGELOG.md +11 -0
- package/README.md +11 -0
- package/lib/commands/compile.js +1 -135
- package/lib/commands/debug.js +1 -673
- package/lib/commands/init.js +1 -239
- package/lib/commands/packages.js +1 -86
- package/lib/commands/preview.js +1 -19
- package/lib/commands/report.js +1 -60
- package/lib/commands/resign.js +1 -88
- package/lib/commands/update.js +1 -358
- package/lib/commands/utils.js +1 -283
- package/lib/index.js +1 -85
- package/lib/plugins/manifest-watch-plugin.js +1 -123
- package/lib/utils.js +1 -117
- package/package.json +9 -9
package/lib/commands/update.js
CHANGED
|
@@ -1,359 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _path = _interopRequireDefault(require("path"));
|
|
4
|
-
|
|
5
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
6
|
-
|
|
7
|
-
var _glob = _interopRequireDefault(require("glob"));
|
|
8
|
-
|
|
9
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
|
-
|
|
11
|
-
var _semver = _interopRequireDefault(require("semver"));
|
|
12
|
-
|
|
13
|
-
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
14
|
-
|
|
15
|
-
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
16
|
-
|
|
17
|
-
var _utils = require("./utils");
|
|
18
|
-
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* Copyright (C) 2017, hapjs.org. All rights reserved.
|
|
23
|
-
*/
|
|
24
|
-
const curDir = process.cwd();
|
|
25
|
-
|
|
26
|
-
const packageInfo = require('../../package.json'); // DSL路径预先定义
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const dslModuleXvmDir = _path.default.dirname(require.resolve('@aiot-toolkit/dsl-xvm/package.json'));
|
|
30
|
-
|
|
31
|
-
const dslModuleVueDir = _path.default.dirname(require.resolve('@aiot-toolkit/dsl-vue/package.json'));
|
|
32
|
-
|
|
33
|
-
const dslModuleHash = {
|
|
34
|
-
xvm: dslModuleXvmDir,
|
|
35
|
-
vue: dslModuleVueDir
|
|
36
|
-
}; // 名称
|
|
37
|
-
|
|
38
|
-
let dslName;
|
|
39
|
-
let dslModuleDir; // 检测工程版本
|
|
40
|
-
|
|
41
|
-
function checkVersion() {
|
|
42
|
-
const result = {
|
|
43
|
-
cur: '',
|
|
44
|
-
toolkit: '',
|
|
45
|
-
res: 0
|
|
46
|
-
};
|
|
47
|
-
let pkg;
|
|
48
|
-
|
|
49
|
-
const curpkgPath = _path.default.join(curDir, 'package.json');
|
|
50
|
-
|
|
51
|
-
if (_fsExtra.default.existsSync(curpkgPath)) {
|
|
52
|
-
pkg = JSON.parse(_fsExtra.default.readFileSync(curpkgPath).toString());
|
|
53
|
-
result.cur = pkg.subversion && pkg.subversion.toolkit || '';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (result.cur === '') {
|
|
57
|
-
result.res = 1;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
result.toolkit = packageInfo.version;
|
|
61
|
-
|
|
62
|
-
if (result.toolkit === '') {
|
|
63
|
-
console.log(`### App Toolkit ### The current toolkit file is wrong and cannot be upgraded. Please re-install and then upgrade`);
|
|
64
|
-
result.res = -1;
|
|
65
|
-
return result;
|
|
66
|
-
} // 版本比较
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (result.res !== 1) {
|
|
70
|
-
result.res = _semver.default.gt(result.toolkit, result.cur) ? 1 : 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* 更新属性
|
|
77
|
-
* @param target
|
|
78
|
-
* @param update
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
function mergeProps(target, update) {
|
|
83
|
-
if (!target) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for (const key in update) {
|
|
88
|
-
if (!target[key] && !/babel-|^webpack$|^koa/.test(key)) {
|
|
89
|
-
target[key] = update[key];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const dependencies = ['babel-cli', 'babel-core', 'babel-eslint', 'babel-loader', 'babel-plugin-syntax-jsx', 'cross-env', 'css-what', 'koa', 'koa-body', 'koa-router', 'koa-send', 'koa-static', 'socket.io', 'style-loader', 'webpack'];
|
|
95
|
-
/**
|
|
96
|
-
* 询问用户是否移除不再需要的依赖
|
|
97
|
-
*
|
|
98
|
-
* hap-toolkit>=0.1.0 将依赖整合到自身
|
|
99
|
-
* koa koa-body webpack 等将不再是用户的直接依赖
|
|
100
|
-
*
|
|
101
|
-
* @param {Package} pkg - 项目信息对象
|
|
102
|
-
* @param {Object} options
|
|
103
|
-
* @param {Boolean} [options.force] - 是否强制更新,将移除所有开发依赖
|
|
104
|
-
* @param {Boolean} [options.updateDeps] - 是否直接更新依赖
|
|
105
|
-
* @param {Package} pkg - 模块信息
|
|
106
|
-
* @returns {Promise<Package>}
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
function cleanupDependencies(pkg, options) {
|
|
110
|
-
if (options.force) {
|
|
111
|
-
pkg.devDependencies = {};
|
|
112
|
-
return Promise.resolve(pkg);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!pkg.devDependencies) {
|
|
116
|
-
return Promise.resolve(pkg);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const deps = dependencies.filter(dep => pkg.devDependencies[dep]);
|
|
120
|
-
|
|
121
|
-
if (!deps.length) {
|
|
122
|
-
return Promise.resolve(pkg);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let promise = Promise.resolve(dependencies);
|
|
126
|
-
|
|
127
|
-
if (!options.updateDeps) {
|
|
128
|
-
promise = new Promise(resolve => {
|
|
129
|
-
const questions = [{
|
|
130
|
-
type: 'confirm',
|
|
131
|
-
name: 'toDelete',
|
|
132
|
-
message: 'The module dependency that has been included in the hap-toolkit is detected, now remove it',
|
|
133
|
-
default: true
|
|
134
|
-
}, {
|
|
135
|
-
type: 'checkbox',
|
|
136
|
-
name: 'selectedDeps',
|
|
137
|
-
message: 'The selected modules below will be removed',
|
|
138
|
-
choices: deps.map(dep => ({
|
|
139
|
-
checked: true,
|
|
140
|
-
name: dep
|
|
141
|
-
})),
|
|
142
|
-
pageSize: deps.length,
|
|
143
|
-
// show all
|
|
144
|
-
when: function (answers) {
|
|
145
|
-
return answers.toDelete;
|
|
146
|
-
}
|
|
147
|
-
}];
|
|
148
|
-
|
|
149
|
-
_inquirer.default.prompt(questions).then(answers => {
|
|
150
|
-
resolve(answers.toDelete ? answers.selectedDeps : []);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return promise.then(selectedDeps => {
|
|
156
|
-
selectedDeps.forEach(dep => {
|
|
157
|
-
pkg.devDependencies[dep] = undefined;
|
|
158
|
-
});
|
|
159
|
-
return pkg;
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* 升级包配置文件
|
|
164
|
-
*
|
|
165
|
-
* @param {Object} options
|
|
166
|
-
* @param {Boolean} [options.force] - 是否强制更新
|
|
167
|
-
* @param {Boolean} [options.updateDeps] - 是否直接更新依赖
|
|
168
|
-
* @returns {Promise<Package>}
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
function upgradePackage(options) {
|
|
173
|
-
console.log(_chalk.default.green(`升级 package.json`));
|
|
174
|
-
|
|
175
|
-
const curpkgPath = _path.default.join(curDir, 'package.json');
|
|
176
|
-
|
|
177
|
-
const curpkg = require(curpkgPath);
|
|
178
|
-
|
|
179
|
-
const tplPkgInfo = require(_path.default.resolve(dslModuleDir, 'templates/app/demo/package.json'));
|
|
180
|
-
|
|
181
|
-
if (options.force) {
|
|
182
|
-
tplPkgInfo.devDependencies = {};
|
|
183
|
-
} // 更新版本号
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
tplPkgInfo.devDependencies['hap-toolkit'] = packageInfo.version;
|
|
187
|
-
|
|
188
|
-
if (tplPkgInfo.subversion) {
|
|
189
|
-
tplPkgInfo.subversion.toolkit = packageInfo.version;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return cleanupDependencies(curpkg, options).then(cleanedPkg => {
|
|
193
|
-
for (const key in tplPkgInfo) {
|
|
194
|
-
const item = tplPkgInfo[key];
|
|
195
|
-
|
|
196
|
-
if (typeof item === 'string' && curpkg[key]) {
|
|
197
|
-
tplPkgInfo[key] = cleanedPkg[key];
|
|
198
|
-
} else {
|
|
199
|
-
mergeProps(item, cleanedPkg[key]);
|
|
200
|
-
}
|
|
201
|
-
} // 更新 json 文件
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
_fsExtra.default.writeFileSync(curpkgPath, JSON.stringify(tplPkgInfo, null, 2));
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* 拷贝模板目录
|
|
209
|
-
* @param dest 目标路径
|
|
210
|
-
* @param src 源文件路径
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
function copyFiles(dest, src) {
|
|
215
|
-
// 遍历收集文件列表
|
|
216
|
-
const pattern = _path.default.join(src, '**/{*,.*}');
|
|
217
|
-
|
|
218
|
-
const files = _glob.default.sync(pattern);
|
|
219
|
-
|
|
220
|
-
files.forEach(file => {
|
|
221
|
-
const relative = _path.default.relative(src, file);
|
|
222
|
-
|
|
223
|
-
const finalPath = _path.default.join(dest, relative); // 覆盖原有文件
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
console.log(_chalk.default.green(`file ${(0, _sharedUtils.relateCwd)(finalPath)} copied.`));
|
|
227
|
-
|
|
228
|
-
_fsExtra.default.copySync(file, finalPath);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* 升级sign目录
|
|
233
|
-
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
function upgradeSign() {
|
|
237
|
-
console.log(_chalk.default.green(`Upgrade signature file`));
|
|
238
|
-
|
|
239
|
-
const destPath = _path.default.join(curDir, 'sign/debug'); // 删除旧tools目录
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
_fsExtra.default.removeSync(destPath); // 重新拷贝
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
(0, _sharedUtils.mkdirsSync)(destPath);
|
|
246
|
-
copyFiles(destPath, _path.default.join(dslModuleDir, 'templates/app/demo/sign/debug'));
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* 升级eslint
|
|
250
|
-
*/
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
function upgradeEslint() {
|
|
254
|
-
// 复制eslint
|
|
255
|
-
const fileNameEslint = '.eslintrc.json';
|
|
256
|
-
|
|
257
|
-
const fileSrcEslint = _path.default.join(dslModuleDir, 'templates/app/demo', fileNameEslint);
|
|
258
|
-
|
|
259
|
-
const fileDstEslint = _path.default.join(curDir, fileNameEslint);
|
|
260
|
-
|
|
261
|
-
_fsExtra.default.copySync(fileSrcEslint, fileDstEslint);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* 更新babel.config.js文件
|
|
265
|
-
*/
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
function upgradeBabelConfig() {
|
|
269
|
-
const babelConfig = 'babel.config.js';
|
|
270
|
-
const babelrc = '.babelrc';
|
|
271
|
-
|
|
272
|
-
const srcBabelConfig = _path.default.join(dslModuleDir, 'templates/app/demo', babelConfig);
|
|
273
|
-
|
|
274
|
-
const distBabelrc = _path.default.join(curDir, babelrc);
|
|
275
|
-
|
|
276
|
-
const distBabelConfig = _path.default.join(curDir, babelConfig);
|
|
277
|
-
|
|
278
|
-
const timeStamp = (0, _utils.formatDate)('yyyyMMdd_hhmmss', new Date());
|
|
279
|
-
console.log(_chalk.default.green(`The project is upgraded to babel7, and the default configuration uses babel.config.js`));
|
|
280
|
-
|
|
281
|
-
if (_fsExtra.default.existsSync(distBabelrc)) {
|
|
282
|
-
const saveBabelrc = _path.default.join(curDir, babelrc + '.old.' + timeStamp);
|
|
283
|
-
|
|
284
|
-
_fsExtra.default.copySync(distBabelrc, saveBabelrc);
|
|
285
|
-
|
|
286
|
-
_fsExtra.default.removeSync(distBabelrc);
|
|
287
|
-
|
|
288
|
-
console.log(_chalk.default.yellow(`### App Toolkit ### The backup file of ${babelrc} is saved as: ${(0, _sharedUtils.relateCwd)(saveBabelrc)}`));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (_fsExtra.default.existsSync(distBabelConfig)) {
|
|
292
|
-
const saveFile = _path.default.join(curDir, _path.default.basename(babelConfig, '.js') + '.old.' + timeStamp + '.js');
|
|
293
|
-
|
|
294
|
-
_fsExtra.default.copySync(distBabelConfig, saveFile);
|
|
295
|
-
|
|
296
|
-
console.log(_chalk.default.yellow(`### App Toolkit ### The backup file of the updated ${babelConfig} is saved as: ${(0, _sharedUtils.relateCwd)(saveFile)}`));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (_fsExtra.default.existsSync(srcBabelConfig)) {
|
|
300
|
-
_fsExtra.default.copySync(srcBabelConfig, distBabelConfig);
|
|
301
|
-
|
|
302
|
-
console.log(_chalk.default.yellow(`### App Toolkit ### The updated ${babelConfig} succeeded!`));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* 更新package.json文件
|
|
307
|
-
*/
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
function savePackage() {
|
|
311
|
-
const file = 'package.json';
|
|
312
|
-
|
|
313
|
-
const filePath = _path.default.join(curDir, file);
|
|
314
|
-
|
|
315
|
-
const timeStamp = (0, _utils.formatDate)('yyyyMMdd_hhmmss', new Date());
|
|
316
|
-
|
|
317
|
-
const saveFile = _path.default.join(curDir, _path.default.basename(file, '.json') + '.old.' + timeStamp + '.json');
|
|
318
|
-
|
|
319
|
-
_fsExtra.default.copySync(filePath, saveFile);
|
|
320
|
-
|
|
321
|
-
console.log(_chalk.default.yellow(`### App Toolkit ### The updated backup file of ${file} is saved as: ${(0, _sharedUtils.relateCwd)(saveFile)}`));
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* 升级工程
|
|
325
|
-
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
function updateProject(options) {
|
|
329
|
-
const ver = checkVersion();
|
|
330
|
-
|
|
331
|
-
if (!options.force) {
|
|
332
|
-
if (ver.res < 0 || ver.res === 0) {
|
|
333
|
-
ver.res === 0 && console.log(`### App Toolkit ### The version is already the latest version`);
|
|
334
|
-
return;
|
|
335
|
-
} // 执行升级
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
console.log(_chalk.default.green(`Upgrade project( ${ver.cur} ----> ${ver.toolkit} )`));
|
|
339
|
-
} else {
|
|
340
|
-
console.log(_chalk.default.yellow(`Force upgrade project( ${ver.cur} ----> ${ver.toolkit} )(There may be compatibility issues)`));
|
|
341
|
-
savePackage();
|
|
342
|
-
} // 设置DSL信息
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
dslName = (0, _sharedUtils.getProjectDslName)(curDir);
|
|
346
|
-
dslModuleDir = dslModuleHash[dslName];
|
|
347
|
-
upgradePackage(options).then(() => {
|
|
348
|
-
// 升级签名
|
|
349
|
-
upgradeSign(); // 升级eslint
|
|
350
|
-
|
|
351
|
-
upgradeEslint(); // 升级babel.config.js
|
|
352
|
-
|
|
353
|
-
upgradeBabelConfig();
|
|
354
|
-
console.log(_chalk.default.green(`Upgrade complete, Please run npm install to update the dependency package`));
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
module.exports = updateProject;
|
|
1
|
+
"use strict";var _path=_interopRequireDefault(require("path")),_fsExtra=_interopRequireDefault(require("fs-extra")),_glob=_interopRequireDefault(require("glob")),_chalk=_interopRequireDefault(require("chalk")),_semver=_interopRequireDefault(require("semver")),_inquirer=_interopRequireDefault(require("inquirer")),_sharedUtils=require("@aiot-toolkit/shared-utils"),_utils=require("./utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const curDir=process.cwd(),packageInfo=require("../../package.json"),dslModuleXvmDir=_path.default.dirname(require.resolve("@aiot-toolkit/dsl-xvm/package.json")),dslModuleVueDir=_path.default.dirname(require.resolve("@aiot-toolkit/dsl-vue/package.json")),dslModuleHash={xvm:dslModuleXvmDir,vue:dslModuleVueDir};let dslName,dslModuleDir;function checkVersion(){const e={cur:"",toolkit:"",res:0};let t;const a=_path.default.join(curDir,"package.json");return _fsExtra.default.existsSync(a)&&(t=JSON.parse(_fsExtra.default.readFileSync(a).toString()),e.cur=t.subversion&&t.subversion.toolkit||""),""===e.cur&&(e.res=1),e.toolkit=packageInfo.version,""===e.toolkit?(console.log("### App Toolkit ### The current toolkit file is wrong and cannot be upgraded. Please re-install and then upgrade"),e.res=-1,e):(1!==e.res&&(e.res=_semver.default.gt(e.toolkit,e.cur)?1:0),e)}function mergeProps(e,t){if(e)for(const a in t)e[a]||/babel-|^webpack$|^koa/.test(a)||(e[a]=t[a])}const dependencies=["babel-cli","babel-core","babel-eslint","babel-loader","babel-plugin-syntax-jsx","cross-env","css-what","koa","koa-body","koa-router","koa-send","koa-static","socket.io","style-loader","webpack"];function cleanupDependencies(e,t){if(t.force)return e.devDependencies={},Promise.resolve(e);if(!e.devDependencies)return Promise.resolve(e);const a=dependencies.filter((t=>e.devDependencies[t]));if(!a.length)return Promise.resolve(e);let o=Promise.resolve(dependencies);return t.updateDeps||(o=new Promise((e=>{const t=[{type:"confirm",name:"toDelete",message:"The module dependency that has been included in the hap-toolkit is detected, now remove it",default:!0},{type:"checkbox",name:"selectedDeps",message:"The selected modules below will be removed",choices:a.map((e=>({checked:!0,name:e}))),pageSize:a.length,when:function(e){return e.toDelete}}];_inquirer.default.prompt(t).then((t=>{e(t.toDelete?t.selectedDeps:[])}))}))),o.then((t=>(t.forEach((t=>{e.devDependencies[t]=void 0})),e)))}function upgradePackage(e){console.log(_chalk.default.green("升级 package.json"));const t=_path.default.join(curDir,"package.json"),a=require(t),o=require(_path.default.resolve(dslModuleDir,"templates/app/demo/package.json"));return e.force&&(o.devDependencies={}),o.devDependencies["hap-toolkit"]=packageInfo.version,o.subversion&&(o.subversion.toolkit=packageInfo.version),cleanupDependencies(a,e).then((e=>{for(const t in o){const l=o[t];"string"==typeof l&&a[t]?o[t]=e[t]:mergeProps(l,e[t])}_fsExtra.default.writeFileSync(t,JSON.stringify(o,null,2))}))}function copyFiles(e,t){const a=_path.default.join(t,"**/{*,.*}");_glob.default.sync(a).forEach((a=>{const o=_path.default.relative(t,a),l=_path.default.join(e,o);console.log(_chalk.default.green(`file ${(0,_sharedUtils.relateCwd)(l)} copied.`)),_fsExtra.default.copySync(a,l)}))}function upgradeSign(){console.log(_chalk.default.green("Upgrade signature file"));const e=_path.default.join(curDir,"sign/debug");_fsExtra.default.removeSync(e),(0,_sharedUtils.mkdirsSync)(e),copyFiles(e,_path.default.join(dslModuleDir,"templates/app/demo/sign/debug"))}function upgradeEslint(){const e=".eslintrc.json",t=_path.default.join(dslModuleDir,"templates/app/demo",e),a=_path.default.join(curDir,e);_fsExtra.default.copySync(t,a)}function upgradeBabelConfig(){const e="babel.config.js",t=".babelrc",a=_path.default.join(dslModuleDir,"templates/app/demo",e),o=_path.default.join(curDir,t),l=_path.default.join(curDir,e),r=(0,_utils.formatDate)("yyyyMMdd_hhmmss",new Date);if(console.log(_chalk.default.green("The project is upgraded to babel7, and the default configuration uses babel.config.js")),_fsExtra.default.existsSync(o)){const e=_path.default.join(curDir,".babelrc.old."+r);_fsExtra.default.copySync(o,e),_fsExtra.default.removeSync(o),console.log(_chalk.default.yellow(`### App Toolkit ### The backup file of .babelrc is saved as: ${(0,_sharedUtils.relateCwd)(e)}`))}if(_fsExtra.default.existsSync(l)){const t=_path.default.join(curDir,_path.default.basename(e,".js")+".old."+r+".js");_fsExtra.default.copySync(l,t),console.log(_chalk.default.yellow(`### App Toolkit ### The backup file of the updated ${e} is saved as: ${(0,_sharedUtils.relateCwd)(t)}`))}_fsExtra.default.existsSync(a)&&(_fsExtra.default.copySync(a,l),console.log(_chalk.default.yellow(`### App Toolkit ### The updated ${e} succeeded!`)))}function savePackage(){const e="package.json",t=_path.default.join(curDir,e),a=(0,_utils.formatDate)("yyyyMMdd_hhmmss",new Date),o=_path.default.join(curDir,_path.default.basename(e,".json")+".old."+a+".json");_fsExtra.default.copySync(t,o),console.log(_chalk.default.yellow(`### App Toolkit ### The updated backup file of ${e} is saved as: ${(0,_sharedUtils.relateCwd)(o)}`))}function updateProject(e){const t=checkVersion();if(e.force)console.log(_chalk.default.yellow(`Force upgrade project( ${t.cur} ----\x3e ${t.toolkit} )(There may be compatibility issues)`)),savePackage();else{if(t.res<0||0===t.res)return void(0===t.res&&console.log("### App Toolkit ### The version is already the latest version"));console.log(_chalk.default.green(`Upgrade project( ${t.cur} ----\x3e ${t.toolkit} )`))}dslName=(0,_sharedUtils.getProjectDslName)(curDir),dslModuleDir=dslModuleHash[dslName],upgradePackage(e).then((()=>{upgradeSign(),upgradeEslint(),upgradeBabelConfig(),console.log(_chalk.default.green("Upgrade complete, Please run npm install to update the dependency package"))}))}module.exports=updateProject;
|
|
359
2
|
//# sourceMappingURL=update.js.map
|
package/lib/commands/utils.js
CHANGED
|
@@ -1,284 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.formatDate = formatDate;
|
|
7
|
-
exports.summaryErrors = summaryErrors;
|
|
8
|
-
exports.summaryWarnings = summaryWarnings;
|
|
9
|
-
exports.getQuickappDebuggerUrl = getQuickappDebuggerUrl;
|
|
10
|
-
exports.getQuickappPreviewUrl = getQuickappPreviewUrl;
|
|
11
|
-
exports.downloadFile = downloadFile;
|
|
12
|
-
exports.sendReq = sendReq;
|
|
13
|
-
exports.getClients = getClients;
|
|
14
|
-
exports.checkQuickappDir = checkQuickappDir;
|
|
15
|
-
exports.getCardContent = getCardContent;
|
|
16
|
-
|
|
17
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
18
|
-
|
|
19
|
-
var _path = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
|
-
var _request = _interopRequireDefault(require("request"));
|
|
22
|
-
|
|
23
|
-
var _http = _interopRequireDefault(require("http"));
|
|
24
|
-
|
|
25
|
-
var _recordClient = require("@aiot-toolkit/shared-utils/lib/record-client");
|
|
26
|
-
|
|
27
|
-
var _config = require("@aiot-toolkit/shared-utils/config");
|
|
28
|
-
|
|
29
|
-
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
30
|
-
|
|
31
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
32
|
-
|
|
33
|
-
/*
|
|
34
|
-
* Copyright (C) 2017, hapjs.org. All rights reserved.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 接受用户指定的输出时间戳格式,输出时间时间戳
|
|
39
|
-
* usage sample:
|
|
40
|
-
* formatDate('yyyy年MM月dd日', new Date() );
|
|
41
|
-
* formatDate('yyyy-MM-dd hh:mm:ss', new Date() );
|
|
42
|
-
* formatDate('这是自定义的yyyy年, 自定义的MM月', new Date())
|
|
43
|
-
*
|
|
44
|
-
* @param {[type]} format 用户指定的时间戳格式, 见上面示例;
|
|
45
|
-
* @param {[type]} date Date实例
|
|
46
|
-
*/
|
|
47
|
-
function formatDate(format, date) {
|
|
48
|
-
let result = format;
|
|
49
|
-
let year, month, day;
|
|
50
|
-
let hour, min, sec;
|
|
51
|
-
|
|
52
|
-
if (format.indexOf('yyyy') >= 0 || format.indexOf('YYYYY') >= 0) {
|
|
53
|
-
year = date.getFullYear();
|
|
54
|
-
result = result.replace(/[yY]{4}/g, year);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (format.indexOf('MM') >= 0) {
|
|
58
|
-
month = date.getMonth() + 1;
|
|
59
|
-
result = result.replace(/MM/g, String(month).length < 2 ? '0' + month : month);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (format.indexOf('dd') >= 0) {
|
|
63
|
-
day = date.getDate();
|
|
64
|
-
result = result.replace(/dd/g, String(day).length < 2 ? '0' + day : day);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (format.indexOf('hh') >= 0 || format.indexOf('HH') >= 0) {
|
|
68
|
-
hour = date.getHours();
|
|
69
|
-
result = result.replace(/[hH]{2}/g, String(hour).length < 2 ? '0' + hour : hour);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (format.indexOf('mm') >= 0) {
|
|
73
|
-
min = date.getMinutes();
|
|
74
|
-
result = result.replace(/mm/g, String(min).length < 2 ? '0' + min : min);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (format.indexOf('ss') >= 0 || format.indexOf('SS') >= 0) {
|
|
78
|
-
sec = date.getSeconds();
|
|
79
|
-
result = result.replace(/[sS]{2}/g, String(sec).length < 2 ? '0' + sec : sec);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 整理错误
|
|
86
|
-
*
|
|
87
|
-
* @param {Object} stats
|
|
88
|
-
* @returns {String}
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
function summaryErrors(stats) {
|
|
93
|
-
const errors = [];
|
|
94
|
-
stats.compilation.errors.forEach(error => {
|
|
95
|
-
const message = error.message; // 如果错误信息显示缺少某些loader,则提示安装
|
|
96
|
-
|
|
97
|
-
const reg = /Can't resolve '(sass-loader|less-loader|stylus-loader)'/;
|
|
98
|
-
const result = reg.exec(message);
|
|
99
|
-
|
|
100
|
-
if (error.name === 'ModuleNotFoundError' && result) {
|
|
101
|
-
let moduleName = result[1];
|
|
102
|
-
|
|
103
|
-
if (moduleName === 'less-loader') {
|
|
104
|
-
moduleName = `less ${moduleName}`;
|
|
105
|
-
} else if (moduleName === 'sass-loader') {
|
|
106
|
-
moduleName = `sass ${moduleName}`;
|
|
107
|
-
} else if (moduleName === 'stylus-loader') {
|
|
108
|
-
moduleName = `stylus ${moduleName}`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
error.message = ` Missing dependency: ${moduleName}, Please execute npm install -D ${moduleName} to install the corresponding dependencies `;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const resourceName = error.module ? error.module.resource : '';
|
|
115
|
-
errors.push(`${resourceName}\r\n${error.message}`);
|
|
116
|
-
}); // 使用 stats.toString,webpack会在前面加上 ERROR 标志,与 colorconsole.error 重复
|
|
117
|
-
|
|
118
|
-
return errors.join('\n\n');
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* 提取警告信息
|
|
122
|
-
* @param {*} stats
|
|
123
|
-
* @returns
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
function summaryWarnings(stats) {
|
|
128
|
-
return stats.compilation.warnings.map(warn => warn.message).join('\n\n');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const quickapp_url = 'https://statres.quickapp.cn/quickapp/quickapptool/release/platform/';
|
|
132
|
-
/**
|
|
133
|
-
* 快应用调试器地址
|
|
134
|
-
* @param version 版本号
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
function getQuickappDebuggerUrl(version) {
|
|
138
|
-
let newVersion = version || 'v1080';
|
|
139
|
-
|
|
140
|
-
_sharedUtils.colorconsole.log(`The version of the Quickapp debugger that started to download is: ${newVersion}`);
|
|
141
|
-
|
|
142
|
-
return `${quickapp_url}quickapp_debugger_${newVersion}.apk`;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* 快应用预览版地址
|
|
146
|
-
* @param version 版本号
|
|
147
|
-
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
function getQuickappPreviewUrl(version) {
|
|
151
|
-
let newVersion = version || 'v1080';
|
|
152
|
-
|
|
153
|
-
_sharedUtils.colorconsole.log(`The version of the Quickapp debugger that started to download is: ${newVersion}`);
|
|
154
|
-
|
|
155
|
-
return `${quickapp_url}quickapp_platform_preview_release_${newVersion}.apk`;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 下载文件
|
|
159
|
-
* @param url 网络文件地址
|
|
160
|
-
* @param fileName 文件名
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
function downloadFile(url, fileName) {
|
|
165
|
-
_sharedUtils.colorconsole.log(`Start downloading file:${fileName}, address:${url}`);
|
|
166
|
-
|
|
167
|
-
return new Promise(function (resolve, reject) {
|
|
168
|
-
(0, _request.default)(url, function (error, response, body) {
|
|
169
|
-
if (!error && response.statusCode === 200) {
|
|
170
|
-
const targetDir = _path.default.join(__dirname, './apk');
|
|
171
|
-
|
|
172
|
-
_fsExtra.default.ensureDirSync(targetDir);
|
|
173
|
-
|
|
174
|
-
let stream = _fsExtra.default.createWriteStream(_path.default.join(targetDir, fileName));
|
|
175
|
-
|
|
176
|
-
(0, _request.default)(url).pipe(stream).on('close', err => {
|
|
177
|
-
if (err) {
|
|
178
|
-
reject(err);
|
|
179
|
-
} else {
|
|
180
|
-
resolve(`Download file ${fileName} successfully`);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
} else {
|
|
184
|
-
if (error) {
|
|
185
|
-
reject(error);
|
|
186
|
-
} else {
|
|
187
|
-
reject(new Error(`Download failed, status code:${response.statusCode}`));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* 向手机设备发送请求
|
|
195
|
-
* @param client {{ ip, port }}
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
async function sendReq(client, api, params) {
|
|
200
|
-
return new Promise(resolve => {
|
|
201
|
-
const requrl = `http://${client.ip}:${client.port}${api}`; // 发送请求
|
|
202
|
-
|
|
203
|
-
let options = {
|
|
204
|
-
host: client.ip,
|
|
205
|
-
port: client.port,
|
|
206
|
-
path: api,
|
|
207
|
-
timeout: 3000
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
if (params) {
|
|
211
|
-
options = Object.assign({}, options, {
|
|
212
|
-
headers: params
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const req = _http.default.request(options, res => {
|
|
217
|
-
res.on('data', data => {
|
|
218
|
-
_sharedUtils.colorconsole.log(`### App Server ### Request ${requrl} succeeded`);
|
|
219
|
-
|
|
220
|
-
resolve(data.toString());
|
|
221
|
-
});
|
|
222
|
-
}).on('error', err => {
|
|
223
|
-
_sharedUtils.colorconsole.error(`### App Server ### Request ${requrl} error message: ${err.message}`);
|
|
224
|
-
}).on('timeout', function () {
|
|
225
|
-
_sharedUtils.colorconsole.log(`### App Server ### Request ${requrl} timed out, please try again`);
|
|
226
|
-
|
|
227
|
-
req.abort();
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
req.end();
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* 获取已连接的设备信息
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
async function getClients() {
|
|
239
|
-
return new Promise(resolve => {
|
|
240
|
-
if (_fsExtra.default.existsSync(_config.clientRecordPath)) {
|
|
241
|
-
const recordData = (0, _recordClient.getRecords)(_config.clientRecordPath);
|
|
242
|
-
const clients = (0, _recordClient.getProjectClients)(recordData);
|
|
243
|
-
|
|
244
|
-
if (clients.length > 0) {
|
|
245
|
-
resolve(clients);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
resolve(null);
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* 判断是否在快应用的目录下
|
|
254
|
-
* @param {String} curDir - 当前命令的执行目录
|
|
255
|
-
*/
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
function checkQuickappDir(curDir, srcDir = 'src') {
|
|
259
|
-
const curpkgPath = _path.default.join(curDir, srcDir, 'manifest.json');
|
|
260
|
-
|
|
261
|
-
if (!_fsExtra.default.existsSync(curpkgPath)) {
|
|
262
|
-
_sharedUtils.colorconsole.error(`Please execute this command under the Quickapp project`);
|
|
263
|
-
|
|
264
|
-
process.exit();
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* 获取卡片内容
|
|
269
|
-
* @param {String} curDir - 当前命令的执行目录
|
|
270
|
-
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
function getCardContent(curDir) {
|
|
274
|
-
const curpkgPath = _path.default.join(curDir, 'src', 'manifest.json');
|
|
275
|
-
|
|
276
|
-
const widgetsContent = (0, _sharedUtils.readJson)(curpkgPath).router.widgets || null;
|
|
277
|
-
|
|
278
|
-
if (!widgetsContent) {
|
|
279
|
-
_sharedUtils.colorconsole.error(`No card configuration in manifest.json`);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return widgetsContent;
|
|
283
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.formatDate=formatDate,exports.summaryErrors=summaryErrors,exports.summaryWarnings=summaryWarnings,exports.getQuickappDebuggerUrl=getQuickappDebuggerUrl,exports.getQuickappPreviewUrl=getQuickappPreviewUrl,exports.downloadFile=downloadFile,exports.sendReq=sendReq,exports.getClients=getClients,exports.checkQuickappDir=checkQuickappDir,exports.getCardContent=getCardContent;var _fsExtra=_interopRequireDefault(require("fs-extra")),_path=_interopRequireDefault(require("path")),_request=_interopRequireDefault(require("request")),_http=_interopRequireDefault(require("http")),_recordClient=require("@aiot-toolkit/shared-utils/lib/record-client"),_config=require("@aiot-toolkit/shared-utils/config"),_sharedUtils=require("@aiot-toolkit/shared-utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function formatDate(e,t){let r,o,s,n,i,a,l=e;return(e.indexOf("yyyy")>=0||e.indexOf("YYYYY")>=0)&&(r=t.getFullYear(),l=l.replace(/[yY]{4}/g,r)),e.indexOf("MM")>=0&&(o=t.getMonth()+1,l=l.replace(/MM/g,String(o).length<2?"0"+o:o)),e.indexOf("dd")>=0&&(s=t.getDate(),l=l.replace(/dd/g,String(s).length<2?"0"+s:s)),(e.indexOf("hh")>=0||e.indexOf("HH")>=0)&&(n=t.getHours(),l=l.replace(/[hH]{2}/g,String(n).length<2?"0"+n:n)),e.indexOf("mm")>=0&&(i=t.getMinutes(),l=l.replace(/mm/g,String(i).length<2?"0"+i:i)),(e.indexOf("ss")>=0||e.indexOf("SS")>=0)&&(a=t.getSeconds(),l=l.replace(/[sS]{2}/g,String(a).length<2?"0"+a:a)),l}function summaryErrors(e){const t=[];return e.compilation.errors.forEach((e=>{const r=e.message,o=/Can't resolve '(sass-loader|less-loader|stylus-loader)'/.exec(r);if("ModuleNotFoundError"===e.name&&o){let t=o[1];"less-loader"===t?t=`less ${t}`:"sass-loader"===t?t=`sass ${t}`:"stylus-loader"===t&&(t=`stylus ${t}`),e.message=` Missing dependency: ${t}, Please execute npm install -D ${t} to install the corresponding dependencies `}const s=e.module?e.module.resource:"";t.push(`${s}\r\n${e.message}`)})),t.join("\n\n")}function summaryWarnings(e){return e.compilation.warnings.map((e=>e.message)).join("\n\n")}const quickapp_url="https://statres.quickapp.cn/quickapp/quickapptool/release/platform/";function getQuickappDebuggerUrl(e){let t=e||"v1080";return _sharedUtils.colorconsole.log(`The version of the Quickapp debugger that started to download is: ${t}`),`${quickapp_url}quickapp_debugger_${t}.apk`}function getQuickappPreviewUrl(e){let t=e||"v1080";return _sharedUtils.colorconsole.log(`The version of the Quickapp debugger that started to download is: ${t}`),`${quickapp_url}quickapp_platform_preview_release_${t}.apk`}function downloadFile(e,t){return _sharedUtils.colorconsole.log(`Start downloading file:${t}, address:${e}`),new Promise((function(r,o){(0,_request.default)(e,(function(s,n,i){if(s||200!==n.statusCode)o(s||new Error(`Download failed, status code:${n.statusCode}`));else{const s=_path.default.join(__dirname,"./apk");_fsExtra.default.ensureDirSync(s);let n=_fsExtra.default.createWriteStream(_path.default.join(s,t));(0,_request.default)(e).pipe(n).on("close",(e=>{e?o(e):r(`Download file ${t} successfully`)}))}}))}))}async function sendReq(e,t,r){return new Promise((o=>{const s=`http://${e.ip}:${e.port}${t}`;let n={host:e.ip,port:e.port,path:t,timeout:3e3};r&&(n=Object.assign({},n,{headers:r}));const i=_http.default.request(n,(e=>{e.on("data",(e=>{_sharedUtils.colorconsole.log(`### App Server ### Request ${s} succeeded`),o(e.toString())}))})).on("error",(e=>{_sharedUtils.colorconsole.error(`### App Server ### Request ${s} error message: ${e.message}`)})).on("timeout",(function(){_sharedUtils.colorconsole.log(`### App Server ### Request ${s} timed out, please try again`),i.abort()}));i.end()}))}async function getClients(){return new Promise((e=>{if(_fsExtra.default.existsSync(_config.clientRecordPath)){const t=(0,_recordClient.getRecords)(_config.clientRecordPath),r=(0,_recordClient.getProjectClients)(t);r.length>0&&e(r)}e(null)}))}function checkQuickappDir(e,t="src"){const r=_path.default.join(e,t,"manifest.json");_fsExtra.default.existsSync(r)||(_sharedUtils.colorconsole.error("Please execute this command under the Quickapp project"),process.exit())}function getCardContent(e){const t=_path.default.join(e,"src","manifest.json"),r=(0,_sharedUtils.readJson)(t).router.widgets||null;return r||_sharedUtils.colorconsole.error("No card configuration in manifest.json"),r}
|
|
284
2
|
//# sourceMappingURL=utils.js.map
|