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,224 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
|
4
|
+
|
|
5
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
6
|
+
|
|
7
|
+
var _init = require("../../lib/commands/init");
|
|
8
|
+
|
|
9
|
+
var _template = _interopRequireDefault(require("@aiot-toolkit/dsl-xvm/lib/template"));
|
|
10
|
+
|
|
11
|
+
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
module.exports.transformProject = async function (projectPath, options) {
|
|
16
|
+
try {
|
|
17
|
+
if (options && options.import) {
|
|
18
|
+
// 开始导入旧应用
|
|
19
|
+
await projectToAspect(options);
|
|
20
|
+
} else if (projectPath) {
|
|
21
|
+
// 开始转换旧应用
|
|
22
|
+
await transformToNewProject(projectPath);
|
|
23
|
+
} else {
|
|
24
|
+
_sharedUtils.colorconsole.log('transform stop: No valid information entered!');
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw new Error(`transform failed! ${error}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 校验输入的路径是否存在
|
|
32
|
+
* @param {*} cwd 工作路径
|
|
33
|
+
* @param {*} projectPath 输入的相对路径
|
|
34
|
+
* @returns 绝对路径
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function validateProjectPath(cwd, projectPath) {
|
|
39
|
+
const absolutePath = _path.default.join(cwd, projectPath);
|
|
40
|
+
|
|
41
|
+
if (!_fsExtra.default.existsSync(absolutePath)) {
|
|
42
|
+
throw new Error(`Path: ${absolutePath} is not exist!`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return absolutePath;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 读取manifest.json中的name字段、package字段
|
|
49
|
+
* @param {*} projectPath 快应用项目目录
|
|
50
|
+
* @returns manifest中的name和package
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function readName(projectPath) {
|
|
55
|
+
const manifestFilePath = _path.default.join(projectPath, 'src', 'manifest.json');
|
|
56
|
+
|
|
57
|
+
const content = _fsExtra.default.readJsonSync(manifestFilePath, {
|
|
58
|
+
encoding: 'utf-8'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (content.name && content.package) {
|
|
62
|
+
return {
|
|
63
|
+
projectName: content.name,
|
|
64
|
+
projectPackageName: content.package
|
|
65
|
+
};
|
|
66
|
+
} else {
|
|
67
|
+
throw new Error('The name and package name fields do not exist in the manifest.json!');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 将快应用项目转换为跨屏项目
|
|
72
|
+
* @param {*} projectPath 待转换的快应用项目相对工作目录的路径
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
async function transformToNewProject(projectPath) {
|
|
77
|
+
projectPath = validateProjectPath(process.cwd(), projectPath);
|
|
78
|
+
|
|
79
|
+
const newProjectPath = _path.default.join(_path.default.dirname(projectPath), `xapp-${_path.default.basename(projectPath)}`); // 读取旧项目中name字段和package字段
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const {
|
|
83
|
+
projectName,
|
|
84
|
+
projectPackageName
|
|
85
|
+
} = readName(projectPath); // 创建空模板
|
|
86
|
+
|
|
87
|
+
await createNewXappProject(_template.default.app.xappMultiScreenTemplate, newProjectPath); // 替换变量
|
|
88
|
+
|
|
89
|
+
renderFilesData(newProjectPath, projectName, projectPackageName); // 拷贝src到新应用的src中
|
|
90
|
+
|
|
91
|
+
const originSrc = _path.default.join(projectPath, 'src');
|
|
92
|
+
|
|
93
|
+
const targetSrc = _path.default.join(newProjectPath, 'main', 'src'); // 替换app.ux文件名为aspect.ux
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
await (0, _init.copyFiles)(targetSrc, originSrc, {
|
|
97
|
+
'app.ux': 'aspect.ux'
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
_sharedUtils.colorconsole.info(`transform success! new project path is ${newProjectPath}`);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 创建空模板
|
|
104
|
+
* @param {*} templatePath 模板路径
|
|
105
|
+
* @param {*} newProjectPath 目标路径
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async function createNewXappProject(templatePath, newProjectPath) {
|
|
110
|
+
if (_fsExtra.default.existsSync(newProjectPath)) {
|
|
111
|
+
// 重复时,报错
|
|
112
|
+
throw new Error(`Create error: Folfer ${_path.default.basename(newProjectPath)} already exists in path ${_path.default.dirname(newProjectPath)}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_fsExtra.default.mkdirSync(newProjectPath);
|
|
116
|
+
|
|
117
|
+
await (0, _init.copyFiles)(newProjectPath, templatePath, {
|
|
118
|
+
_gitignore: '.gitignore'
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* render files
|
|
123
|
+
* @param {*} newProjectPath 项目路径
|
|
124
|
+
* @param {*} projectName 替换字段值
|
|
125
|
+
* @param {*} projectPackageName 替换字段值
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
function renderFilesData(newProjectPath, projectName, projectPackageName) {
|
|
130
|
+
const renderData = {
|
|
131
|
+
appName: projectName,
|
|
132
|
+
packageName: projectPackageName,
|
|
133
|
+
toolkitVersion: require('../../package.json').version,
|
|
134
|
+
dirName: _path.default.basename(newProjectPath)
|
|
135
|
+
};
|
|
136
|
+
const configFiles = ['package.json', 'app/manifest.json', '.project.json', 'README.md'];
|
|
137
|
+
const files = configFiles.map(file => _path.default.join(newProjectPath, file));
|
|
138
|
+
files.forEach(filePath => {
|
|
139
|
+
let content = _fsExtra.default.readFileSync(filePath, 'utf-8');
|
|
140
|
+
|
|
141
|
+
content = (0, _sharedUtils.renderString)(content, renderData);
|
|
142
|
+
|
|
143
|
+
_fsExtra.default.writeFileSync(filePath, content);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 导入旧应用
|
|
148
|
+
* @param {*} options 命令参数,包含导入项目的相对路径
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
async function projectToAspect(options) {
|
|
153
|
+
const importPath = options.import;
|
|
154
|
+
const targetProjectPath = process.cwd();
|
|
155
|
+
const projectPath = validateProjectPath(targetProjectPath, importPath); // 读取name和packageName
|
|
156
|
+
|
|
157
|
+
const {
|
|
158
|
+
projectName,
|
|
159
|
+
projectPackageName
|
|
160
|
+
} = readName(projectPath); // 创建一个aspect项目
|
|
161
|
+
|
|
162
|
+
const newProjectPath = _path.default.join(targetProjectPath, projectPackageName);
|
|
163
|
+
|
|
164
|
+
await createNewXappProject(_template.default.app.xappAspect, newProjectPath); // render config.json
|
|
165
|
+
|
|
166
|
+
const renderData = {
|
|
167
|
+
appName: projectName
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const filePath = _path.default.join(newProjectPath, 'config.json');
|
|
171
|
+
|
|
172
|
+
let content = _fsExtra.default.readFileSync(filePath, 'utf-8');
|
|
173
|
+
|
|
174
|
+
content = (0, _sharedUtils.renderString)(content, renderData);
|
|
175
|
+
|
|
176
|
+
_fsExtra.default.writeFileSync(filePath, content); // 先清空再拷贝src
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
const originSrc = _path.default.join(projectPath, 'src');
|
|
180
|
+
|
|
181
|
+
const targetSrc = _path.default.join(newProjectPath, 'src');
|
|
182
|
+
|
|
183
|
+
_fsExtra.default.emptyDirSync(targetSrc);
|
|
184
|
+
|
|
185
|
+
await (0, _init.copyFiles)(targetSrc, originSrc, {
|
|
186
|
+
'app.ux': 'aspect.ux'
|
|
187
|
+
}); // 修改配置
|
|
188
|
+
|
|
189
|
+
updateAppManifest(targetProjectPath, projectPackageName);
|
|
190
|
+
|
|
191
|
+
_sharedUtils.colorconsole.info(`import success! new aspect name is ${projectPackageName}`);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 更新app/manifest.json文件
|
|
195
|
+
* @param {*} projectPath 项目路径
|
|
196
|
+
* @param {*} projectPackageName 包名
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
function updateAppManifest(projectPath, projectPackageName) {
|
|
201
|
+
const manifestFilePath = _path.default.join(projectPath, 'app', 'manifest.json');
|
|
202
|
+
|
|
203
|
+
const manifestContent = _fsExtra.default.readJSONSync(manifestFilePath, {
|
|
204
|
+
encoding: 'utf-8'
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const aspectInfo = {
|
|
208
|
+
path: `${projectPackageName}`,
|
|
209
|
+
devices: ['watch'],
|
|
210
|
+
autoStart: true
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
if (manifestContent && manifestContent.router && manifestContent.router.aspects && manifestContent.router.aspects instanceof Object) {
|
|
214
|
+
manifestContent.router.aspects[`${projectPackageName}`] = [aspectInfo];
|
|
215
|
+
|
|
216
|
+
_fsExtra.default.writeJSONSync(manifestFilePath, manifestContent, {
|
|
217
|
+
spaces: 2
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
// 报错,router.aspects不存在或者格式错误
|
|
221
|
+
throw new Error('router.aspects does not exist or is in the wrong format');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
2
224
|
//# sourceMappingURL=transform.js.map
|
package/lib/commands/update.js
CHANGED
|
@@ -1,2 +1,359 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
2
359
|
//# sourceMappingURL=update.js.map
|