create-aiot 2.0.1-alpha.8 → 2.0.2-batchmanifest-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/bin.js +17 -5
- package/lib/index.d.ts +2 -1
- package/lib/index.js +91 -48
- package/lib/interface/IProjectParam.d.ts +1 -1
- package/lib/interface/IProjectParam.js +0 -2
- package/lib/interface/ITemplate.js +0 -2
- package/lib/template/template.json +16 -11
- package/lib/template/ux/project.config.json +1 -1
- package/lib/template/vela-demo/README.md +25 -0
- package/lib/template/vela-demo/_gitignore +5 -0
- package/lib/template/vela-demo/package.json +22 -0
- package/lib/template/vela-demo/src/app.ux +10 -0
- package/lib/template/vela-demo/src/common/logo.png +0 -0
- package/lib/template/vela-demo/src/config-watch.json +1 -0
- package/lib/template/vela-demo/src/i18n/defaults.json +1 -0
- package/lib/template/vela-demo/src/i18n/en.json +1 -0
- package/lib/template/vela-demo/src/i18n/zh-CN.json +1 -0
- package/lib/template/vela-demo/src/manifest.json +32 -0
- package/lib/template/vela-demo/src/pages/detail/detail.ux +26 -0
- package/lib/template/vela-demo/src/pages/index/index.ux +49 -0
- package/lib/template/xts/app-package-name/_gitignore +4 -0
- package/lib/template/{xts-app-template → xts}/app-package-name/app/manifest.json +2 -2
- package/lib/utils/TemplateUtil.d.ts +6 -1
- package/lib/utils/TemplateUtil.js +32 -10
- package/package.json +7 -8
- package/lib/bin.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/interface/IProjectParam.js.map +0 -1
- package/lib/interface/ITemplate.js.map +0 -1
- package/lib/utils/TemplateUtil.js.map +0 -1
- /package/lib/template/{xts-app-template → xts}/app-package-name/app/app.xts +0 -0
- /package/lib/template/{xts-app-template → xts}/app-package-name/app/resources/icon.png +0 -0
- /package/lib/template/{xts-app-template → xts}/aspect1/config.json +0 -0
- /package/lib/template/{xts-app-template → xts}/aspect1/src/aspect.xts +0 -0
- /package/lib/template/{xts-app-template → xts}/aspect1/src/manifest.json +0 -0
- /package/lib/template/{xts-app-template → xts}/aspect1/src/pages/Home.xts +0 -0
- /package/lib/template/{xts-app-template → xts}/aspect1/src/resources/logo.png +0 -0
package/lib/bin.js
CHANGED
|
@@ -11,20 +11,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
const commander_1 = require("@aiot-toolkit/commander");
|
|
14
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
14
15
|
const _1 = require(".");
|
|
15
16
|
function main() {
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
|
|
18
|
+
if (process.argv.length <= 2) {
|
|
19
|
+
const answer = yield (0, prompts_1.select)({
|
|
20
|
+
message: 'Select a framework:',
|
|
21
|
+
choices: [
|
|
22
|
+
{
|
|
23
|
+
value: 'ux'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: 'xts'
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
process.argv.push(answer);
|
|
31
|
+
}
|
|
18
32
|
// 创建命令行配置
|
|
19
33
|
const config = {
|
|
20
34
|
name: 'create-aiot',
|
|
21
35
|
description: 'create aiot project',
|
|
22
|
-
version: '
|
|
23
|
-
|
|
36
|
+
version: require('../package.json').version,
|
|
37
|
+
commandList: [yield (0, _1.getCrerateXtsCommand)(), yield (0, _1.getUxCreateCommand)()]
|
|
24
38
|
};
|
|
25
39
|
commander_1.Command.registeProgram(config);
|
|
26
40
|
});
|
|
27
41
|
}
|
|
28
42
|
main();
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=bin.js.map
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -12,17 +12,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.getCrerateXtsCommand = exports.getUxCreateCommand = void 0;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
18
|
const TemplateUtil_1 = __importDefault(require("./utils/TemplateUtil"));
|
|
19
|
-
|
|
19
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
20
|
+
function createAction(options, projectType) {
|
|
20
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
|
|
22
|
+
try {
|
|
23
|
+
const templateList = yield TemplateUtil_1.default.requestTemplateList(projectType);
|
|
24
|
+
const { name, aspect, packageName, template, eslint = false } = options;
|
|
25
|
+
const templateItem = templateList.find((item) => item.name === template);
|
|
26
|
+
if (templateItem) {
|
|
27
|
+
const param = {
|
|
28
|
+
name,
|
|
29
|
+
template: templateItem,
|
|
30
|
+
packageName,
|
|
31
|
+
tools: {
|
|
32
|
+
eslint
|
|
33
|
+
},
|
|
34
|
+
aspect
|
|
35
|
+
};
|
|
36
|
+
yield TemplateUtil_1.default.createProject(param, {
|
|
37
|
+
data: { appName: name, packageName },
|
|
38
|
+
includes: (path) => {
|
|
39
|
+
const stats = fs_1.default.statSync(path);
|
|
40
|
+
if (stats.isDirectory()) {
|
|
41
|
+
return ['src'].includes(path_1.default.basename(path));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return ['.json', '.ux'].includes(path_1.default.extname(path));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error('');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
ColorConsole_1.default.error(`Create project error: ${error}`);
|
|
55
|
+
process.exit();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function getUxCreateCommand() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const templateList = yield TemplateUtil_1.default.requestTemplateList('ux');
|
|
22
62
|
return {
|
|
23
|
-
name: '',
|
|
63
|
+
name: 'ux',
|
|
24
64
|
description: 'default',
|
|
25
65
|
paramList: [
|
|
66
|
+
{
|
|
67
|
+
name: 'template',
|
|
68
|
+
description: 'prject template',
|
|
69
|
+
type: 'select',
|
|
70
|
+
enableInquirer: true,
|
|
71
|
+
choices: templateList.map((item) => {
|
|
72
|
+
return {
|
|
73
|
+
value: item.name,
|
|
74
|
+
description: item.description
|
|
75
|
+
};
|
|
76
|
+
})
|
|
77
|
+
},
|
|
26
78
|
{
|
|
27
79
|
name: 'name',
|
|
28
80
|
description: 'poject name',
|
|
@@ -32,14 +84,22 @@ function getAiotCreateCommand() {
|
|
|
32
84
|
validate(value) {
|
|
33
85
|
return TemplateUtil_1.default.validateProjectName(value);
|
|
34
86
|
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
action: (option) => {
|
|
90
|
+
createAction(option, 'ux');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
exports.getUxCreateCommand = getUxCreateCommand;
|
|
96
|
+
function getCrerateXtsCommand() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const templateList = yield TemplateUtil_1.default.requestTemplateList('xts');
|
|
99
|
+
return {
|
|
100
|
+
name: 'xts',
|
|
101
|
+
description: 'create xts template project',
|
|
102
|
+
paramList: [
|
|
43
103
|
{
|
|
44
104
|
name: 'template',
|
|
45
105
|
description: 'prject template',
|
|
@@ -53,51 +113,34 @@ function getAiotCreateCommand() {
|
|
|
53
113
|
})
|
|
54
114
|
},
|
|
55
115
|
{
|
|
56
|
-
name: '
|
|
57
|
-
|
|
58
|
-
|
|
116
|
+
name: 'name',
|
|
117
|
+
description: 'poject name',
|
|
118
|
+
enableInquirer: true,
|
|
119
|
+
defaultValue: 'xts-project',
|
|
120
|
+
type: 'string',
|
|
121
|
+
validate(value) {
|
|
122
|
+
return TemplateUtil_1.default.validateProjectName(value);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'packageName',
|
|
127
|
+
description: 'package name',
|
|
59
128
|
enableInquirer: true,
|
|
60
|
-
defaultValue:
|
|
129
|
+
defaultValue: 'xts.app.test',
|
|
130
|
+
type: 'string'
|
|
61
131
|
},
|
|
62
132
|
{
|
|
63
133
|
name: 'aspect',
|
|
64
134
|
type: 'string',
|
|
65
|
-
|
|
135
|
+
defaultValue: 'aspect1',
|
|
136
|
+
description: 'Do you need to create some aspect, with multiple aspect names separated by commas',
|
|
137
|
+
enableInquirer: true
|
|
66
138
|
}
|
|
67
139
|
],
|
|
68
140
|
action: (option) => {
|
|
69
|
-
|
|
70
|
-
const templateItem = templateList.find((item) => item.name === template);
|
|
71
|
-
if (templateItem) {
|
|
72
|
-
const param = {
|
|
73
|
-
name,
|
|
74
|
-
version: v,
|
|
75
|
-
template: templateItem,
|
|
76
|
-
tools: {
|
|
77
|
-
eslint
|
|
78
|
-
},
|
|
79
|
-
aspect
|
|
80
|
-
};
|
|
81
|
-
TemplateUtil_1.default.createProject(param, {
|
|
82
|
-
data: { version: v, appName: name },
|
|
83
|
-
includes: (path) => {
|
|
84
|
-
const stats = fs_1.default.statSync(path);
|
|
85
|
-
if (stats.isDirectory()) {
|
|
86
|
-
return ['src'].includes(path_1.default.basename(path));
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return ['.json', '.ux'].includes(path_1.default.extname(path));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
console.log('template error');
|
|
96
|
-
}
|
|
141
|
+
createAction(option, 'xts');
|
|
97
142
|
}
|
|
98
143
|
};
|
|
99
144
|
});
|
|
100
145
|
}
|
|
101
|
-
exports.
|
|
102
|
-
|
|
103
|
-
//# sourceMappingURL=index.js.map
|
|
146
|
+
exports.getCrerateXtsCommand = getCrerateXtsCommand;
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"type": "ux",
|
|
4
|
+
"demoList": [
|
|
5
|
+
{
|
|
6
|
+
"name": "vela-demo",
|
|
7
|
+
"path": "./vela-demo",
|
|
8
|
+
"description": "vela demo template"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
6
11
|
},
|
|
7
12
|
{
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
"type": "xts",
|
|
14
|
+
"demoList": [
|
|
15
|
+
{
|
|
16
|
+
"name": "xts-demo",
|
|
17
|
+
"path": "./xts/app-package-name",
|
|
18
|
+
"description": "xts demo template"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
16
21
|
}
|
|
17
22
|
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## 快速上手
|
|
2
|
+
|
|
3
|
+
### 1. 开发
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install
|
|
7
|
+
npm run start
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### 2. 构建
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
npm run build
|
|
14
|
+
npm run release
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 3. 调试
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm run watch
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 了解更多
|
|
24
|
+
|
|
25
|
+
你可以通过我们的[官方文档](https://iot.mi.com/vela/quickapp)熟悉和了解快应用。
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{ appName }}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=8.10"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start": "aiot start --watch",
|
|
10
|
+
"build": "aiot build",
|
|
11
|
+
"release": "aiot release",
|
|
12
|
+
"lint": "eslint --format codeframe --fix --ext .ux,.js src/"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@aiot-toolkit/velasim": "^0.1.23",
|
|
16
|
+
"@aiot-toolkit/jsc": "^1.0.3",
|
|
17
|
+
"aiot-toolkit": "^{{ toolkitVersion }}",
|
|
18
|
+
"babel-eslint": "^10.0.1",
|
|
19
|
+
"eslint": "^6.8.0",
|
|
20
|
+
"eslint-plugin-ux": "^0.0.4"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"a":{"b":"default hello"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"a":{"b":"hello"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"a":{"b":"你好"}}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "com.application.watch.demo",
|
|
3
|
+
"name": "{{appName}}",
|
|
4
|
+
"versionName": "1.0.0",
|
|
5
|
+
"versionCode": 1,
|
|
6
|
+
"minPlatformVersion": 1200,
|
|
7
|
+
"icon": "/common/logo.png",
|
|
8
|
+
"simulationVersion": "default",
|
|
9
|
+
"deviceTypeList": [
|
|
10
|
+
"watch"
|
|
11
|
+
],
|
|
12
|
+
"features": [
|
|
13
|
+
{
|
|
14
|
+
"name": "system.router"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"config": {
|
|
18
|
+
"logLevel": "log",
|
|
19
|
+
"designWidth": 480
|
|
20
|
+
},
|
|
21
|
+
"router": {
|
|
22
|
+
"entry": "pages/index",
|
|
23
|
+
"pages": {
|
|
24
|
+
"pages/index": {
|
|
25
|
+
"component": "index"
|
|
26
|
+
},
|
|
27
|
+
"pages/detail": {
|
|
28
|
+
"component": "detail"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="demo-page">
|
|
3
|
+
<text class="title">{{text}}</text>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
private: {
|
|
10
|
+
text: '欢迎打开详情页'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<style>
|
|
16
|
+
.demo-page {
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
align-items: center;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.title {
|
|
23
|
+
font-size: 20px;
|
|
24
|
+
text-align: center;
|
|
25
|
+
}
|
|
26
|
+
</style>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="demo-page">
|
|
3
|
+
<text class="title">{{$t('a.b')}},欢迎打开{{title}}</text>
|
|
4
|
+
<!-- 点击跳转详情页 -->
|
|
5
|
+
<input class="btn" type="button" value="跳转到详情页" onclick="routeDetail" />
|
|
6
|
+
</div>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
import router from '@system.router'
|
|
11
|
+
import configuration from '@system.configuration'
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
// 页面级组件的数据模型,影响传入数据的覆盖机制:private内定义的属性不允许被覆盖
|
|
15
|
+
private: {
|
|
16
|
+
title: '示例页面'
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
routeDetail() {
|
|
20
|
+
// 跳转到应用内的某个页面,router用法详见:文档->接口->页面路由
|
|
21
|
+
router.push({
|
|
22
|
+
uri: '/pages/detail'
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<style>
|
|
29
|
+
.demo-page {
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
align-items: center;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.title {
|
|
36
|
+
font-size: 20px;
|
|
37
|
+
text-align: center;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.btn {
|
|
41
|
+
width: 200px;
|
|
42
|
+
height: 40px;
|
|
43
|
+
margin-top: 20px;
|
|
44
|
+
border-radius: 5px;
|
|
45
|
+
background-color: #09ba07;
|
|
46
|
+
font-size: 20px;
|
|
47
|
+
color: #ffffff;
|
|
48
|
+
}
|
|
49
|
+
</style>
|
|
@@ -4,13 +4,14 @@ import ITemplate from '../interface/ITemplate';
|
|
|
4
4
|
* TemplateUtil
|
|
5
5
|
*/
|
|
6
6
|
declare class TemplateUtil {
|
|
7
|
-
static requestTemplateList(): Promise<ITemplate[]>;
|
|
7
|
+
static requestTemplateList(type: string): Promise<ITemplate[]>;
|
|
8
8
|
/**
|
|
9
9
|
* 验证项目名称,只能包含:字母、数字、-、_
|
|
10
10
|
* @param value
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
static validateProjectName(value: string): boolean | string;
|
|
14
|
+
static createXtsProject(): Promise<void>;
|
|
14
15
|
static createProject(param: IProjectParam, keywords?: {
|
|
15
16
|
data: Record<string, string>;
|
|
16
17
|
includes?: (path: string) => boolean;
|
|
@@ -30,5 +31,9 @@ declare class TemplateUtil {
|
|
|
30
31
|
* @param aspect
|
|
31
32
|
*/
|
|
32
33
|
static createAspect(projectAbsolutePath: string, aspect: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* 修改_gitignore为.gitignore
|
|
36
|
+
*/
|
|
37
|
+
static changeFileName(projectAbsolutePath: string): void;
|
|
33
38
|
}
|
|
34
39
|
export default TemplateUtil;
|
|
@@ -12,19 +12,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
+
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
15
17
|
const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
|
|
16
18
|
const NetworkUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/NetworkUtil"));
|
|
17
19
|
const prompts_1 = require("@inquirer/prompts");
|
|
18
20
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
21
|
const path_1 = __importDefault(require("path"));
|
|
20
|
-
const
|
|
22
|
+
const json = require('../template/template.json');
|
|
21
23
|
/**
|
|
22
24
|
* TemplateUtil
|
|
23
25
|
*/
|
|
24
26
|
class TemplateUtil {
|
|
25
|
-
static requestTemplateList() {
|
|
27
|
+
static requestTemplateList(type) {
|
|
26
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
|
|
29
|
+
const item = json.find((item) => item.type === type);
|
|
30
|
+
if (!item || !item.demoList) {
|
|
31
|
+
ColorConsole_1.default.throw(`no`, { word: type, style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw) }, `template`);
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return item.demoList;
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
37
|
/**
|
|
@@ -42,6 +49,9 @@ class TemplateUtil {
|
|
|
42
49
|
}
|
|
43
50
|
return true;
|
|
44
51
|
}
|
|
52
|
+
static createXtsProject() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
54
|
+
}
|
|
45
55
|
static createProject(param, keywords, plugins) {
|
|
46
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
57
|
const { name, template, aspect } = param;
|
|
@@ -49,7 +59,7 @@ class TemplateUtil {
|
|
|
49
59
|
let projectName = name;
|
|
50
60
|
let projectAbsolutePath = path_1.default.join(process.cwd(), projectName);
|
|
51
61
|
while (fs_extra_1.default.existsSync(projectAbsolutePath)) {
|
|
52
|
-
|
|
62
|
+
ColorConsole_1.default.warn(`${projectAbsolutePath} exists. `);
|
|
53
63
|
projectName = yield (0, prompts_1.input)({
|
|
54
64
|
message: 'please new project name',
|
|
55
65
|
validate: this.validateProjectName
|
|
@@ -59,6 +69,7 @@ class TemplateUtil {
|
|
|
59
69
|
fs_extra_1.default.mkdirSync(projectAbsolutePath);
|
|
60
70
|
// 复制模板
|
|
61
71
|
if (template) {
|
|
72
|
+
ColorConsole_1.default.info('Create project start ...');
|
|
62
73
|
const { path } = template;
|
|
63
74
|
// 远程
|
|
64
75
|
if (['http', 'git'].find((item) => path.startsWith(item))) {
|
|
@@ -68,20 +79,25 @@ class TemplateUtil {
|
|
|
68
79
|
else {
|
|
69
80
|
const templateAbsolutePath = path_1.default.join(__dirname, '../template/', path);
|
|
70
81
|
fs_extra_1.default.copySync(templateAbsolutePath, projectAbsolutePath);
|
|
71
|
-
//
|
|
72
|
-
|
|
82
|
+
// 修改_gitignore为.gitignore
|
|
83
|
+
TemplateUtil.changeFileName(projectAbsolutePath);
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
86
|
// 遍历项目文件,替换词语
|
|
76
87
|
if (keywords && keywords.data) {
|
|
88
|
+
// ux项目,添加toolkitVersion
|
|
89
|
+
keywords['data']['toolkitVersion'] = require('../../package.json').version;
|
|
77
90
|
TemplateUtil.performReplace(keywords, projectAbsolutePath);
|
|
78
91
|
}
|
|
92
|
+
// xts项目-处理aspect内容
|
|
93
|
+
aspect && TemplateUtil.createAspect(projectAbsolutePath, aspect);
|
|
79
94
|
// 执行插件
|
|
80
95
|
if (plugins) {
|
|
81
96
|
for (let item of plugins) {
|
|
82
97
|
yield item(projectAbsolutePath, param);
|
|
83
98
|
}
|
|
84
99
|
}
|
|
100
|
+
ColorConsole_1.default.success(`Create project finish. project path: ${projectAbsolutePath}`);
|
|
85
101
|
});
|
|
86
102
|
}
|
|
87
103
|
/**
|
|
@@ -106,7 +122,7 @@ class TemplateUtil {
|
|
|
106
122
|
static createAspect(projectAbsolutePath, aspect) {
|
|
107
123
|
// 按照逗号分割字符串,且去掉空格
|
|
108
124
|
const aspects = aspect.replace(' ', '').split(',');
|
|
109
|
-
const aspectAbsolutePath = path_1.default.join(__dirname, '../template', 'xts
|
|
125
|
+
const aspectAbsolutePath = path_1.default.join(__dirname, '../template', 'xts', 'aspect1');
|
|
110
126
|
// 循环生成自定义aspect
|
|
111
127
|
aspects.map((aspectItem) => {
|
|
112
128
|
const targetAspectPath = path_1.default.join(projectAbsolutePath, aspectItem);
|
|
@@ -123,10 +139,16 @@ class TemplateUtil {
|
|
|
123
139
|
return ['.json', '.ux'].includes(path_1.default.extname(path));
|
|
124
140
|
}
|
|
125
141
|
}
|
|
126
|
-
},
|
|
142
|
+
}, targetAspectPath);
|
|
127
143
|
});
|
|
128
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* 修改_gitignore为.gitignore
|
|
147
|
+
*/
|
|
148
|
+
static changeFileName(projectAbsolutePath) {
|
|
149
|
+
const oldPath = path_1.default.join(projectAbsolutePath, '_gitignore');
|
|
150
|
+
const newPath = path_1.default.join(projectAbsolutePath, '.gitignore');
|
|
151
|
+
fs_extra_1.default.renameSync(oldPath, newPath);
|
|
152
|
+
}
|
|
129
153
|
}
|
|
130
154
|
exports.default = TemplateUtil;
|
|
131
|
-
|
|
132
|
-
//# sourceMappingURL=TemplateUtil.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-aiot",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-batchmanifest-beta.1",
|
|
4
4
|
"description": "An easy way to start aiot project",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -19,21 +19,20 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"lib"
|
|
21
21
|
],
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "ssh://xujunjie1@git.mioffice.cn:29418/vela/aiot-toolkit"
|
|
25
|
-
},
|
|
26
22
|
"scripts": {
|
|
27
23
|
"test": "node ./__tests__/create-aiot.test.js"
|
|
28
24
|
},
|
|
29
25
|
"dependencies": {
|
|
30
|
-
"@aiot-toolkit/commander": "2.0.
|
|
26
|
+
"@aiot-toolkit/commander": "2.0.2-batchmanifest-beta.1",
|
|
27
|
+
"@inquirer/prompts": "^3.0.3",
|
|
31
28
|
"ansi-colors": "^4.1.3",
|
|
32
29
|
"cli-progress": "^3.12.0",
|
|
33
30
|
"simple-git": "^3.19.1"
|
|
34
31
|
},
|
|
35
32
|
"devDependencies": {
|
|
36
|
-
"@types/cli-progress": "^3.11.0"
|
|
33
|
+
"@types/cli-progress": "^3.11.0",
|
|
34
|
+
"@types/fs-extra": "^11.0.4",
|
|
35
|
+
"fs-extra": "^11.2.0"
|
|
37
36
|
},
|
|
38
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9e58a0cbe0e2d35a38e99d669398caaa8fd648a8"
|
|
39
38
|
}
|
package/lib/bin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["bin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,uDAA2D;AAC3D,wBAAwC;AAExC,SAAe,IAAI;;QACjB,MAAM,OAAO,GAAG,MAAM,IAAA,uBAAoB,GAAE,CAAA;QAC5C,UAAU;QACV,MAAM,MAAM,GAAa;YACvB,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,qBAAqB;YAClC,OAAO,EAAE,OAAO;YAChB,cAAc,EAAE,OAAO;SACxB,CAAA;QAED,mBAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;CAAA;AAED,IAAI,EAAE,CAAA","file":"bin.js","sourcesContent":["#!/usr/bin/env node\n\nimport { Command, IProgram } from '@aiot-toolkit/commander'\nimport { getAiotCreateCommand } from '.'\n\nasync function main() {\n const command = await getAiotCreateCommand()\n // 创建命令行配置\n const config: IProgram = {\n name: 'create-aiot',\n description: 'create aiot project',\n version: '2.0.0',\n defaultCommand: command\n }\n\n Command.registeProgram(config)\n}\n\nmain()\n"],"sourceRoot":"../src"}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,4CAAmB;AACnB,gDAAuB;AAEvB,wEAA+C;AAC/C,SAAsB,oBAAoB;;QACxC,MAAM,YAAY,GAAG,MAAM,sBAAY,CAAC,mBAAmB,EAAE,CAAA;QAE7D,OAAO;YACL,IAAI,EAAE,EAAE;YACR,WAAW,EAAE,SAAS;YACtB,SAAS,EAAE;gBACT;oBACE,IAAI,EAAE,MAAM;oBACZ,WAAW,EAAE,aAAa;oBAC1B,cAAc,EAAE,IAAI;oBACpB,YAAY,EAAE,cAAc;oBAC5B,IAAI,EAAE,QAAQ;oBACd,QAAQ,CAAC,KAAa;wBACpB,OAAO,sBAAY,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAA;oBAChD,CAAC;iBACF;gBACD;oBACE,IAAI,EAAE,GAAG;oBACT,WAAW,EAAE,gBAAgB;oBAC7B,cAAc,EAAE,IAAI;oBACpB,YAAY,EAAE,OAAO;oBACrB,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,IAAI,EAAE,UAAU;oBAChB,WAAW,EAAE,iBAAiB;oBAC9B,IAAI,EAAE,QAAQ;oBACd,cAAc,EAAE,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C,CAAC,CAAA;6BAC7C;iCAAM;gCACL,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;6BACrD;wBACH,CAAC;qBACF,CAAC,CAAA;iBACH;qBAAM;oBACL,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;iBAC9B;YACH,CAAC;SACF,CAAA;IACH,CAAC;CAAA;AA9ED,oDA8EC","file":"index.js","sourcesContent":["import { ICommand } from '@aiot-toolkit/commander'\nimport fs from 'fs'\nimport Path from 'path'\nimport IProjectParam from './interface/IProjectParam'\nimport TemplateUtil from './utils/TemplateUtil'\nexport async function getAiotCreateCommand(): Promise<ICommand> {\n const templateList = await TemplateUtil.requestTemplateList()\n\n return {\n name: '',\n description: 'default',\n paramList: [\n {\n name: 'name',\n description: 'poject name',\n enableInquirer: true,\n defaultValue: 'aiot-project',\n type: 'string',\n validate(value: string) {\n return TemplateUtil.validateProjectName(value)\n }\n },\n {\n name: 'v',\n description: 'poject version',\n enableInquirer: true,\n defaultValue: '1.0.0',\n type: 'string'\n },\n {\n name: 'template',\n description: 'prject template',\n type: 'select',\n enableInquirer: true,\n choices: templateList.map((item) => {\n return {\n value: item.name,\n description: item.description\n }\n })\n },\n {\n name: 'eslint',\n type: 'confirm',\n description: 'Enabling eslint, if true, will create an eslint file',\n enableInquirer: true,\n defaultValue: false\n },\n {\n name: 'aspect',\n type: 'string',\n description: '配置aspect名称'\n }\n ],\n action: (option: any) => {\n const { name, template, eslint, v, aspect } = option\n const templateItem = templateList.find((item) => item.name === template)\n if (templateItem) {\n const param: IProjectParam = {\n name,\n version: v,\n template: templateItem,\n tools: {\n eslint\n },\n aspect\n }\n TemplateUtil.createProject(param, {\n data: { version: v, appName: name },\n includes: (path) => {\n const stats = fs.statSync(path)\n if (stats.isDirectory()) {\n return ['src'].includes(Path.basename(path))\n } else {\n return ['.json', '.ux'].includes(Path.extname(path))\n }\n }\n })\n } else {\n console.log('template error')\n }\n }\n }\n}\n"],"sourceRoot":"../src"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["interface/IProjectParam.ts"],"names":[],"mappings":"","file":"IProjectParam.js","sourcesContent":["import ITemplate from './ITemplate'\n\n/**\n * IProjectParam\n */\nexport default interface IProjectParam {\n name: string\n version: string\n template: ITemplate\n tools: {\n eslint: boolean\n }\n aspect?: string\n}\n"],"sourceRoot":"../../src"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["interface/ITemplate.ts"],"names":[],"mappings":"","file":"ITemplate.js","sourcesContent":["/**\n * ITemplate\n */\nexport default interface ITemplate {\n name: string\n path: string\n disabled?: boolean\n description?: string\n}\n"],"sourceRoot":"../../src"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils/TemplateUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6FAAoE;AACpE,mGAA0E;AAC1E,+CAAyC;AACzC,wDAAyB;AACzB,gDAAuB;AAGvB,8EAA4C;AAE5C;;GAEG;AACH,MAAM,YAAY;IAChB,MAAM,CAAO,mBAAmB;;YAC9B,OAAO,uBAAI,CAAA;QACb,CAAC;KAAA;IAED;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,CAAC,KAAa;QACtC,MAAM,GAAG,GAAG,gCAAgC,CAAA;QAC5C,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,6BAA6B,CAAA;SACrC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACpB,OAAO,mEAAmE,CAAA;SAC3E;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,CAAO,aAAa,CACxB,KAAoB,EACpB,QAGC,EACD,OAA0E;;YAE1E,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,CAAA;YAExC,yBAAyB;YACzB,IAAI,WAAW,GAAG,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IAAI,EAAE,EAAE;oBACjB,MAAM,KAAK,GAAG,kBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;oBAC/B,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE;wBACvB,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;qBAC7C;yBAAM;wBACL,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;qBACrD;gBACH,CAAC;aACF,EACD,mBAAmB,CACpB,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AACD,kBAAe,YAAY,CAAA","file":"TemplateUtil.js","sourcesContent":["import FileUtil from '@aiot-toolkit/shared-utils/lib/utils/FileUtil'\nimport NetworkUtil from '@aiot-toolkit/shared-utils/lib/utils/NetworkUtil'\nimport { input } from '@inquirer/prompts'\nimport FS from 'fs-extra'\nimport Path from 'path'\nimport IProjectParam from '../interface/IProjectParam'\nimport ITemplate from '../interface/ITemplate'\nimport json from '../template/template.json'\n\n/**\n * TemplateUtil\n */\nclass TemplateUtil {\n static async requestTemplateList(): Promise<ITemplate[]> {\n return json\n }\n\n /**\n * 验证项目名称,只能包含:字母、数字、-、_\n * @param value\n * @returns\n */\n static validateProjectName(value: string): boolean | string {\n const reg = /^[0-9a-zA-Z_\\u4e00-\\u9fa5\\-]+$/\n if (!value) {\n return `Please enter a project name`\n }\n if (!reg.test(value)) {\n return 'The project name can contain only Chinese, letters, number, _ , -'\n }\n\n return true\n }\n\n static async createProject(\n param: IProjectParam,\n keywords?: {\n data: Record<string, string>\n includes?: (path: string) => boolean\n },\n plugins?: ((projectPath: string, param: IProjectParam) => Promise<void>)[]\n ) {\n const { name, template, aspect } = param\n\n // 获取项目名称和绝对路径,如果存在,则再次输入\n let projectName = name\n let projectAbsolutePath = Path.join(process.cwd(), projectName)\n while (FS.existsSync(projectAbsolutePath)) {\n console.log(`${projectAbsolutePath} exists. `)\n projectName = await input({\n message: 'please new project name',\n validate: this.validateProjectName\n })\n projectAbsolutePath = Path.join(process.cwd(), projectName)\n }\n\n FS.mkdirSync(projectAbsolutePath)\n\n // 复制模板\n if (template) {\n const { path } = template\n // 远程\n if (['http', 'git'].find((item) => path.startsWith(item))) {\n await NetworkUtil.gitClone(path, projectAbsolutePath)\n }\n //本地\n else {\n const templateAbsolutePath = Path.join(__dirname, '../template/', path)\n FS.copySync(templateAbsolutePath, projectAbsolutePath)\n // xts项目-处理aspect内容\n aspect && TemplateUtil.createAspect(projectAbsolutePath, aspect)\n }\n }\n // 遍历项目文件,替换词语\n if (keywords && keywords.data) {\n TemplateUtil.performReplace(keywords, projectAbsolutePath)\n }\n\n // 执行插件\n if (plugins) {\n for (let item of plugins) {\n await item(projectAbsolutePath, param)\n }\n }\n }\n /**\n * 遍历项目文件,替换词语\n * @param keywords\n * @param projectAbsolutePath\n */\n static performReplace(\n keywords: {\n data: Record<string, string>\n includes?: (path: string) => boolean\n },\n projectAbsolutePath: string\n ) {\n const { data, includes } = keywords\n const files = FileUtil.readAlldirSync(projectAbsolutePath, includes)\n if (files && files.length) {\n files.forEach((item) => {\n FileUtil.replaceFileContent(item, data)\n })\n }\n }\n /**\n * xts项目-处理aspect内容\n * @param projectAbsolutePath\n * @param aspect\n */\n static createAspect(projectAbsolutePath: string, aspect: string) {\n // 按照逗号分割字符串,且去掉空格\n const aspects = aspect.replace(' ', '').split(',')\n const aspectAbsolutePath = Path.join(__dirname, '../template', 'xts-app-template', 'aspect1')\n // 循环生成自定义aspect\n aspects.map((aspectItem) => {\n const targetAspectPath = Path.join(projectAbsolutePath, aspectItem)\n FS.copySync(aspectAbsolutePath, targetAspectPath)\n // 替换关键字\n TemplateUtil.performReplace(\n {\n data: { aspectName: aspectItem },\n includes: (path) => {\n const stats = FS.statSync(path)\n if (stats.isDirectory()) {\n return ['src'].includes(Path.basename(path))\n } else {\n return ['.json', '.ux'].includes(Path.extname(path))\n }\n }\n },\n projectAbsolutePath\n )\n })\n }\n}\nexport default TemplateUtil\n"],"sourceRoot":"../../src"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|