@gmcb/cli 0.1.8

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/CHANGELOG.md ADDED
@@ -0,0 +1,186 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [0.1.8](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.7...@gmcb/cli@0.1.8) (2025-04-09)
7
+
8
+ **Note:** Version bump only for package @gmcb/cli
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.1.7](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.6...@gmcb/cli@0.1.7) (2025-04-08)
15
+
16
+ **Note:** Version bump only for package @gmcb/cli
17
+
18
+
19
+
20
+
21
+
22
+
23
+ ## [0.1.6](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.5...@gmcb/cli@0.1.6) (2025-02-25)
24
+
25
+ **Note:** Version bump only for package @gmcb/cli
26
+
27
+
28
+
29
+
30
+
31
+ ## [0.1.5](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.4...@gmcb/cli@0.1.5) (2025-02-24)
32
+
33
+ **Note:** Version bump only for package @gmcb/cli
34
+
35
+
36
+
37
+
38
+
39
+ ## [0.1.4](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.3...@gmcb/cli@0.1.4) (2025-02-23)
40
+
41
+ **Note:** Version bump only for package @gmcb/cli
42
+
43
+
44
+
45
+
46
+
47
+ ## [0.1.3](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.2...@gmcb/cli@0.1.3) (2025-02-23)
48
+
49
+
50
+ ### Bug Fixes
51
+
52
+ * 构建其他项目环境不正确 ([bf3329a](http://10.10.200.92:8090/gmcb/front-end/commits/bf3329afb1d61cd5cc1d6ffbec8e6a8f2ed77e60))
53
+
54
+
55
+
56
+
57
+
58
+ ## [0.1.2](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.1...@gmcb/cli@0.1.2) (2025-02-23)
59
+
60
+ **Note:** Version bump only for package @gmcb/cli
61
+
62
+
63
+
64
+
65
+
66
+ ## [0.1.1](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.0...@gmcb/cli@0.1.1) (2025-02-23)
67
+
68
+ **Note:** Version bump only for package @gmcb/cli
69
+
70
+
71
+
72
+
73
+
74
+ # [0.1.0](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.12...@gmcb/cli@0.1.0) (2025-02-23)
75
+
76
+
77
+ ### Features
78
+
79
+ * 新增复制命令 ([ab5e74d](http://10.10.200.92:8090/gmcb/front-end/commits/ab5e74d6236d4b57c1642c3e1abc9da23cb63129))
80
+ * 新增构建桌面应用 ([c1e13cc](http://10.10.200.92:8090/gmcb/front-end/commits/c1e13cc0aa0770be95599f1ab7ad0fa860487cec))
81
+
82
+
83
+
84
+
85
+
86
+ ## [0.0.12](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.11...@gmcb/cli@0.0.12) (2025-02-18)
87
+
88
+ **Note:** Version bump only for package @gmcb/cli
89
+
90
+
91
+
92
+
93
+
94
+ ## [0.0.11](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.10...@gmcb/cli@0.0.11) (2025-02-18)
95
+
96
+
97
+ ### Bug Fixes
98
+
99
+ * 正在构建时切换分支导致发布环境错误 ([f024ddb](http://10.10.200.92:8090/gmcb/front-end/commits/f024ddba996fbc48163e4ff5d49c9490058a5361))
100
+
101
+
102
+
103
+
104
+
105
+ ## [0.0.10](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.9...@gmcb/cli@0.0.10) (2025-02-08)
106
+
107
+
108
+ ### Bug Fixes
109
+
110
+ * hbuilderx未启动时无提示 ([5eb1ccc](http://10.10.200.92:8090/gmcb/front-end/commits/5eb1ccc2e6854dae4cf32aa5de81676e0a568f33))
111
+
112
+
113
+
114
+
115
+
116
+
117
+ ## [0.0.9](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.8...@gmcb/cli@0.0.9) (2025-02-05)
118
+
119
+ **Note:** Version bump only for package @gmcb/cli
120
+
121
+
122
+
123
+
124
+
125
+ ## [0.0.8](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.7...@gmcb/cli@0.0.8) (2025-02-05)
126
+
127
+ **Note:** Version bump only for package @gmcb/cli
128
+
129
+
130
+
131
+
132
+
133
+ ## [0.0.7](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.6...@gmcb/cli@0.0.7) (2025-02-04)
134
+
135
+ **Note:** Version bump only for package @gmcb/cli
136
+
137
+
138
+
139
+
140
+
141
+
142
+ ## [0.0.6](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.5...@gmcb/cli@0.0.6) (2025-02-04)
143
+
144
+ **Note:** Version bump only for package @gmcb/cli
145
+
146
+
147
+
148
+
149
+
150
+ ## [0.0.5](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.4...@gmcb/cli@0.0.5) (2025-02-04)
151
+
152
+ **Note:** Version bump only for package @gmcb/cli
153
+
154
+
155
+
156
+
157
+
158
+ ## [0.0.4](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.3...@gmcb/cli@0.0.4) (2025-02-04)
159
+
160
+ **Note:** Version bump only for package @gmcb/cli
161
+
162
+
163
+
164
+
165
+
166
+
167
+ ## [0.0.3](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.2...@gmcb/cli@0.0.3) (2025-02-02)
168
+
169
+ **Note:** Version bump only for package @gmcb/cli
170
+
171
+
172
+
173
+
174
+
175
+ ## [0.0.2](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.0.1...@gmcb/cli@0.0.2) (2025-02-02)
176
+
177
+ **Note:** Version bump only for package @gmcb/cli
178
+
179
+
180
+
181
+
182
+
183
+
184
+ ## [0.0.1](http://10.10.200.92:8090/gmcb/front-end/compare/@gmcb/cli@0.1.0-alpha.0...@gmcb/cli@0.0.1) (2025-02-02)
185
+
186
+ **Note:** Version bump only for package @gmcb/cli
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # @gmcb/cli
2
+
3
+ 工茂草本前端命令行工具
4
+
5
+ ## 安装
6
+
7
+ ```
8
+ npm i @gmcb/cli -g
9
+ ```
10
+
11
+ ## 使用
12
+ ```
13
+ gmcb build
14
+ ```
@@ -0,0 +1,2 @@
1
+ export declare function getCommands(...args: any[]): Promise<string[]>;
2
+ export default function (...args: any[]): Promise<string[]>;
@@ -0,0 +1,208 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getCommands = getCommands;
30
+ exports.default = default_1;
31
+ const fs_1 = require("fs");
32
+ const path_1 = require("path");
33
+ const fs_extra_1 = require("fs-extra");
34
+ const simple_git_1 = __importDefault(require("simple-git"));
35
+ const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
36
+ const adm_zip_1 = __importDefault(require("adm-zip"));
37
+ const ora_1 = __importDefault(require("ora"));
38
+ const delay_1 = __importDefault(require("delay"));
39
+ const platform = __importStar(require("../commands/platform"));
40
+ const utils_1 = require("../utils");
41
+ const config_1 = require("./config");
42
+ let config = null;
43
+ let envPath = utils_1.BUILD_ENV_PATH;
44
+ async function getCommands(...args) {
45
+ if (!config) {
46
+ config = (0, config_1.getMergeConfig)();
47
+ }
48
+ const opts = args[0];
49
+ if (config.branch && config.branch !== 'false') {
50
+ opts.branch = config.branch;
51
+ }
52
+ if (opts.branch) {
53
+ try {
54
+ const git = (0, simple_git_1.default)();
55
+ const branch = await git.branch();
56
+ if (opts.branch === true || opts.branch === 'true' || opts.branch.split(/\s*,\s*/).includes(branch.current)) {
57
+ opts.branch = branch.current;
58
+ }
59
+ else {
60
+ utils_1.log.error(`请将分支切换为“${opts.branch}”分支,并重新构建!`);
61
+ }
62
+ }
63
+ catch (e) {
64
+ utils_1.log.warning(e?.message);
65
+ opts.branch = false;
66
+ }
67
+ }
68
+ let commands = ['cross-env', 'NODE_ENV=production'];
69
+ const bin = (0, utils_1.getBinPath)(opts.compiler);
70
+ const buildEnv = ['master', 'main'].includes(opts.branch) ? 'prod' : opts.branch || opts.env;
71
+ if (buildEnv) {
72
+ commands.push(`BUILD_ENV=${buildEnv}`);
73
+ }
74
+ const currentName = (0, path_1.basename)(utils_1.COMMAND_PATH);
75
+ const projectName = opts.project || currentName;
76
+ if (opts.compiler === 'uni') {
77
+ if (projectName === currentName && utils_1.HAS_SRC && !opts.platform?.startsWith('app')) {
78
+ commands = [...commands, bin, 'build -p', opts.platform];
79
+ }
80
+ else {
81
+ if (!(0, fs_1.existsSync)(config?.cli?.hbuilderx)) {
82
+ utils_1.log.error('HbuilderX Cli路径不正确,请执行“gmcb config --cli.hbuilderx <cli-path>”设置正确的路径!');
83
+ }
84
+ if (projectName !== currentName) {
85
+ const sourcePath = (0, path_1.join)(utils_1.COMMAND_PATH, opts.source);
86
+ envPath = (0, path_1.join)(sourcePath, 'buildenv');
87
+ if (opts.source && opts.branch) {
88
+ const git = (0, simple_git_1.default)(sourcePath);
89
+ const branch = await git.branch();
90
+ if (opts.branch !== branch.current) {
91
+ utils_1.log.error(`您当前构建分支为“${opts.branch}”,项目“${projectName}”构建分支为“${branch.current}”,分支不一致,无法完成构建,请更改后重试!`);
92
+ }
93
+ }
94
+ }
95
+ let cmds = [];
96
+ if (buildEnv) {
97
+ (0, fs_extra_1.ensureFileSync)(envPath);
98
+ const currentEnv = (0, fs_1.readFileSync)(envPath).toString().trim();
99
+ if (currentEnv && buildEnv !== currentEnv) {
100
+ utils_1.log.error(`“${currentEnv}”环境正在构建,请等待构建完成再进行“${buildEnv}”环境构建,若构建已完成或者您已撤销,请删除根目录buildenv文件再进行操作!`);
101
+ }
102
+ (0, fs_1.writeFileSync)(envPath, buildEnv);
103
+ }
104
+ if (opts.platform.startsWith('app')) {
105
+ const app = platform.app(opts);
106
+ if (opts.wgt) {
107
+ let index = app.wgt.indexOf('--path');
108
+ if (index === -1) {
109
+ index = app.wgt.length;
110
+ app.wgt = [...app.wgt, '--path', (0, path_1.resolve)('unpackage/release')];
111
+ }
112
+ const wgtDist = app.wgt[index + 1];
113
+ (0, fs_extra_1.ensureDirSync)(wgtDist);
114
+ const manifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(utils_1.MAINFEST_PATH).toString()));
115
+ if (manifest.appid) {
116
+ (0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
117
+ }
118
+ cmds = ['publish', '--platform APP', '--type wgt', ...app.wgt];
119
+ }
120
+ else if (opts.res) {
121
+ cmds = ['publish', '--platform APP', '--type appResource'];
122
+ }
123
+ else {
124
+ cmds = ['pack', '--platform'];
125
+ if (opts.platform === 'app') {
126
+ const _platform = 'android,ios';
127
+ cmds = [...cmds, _platform, ...app.common, ...app.android, ...app.ios];
128
+ }
129
+ else {
130
+ const _platform = opts.platform.replace('app-', '');
131
+ cmds = [...cmds, _platform, ...app.common, ...app[_platform]];
132
+ }
133
+ }
134
+ }
135
+ else if (opts.platform.startsWith('mp')) {
136
+ const mp = platform.mp();
137
+ const manifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(utils_1.MAINFEST_PATH).toString()));
138
+ cmds = [
139
+ 'publish',
140
+ '--platform',
141
+ opts.platform.toUpperCase(),
142
+ '--appid',
143
+ manifest[opts.platform].appid,
144
+ ...mp.common,
145
+ ];
146
+ }
147
+ else if (opts.platform === 'h5') {
148
+ const h5 = platform.h5();
149
+ cmds = ['publish', '--platform h5', ...h5];
150
+ }
151
+ commands = [...commands, config?.cli?.hbuilderx, ...cmds, '--project', projectName];
152
+ }
153
+ }
154
+ else if (opts.compiler === 'electron-vite') {
155
+ commands = [...commands, bin, 'build', `&& cross-env CHANNEL=-${buildEnv}`];
156
+ if (opts.zip) {
157
+ commands.push('electron-builder --dir');
158
+ }
159
+ else if (opts.win) {
160
+ commands.push('electron-builder --win');
161
+ }
162
+ else if (opts.mac) {
163
+ commands.push('electron-builder --mac');
164
+ }
165
+ else if (opts.linux) {
166
+ commands.push('electron-builder --linux');
167
+ }
168
+ }
169
+ else {
170
+ commands = [...commands, bin, 'build'];
171
+ }
172
+ return commands;
173
+ }
174
+ async function createZip() {
175
+ const spinner = (0, ora_1.default)(`正在生成资源文件...`).start();
176
+ await (0, delay_1.default)(1000);
177
+ const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
178
+ const zip = new adm_zip_1.default();
179
+ const name = config.app?.zip?.name ?? `${String(pkg.name).toLowerCase()}.zip`;
180
+ const source = (0, path_1.join)(utils_1.COMMAND_PATH, config.app?.zip?.source ?? 'dist/win-unpacked/resources');
181
+ const dest = (0, path_1.join)(utils_1.COMMAND_PATH, `${config.app?.zip?.path ?? 'unpackage/release'}/${name}`);
182
+ if ((0, fs_1.existsSync)(dest)) {
183
+ (0, fs_1.unlinkSync)(dest);
184
+ }
185
+ zip.addLocalFolder(source);
186
+ zip.writeZip(dest);
187
+ spinner.stop();
188
+ spinner.succeed(`资源导出成功,路径为:${dest}`);
189
+ }
190
+ async function default_1(...args) {
191
+ const opts = args[0];
192
+ const commands = await getCommands(...args);
193
+ const command = commands.join(' ');
194
+ const time = Date.now();
195
+ (0, utils_1.spawnSync)(command);
196
+ if ((0, fs_1.existsSync)(envPath)) {
197
+ (0, fs_1.unlinkSync)(envPath);
198
+ }
199
+ if ((Date.now() - time) / 1000 <= 1) {
200
+ if (command.includes(config.cli.hbuilderx)) {
201
+ utils_1.log.error('检测到您的HbuilderX未启动或项目管理器中未发现构建项目,请检查后重试!');
202
+ }
203
+ }
204
+ if (opts.compiler === 'electron-vite' && opts.zip) {
205
+ await createZip();
206
+ }
207
+ return commands;
208
+ }
@@ -0,0 +1,63 @@
1
+ interface Cli {
2
+ hbuilderx?: string;
3
+ weixin?: string;
4
+ alipay?: string;
5
+ }
6
+ interface Cos {
7
+ bucket?: string;
8
+ region?: string;
9
+ path?: string;
10
+ }
11
+ interface App {
12
+ android?: {
13
+ packagename?: string;
14
+ androidpacktype?: number;
15
+ certalias?: string;
16
+ certfile?: string;
17
+ certpassword?: string;
18
+ };
19
+ ios?: {
20
+ bundle?: string;
21
+ supporteddevice?: string;
22
+ profile?: string;
23
+ certfile?: string;
24
+ certpassword?: string;
25
+ };
26
+ wgt?: {
27
+ name?: string;
28
+ path?: string;
29
+ };
30
+ zip?: {
31
+ name?: string;
32
+ path?: string;
33
+ source?: string;
34
+ };
35
+ custom?: App;
36
+ }
37
+ interface Mp {
38
+ weixin?: {
39
+ privatekey?: string;
40
+ };
41
+ alipay?: {
42
+ privatekey?: string;
43
+ };
44
+ }
45
+ interface H5 {
46
+ }
47
+ export interface BaseConfig {
48
+ branch?: string | boolean;
49
+ cos?: Cos;
50
+ cli?: Cli;
51
+ }
52
+ export interface Config extends BaseConfig {
53
+ env?: string;
54
+ app?: App;
55
+ mp?: Mp;
56
+ h5?: H5;
57
+ }
58
+ export declare function getConfig(): BaseConfig;
59
+ export declare function getLocalConfig(): Config;
60
+ export declare function getMergeConfig(): Config;
61
+ export declare function setConfig(config: any): void;
62
+ export default function (...args: any[]): Promise<void>;
63
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfig = getConfig;
4
+ exports.getLocalConfig = getLocalConfig;
5
+ exports.getMergeConfig = getMergeConfig;
6
+ exports.setConfig = setConfig;
7
+ exports.default = default_1;
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const lodash_1 = require("lodash");
11
+ const flat_1 = require("flat");
12
+ const fs_extra_1 = require("fs-extra");
13
+ const utils_1 = require("../utils");
14
+ function getConfig() {
15
+ if (!(0, fs_1.existsSync)(utils_1.CONFIG_PATH)) {
16
+ let hbuilderx = '';
17
+ if (utils_1.IS_MAC) {
18
+ hbuilderx = '/Applications/HBuilderX.app/Contents/MacOS/cli';
19
+ }
20
+ else if (utils_1.IS_WIN) {
21
+ hbuilderx = (0, path_1.join)(utils_1.HOME_PATH, 'AppData/Local/Programs/HBuilderX/cli.exe');
22
+ }
23
+ (0, fs_extra_1.writeJsonSync)(utils_1.CONFIG_PATH, {
24
+ cli: {
25
+ hbuilderx,
26
+ },
27
+ }, { spaces: 2 });
28
+ }
29
+ return (0, fs_extra_1.readJsonSync)(utils_1.CONFIG_PATH, { throws: false }) || {};
30
+ }
31
+ function getLocalConfig() {
32
+ if ((0, fs_1.existsSync)(utils_1.LOCAL_CONFIG_PATH)) {
33
+ return (0, fs_extra_1.readJsonSync)(utils_1.LOCAL_CONFIG_PATH, { throws: false }) || {};
34
+ }
35
+ return {};
36
+ }
37
+ function getMergeConfig() {
38
+ return (0, lodash_1.merge)({}, getConfig(), getLocalConfig());
39
+ }
40
+ function setConfig(config) {
41
+ const conf = getConfig();
42
+ (0, fs_extra_1.writeJsonSync)(utils_1.CONFIG_PATH, (0, lodash_1.merge)({}, conf, config), { spaces: 2 });
43
+ }
44
+ async function default_1(...args) {
45
+ if (args[0] === 'list') {
46
+ const obj = (0, flat_1.flatten)(getMergeConfig());
47
+ Object.keys(obj).forEach((key) => {
48
+ console.log(`${key}=${obj[key]}`);
49
+ });
50
+ }
51
+ else if (args[0]) {
52
+ const obj = (0, flat_1.flatten)(getMergeConfig());
53
+ if (obj[args[0]] != null) {
54
+ console.log(obj[args[0]]);
55
+ }
56
+ }
57
+ else if (args[1]) {
58
+ setConfig((0, flat_1.unflatten)(args[1]));
59
+ }
60
+ }
@@ -0,0 +1 @@
1
+ export default function (...args: any[]): Promise<void>;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = default_1;
7
+ const path_1 = require("path");
8
+ const fs_1 = require("fs");
9
+ const fs_extra_1 = require("fs-extra");
10
+ const ora_1 = __importDefault(require("ora"));
11
+ const delay_1 = __importDefault(require("delay"));
12
+ const utils_1 = require("../utils");
13
+ async function default_1(...args) {
14
+ const opts = args[0];
15
+ if (!opts.source) {
16
+ utils_1.log.error('请使用-s或--source设置复制的资源目录');
17
+ }
18
+ if (!opts.dest) {
19
+ utils_1.log.error('请使用-d或--dest设置复制资源的目标目录');
20
+ }
21
+ const sourcePath = (0, path_1.join)(utils_1.COMMAND_PATH, opts.source);
22
+ const destPath = (0, path_1.join)(utils_1.COMMAND_PATH, opts.dest);
23
+ const srcPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'src');
24
+ const indexPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'index.html');
25
+ let ignore = [];
26
+ if (opts.clean) {
27
+ (0, fs_extra_1.removeSync)(destPath);
28
+ }
29
+ (0, fs_extra_1.ensureDirSync)(destPath);
30
+ if (opts.ignore) {
31
+ ignore = opts.ignore.toLowerCase().split(',');
32
+ }
33
+ const spinner = (0, ora_1.default)('正在同步资源...').start();
34
+ await (0, delay_1.default)(1000);
35
+ (0, fs_1.readdirSync)(sourcePath).forEach((file) => {
36
+ if (!file.startsWith('.') &&
37
+ ![
38
+ 'env',
39
+ 'node_modules',
40
+ 'unpackage',
41
+ 'dist',
42
+ 'src',
43
+ 'out',
44
+ 'nativeplugins',
45
+ 'scripts',
46
+ 'buildenv',
47
+ 'license',
48
+ 'readme.md',
49
+ 'vite.config.js',
50
+ 'vite.config.ts',
51
+ 'uni.build.json',
52
+ 'tsconfig.json',
53
+ 'package.json',
54
+ 'package-lock.json',
55
+ 'yarn.lock',
56
+ 'pnpm-lock.yaml',
57
+ ]
58
+ .concat(ignore)
59
+ .includes(file.toLowerCase()) &&
60
+ !/\.d\.ts$/i.test(file) &&
61
+ !/\.log$/i.test(file)) {
62
+ const source = (0, path_1.join)(sourcePath, file);
63
+ const isDir = (0, fs_1.statSync)(source).isDirectory();
64
+ const dest = (0, path_1.join)(destPath, file);
65
+ if (opts.link) {
66
+ if (!(0, fs_1.existsSync)(dest)) {
67
+ (0, fs_1.symlinkSync)(source, dest, isDir ? 'dir' : 'file');
68
+ }
69
+ }
70
+ else if ((isDir && (0, fs_1.readdirSync)(source).length) || !isDir) {
71
+ (0, fs_extra_1.copySync)(source, dest);
72
+ }
73
+ }
74
+ });
75
+ if (srcPath === destPath && utils_1.COMMAND_PATH === sourcePath) {
76
+ if ((0, fs_1.existsSync)(indexPath)) {
77
+ (0, fs_extra_1.writeFileSync)(indexPath, (0, fs_extra_1.readFileSync)(indexPath)
78
+ .toString()
79
+ .replace(/(=['"])\.?(\/main\.)/i, '$1/src$2'));
80
+ }
81
+ }
82
+ spinner.stop();
83
+ }
@@ -0,0 +1 @@
1
+ export default function (...args: any[]): Promise<void>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = default_1;
7
+ const path_1 = require("path");
8
+ const inquirer_1 = __importDefault(require("inquirer"));
9
+ const download_1 = __importDefault(require("download"));
10
+ const ora_1 = __importDefault(require("ora"));
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ const utils_1 = require("../utils");
13
+ function downloadTemplate(name, dest) {
14
+ if (!/https?:/.test(name)) {
15
+ name = `https://git.keeprisk.cn/${name}`;
16
+ }
17
+ const [url, branch = 'master'] = name.split('#');
18
+ const array = url.replace(/\/+$/, '').split('/');
19
+ const repoName = array.pop();
20
+ return (0, download_1.default)(`${url}/-/archive/${branch}/${repoName}-${branch}.zip`, dest, { extract: true, strip: 1 });
21
+ }
22
+ async function default_1(...args) {
23
+ const name = args[0];
24
+ const opts = args[2];
25
+ const dest = (0, path_1.join)(utils_1.COMMAND_PATH, name);
26
+ let { template } = opts;
27
+ if (!template) {
28
+ template = 'project-template/uniapp';
29
+ const res = await inquirer_1.default.prompt([
30
+ {
31
+ type: 'list',
32
+ name: 'template',
33
+ message: '请选择模版类型',
34
+ choices: [
35
+ {
36
+ name: 'JS模版',
37
+ value: '',
38
+ },
39
+ {
40
+ name: 'TS模版',
41
+ value: '-ts',
42
+ },
43
+ ],
44
+ },
45
+ ]);
46
+ template += res.template;
47
+ }
48
+ const spinner = (0, ora_1.default)('模版下载中...');
49
+ try {
50
+ spinner.start();
51
+ await downloadTemplate(template, dest);
52
+ spinner.succeed('模版已下载,请执行以下命令:');
53
+ const rela = (0, path_1.relative)(utils_1.COMMAND_PATH, dest);
54
+ if (rela) {
55
+ console.log(chalk_1.default.blueBright(`$ cd ${rela}`));
56
+ }
57
+ console.log(chalk_1.default.blueBright('$ nrm use coding'));
58
+ console.log(chalk_1.default.blueBright('$ npm i'));
59
+ }
60
+ catch (e) {
61
+ spinner.fail('模版已下载失败:' + e.message);
62
+ }
63
+ finally {
64
+ spinner.stop();
65
+ }
66
+ }