coda-cli 1.0.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.
Files changed (46) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +76 -0
  3. package/package.json +45 -0
  4. package/src/bin/index.js +4 -0
  5. package/src/bin/index.ts +2 -0
  6. package/src/cli-api/cmd.js +86 -0
  7. package/src/cli-api/cmd.ts +104 -0
  8. package/src/cli-api/data.js +135 -0
  9. package/src/cli-api/data.ts +146 -0
  10. package/src/cli-api/date.js +23 -0
  11. package/src/cli-api/date.ts +22 -0
  12. package/src/cli-api/event.js +6 -0
  13. package/src/cli-api/event.ts +6 -0
  14. package/src/cli-api/fs.js +236 -0
  15. package/src/cli-api/fs.ts +213 -0
  16. package/src/cli-api/git.js +328 -0
  17. package/src/cli-api/git.ts +397 -0
  18. package/src/cli-api/index.js +22 -0
  19. package/src/cli-api/index.ts +10 -0
  20. package/src/cli-api/packages.js +69 -0
  21. package/src/cli-api/packages.ts +73 -0
  22. package/src/cli-api/request.js +55 -0
  23. package/src/cli-api/request.ts +67 -0
  24. package/src/cli-core/cli.js +135 -0
  25. package/src/cli-core/cli.ts +145 -0
  26. package/src/cli-core/index.js +51 -0
  27. package/src/cli-core/index.ts +58 -0
  28. package/src/cli-core/queue.js +60 -0
  29. package/src/cli-core/queue.ts +68 -0
  30. package/src/cli-core/watcher.js +31 -0
  31. package/src/cli-core/watcher.ts +31 -0
  32. package/src/config/commands.json +20 -0
  33. package/src/generator/cmd-create/index.js +170 -0
  34. package/src/generator/cmd-create/index.ts +164 -0
  35. package/src/generator/cmd-create/tmpl/index.js +39 -0
  36. package/src/generator/cmd-create/tmpl/index.ts +46 -0
  37. package/src/generator/cmd-delete/index.js +129 -0
  38. package/src/generator/cmd-delete/index.ts +122 -0
  39. package/src/generator/startup.js +253 -0
  40. package/src/generator/startup.ts +225 -0
  41. package/src/service/lang.js +73 -0
  42. package/src/service/lang.ts +71 -0
  43. package/src/service/util.js +120 -0
  44. package/src/service/util.ts +91 -0
  45. package/src/types/index.js +2 -0
  46. package/src/types/index.ts +29 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.queue = queue;
