create-aiot 2.0.1-alpha.0

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/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # `create-aiot`
2
+
3
+ 新建 vela 项目的工具,可指定项目名称、模板、启用的工具(例如 eslint)等。
4
+
5
+ ## 使用
6
+
7
+ ### 命令
8
+
9
+ `npm create aiot`
10
+
11
+ 仅输入命令,会使用询问的方式获取各项参数。
12
+
13
+ 也可直接输入参数,避免询问,示例:`npm create aiot --name my-project`
14
+
15
+ ### 参数列表
16
+
17
+ | 参数名 | 描述 | 类型 | 默认值 |
18
+ | -------- | ----------- | ------ | ------------ |
19
+ | name | 项目名称 | string | aiot-project |
20
+ | v | 项目版本 | string | 1.0.0 |
21
+ | template | 模板名称 | string | 无 |
22
+ | eslint | 启用 eslint | string | false |
23
+
24
+ ## 贡献模板
25
+
26
+ 待定
package/lib/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/bin.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ const commander_1 = require("@aiot-toolkit/commander");
14
+ const _1 = require(".");
15
+ function main() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const command = yield (0, _1.getAiotCreateCommand)();
18
+ // 创建命令行配置
19
+ const config = {
20
+ name: 'create-aiot',
21
+ description: 'create aiot project',
22
+ version: '2.0.0',
23
+ defaultCommand: command
24
+ };
25
+ commander_1.Command.registeProgram(config);
26
+ });
27
+ }
28
+ main();
29
+
30
+ //# sourceMappingURL=bin.js.map
package/lib/bin.js.map ADDED
@@ -0,0 +1 @@
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.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { ICommand } from '@aiot-toolkit/commander';
2
+ export declare function getAiotCreateCommand(): Promise<ICommand>;
package/lib/index.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getAiotCreateCommand = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const TemplateUtil_1 = __importDefault(require("./utils/TemplateUtil"));
19
+ function getAiotCreateCommand() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const templateList = yield TemplateUtil_1.default.requestTemplateList();
22
+ return {
23
+ name: '',
24
+ description: 'default',
25
+ paramList: [
26
+ {
27
+ name: 'name',
28
+ description: 'poject name',
29
+ enableInquirer: true,
30
+ defaultValue: 'aiot-project',
31
+ type: 'string',
32
+ validate(value) {
33
+ return TemplateUtil_1.default.validateProjectName(value);
34
+ }
35
+ },
36
+ {
37
+ name: 'v',
38
+ description: 'poject version',
39
+ enableInquirer: true,
40
+ defaultValue: '1.0.0',
41
+ type: 'string'
42
+ },
43
+ {
44
+ name: 'template',
45
+ description: 'prject template',
46
+ type: 'select',
47
+ enableInquirer: true,
48
+ choices: templateList.map((item) => {
49
+ return {
50
+ value: item.name,
51
+ description: item.description
52
+ };
53
+ })
54
+ },
55
+ {
56
+ name: 'eslint',
57
+ type: 'confirm',
58
+ description: 'Enabling eslint, if true, will create an eslint file',
59
+ enableInquirer: true,
60
+ defaultValue: false
61
+ },
62
+ {
63
+ name: 'aspect',
64
+ type: 'string',
65
+ description: '配置aspect名称'
66
+ }
67
+ ],
68
+ action: (option) => {
69
+ const { name, template, eslint, v, aspect } = option;
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
+ }
97
+ }
98
+ };
99
+ });
100
+ }
101
+ exports.getAiotCreateCommand = getAiotCreateCommand;
102
+
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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,E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AC,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"}
@@ -0,0 +1,13 @@
1
+ import ITemplate from './ITemplate';
2
+ /**
3
+ * IProjectParam
4
+ */
5
+ export default interface IProjectParam {
6
+ name: string;
7
+ version: string;
8
+ template: ITemplate;
9
+ tools: {
10
+ eslint: boolean;
11
+ };
12
+ aspect?: string;
13
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=IProjectParam.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * ITemplate
3
+ */
4
+ export default interface ITemplate {
5
+ name: string;
6
+ path: string;
7
+ disabled?: boolean;
8
+ description?: string;
9
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=ITemplate.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "name": "ux",
4
+ "path": "./ux",
5
+ "description": "ux-it is..."
6
+ },
7
+ {
8
+ "name": "xts-app-template",
9
+ "path": "./xts-app-template/app-package-name",
10
+ "description": "xts app template"
11
+ },
12
+ {
13
+ "name": "test_git",
14
+ "path": "https://github.com/dcloudio/hello-uniapp.git",
15
+ "description": "this is ..., from git"
16
+ }
17
+ ]
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "{{appName}}",
3
+ "version": "{{version }}",
4
+ "projectType": "ux"
5
+ }
@@ -0,0 +1,3 @@
1
+ <template>
2
+ appname is {{appName}}
3
+ </template>
@@ -0,0 +1,17 @@
1
+ app MainApp {
2
+ onCreate(intent) {
3
+ console.log('App onCreate.')
4
+ }
5
+
6
+ onForeground() {
7
+ console.log('App onForeground.')
8
+ }
9
+
10
+ onBackground() {
11
+ console.log('App onBackground.')
12
+ }
13
+
14
+ onDestroy() {
15
+ console.log('App onDestroy.')
16
+ }
17
+ }
@@ -0,0 +1,68 @@
1
+ {
2
+ "package": "ts.app.template",
3
+ "name": "{{appName}}",
4
+ "icon": "/$app_resource/icon.png",
5
+ "versionName": "1.0",
6
+ "versionCode": 1,
7
+ "minPlatformVersion": 1000,
8
+ "features": [
9
+ {
10
+ "name": "system.shortcut"
11
+ }
12
+ ],
13
+ "config": {
14
+ "logLevel": "log",
15
+ "network": {
16
+ "connectTimeout": 10000,
17
+ "readTimeout": 10000,
18
+ "writeTimeout": 10000
19
+ }
20
+ },
21
+ "display": {
22
+ "backgroundColor": "#ffffff",
23
+ "fullScreen": false,
24
+ "titleBar": true,
25
+ "titleBarBackgroundColor": "#000000",
26
+ "titleBarTextColor": "#fffff",
27
+ "statusBarImmersive": false,
28
+ "statusBarTextStyle": "auto",
29
+ "statusBarBackgroundColor": "#000000",
30
+ "themeMode": -1
31
+ },
32
+ "trustedSslDomains": ["www.quickapp.cn", "m.quickapp.cn"],
33
+ "router": {
34
+ "aspects": {
35
+ "home": [
36
+ {
37
+ "path": "aspect1",
38
+ "devices": ["phone", "pad"],
39
+ "autoStart": true
40
+ }
41
+ ]
42
+ }
43
+ },
44
+ "rules": {
45
+ "screenRule1": {
46
+ "screenWidth": {
47
+ "operator": "include",
48
+ "values": ["100", "200"]
49
+ },
50
+ "screenShape": {
51
+ "operator": "include",
52
+ "values": ["rect"]
53
+ }
54
+ },
55
+ "screenRule2": {
56
+ "screenWidth": {
57
+ "operator": "exclude",
58
+ "values": ["800", "400"]
59
+ }
60
+ },
61
+ "circleRule": {
62
+ "screenShape": {
63
+ "operator": "include",
64
+ "values": ["circle"]
65
+ }
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "{{aspectName}}",
3
+ "type": "UI",
4
+ "virtualMachine": "TS",
5
+ "display": {},
6
+ "permissions": {},
7
+ "window": {}
8
+ }
@@ -0,0 +1,17 @@
1
+ vaspect MainAspect {
2
+ onCreate(intent) {
3
+ console.log('MainAspect onCreate.')
4
+ }
5
+
6
+ onShow() {
7
+ console.log('MainAspect onShow.')
8
+ }
9
+
10
+ onHide() {
11
+ console.log('MainAspect onHide.')
12
+ }
13
+
14
+ onDestroy() {
15
+ console.log('MainAspect onDestroy.')
16
+ }
17
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "{{aspectName}}",
3
+ "versionName": "1.9.1",
4
+ "versionCode": 10900001,
5
+ "description": "主模块",
6
+ "icon": "$file:logo.png",
7
+ "logLevel": "log",
8
+ "router": {
9
+ "entry": "Home",
10
+ "pages": {
11
+ "Home": {
12
+ "path": "pages/Home"
13
+ }
14
+ }
15
+ },
16
+ "features": [
17
+ {
18
+ "name": "system.shortcut"
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,35 @@
1
+ @Main
2
+ component Home {
3
+ @State message: string = 'Hello World'
4
+
5
+ onShow() {
6
+ console.log('home--onShow')
7
+ }
8
+
9
+ render() {
10
+ Row() {
11
+ Column() {
12
+ Text(this.message)
13
+ .color('#000000')
14
+ .fontSize('15px')
15
+ .fontWeight('bold')
16
+ Button('click')
17
+ .width('220px')
18
+ .height('80px')
19
+ .marginTop('20px')
20
+ .onClick((params?: PlainObject) => {
21
+ this.changeMessage()
22
+ })
23
+ }
24
+ .width('100%')
25
+ .alignItems('center')
26
+ .justifyContent('center')
27
+ }
28
+ .height('100%')
29
+ }
30
+
31
+ changeMessage() {
32
+ this.setState({ message: 'Hello Tomorrow' })
33
+ }
34
+
35
+ }
@@ -0,0 +1,9 @@
1
+ 生成 xts 项目模板需要注意:
2
+ 1、用户输入的英文包名,应用在 app-package-name 目录名 及 /app/manifest.json 中的 package 值;
3
+ 2、用户输入的中文包名,应用在 /app/manifest.json 中的 name 值;
4
+
5
+ 3、用户输入的英文 aspect 名,应用在
6
+ a、aspect1 目录名;
7
+ b、/aspect1/config.json 中的 name 值;
8
+ c、/aspect1/src/manifest.json 中的 name 值;
9
+
@@ -0,0 +1,34 @@
1
+ import IProjectParam from '../interface/IProjectParam';
2
+ import ITemplate from '../interface/ITemplate';
3
+ /**
4
+ * TemplateUtil
5
+ */
6
+ declare class TemplateUtil {
7
+ static requestTemplateList(): Promise<ITemplate[]>;
8
+ /**
9
+ * 验证项目名称,只能包含:字母、数字、-、_
10
+ * @param value
11
+ * @returns
12
+ */
13
+ static validateProjectName(value: string): boolean | string;
14
+ static createProject(param: IProjectParam, keywords?: {
15
+ data: Record<string, string>;
16
+ includes?: (path: string) => boolean;
17
+ }, plugins?: ((projectPath: string, param: IProjectParam) => Promise<void>)[]): Promise<void>;
18
+ /**
19
+ * 遍历项目文件,替换词语
20
+ * @param keywords
21
+ * @param projectAbsolutePath
22
+ */
23
+ static performReplace(keywords: {
24
+ data: Record<string, string>;
25
+ includes?: (path: string) => boolean;
26
+ }, projectAbsolutePath: string): void;
27
+ /**
28
+ * xts项目-处理aspect内容
29
+ * @param projectAbsolutePath
30
+ * @param aspect
31
+ */
32
+ static createAspect(projectAbsolutePath: string, aspect: string): void;
33
+ }
34
+ export default TemplateUtil;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
16
+ const NetworkUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/NetworkUtil"));
17
+ const prompts_1 = require("@inquirer/prompts");
18
+ const fs_extra_1 = __importDefault(require("fs-extra"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const template_json_1 = __importDefault(require("../template/template.json"));
21
+ /**
22
+ * TemplateUtil
23
+ */
24
+ class TemplateUtil {
25
+ static requestTemplateList() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return template_json_1.default;
28
+ });
29
+ }
30
+ /**
31
+ * 验证项目名称,只能包含:字母、数字、-、_
32
+ * @param value
33
+ * @returns
34
+ */
35
+ static validateProjectName(value) {
36
+ const reg = /^[0-9a-zA-Z_\u4e00-\u9fa5\-]+$/;
37
+ if (!value) {
38
+ return `Please enter a project name`;
39
+ }
40
+ if (!reg.test(value)) {
41
+ return 'The project name can contain only Chinese, letters, number, _ , -';
42
+ }
43
+ return true;
44
+ }
45
+ static createProject(param, keywords, plugins) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const { name, template, aspect } = param;
48
+ // 获取项目名称和绝对路径,如果存在,则再次输入
49
+ let projectName = name;
50
+ let projectAbsolutePath = path_1.default.join(process.cwd(), projectName);
51
+ while (fs_extra_1.default.existsSync(projectAbsolutePath)) {
52
+ console.log(`${projectAbsolutePath} exists. `);
53
+ projectName = yield (0, prompts_1.input)({
54
+ message: 'please new project name',
55
+ validate: this.validateProjectName
56
+ });
57
+ projectAbsolutePath = path_1.default.join(process.cwd(), projectName);
58
+ }
59
+ fs_extra_1.default.mkdirSync(projectAbsolutePath);
60
+ // 复制模板
61
+ if (template) {
62
+ const { path } = template;
63
+ // 远程
64
+ if (['http', 'git'].find((item) => path.startsWith(item))) {
65
+ yield NetworkUtil_1.default.gitClone(path, projectAbsolutePath);
66
+ }
67
+ //本地
68
+ else {
69
+ const templateAbsolutePath = path_1.default.join(__dirname, '../template/', path);
70
+ fs_extra_1.default.copySync(templateAbsolutePath, projectAbsolutePath);
71
+ // xts项目-处理aspect内容
72
+ aspect && TemplateUtil.createAspect(projectAbsolutePath, aspect);
73
+ }
74
+ }
75
+ // 遍历项目文件,替换词语
76
+ if (keywords && keywords.data) {
77
+ TemplateUtil.performReplace(keywords, projectAbsolutePath);
78
+ }
79
+ // 执行插件
80
+ if (plugins) {
81
+ for (let item of plugins) {
82
+ yield item(projectAbsolutePath, param);
83
+ }
84
+ }
85
+ });
86
+ }
87
+ /**
88
+ * 遍历项目文件,替换词语
89
+ * @param keywords
90
+ * @param projectAbsolutePath
91
+ */
92
+ static performReplace(keywords, projectAbsolutePath) {
93
+ const { data, includes } = keywords;
94
+ const files = FileUtil_1.default.readAlldirSync(projectAbsolutePath, includes);
95
+ if (files && files.length) {
96
+ files.forEach((item) => {
97
+ FileUtil_1.default.replaceFileContent(item, data);
98
+ });
99
+ }
100
+ }
101
+ /**
102
+ * xts项目-处理aspect内容
103
+ * @param projectAbsolutePath
104
+ * @param aspect
105
+ */
106
+ static createAspect(projectAbsolutePath, aspect) {
107
+ // 按照逗号分割字符串,且去掉空格
108
+ const aspects = aspect.replace(' ', '').split(',');
109
+ const aspectAbsolutePath = path_1.default.join(__dirname, '../template', 'xts-app-template', 'aspect1');
110
+ // 循环生成自定义aspect
111
+ aspects.map((aspectItem) => {
112
+ const targetAspectPath = path_1.default.join(projectAbsolutePath, aspectItem);
113
+ fs_extra_1.default.copySync(aspectAbsolutePath, targetAspectPath);
114
+ // 替换关键字
115
+ TemplateUtil.performReplace({
116
+ data: { aspectName: aspectItem },
117
+ includes: (path) => {
118
+ const stats = fs_extra_1.default.statSync(path);
119
+ if (stats.isDirectory()) {
120
+ return ['src'].includes(path_1.default.basename(path));
121
+ }
122
+ else {
123
+ return ['.json', '.ux'].includes(path_1.default.extname(path));
124
+ }
125
+ }
126
+ }, projectAbsolutePath);
127
+ });
128
+ }
129
+ }
130
+ exports.default = TemplateUtil;
131
+
132
+ //# sourceMappingURL=TemplateUtil.js.map
@@ -0,0 +1 @@
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;gBACzC,OAAO,CAAC,GAAG,CAAC,GAAG,mBAAmB,WAAW,CAAC,CAAA;gBAC9C,WAAW,GAAG,MAAM,IAAA,eAAK,EAAC;oBACxB,OAAO,EAAE,yBAAyB;oBAClC,QAAQ,E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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"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "create-aiot",
3
+ "version": "2.0.1-alpha.0",
4
+ "description": "An easy way to start aiot project",
5
+ "main": "lib/index.js",
6
+ "keywords": [
7
+ "aiot",
8
+ "create-project"
9
+ ],
10
+ "homepage": "",
11
+ "license": "ISC",
12
+ "bin": {
13
+ "create-aiot": "lib/bin.js"
14
+ },
15
+ "directories": {
16
+ "lib": "lib",
17
+ "test": "__tests__"
18
+ },
19
+ "files": [
20
+ "lib"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "ssh://xujunjie1@git.mioffice.cn:29418/vela/aiot-toolkit"
25
+ },
26
+ "scripts": {
27
+ "test": "node ./__tests__/create-aiot.test.js"
28
+ },
29
+ "dependencies": {
30
+ "@aiot-toolkit/commander": "2.0.1-alpha.0",
31
+ "ansi-colors": "^4.1.3",
32
+ "cli-progress": "^3.12.0",
33
+ "simple-git": "^3.19.1"
34
+ },
35
+ "devDependencies": {
36
+ "@types/cli-progress": "^3.11.0"
37
+ },
38
+ "gitHead": "cde5c75fa09622188ee4f1322ff9d53faf4d8520"
39
+ }