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,236 @@
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
+ exports.FS = void 0;
40
+ const nodeFS = __importStar(require("fs"));
41
+ const nodePath = __importStar(require("path"));
42
+ const glob = __importStar(require("glob"));
43
+ const fs_extra_1 = __importDefault(require("fs-extra"));
44
+ exports.FS = {
45
+ /**
46
+ * 获取目标根路径
47
+ * @returns 返回路径字符串
48
+ */
49
+ processRoot() {
50
+ return process.cwd();
51
+ },
52
+ /**
53
+ * 拼接路径
54
+ * @param paths 路径名称
55
+ * @returns 返回拼接后的路径字符串
56
+ */
57
+ join(...paths) {
58
+ return nodePath.join(...paths);
59
+ },
60
+ /**
61
+ * 获取绝对路径
62
+ * @param paths 路径名称
63
+ * @returns 返回绝对路径字符串
64
+ */
65
+ resolve(...paths) {
66
+ return nodePath.resolve(...paths);
67
+ },
68
+ /**
69
+ * 获取相对路径
70
+ * @param rootpath 根路径
71
+ * @param pathNames 目标路径名称
72
+ * @returns 返回相对路径字符串
73
+ */
74
+ relative(rootpath, pathNames) {
75
+ return nodePath.relative(rootpath, pathNames);
76
+ },
77
+ /**
78
+ * 验证路径是否为绝对路径
79
+ * @param filePath 文件路径
80
+ * @returns 是否为绝对路径
81
+ */
82
+ isAbsolutePath(filePath) {
83
+ return nodePath.isAbsolute(filePath);
84
+ },
85
+ /**
86
+ * 验证路径是否存在
87
+ * @param path 路径名称
88
+ * @returns 是否存在
89
+ */
90
+ hasPath(path) {
91
+ return nodeFS.existsSync(path);
92
+ },
93
+ /**
94
+ * 获取文件名(基本名)
95
+ * @param filePath 文件路径
96
+ * @param ext 后缀名
97
+ * @returns 文件名字符串
98
+ */
99
+ baseName(filePath, ext) {
100
+ return nodePath.basename(filePath, ext);
101
+ },
102
+ /**
103
+ * 通过分隔符拆分文件路径并获取指定部分
104
+ * @param filePath 文件路径
105
+ * @param splitStr 用于拆分文件路径的分隔符
106
+ * @returns 拆分后的字符串
107
+ */
108
+ splitFileName(filePath, splitStr) {
109
+ return filePath.split(splitStr)[1];
110
+ },
111
+ /**
112
+ * 获取 Windows 或 Linux 系统的路径分隔符
113
+ * @returns 路径分隔符字符串
114
+ */
115
+ getSlash() {
116
+ if (process.platform === 'win32') {
117
+ return '\\';
118
+ }
119
+ else {
120
+ return '/';
121
+ }
122
+ },
123
+ /**
124
+ * 根据匹配模式获取所有文件
125
+ * @param pattern 匹配模式字符串
126
+ * @returns 文件路径数组
127
+ */
128
+ getFiles(pattern) {
129
+ let files = [];
130
+ let resource = glob.sync(pattern, { dot: true });
131
+ resource.forEach((item) => {
132
+ if (nodeFS.statSync(item).isFile()) {
133
+ files.push(item);
134
+ }
135
+ });
136
+ return files;
137
+ },
138
+ /**
139
+ * 批量删除不同目录下的文件(不能删除文件夹)
140
+ * @param files 包含文件路径的数组
141
+ * @param fn 错误回调函数
142
+ */
143
+ deleteFiles(files, fn) {
144
+ files.forEach(file => {
145
+ nodeFS.unlink(file, err => {
146
+ if (err && fn) {
147
+ fn(err);
148
+ }
149
+ });
150
+ });
151
+ },
152
+ /**
153
+ * 删除文件夹及其内部文件
154
+ * @param folder 文件夹路径名称
155
+ * @param sync 是否需要同步执行
156
+ */
157
+ deleteFolder(folder, sync) {
158
+ const del = require('del');
159
+ if (sync) {
160
+ del.sync(folder, { force: true });
161
+ }
162
+ else {
163
+ del(folder, { force: true });
164
+ }
165
+ },
166
+ /**
167
+ * 复制文件
168
+ * @param path 源文件路径
169
+ * @param targetPath 目标文件路径
170
+ * @param opt 复制选项或过滤函数
171
+ */
172
+ copyFile(path, targetPath, opt) {
173
+ if (opt) {
174
+ fs_extra_1.default.copySync(path, targetPath, opt);
175
+ }
176
+ else {
177
+ fs_extra_1.default.copySync(path, targetPath);
178
+ }
179
+ },
180
+ /**
181
+ * 创建文件夹
182
+ * @param dir 路径名称
183
+ */
184
+ createFloder(dir) {
185
+ fs_extra_1.default.ensureDirSync(dir);
186
+ },
187
+ /**
188
+ * 创建空文件
189
+ * @param filePath 文件路径名称
190
+ * @param fn 回调函数
191
+ */
192
+ createFile(filePath, fn) {
193
+ fs_extra_1.default.ensureFileSync(filePath);
194
+ if (fn) {
195
+ fn(filePath);
196
+ }
197
+ },
198
+ /**
199
+ * 从文件中读取内容
200
+ * @param filePath 文件路径
201
+ * @param isJSON 是否解析为 JSON
202
+ * @returns 字符串或 JSON 对象
203
+ */
204
+ readFile(filePath, isJSON) {
205
+ let content;
206
+ let data = nodeFS.readFileSync(filePath, {
207
+ encoding: 'utf-8',
208
+ });
209
+ if (isJSON) {
210
+ if (data.length === 0) {
211
+ return {};
212
+ }
213
+ content = JSON.parse(data);
214
+ }
215
+ else {
216
+ if (data.length === 0) {
217
+ return '';
218
+ }
219
+ content = data;
220
+ }
221
+ return content;
222
+ },
223
+ /**
224
+ * 将内容写入文件
225
+ * @param filePath 文件路径
226
+ * @param fileContent 字符串或 JSON 内容
227
+ * @param isJSON 是否为 JSON 格式
228
+ */
229
+ writeFile(filePath, fileContent, isJSON) {
230
+ let data = isJSON ? JSON.stringify(fileContent, null, 2) : fileContent;
231
+ nodeFS.writeFileSync(filePath, data, {
232
+ encoding: 'utf-8',
233
+ });
234
+ },
235
+ };
236
+ exports.default = exports.FS;
@@ -0,0 +1,213 @@
1
+ import * as nodeFS from 'fs';
2
+ import * as nodePath from 'path';
3
+ import * as glob from 'glob';
4
+ import fsExtra from 'fs-extra';
5
+
6
+ export const FS = {
7
+ /**
8
+ * 获取目标根路径
9
+ * @returns 返回路径字符串
10
+ */
11
+ processRoot(): string {
12
+ return process.cwd();
13
+ },
14
+
15
+ /**
16
+ * 拼接路径
17
+ * @param paths 路径名称
18
+ * @returns 返回拼接后的路径字符串
19
+ */
20
+ join(...paths: string[]): string {
21
+ return nodePath.join(...paths);
22
+ },
23
+
24
+ /**
25
+ * 获取绝对路径
26
+ * @param paths 路径名称
27
+ * @returns 返回绝对路径字符串
28
+ */
29
+ resolve(...paths: string[]): string {
30
+ return nodePath.resolve(...paths);
31
+ },
32
+
33
+ /**
34
+ * 获取相对路径
35
+ * @param rootpath 根路径
36
+ * @param pathNames 目标路径名称
37
+ * @returns 返回相对路径字符串
38
+ */
39
+ relative(rootpath: string, pathNames: string): string {
40
+ return nodePath.relative(rootpath, pathNames);
41
+ },
42
+
43
+ /**
44
+ * 验证路径是否为绝对路径
45
+ * @param filePath 文件路径
46
+ * @returns 是否为绝对路径
47
+ */
48
+ isAbsolutePath(filePath: string): boolean {
49
+ return nodePath.isAbsolute(filePath);
50
+ },
51
+
52
+ /**
53
+ * 验证路径是否存在
54
+ * @param path 路径名称
55
+ * @returns 是否存在
56
+ */
57
+ hasPath(path: string): boolean {
58
+ return nodeFS.existsSync(path);
59
+ },
60
+
61
+ /**
62
+ * 获取文件名(基本名)
63
+ * @param filePath 文件路径
64
+ * @param ext 后缀名
65
+ * @returns 文件名字符串
66
+ */
67
+ baseName(filePath: string, ext?: string): string {
68
+ return nodePath.basename(filePath, ext);
69
+ },
70
+
71
+ /**
72
+ * 通过分隔符拆分文件路径并获取指定部分
73
+ * @param filePath 文件路径
74
+ * @param splitStr 用于拆分文件路径的分隔符
75
+ * @returns 拆分后的字符串
76
+ */
77
+ splitFileName(filePath: string, splitStr: string): string {
78
+ return filePath.split(splitStr)[1];
79
+ },
80
+
81
+ /**
82
+ * 获取 Windows 或 Linux 系统的路径分隔符
83
+ * @returns 路径分隔符字符串
84
+ */
85
+ getSlash(): string {
86
+ if (process.platform === 'win32') {
87
+ return '\\';
88
+ } else {
89
+ return '/';
90
+ }
91
+ },
92
+
93
+ /**
94
+ * 根据匹配模式获取所有文件
95
+ * @param pattern 匹配模式字符串
96
+ * @returns 文件路径数组
97
+ */
98
+ getFiles(pattern: string): string[] {
99
+ let files: string[] = [];
100
+ let resource = glob.sync(pattern, {dot: true});
101
+ resource.forEach((item: string) => {
102
+ if (nodeFS.statSync(item).isFile()) {
103
+ files.push(item);
104
+ }
105
+ });
106
+ return files;
107
+ },
108
+
109
+ /**
110
+ * 批量删除不同目录下的文件(不能删除文件夹)
111
+ * @param files 包含文件路径的数组
112
+ * @param fn 错误回调函数
113
+ */
114
+ deleteFiles(files: string[], fn?: (err: NodeJS.ErrnoException | null) => void): void {
115
+ files.forEach(file => {
116
+ nodeFS.unlink(file, err => {
117
+ if (err && fn) {
118
+ fn(err);
119
+ }
120
+ });
121
+ });
122
+ },
123
+
124
+ /**
125
+ * 删除文件夹及其内部文件
126
+ * @param folder 文件夹路径名称
127
+ * @param sync 是否需要同步执行
128
+ */
129
+ deleteFolder(folder: string, sync?: boolean): void {
130
+ const del = require('del');
131
+ if (sync) {
132
+ del.sync(folder, {force: true});
133
+ } else {
134
+ del(folder, {force: true});
135
+ }
136
+ },
137
+
138
+ /**
139
+ * 复制文件
140
+ * @param path 源文件路径
141
+ * @param targetPath 目标文件路径
142
+ * @param opt 复制选项或过滤函数
143
+ */
144
+ copyFile(path: string, targetPath: string, opt?: fsExtra.CopySyncOptions): void {
145
+ if (opt) {
146
+ fsExtra.copySync(path, targetPath, opt);
147
+ } else {
148
+ fsExtra.copySync(path, targetPath);
149
+ }
150
+ },
151
+
152
+ /**
153
+ * 创建文件夹
154
+ * @param dir 路径名称
155
+ */
156
+ createFloder(dir: string): void {
157
+ fsExtra.ensureDirSync(dir);
158
+ },
159
+
160
+ /**
161
+ * 创建空文件
162
+ * @param filePath 文件路径名称
163
+ * @param fn 回调函数
164
+ */
165
+ createFile(filePath: string, fn?: (filePath: string) => void): void {
166
+ fsExtra.ensureFileSync(filePath);
167
+ if (fn) {
168
+ fn(filePath);
169
+ }
170
+ },
171
+
172
+ /**
173
+ * 从文件中读取内容
174
+ * @param filePath 文件路径
175
+ * @param isJSON 是否解析为 JSON
176
+ * @returns 字符串或 JSON 对象
177
+ */
178
+ readFile(filePath: string, isJSON?: boolean): any {
179
+ let content: any;
180
+ let data = nodeFS.readFileSync(filePath, {
181
+ encoding: 'utf-8',
182
+ });
183
+
184
+ if (isJSON) {
185
+ if (data.length === 0) {
186
+ return {};
187
+ }
188
+ content = JSON.parse(data);
189
+ } else {
190
+ if (data.length === 0) {
191
+ return '';
192
+ }
193
+ content = data;
194
+ }
195
+
196
+ return content;
197
+ },
198
+
199
+ /**
200
+ * 将内容写入文件
201
+ * @param filePath 文件路径
202
+ * @param fileContent 字符串或 JSON 内容
203
+ * @param isJSON 是否为 JSON 格式
204
+ */
205
+ writeFile(filePath: string, fileContent: any, isJSON?: boolean): void {
206
+ let data = isJSON ? JSON.stringify(fileContent, null, 2) : fileContent;
207
+ nodeFS.writeFileSync(filePath, data, {
208
+ encoding: 'utf-8',
209
+ });
210
+ },
211
+ };
212
+
213
+ export default FS;