create-aiot 2.0.1-alpha.9 → 2.0.2-dev.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 +1 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +92 -44
- 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 +26 -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 +23 -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-package-name/app/manifest.json +2 -2
- package/lib/utils/TemplateUtil.d.ts +6 -1
- package/lib/utils/TemplateUtil.js +36 -9
- package/package.json +3 -3
- 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/bin.js
CHANGED
|
@@ -14,17 +14,14 @@ const commander_1 = require("@aiot-toolkit/commander");
|
|
|
14
14
|
const _1 = require(".");
|
|
15
15
|
function main() {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const command = yield (0, _1.getAiotCreateCommand)();
|
|
18
17
|
// 创建命令行配置
|
|
19
18
|
const config = {
|
|
20
19
|
name: 'create-aiot',
|
|
21
20
|
description: 'create aiot project',
|
|
22
21
|
version: '2.0.0',
|
|
23
|
-
|
|
22
|
+
commandList: [yield (0, _1.getCrerateXtsCommand)(), yield (0, _1.getUxCreateCommand)()]
|
|
24
23
|
};
|
|
25
24
|
commander_1.Command.registeProgram(config);
|
|
26
25
|
});
|
|
27
26
|
}
|
|
28
27
|
main();
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=bin.js.map
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -12,17 +12,62 @@ 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
|
-
function
|
|
19
|
+
function createAction(options, projectType) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const templateList = yield TemplateUtil_1.default.requestTemplateList();
|
|
21
|
+
const templateList = yield TemplateUtil_1.default.requestTemplateList(projectType);
|
|
22
|
+
const { name, aspect, packageName, template, eslint = false } = options;
|
|
23
|
+
const templateItem = templateList.find((item) => item.name === template);
|
|
24
|
+
if (templateItem) {
|
|
25
|
+
const param = {
|
|
26
|
+
name,
|
|
27
|
+
template: templateItem,
|
|
28
|
+
packageName,
|
|
29
|
+
tools: {
|
|
30
|
+
eslint
|
|
31
|
+
},
|
|
32
|
+
aspect
|
|
33
|
+
};
|
|
34
|
+
TemplateUtil_1.default.createProject(param, {
|
|
35
|
+
data: { appName: name, packageName },
|
|
36
|
+
includes: (path) => {
|
|
37
|
+
const stats = fs_1.default.statSync(path);
|
|
38
|
+
if (stats.isDirectory()) {
|
|
39
|
+
return ['src'].includes(path_1.default.basename(path));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return ['.json', '.ux'].includes(path_1.default.extname(path));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log('template error');
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function getUxCreateCommand() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const templateList = yield TemplateUtil_1.default.requestTemplateList('ux');
|
|
22
55
|
return {
|
|
23
|
-
name: '',
|
|
56
|
+
name: 'ux',
|
|
24
57
|
description: 'default',
|
|
25
58
|
paramList: [
|
|
59
|
+
{
|
|
60
|
+
name: 'template',
|
|
61
|
+
description: 'prject template',
|
|
62
|
+
type: 'select',
|
|
63
|
+
enableInquirer: true,
|
|
64
|
+
choices: templateList.map((item) => {
|
|
65
|
+
return {
|
|
66
|
+
value: item.name,
|
|
67
|
+
description: item.description
|
|
68
|
+
};
|
|
69
|
+
})
|
|
70
|
+
},
|
|
26
71
|
{
|
|
27
72
|
name: 'name',
|
|
28
73
|
description: 'poject name',
|
|
@@ -34,12 +79,32 @@ function getAiotCreateCommand() {
|
|
|
34
79
|
}
|
|
35
80
|
},
|
|
36
81
|
{
|
|
37
|
-
name: '
|
|
38
|
-
|
|
82
|
+
name: 'eslint',
|
|
83
|
+
type: 'confirm',
|
|
84
|
+
description: 'Enabling eslint, if true, will create an eslint file',
|
|
39
85
|
enableInquirer: true,
|
|
40
|
-
defaultValue:
|
|
41
|
-
type: 'string'
|
|
86
|
+
defaultValue: false
|
|
42
87
|
},
|
|
88
|
+
{
|
|
89
|
+
name: 'aspect',
|
|
90
|
+
type: 'string',
|
|
91
|
+
description: '配置aspect名称'
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
action: (option) => {
|
|
95
|
+
createAction(option, 'ux');
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.getUxCreateCommand = getUxCreateCommand;
|
|
101
|
+
function getCrerateXtsCommand() {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const templateList = yield TemplateUtil_1.default.requestTemplateList('xts');
|
|
104
|
+
return {
|
|
105
|
+
name: 'xts',
|
|
106
|
+
description: 'create xts template project',
|
|
107
|
+
paramList: [
|
|
43
108
|
{
|
|
44
109
|
name: 'template',
|
|
45
110
|
description: 'prject template',
|
|
@@ -53,51 +118,34 @@ function getAiotCreateCommand() {
|
|
|
53
118
|
})
|
|
54
119
|
},
|
|
55
120
|
{
|
|
56
|
-
name: '
|
|
57
|
-
|
|
58
|
-
description: 'Enabling eslint, if true, will create an eslint file',
|
|
121
|
+
name: 'name',
|
|
122
|
+
description: 'poject name',
|
|
59
123
|
enableInquirer: true,
|
|
60
|
-
defaultValue:
|
|
124
|
+
defaultValue: 'xts-project',
|
|
125
|
+
type: 'string',
|
|
126
|
+
validate(value) {
|
|
127
|
+
return TemplateUtil_1.default.validateProjectName(value);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'packageName',
|
|
132
|
+
description: 'package name',
|
|
133
|
+
enableInquirer: true,
|
|
134
|
+
defaultValue: 'xts.app.test',
|
|
135
|
+
type: 'string'
|
|
61
136
|
},
|
|
62
137
|
{
|
|
63
138
|
name: 'aspect',
|
|
64
139
|
type: 'string',
|
|
65
|
-
|
|
140
|
+
defaultValue: 'aspect1',
|
|
141
|
+
description: 'Do you need to create some aspect, with multiple aspect names separated by commas',
|
|
142
|
+
enableInquirer: true
|
|
66
143
|
}
|
|
67
144
|
],
|
|
68
145
|
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
|
-
}
|
|
146
|
+
createAction(option, 'xts');
|
|
97
147
|
}
|
|
98
148
|
};
|
|
99
149
|
});
|
|
100
150
|
}
|
|
101
|
-
exports.
|
|
102
|
-
|
|
103
|
-
//# sourceMappingURL=index.js.map
|
|
151
|
+
exports.getCrerateXtsCommand = getCrerateXtsCommand;
|
|
@@ -1,17 +1,32 @@
|
|
|
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
|
+
{
|
|
11
|
+
"name": "test_git",
|
|
12
|
+
"path": "https://github.com/dcloudio/hello-uniapp.git",
|
|
13
|
+
"description": "this is ..., from git"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
6
16
|
},
|
|
7
17
|
{
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
"type": "xts",
|
|
19
|
+
"demoList": [
|
|
20
|
+
{
|
|
21
|
+
"name": "xts",
|
|
22
|
+
"path": "./xts/app-package-name",
|
|
23
|
+
"description": "xts app template"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "xts2",
|
|
27
|
+
"path": "./xts/app-package-name",
|
|
28
|
+
"description": "其实我和上面的一样"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
16
31
|
}
|
|
17
32
|
]
|
|
@@ -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,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{ appName }}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=8.10"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start": "aiot server --watch --open-nuttx",
|
|
10
|
+
"build": "aiot build",
|
|
11
|
+
"release": "aiot release",
|
|
12
|
+
"watch": "aiot watch --open-nuttx",
|
|
13
|
+
"lint": "eslint --format codeframe --fix --ext .ux,.js src/"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@aiot-toolkit/velasim": "^0.1.23",
|
|
17
|
+
"@aiot-toolkit/jsc": "^1.0.3",
|
|
18
|
+
"aiot-toolkit": "^{{ toolkitVersion }}",
|
|
19
|
+
"babel-eslint": "^10.0.1",
|
|
20
|
+
"eslint": "^6.8.0",
|
|
21
|
+
"eslint-plugin-ux": "^0.0.4"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
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
|
|
@@ -68,14 +78,18 @@ class TemplateUtil {
|
|
|
68
78
|
else {
|
|
69
79
|
const templateAbsolutePath = path_1.default.join(__dirname, '../template/', path);
|
|
70
80
|
fs_extra_1.default.copySync(templateAbsolutePath, projectAbsolutePath);
|
|
71
|
-
//
|
|
72
|
-
|
|
81
|
+
// 修改_gitignore为.gitignore
|
|
82
|
+
TemplateUtil.changeFileName(projectAbsolutePath);
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
85
|
// 遍历项目文件,替换词语
|
|
76
86
|
if (keywords && keywords.data) {
|
|
87
|
+
// ux项目,添加toolkitVersion
|
|
88
|
+
keywords['data']['toolkitVersion'] = require('../../package.json').version;
|
|
77
89
|
TemplateUtil.performReplace(keywords, projectAbsolutePath);
|
|
78
90
|
}
|
|
91
|
+
// xts项目-处理aspect内容
|
|
92
|
+
aspect && TemplateUtil.createAspect(projectAbsolutePath, aspect);
|
|
79
93
|
// 执行插件
|
|
80
94
|
if (plugins) {
|
|
81
95
|
for (let item of plugins) {
|
|
@@ -123,10 +137,23 @@ class TemplateUtil {
|
|
|
123
137
|
return ['.json', '.ux'].includes(path_1.default.extname(path));
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
|
-
},
|
|
140
|
+
}, targetAspectPath);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 修改_gitignore为.gitignore
|
|
145
|
+
*/
|
|
146
|
+
static changeFileName(projectAbsolutePath) {
|
|
147
|
+
const oldPath = path_1.default.join(projectAbsolutePath, '_gitignore');
|
|
148
|
+
const newPath = path_1.default.join(projectAbsolutePath, '.gitignore');
|
|
149
|
+
fs_extra_1.default.rename(oldPath, newPath, (err) => {
|
|
150
|
+
if (err) {
|
|
151
|
+
ColorConsole_1.default.throw(`File _gitignore rename error ${err}`);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
ColorConsole_1.default.log(`File .gitignore rename success`);
|
|
155
|
+
}
|
|
127
156
|
});
|
|
128
157
|
}
|
|
129
158
|
}
|
|
130
159
|
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-dev.1",
|
|
4
4
|
"description": "An easy way to start aiot project",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"test": "node ./__tests__/create-aiot.test.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@aiot-toolkit/commander": "2.0.
|
|
30
|
+
"@aiot-toolkit/commander": "2.0.2-dev.1",
|
|
31
31
|
"ansi-colors": "^4.1.3",
|
|
32
32
|
"cli-progress": "^3.12.0",
|
|
33
33
|
"simple-git": "^3.19.1"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/cli-progress": "^3.11.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "0beecc786c41b73ab2dabeaad06fb4ad19115f4b"
|
|
39
39
|
}
|
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,IAAI;oBACpB,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;wBACjC,OAAO;4BACL,KAAK,EAAE,IAAI,CAAC,IAAI;4BAChB,WAAW,EAAE,IAAI,CAAC,WAAW;yBAC9B,C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,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,IAAI,CAAA;YACtB,IAAI,mBAAmB,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAA;YAC/D,OAAO,kBAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE;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Q,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', '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"}
|