@gmcb/cli 0.9.4 → 0.9.6
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 +23 -6
- package/lib/actions/build.js +51 -68
- package/lib/scripts/wgt-apk.js +4 -8
- package/lib/scripts/zip-exe.js +3 -8
- package/lib/utils/function.d.ts +6 -2
- package/lib/utils/function.js +20 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [0.9.
|
|
6
|
+
## [0.9.6](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.5...@gmcb/cli@0.9.6) (2026-11-04)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @gmcb/cli
|
|
9
9
|
|
|
@@ -11,18 +11,35 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
## [0.9.
|
|
14
|
+
## [0.9.5](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.4...@gmcb/cli@0.9.5) (2026-11-04)
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
### Bug Fixes
|
|
18
|
-
|
|
19
|
-
* 合并 CLI 调整(image/config 命令、gradlew 构建流程与 uni-app x 路由) ([4e1734b](http://10.10.10.16/caoben/front-end-tools/commits/4e1734b7ae1ec0c3f2a910c27d9220f1ea7010ec))
|
|
16
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
20
17
|
|
|
21
18
|
|
|
22
19
|
|
|
23
20
|
|
|
24
21
|
|
|
25
22
|
|
|
23
|
+
## [0.9.4](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.3...@gmcb/cli@0.9.4) (2026-11-04)
|
|
24
|
+
|
|
25
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## [0.9.3](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.2...@gmcb/cli@0.9.3) (2026-11-04)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* 合并 CLI 调整(image/config 命令、gradlew 构建流程与 uni-app x 路由) ([4e1734b](http://10.10.10.16/caoben/front-end-tools/commits/4e1734b7ae1ec0c3f2a910c27d9220f1ea7010ec))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
26
43
|
## [0.9.2](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.1...@gmcb/cli@0.9.2) (2026-11-02)
|
|
27
44
|
|
|
28
45
|
**Note:** Version bump only for package @gmcb/cli
|
package/lib/actions/build.js
CHANGED
|
@@ -37,7 +37,6 @@ const https_1 = __importDefault(require("https"));
|
|
|
37
37
|
const http_1 = __importDefault(require("http"));
|
|
38
38
|
const fs_extra_1 = require("fs-extra");
|
|
39
39
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
40
|
-
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
41
40
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
42
41
|
const ora_1 = __importDefault(require("ora"));
|
|
43
42
|
const delay_1 = __importDefault(require("delay"));
|
|
@@ -77,7 +76,7 @@ async function syncLatestVersion() {
|
|
|
77
76
|
const hasPackage = (0, fs_1.existsSync)(utils_1.PACKAGE_PATH);
|
|
78
77
|
const pkg = hasPackage ? (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH) : {};
|
|
79
78
|
const manifest = (0, utils_1.readManifest)();
|
|
80
|
-
const appId = pkg.appId ||
|
|
79
|
+
const appId = pkg.appId || manifest.appid;
|
|
81
80
|
if (!appId) {
|
|
82
81
|
spinner.warn('未在 package.json 或 manifest.json 中找到 appId/appid,跳过版本号同步');
|
|
83
82
|
return;
|
|
@@ -122,7 +121,6 @@ async function getCommands(...args) {
|
|
|
122
121
|
if (opts.platform === 'web') {
|
|
123
122
|
opts.platform = 'h5';
|
|
124
123
|
}
|
|
125
|
-
const isUniappX = (0, utils_1.isUniappXManifest)();
|
|
126
124
|
if (config_1.CONFIG_DATA.branch && config_1.CONFIG_DATA.branch !== 'false') {
|
|
127
125
|
opts.branch = config_1.CONFIG_DATA.branch;
|
|
128
126
|
}
|
|
@@ -152,6 +150,21 @@ async function getCommands(...args) {
|
|
|
152
150
|
const currentName = (0, path_1.basename)(utils_1.COMMAND_PATH);
|
|
153
151
|
const projectName = opts.project || currentName;
|
|
154
152
|
if (opts.compiler === 'uni') {
|
|
153
|
+
let projectPath = utils_1.COMMAND_PATH;
|
|
154
|
+
if (projectName !== currentName) {
|
|
155
|
+
if (opts.source) {
|
|
156
|
+
projectPath = (0, path_1.join)(utils_1.COMMAND_PATH, opts.source);
|
|
157
|
+
}
|
|
158
|
+
envPath = (0, path_1.join)(projectPath, 'buildenv');
|
|
159
|
+
if (opts.source && opts.branch) {
|
|
160
|
+
const git = (0, simple_git_1.default)(projectPath);
|
|
161
|
+
const branch = await git.branch();
|
|
162
|
+
if (opts.branch !== branch.current) {
|
|
163
|
+
utils_1.log.error(`您当前构建分支为“${opts.branch}”,项目“${projectName}”构建分支为“${branch.current}”,分支不一致,无法完成构建,请更改后重试!`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const isUniappX = (0, utils_1.isUniappXManifest)(projectPath);
|
|
155
168
|
const isUniappXApp = isUniappX && opts.platform.startsWith('app');
|
|
156
169
|
// 无 src、uni-app x 的 App 平台、-P 指定了不同的 HBuilderX 项目名时都必须由 HBuilderX 构建,统一归一到 opts.pack
|
|
157
170
|
if (!utils_1.HAS_SRC || isUniappXApp || projectName !== currentName) {
|
|
@@ -167,17 +180,6 @@ async function getCommands(...args) {
|
|
|
167
180
|
if (!(0, fs_1.existsSync)(utils_1.PACKAGE_PATH)) {
|
|
168
181
|
commands = [];
|
|
169
182
|
}
|
|
170
|
-
if (projectName !== currentName) {
|
|
171
|
-
const sourcePath = opts.source ? (0, path_1.join)(utils_1.COMMAND_PATH, opts.source) : utils_1.COMMAND_PATH;
|
|
172
|
-
envPath = (0, path_1.join)(sourcePath, 'buildenv');
|
|
173
|
-
if (opts.source && opts.branch) {
|
|
174
|
-
const git = (0, simple_git_1.default)(sourcePath);
|
|
175
|
-
const branch = await git.branch();
|
|
176
|
-
if (opts.branch !== branch.current) {
|
|
177
|
-
utils_1.log.error(`您当前构建分支为“${opts.branch}”,项目“${projectName}”构建分支为“${branch.current}”,分支不一致,无法完成构建,请更改后重试!`);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
183
|
let cmds = [];
|
|
182
184
|
if (buildEnv) {
|
|
183
185
|
(0, fs_extra_1.ensureFileSync)(envPath);
|
|
@@ -201,7 +203,7 @@ async function getCommands(...args) {
|
|
|
201
203
|
}
|
|
202
204
|
const wgtDist = app.wgt[index + 1];
|
|
203
205
|
(0, fs_extra_1.ensureDirSync)(wgtDist);
|
|
204
|
-
const manifest =
|
|
206
|
+
const manifest = (0, utils_1.readManifest)(projectPath);
|
|
205
207
|
if (manifest.appid) {
|
|
206
208
|
(0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
|
|
207
209
|
}
|
|
@@ -238,7 +240,7 @@ async function getCommands(...args) {
|
|
|
238
240
|
}
|
|
239
241
|
else if (opts.platform.startsWith('mp')) {
|
|
240
242
|
const mp = platform.mp();
|
|
241
|
-
const manifest =
|
|
243
|
+
const manifest = (0, utils_1.readManifest)(projectPath);
|
|
242
244
|
const appid = manifest[opts.platform]?.appid;
|
|
243
245
|
cmds = [
|
|
244
246
|
'publish',
|
|
@@ -256,7 +258,8 @@ async function getCommands(...args) {
|
|
|
256
258
|
utils_1.log.error(`不支持的平台:${opts.platform}`);
|
|
257
259
|
}
|
|
258
260
|
if (cmds) {
|
|
259
|
-
|
|
261
|
+
// HBuilderX CLI 的 --project 支持绝对路径:统一传工程目录(--source 时为源码工程目录),无需先 project open
|
|
262
|
+
commands = [...commands, config_1.CONFIG_DATA?.cli?.hbuilderx, ...cmds, '--project', projectPath];
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
}
|
|
@@ -367,57 +370,32 @@ function downloadFile(url, dest) {
|
|
|
367
370
|
.on('error', rej);
|
|
368
371
|
});
|
|
369
372
|
}
|
|
370
|
-
/**
|
|
371
|
-
* 调用 HBuilderX CLI 对 .repo 工程执行 project open/close
|
|
372
|
-
* - open 用于让 HBuilderX 加载最新的 manifest.json / package.json
|
|
373
|
-
* - close 用于构建后释放项目
|
|
374
|
-
* 错误在本函数内处理:open 失败提示并退出,close 失败仅告警
|
|
375
|
-
*/
|
|
376
|
-
function runHBuilderXProject(action, repoDir) {
|
|
377
|
-
const hbuilderxCli = config_1.CONFIG_DATA?.cli?.hbuilderx;
|
|
378
|
-
if (!hbuilderxCli) {
|
|
379
|
-
utils_1.log.error('HbuilderX Cli路径不正确,请执行“gmcb config --cli.hbuilderx <cli-path>”设置正确的路径!');
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
try {
|
|
383
|
-
(0, child_process_1.execSync)(`"${hbuilderxCli}" project ${action} --path "${repoDir}"`, { cwd: repoDir, stdio: 'inherit' });
|
|
384
|
-
}
|
|
385
|
-
catch (err) {
|
|
386
|
-
const message = err?.message || String(err);
|
|
387
|
-
if (action === 'open') {
|
|
388
|
-
utils_1.log.error(`打开 HBuilderX 项目失败:${message}`);
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
utils_1.log.warning(`关闭 HBuilderX 项目失败:${message}`);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
373
|
async function pullRemoteResources(opts) {
|
|
396
374
|
const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
|
|
397
375
|
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
398
376
|
const appId = pkg.appId;
|
|
399
|
-
//
|
|
377
|
+
// 获取应用信息
|
|
400
378
|
const appInfo = await (0, apis_1.getAppInfo)(appId);
|
|
401
379
|
const { appName, iconUrl, configJson } = appInfo;
|
|
402
|
-
//
|
|
380
|
+
// 确定仓库地址
|
|
403
381
|
const repoUrl = configJson.repo || config_1.CONFIG_DATA.pull?.repo;
|
|
404
|
-
//
|
|
382
|
+
// 确定分支:使用 buildEnv,默认 master;prod 对应 master 分支
|
|
405
383
|
const buildEnv = process.env.BUILD_ENV;
|
|
406
384
|
const branch = buildEnv.startsWith('pro') || !buildEnv ? 'master' : buildEnv;
|
|
407
|
-
//
|
|
385
|
+
// 拉取代码到 COMMAND_PATH/.repo/{appId}
|
|
408
386
|
const repoDir = (0, path_1.join)(utils_1.COMMAND_PATH, '.repo', appId);
|
|
409
387
|
if ((0, fs_1.existsSync)((0, path_1.join)(repoDir, '.git'))) {
|
|
410
388
|
try {
|
|
411
389
|
// 已有目录:fetch 目标分支 + 校验远程分支 + 切换 + pull
|
|
412
390
|
const repoGit = (0, simple_git_1.default)(repoDir);
|
|
413
|
-
//
|
|
391
|
+
// 撤销上次构建残留的本地修改,防止拉取冲突
|
|
414
392
|
await repoGit.reset(['--hard']);
|
|
415
|
-
//
|
|
416
|
-
//
|
|
393
|
+
// 拉取目标分支(显式指定,不受 --single-branch refspec 限制)
|
|
394
|
+
// --prune 确保远程已删除的分支不会残留在本地引用中
|
|
417
395
|
await repoGit.fetch('origin', `+refs/heads/${branch}:refs/remotes/origin/${branch}`, ['--prune']);
|
|
418
|
-
//
|
|
396
|
+
// 切换分支:-B 强制创建/重置本地分支指向 origin/{branch}
|
|
419
397
|
await repoGit.checkout(['-B', branch, `origin/${branch}`, '-f']);
|
|
420
|
-
//
|
|
398
|
+
// 拉取最新代码
|
|
421
399
|
await repoGit.pull('origin', branch);
|
|
422
400
|
}
|
|
423
401
|
catch (err) {
|
|
@@ -436,14 +414,17 @@ async function pullRemoteResources(opts) {
|
|
|
436
414
|
}
|
|
437
415
|
}
|
|
438
416
|
spinner.stop();
|
|
439
|
-
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
417
|
+
const manifestPath = (0, utils_1.getManifestPath)(repoDir);
|
|
418
|
+
const repoManifest = (0, utils_1.readManifest)(repoDir);
|
|
419
|
+
const isUniappX = (0, utils_1.isUniappXManifest)(repoManifest);
|
|
420
|
+
if (manifestPath) {
|
|
421
|
+
let manifestContent = (0, utils_1.readManifest)(repoDir, false);
|
|
422
|
+
manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name": "${appName}"`);
|
|
423
|
+
manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${pkg.version}"`);
|
|
424
|
+
manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode": ${pkg.versionCode}`);
|
|
425
|
+
(0, fs_1.writeFileSync)(manifestPath, manifestContent);
|
|
426
|
+
}
|
|
427
|
+
// 修改仓库 package.json scripts
|
|
447
428
|
const repoPkgPath = (0, path_1.join)(repoDir, 'package.json');
|
|
448
429
|
const repoPkg = (0, fs_extra_1.readJsonSync)(repoPkgPath);
|
|
449
430
|
if (!repoPkg.scripts)
|
|
@@ -453,13 +434,19 @@ async function pullRemoteResources(opts) {
|
|
|
453
434
|
repoPkg.scripts['copy:h5'] = 'gmcb copy -s ./dist/build/h5 -d ../../out/renderer/{package.appId}/ --clean';
|
|
454
435
|
}
|
|
455
436
|
if (opts.compiler === 'gradlew') {
|
|
456
|
-
|
|
457
|
-
'
|
|
437
|
+
if (isUniappX) {
|
|
438
|
+
repoPkg.scripts['copy:android'] =
|
|
439
|
+
'gmcb copy -s ./unpackage/resources/app-android/{manifest.appid} -d ../../app/src/main/assets/apps/{manifest.appid}/ --clean';
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
repoPkg.scripts['copy:android'] =
|
|
443
|
+
'gmcb copy -s ./dist/build/app -d ../../app/src/main/assets/apps/{manifest.appid}/www/ --clean';
|
|
444
|
+
}
|
|
458
445
|
}
|
|
459
446
|
(0, fs_extra_1.writeJsonSync)(repoPkgPath, repoPkg, { spaces: 2 });
|
|
460
|
-
//
|
|
447
|
+
// 执行 npm install
|
|
461
448
|
(0, child_process_1.execSync)('npm install', { cwd: repoDir, stdio: 'inherit' });
|
|
462
|
-
//
|
|
449
|
+
// 构建 + 拷贝 + 修改主项目配置(根据 compiler 类型)
|
|
463
450
|
if (opts.compiler === 'electron-vite') {
|
|
464
451
|
// 构建 H5 并拷贝
|
|
465
452
|
(0, child_process_1.execSync)(`npm run build:h5:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
|
|
@@ -482,10 +469,7 @@ async function pullRemoteResources(opts) {
|
|
|
482
469
|
}
|
|
483
470
|
}
|
|
484
471
|
if (opts.compiler === 'gradlew') {
|
|
485
|
-
// 构建 App 并拷贝:构建前 open 让 HBuilderX 加载最新工程信息,构建后 close
|
|
486
|
-
runHBuilderXProject('open', repoDir);
|
|
487
472
|
(0, child_process_1.execSync)(`npm run build:android:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
|
|
488
|
-
runHBuilderXProject('close', repoDir);
|
|
489
473
|
(0, child_process_1.execSync)('npm run copy:android', { cwd: repoDir, stdio: 'inherit' });
|
|
490
474
|
// 修改主项目 strings.xml 中的应用名称
|
|
491
475
|
const stringsPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
|
|
@@ -512,9 +496,8 @@ async function pullRemoteResources(opts) {
|
|
|
512
496
|
(0, fs_1.copyFileSync)(iconPath, pushPath);
|
|
513
497
|
}
|
|
514
498
|
}
|
|
515
|
-
//
|
|
499
|
+
// updateMode=2 时打包资源为 zip/wgt
|
|
516
500
|
if (config_1.CONFIG_DATA.publish?.updateMode == 2) {
|
|
517
|
-
const repoManifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)((0, path_1.join)(repoDir, 'src', 'manifest.json'), 'utf-8')));
|
|
518
501
|
const releaseDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'unpackage', 'release');
|
|
519
502
|
(0, fs_extra_1.ensureDirSync)(releaseDir);
|
|
520
503
|
if (opts.compiler === 'electron-vite') {
|
package/lib/scripts/wgt-apk.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.default = default_1;
|
|
7
4
|
const fs_1 = require("fs");
|
|
8
5
|
const path_1 = require("path");
|
|
9
6
|
const fs_extra_1 = require("fs-extra");
|
|
10
|
-
const
|
|
11
|
-
const const_1 = require("../utils/const");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
12
8
|
const publish_1 = require("./publish");
|
|
13
9
|
async function default_1() {
|
|
14
|
-
const pkg = (0, fs_extra_1.readJsonSync)(
|
|
15
|
-
const repoManifest =
|
|
16
|
-
const gradleContent = (0, fs_1.readFileSync)((0, path_1.join)(
|
|
10
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
11
|
+
const repoManifest = (0, utils_1.readManifest)((0, path_1.join)(utils_1.COMMAND_PATH, '.repo', pkg.appId));
|
|
12
|
+
const gradleContent = (0, fs_1.readFileSync)((0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle'), 'utf-8');
|
|
17
13
|
const versionName = gradleContent.match(/versionName\s+"([^"]*)"/)?.[1];
|
|
18
14
|
const versionCode = gradleContent.match(/versionCode\s+(\d+)/)?.[1];
|
|
19
15
|
await (0, publish_1.publish)({
|
package/lib/scripts/zip-exe.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.default = default_1;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
4
|
const path_1 = require("path");
|
|
9
5
|
const fs_extra_1 = require("fs-extra");
|
|
10
|
-
const
|
|
11
|
-
const const_1 = require("../utils/const");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
12
7
|
const publish_1 = require("./publish");
|
|
13
8
|
async function default_1() {
|
|
14
|
-
const pkg = (0, fs_extra_1.readJsonSync)(
|
|
15
|
-
const repoManifest =
|
|
9
|
+
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
10
|
+
const repoManifest = (0, utils_1.readManifest)((0, path_1.join)(utils_1.COMMAND_PATH, '.repo', pkg.appId));
|
|
16
11
|
await (0, publish_1.publish)({
|
|
17
12
|
files: [
|
|
18
13
|
{ ext: 'zip', name: repoManifest.appid, path: 'unpackage/release' },
|
package/lib/utils/function.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/** 工程 manifest 实际路径:src/manifest.json 优先,其次根目录;不存在返回 undefined */
|
|
2
|
+
export declare function getManifestPath(path?: string): string | undefined;
|
|
3
|
+
export declare function readManifest(path?: string): Record<string, unknown>;
|
|
4
|
+
export declare function readManifest(path: string | undefined, parse: false): string;
|
|
2
5
|
/**
|
|
3
6
|
* 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
|
|
7
|
+
* @param pathOrManifest 工程目录(自动读取 manifest.json)或已解析的 manifest 对象
|
|
4
8
|
*/
|
|
5
|
-
export declare function isUniappXManifest(
|
|
9
|
+
export declare function isUniappXManifest(pathOrManifest?: string | Record<string, unknown>): boolean;
|
|
6
10
|
export declare function objectToCommand(obj?: Record<string, any>): {};
|
|
7
11
|
export declare function filterToArray(obj?: Record<string, any>): any[];
|
|
8
12
|
export declare function spawnSync(command?: string): import("child_process").SpawnSyncReturns<Buffer>;
|
package/lib/utils/function.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getManifestPath = getManifestPath;
|
|
6
7
|
exports.readManifest = readManifest;
|
|
7
8
|
exports.isUniappXManifest = isUniappXManifest;
|
|
8
9
|
exports.objectToCommand = objectToCommand;
|
|
@@ -18,19 +19,29 @@ const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
|
18
19
|
const flat_1 = require("flat");
|
|
19
20
|
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
20
21
|
const const_1 = require("./const");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
/** 工程 manifest 实际路径:src/manifest.json 优先,其次根目录;不存在返回 undefined */
|
|
23
|
+
function getManifestPath(path = const_1.COMMAND_PATH) {
|
|
24
|
+
const candidates = [(0, path_1.join)(path, 'src', 'manifest.json'), (0, path_1.join)(path, 'manifest.json')];
|
|
25
|
+
return candidates.find((p) => (0, fs_1.existsSync)(p));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 读取指定工程目录的 manifest.json
|
|
29
|
+
* @param path 工程目录,默认当前工程
|
|
30
|
+
* @param parse 是否解析为对象(默认 true);false 时返回原始文本(保留注释,便于回写),文件不存在时返回空字符串
|
|
31
|
+
*/
|
|
32
|
+
function readManifest(path = const_1.COMMAND_PATH, parse = true) {
|
|
33
|
+
const manifestPath = getManifestPath(path);
|
|
34
|
+
if (!manifestPath)
|
|
35
|
+
return parse ? {} : '';
|
|
36
|
+
const content = (0, fs_1.readFileSync)(manifestPath, 'utf-8');
|
|
37
|
+
return parse ? JSON.parse((0, strip_json_comments_1.default)(content)) : content;
|
|
29
38
|
}
|
|
30
39
|
/**
|
|
31
40
|
* 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
|
|
41
|
+
* @param pathOrManifest 工程目录(自动读取 manifest.json)或已解析的 manifest 对象
|
|
32
42
|
*/
|
|
33
|
-
function isUniappXManifest(
|
|
43
|
+
function isUniappXManifest(pathOrManifest = const_1.COMMAND_PATH) {
|
|
44
|
+
const manifest = typeof pathOrManifest === 'string' ? readManifest(pathOrManifest) : pathOrManifest;
|
|
34
45
|
return Object.prototype.hasOwnProperty.call(manifest, 'uni-app-x');
|
|
35
46
|
}
|
|
36
47
|
function objectToCommand(obj = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmcb/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "工茂草本前端命令行工具",
|
|
5
5
|
"author": "yinjiazeng@163.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"@types/rimraf": "^4.0.5",
|
|
59
59
|
"@types/user-home": "^2.0.2"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "2dd2ec551cda9a22e709e05f6e3ad5803551d762"
|
|
62
62
|
}
|