4
+ function queue() {
5
+ const tasks = [];
6
+ const layzs = [];
7
+ const dequeue = () => {
8
+ let current = tasks.shift();
9
+ if (current) {
10
+ current();
11
+ }
12
+ };
13
+ /**
14
+ * 将任务加入延迟队列
15
+ */
16
+ const dequeueLayz = () => {
17
+ if (layzs.length === 0) {
18
+ return;
19
+ }
20
+ let current = layzs.shift();
21
+ if (current) {
22
+ current();
23
+ }
24
+ };
25
+ /**
26
+ * 将任务加入队列
27
+ * @param task 任务函数
28
+ * @param layz 是否为延迟执行任务
29
+ */
30
+ const enqueue = (task, layz) => {
31
+ if (!layz) {
32
+ tasks.push(task);
33
+ }
34
+ else {
35
+ layzs.push(task);
36
+ }
37
+ };
38
+ /**
39
+ * 通知下一个任务并执行出队
40
+ * @param nextLayz 下一个任务是否为延迟执行
41
+ */
42
+ const next = (nextLayz) => {
43
+ if (tasks.length === 0) {
44
+ dequeueLayz();
45
+ return;
46
+ }
47
+ if (nextLayz) {
48
+ let nextTask = tasks.shift();
49
+ if (nextTask) {
50
+ layzs.unshift(nextTask);
51
+ }
52
+ }
53
+ dequeue();
54
+ };
55
+ return {
56
+ enqueue,
57
+ next,
58
+ };
59
+ }
60
+ exports.default = queue;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * 定义任务函数类型
3
+ */
4
+ type Task = () => void;
5
+
6
+ export function queue() {
7
+ const tasks: Task[] = [];
8
+ const layzs: Task[] = [];
9
+
10
+ const dequeue = (): void => {
11
+ let current = tasks.shift();
12
+ if (current) {
13
+ current();
14
+ }
15
+ };
16
+
17
+ /**
18
+ * 将任务加入延迟队列
19
+ */
20
+ const dequeueLayz = (): void => {
21
+ if (layzs.length === 0) {
22
+ return;
23
+ }
24
+ let current = layzs.shift();
25
+ if (current) {
26
+ current();
27
+ }
28
+ };
29
+
30
+ /**
31
+ * 将任务加入队列
32
+ * @param task 任务函数
33
+ * @param layz 是否为延迟执行任务
34
+ */
35
+ const enqueue = (task: Task, layz?: boolean): void => {
36
+ if (!layz) {
37
+ tasks.push(task);
38
+ } else {
39
+ layzs.push(task);
40
+ }
41
+ };
42
+
43
+ /**
44
+ * 通知下一个任务并执行出队
45
+ * @param nextLayz 下一个任务是否为延迟执行
46
+ */
47
+ const next = (nextLayz?: boolean): void => {
48
+ if (tasks.length === 0) {
49
+ dequeueLayz();
50
+ return;
51
+ }
52
+ if (nextLayz) {
53
+ let nextTask = tasks.shift();
54
+ if (nextTask) {
55
+ layzs.unshift(nextTask);
56
+ }
57
+ }
58
+
59
+ dequeue();
60
+ };
61
+
62
+ return {
63
+ enqueue,
64
+ next,
65
+ };
66
+ }
67
+
68
+ export default queue;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Subscribe = Subscribe;
4
+ exports.Publish = Publish;
5
+ const events_1 = require("events");
6
+ // 创建全局事件发射器实例
7
+ const emitter = new events_1.EventEmitter();
8
+ /**
9
+ * 订阅指定通道的事件
10
+ * @template T 消息数据类型
11
+ * @param channel 通道/事件名称
12
+ * @param fn 收到消息时的回调函数
13
+ */
14
+ function Subscribe(channel, fn) {
15
+ emitter.on(channel, (message) => {
16
+ fn(message);
17
+ });
18
+ }
19
+ /**
20
+ * 向指定通道发布事件消息
21
+ * @template T 消息数据类型
22
+ * @param channel 通道/事件名称
23
+ * @param message 要发送的消息内容
24
+ */
25
+ function Publish(channel, message) {
26
+ emitter.emit(channel, message);
27
+ }
28
+ exports.default = {
29
+ Subscribe,
30
+ Publish,
31
+ };
@@ -0,0 +1,31 @@
1
+ import {EventEmitter} from 'events';
2
+
3
+ // 创建全局事件发射器实例
4
+ const emitter = new EventEmitter();
5
+
6
+ /**
7
+ * 订阅指定通道的事件
8
+ * @template T 消息数据类型
9
+ * @param channel 通道/事件名称
10
+ * @param fn 收到消息时的回调函数
11
+ */
12
+ export function Subscribe<T = any>(channel: string, fn: (message: T) => void): void {
13
+ emitter.on(channel, (message: T) => {
14
+ fn(message);
15
+ });
16
+ }
17
+
18
+ /**
19
+ * 向指定通道发布事件消息
20
+ * @template T 消息数据类型
21
+ * @param channel 通道/事件名称
22
+ * @param message 要发送的消息内容
23
+ */
24
+ export function Publish<T = any>(channel: string, message: T): void {
25
+ emitter.emit(channel, message);
26
+ }
27
+
28
+ export default {
29
+ Subscribe,
30
+ Publish,
31
+ };
@@ -0,0 +1,20 @@
1
+ {
2
+ "wordsLen": 2,
3
+ "packageName": "code-agent",
4
+ "name": "coda",
5
+ "commands": [
6
+ {
7
+ "command": "cmd create",
8
+ "description": "code-agent增加命令",
9
+ "custom": false
10
+ },
11
+ {
12
+ "command": "cmd delete",
13
+ "description": "删除命令",
14
+ "custom": false
15
+ }
16
+ ],
17
+ "inAnyPath": ["cmd create", "cmd delete", "add project"],
18
+ "buildIn": ["cmd create", "cmd delete"],
19
+ "store": "https://registry.npmjs.org"
20
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const cli_core_1 = require("../../cli-core/index.js");
40
+ const API = __importStar(require("../../cli-api/index.js"));
41
+ const util_1 = require("../../service/util.js");
42
+ const lang_1 = require("../../service/lang.js");
43
+ const commands_json_1 = __importDefault(require("../../config/commands.json"));
44
+ const CLIConfig = commands_json_1.default;
45
+ let args = process.argv.slice(2);
46
+ const npmRootPath = args[0];
47
+ const methods = {
48
+ /**
49
+ * 添加到基础配置文件
50
+ */
51
+ addToBaseConfig(folderName, description, inAnyPath) {
52
+ cli_core_1.CLI.loading.start(lang_1.Lang.BUILDIN.ADD_CMD_CONFIG);
53
+ let cmd = folderName.replace(/-/g, ' ');
54
+ let cliCfgPath = API.fs.join(npmRootPath, CLIConfig.packageName, 'src', 'config', 'commands.json');
55
+ let config = Object.assign({}, CLIConfig);
56
+ config.commands.push({
57
+ command: cmd,
58
+ description: description,
59
+ custom: false,
60
+ });
61
+ config.commands = API.data.arraySort(config.commands, 'command');
62
+ if (!inAnyPath && config.inAnyPath.indexOf(cmd) === -1) {
63
+ config.inAnyPath.push(cmd);
64
+ config.inAnyPath = API.data.arraySort(config.inAnyPath);
65
+ }
66
+ API.fs.writeFile(cliCfgPath, config, true);
67
+ cli_core_1.CLI.loading.succeed(lang_1.Lang.BUILDIN.ADD_CMD_CONFIG_SUCCESS);
68
+ },
69
+ /**
70
+ * 添加到扩展目录
71
+ */
72
+ addToExtensions(folderName) {
73
+ cli_core_1.CLI.loading.start(lang_1.Lang.BUILDIN.ADD_CMD_EXTENSIONS);
74
+ const cmdFolderPath = API.fs.join(npmRootPath, CLIConfig.packageName, 'src', 'extensions', folderName);
75
+ const cmdIndexPath = API.fs.join(cmdFolderPath, 'index.js');
76
+ const baseIndexTmpl = API.fs.join(npmRootPath, CLIConfig.packageName, 'src', 'generator', 'cmd-create', 'tmpl', 'index.js');
77
+ API.fs.createFloder(cmdFolderPath);
78
+ API.fs.copyFile(baseIndexTmpl, cmdIndexPath);
79
+ cli_core_1.CLI.loading.succeed(lang_1.Lang.BUILDIN.ADD_CMD_EXTENSIONS_SUCCESS);
80
+ },
81
+ /**
82
+ * 添加到 package.json 的 scripts 中
83
+ */
84
+ addToPkgBin(folderName) {
85
+ const temp = folderName.split('-');
86
+ const cmd = `${CLIConfig.name} ${temp.join(' ')}`;
87
+ cli_core_1.CLI.loading.start(lang_1.Lang.BUILDIN.ADD_CMD_PACKAGE);
88
+ const pkg = API.fs.join(npmRootPath, CLIConfig.packageName, 'package.json');
89
+ const pkgJson = API.fs.readFile(pkg, true);
90
+ if (pkgJson.scripts) {
91
+ pkgJson.scripts[`debug_${folderName}`] = `cross-env DEBUG_ENV=true ${cmd}`;
92
+ }
93
+ API.fs.writeFile(pkg, pkgJson, true);
94
+ cli_core_1.CLI.loading.succeed(lang_1.Lang.BUILDIN.ADD_CMD_PACKAGE_SUCCESS);
95
+ },
96
+ };
97
+ cli_core_1.Base.extends({
98
+ init() {
99
+ cli_core_1.Base.state = {
100
+ folderName: '',
101
+ description: '',
102
+ isStartUserRootPath: true,
103
+ };
104
+ cli_core_1.Wait.next();
105
+ },
106
+ async prompt() {
107
+ const questions = [
108
+ {
109
+ type: 'input',
110
+ name: 'folderName',
111
+ message: lang_1.Lang.BUILDIN.CMD_NAME,
112
+ default: cli_core_1.Base.state.folderName,
113
+ validate: (input) => {
114
+ let commonValidate = util_1.Util.volidateFileName(input);
115
+ if (commonValidate === true) {
116
+ let tempPath = API.fs.join(npmRootPath, CLIConfig.packageName, 'src', 'extensions', input);
117
+ if (API.fs.hasPath(tempPath)) {
118
+ return `${input} ${lang_1.Lang.BUILDIN.EXSITED}`;
119
+ }
120
+ return true;
121
+ }
122
+ else {
123
+ return commonValidate;
124
+ }
125
+ },
126
+ },
127
+ {
128
+ type: 'input',
129
+ name: 'description',
130
+ message: lang_1.Lang.BUILDIN.CMD_DESCRIPTION,
131
+ default: cli_core_1.Base.state.description,
132
+ validate: (input) => {
133
+ if (input.length !== 0) {
134
+ return true;
135
+ }
136
+ else {
137
+ return false;
138
+ }
139
+ },
140
+ },
141
+ {
142
+ type: 'confirm',
143
+ name: 'isStartUserRootPath',
144
+ message: lang_1.Lang.BUILDIN.IS_RUN_ANNY_PATH,
145
+ default: true,
146
+ },
147
+ ];
148
+ const answers = await cli_core_1.CLI.addQuestions(questions);
149
+ cli_core_1.Base.state.folderName = answers.folderName;
150
+ cli_core_1.Base.state.description = answers.description;
151
+ cli_core_1.Base.state.isStartUserRootPath = answers.isStartUserRootPath;
152
+ cli_core_1.Wait.next();
153
+ },
154
+ default() {
155
+ cli_core_1.Wait.next();
156
+ },
157
+ writing() {
158
+ methods.addToBaseConfig(cli_core_1.Base.state.folderName, cli_core_1.Base.state.description, cli_core_1.Base.state.isStartUserRootData ?? cli_core_1.Base.state.isStartUserRootPath);
159
+ methods.addToExtensions(cli_core_1.Base.state.folderName);
160
+ methods.addToPkgBin(cli_core_1.Base.state.folderName);
161
+ cli_core_1.Wait.next();
162
+ },
163
+ install() {
164
+ cli_core_1.Wait.next();
165
+ },
166
+ end() {
167
+ cli_core_1.CLI.log.success(lang_1.Lang.MSG_SUCCESS, lang_1.Lang.BUILDIN.CMD_CREATE_SUCCESS);
168
+ cli_core_1.Wait.next();
169
+ },
170
+ });
@@ -0,0 +1,164 @@
1
+ import {Base, Wait, CLI} from '@/cli-core';
2
+ import * as API from '@/cli-api';
3
+ import {Util} from '@/service/util';
4
+ import {Lang} from '@/service/lang';
5
+ import CLIConfigData from '@/config/commands.json';
6
+ import {CLIConfigType} from '@/types';
7
+
8
+ const CLIConfig: CLIConfigType = CLIConfigData as CLIConfigType;
9
+
10
+ let args = process.argv.slice(2);
11
+ const npmRootPath = args[0];
12
+
13
+ const methods = {
14
+ /**
15
+ * 添加到基础配置文件
16
+ */
17
+ addToBaseConfig(folderName: string, description: string, inAnyPath: boolean): void {
18
+ CLI.loading.start(Lang.BUILDIN.ADD_CMD_CONFIG);
19
+ let cmd = folderName.replace(/-/g, ' ');
20
+ let cliCfgPath = API.fs.join(
21
+ npmRootPath,
22
+ CLIConfig.packageName,
23
+ 'src',
24
+ 'config',
25
+ 'commands.json',
26
+ );
27
+ let config = Object.assign({}, CLIConfig);
28
+
29
+ config.commands.push({
30
+ command: cmd,
31
+ description: description,
32
+ custom: false,
33
+ });
34
+ config.commands = API.data.arraySort(config.commands, 'command');
35
+ if (!inAnyPath && config.inAnyPath.indexOf(cmd) === -1) {
36
+ config.inAnyPath.push(cmd);
37
+ config.inAnyPath = API.data.arraySort(config.inAnyPath);
38
+ }
39
+
40
+ API.fs.writeFile(cliCfgPath, config, true);
41
+ CLI.loading.succeed(Lang.BUILDIN.ADD_CMD_CONFIG_SUCCESS);
42
+ },
43
+
44
+ /**
45
+ * 添加到扩展目录
46
+ */
47
+ addToExtensions(folderName: string): void {
48
+ CLI.loading.start(Lang.BUILDIN.ADD_CMD_EXTENSIONS);
49
+ const cmdFolderPath = API.fs.join(
50
+ npmRootPath,
51
+ CLIConfig.packageName,
52
+ 'src',
53
+ 'extensions',
54
+ folderName,
55
+ );
56
+ const cmdIndexPath = API.fs.join(cmdFolderPath, 'index.js');
57
+ const baseIndexTmpl = API.fs.join(
58
+ npmRootPath,
59
+ CLIConfig.packageName,
60
+ 'src',
61
+ 'generator',
62
+ 'cmd-create',
63
+ 'tmpl',
64
+ 'index.js',
65
+ );
66
+
67
+ API.fs.createFloder(cmdFolderPath);
68
+ API.fs.copyFile(baseIndexTmpl, cmdIndexPath);
69
+ CLI.loading.succeed(Lang.BUILDIN.ADD_CMD_EXTENSIONS_SUCCESS);
70
+ },
71
+ };
72
+
73
+ Base.extends({
74
+ init(): void {
75
+ Base.state = {
76
+ folderName: '',
77
+ description: '',
78
+ isStartUserRootPath: true,
79
+ };
80
+
81
+ Wait.next();
82
+ },
83
+
84
+ async prompt(): Promise<void> {
85
+ const questions: any[] = [
86
+ {
87
+ type: 'input',
88
+ name: 'folderName',
89
+ message: Lang.BUILDIN.CMD_NAME,
90
+ default: Base.state.folderName,
91
+ validate: (input: string) => {
92
+ let commonValidate = Util.volidateFileName(input);
93
+
94
+ if (commonValidate === true) {
95
+ let tempPath = API.fs.join(
96
+ npmRootPath,
97
+ CLIConfig.packageName,
98
+ 'src',
99
+ 'extensions',
100
+ input,
101
+ );
102
+
103
+ if (API.fs.hasPath(tempPath)) {
104
+ return `${input} ${Lang.BUILDIN.EXSITED}`;
105
+ }
106
+
107
+ return true;
108
+ } else {
109
+ return commonValidate;
110
+ }
111
+ },
112
+ },
113
+ {
114
+ type: 'input',
115
+ name: 'description',
116
+ message: Lang.BUILDIN.CMD_DESCRIPTION,
117
+ default: Base.state.description,
118
+ validate: (input: string) => {
119
+ if (input.length !== 0) {
120
+ return true;
121
+ } else {
122
+ return false;
123
+ }
124
+ },
125
+ },
126
+ {
127
+ type: 'confirm',
128
+ name: 'isStartUserRootPath',
129
+ message: Lang.BUILDIN.IS_RUN_ANNY_PATH,
130
+ default: true,
131
+ },
132
+ ];
133
+
134
+ const answers = await CLI.addQuestions(questions);
135
+ Base.state.folderName = answers.folderName;
136
+ Base.state.description = answers.description;
137
+ Base.state.isStartUserRootPath = answers.isStartUserRootPath;
138
+
139
+ Wait.next();
140
+ },
141
+
142
+ default(): void {
143
+ Wait.next();
144
+ },
145
+
146
+ writing(): void {
147
+ methods.addToBaseConfig(
148
+ Base.state.folderName,
149
+ Base.state.description,
150
+ Base.state.isStartUserRootData ?? Base.state.isStartUserRootPath,
151
+ );
152
+ methods.addToExtensions(Base.state.folderName);
153
+ Wait.next();
154
+ },
155
+
156
+ install(): void {
157
+ Wait.next();
158
+ },
159
+
160
+ end(): void {
161
+ CLI.log.success(Lang.MSG_SUCCESS, Lang.BUILDIN.CMD_CREATE_SUCCESS);
162
+ Wait.next();
163
+ },
164
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_core_1 = require("../../../cli-core/index.js");
4
+ cli_core_1.Base.extends({
5
+ init() {
6
+ cli_core_1.Base.state = {
7
+ // TODO: 定义全局状态和方法
8
+ };
9
+ cli_core_1.CLI.log.debug('run step 1: init done');
10
+ cli_core_1.Wait.next();
11
+ },
12
+ async prompt() {
13
+ const questions = [];
14
+ const answers = await cli_core_1.CLI.addQuestions(questions);
15
+ // TODO: 通过 "answers" 设置全局状态值
16
+ cli_core_1.CLI.log.debug('run step 2: prompt done');
17
+ cli_core_1.Wait.next();
18
+ },
19
+ async default() {
20
+ // TODO: 处理一些需要计算的流程
21
+ cli_core_1.CLI.log.debug('run step 3: default done');
22
+ cli_core_1.Wait.next();
23
+ },
24
+ async writing() {
25
+ // TODO: 编写文件
26
+ cli_core_1.CLI.log.debug('run step 4: writing done');
27
+ cli_core_1.Wait.next();
28
+ },
29
+ async install() {
30
+ // TODO: 从 NPM 安装所需的库
31
+ cli_core_1.CLI.log.debug('run step 5: install done');
32
+ cli_core_1.Wait.next();
33
+ },
34
+ end() {
35
+ // TODO: 显示此命令执行成功的消息
36
+ cli_core_1.CLI.log.debug('run step 6: end done');
37
+ cli_core_1.Wait.next();
38
+ },
39
+ });
@@ -0,0 +1,46 @@
1
+ import {Base, Wait, CLI, ChildProcess} from '@/cli-core';
2
+ import * as API from '@/cli-api';
3
+ import inquirer, {Answers, PromptSession} from 'inquirer';
4
+
5
+ Base.extends({
6
+ init(): void {
7
+ Base.state = {
8
+ // TODO: 定义全局状态和方法
9
+ };
10
+
11
+ CLI.log.debug('run step 1: init done');
12
+ Wait.next();
13
+ },
14
+
15
+ async prompt(): Promise<void> {
16
+ const questions: any[] = [];
17
+ const answers: Answers = await CLI.addQuestions(questions);
18
+ // TODO: 通过 "answers" 设置全局状态值
19
+ CLI.log.debug('run step 2: prompt done');
20
+ Wait.next();
21
+ },
22
+
23
+ async default(): Promise<void> {
24
+ // TODO: 处理一些需要计算的流程
25
+ CLI.log.debug('run step 3: default done');
26
+ Wait.next();
27
+ },
28
+
29
+ async writing(): Promise<void> {
30
+ // TODO: 编写文件
31
+ CLI.log.debug('run step 4: writing done');
32
+ Wait.next();
33
+ },
34
+
35
+ async install(): Promise<void> {
36
+ // TODO: 从 NPM 安装所需的库
37
+ CLI.log.debug('run step 5: install done');
38
+ Wait.next();
39
+ },
40
+
41
+ end(): void {
42
+ // TODO: 显示此命令执行成功的消息
43
+ CLI.log.debug('run step 6: end done');
44
+ Wait.next();
45
+ },
46
+ });