@tomjs/hbuilderx-cli 1.1.0 → 1.2.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/dist/index.js +15 -9
- package/dist/types.d.ts +38 -0
- package/dist/types.js +1 -0
- package/package.json +9 -2
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { cosmiconfig } from "cosmiconfig";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { mkdirp, readJson, writeFile } from "@tomjs/node";
|
|
7
7
|
import archiver from "archiver";
|
|
8
|
+
import { glob } from "glob";
|
|
8
9
|
import colors from "picocolors";
|
|
9
10
|
import Logger from "@tomjs/logger";
|
|
10
11
|
import chokidar from "chokidar";
|
|
@@ -40,12 +41,6 @@ function setOptions(opts) {
|
|
|
40
41
|
//#endregion
|
|
41
42
|
//#region src/pack.ts
|
|
42
43
|
async function packExtension(opts) {
|
|
43
|
-
const packFiles = Array.isArray(opts.packFiles) ? opts.packFiles : [
|
|
44
|
-
"dist",
|
|
45
|
-
"package.json",
|
|
46
|
-
"license"
|
|
47
|
-
];
|
|
48
|
-
if (!packFiles.includes("package.json")) packFiles.push("package.json");
|
|
49
44
|
const cwd = opts.cwd || process.cwd();
|
|
50
45
|
const pkgPath = path.join(cwd, "package.json");
|
|
51
46
|
if (!fs.existsSync(pkgPath)) {
|
|
@@ -53,12 +48,23 @@ async function packExtension(opts) {
|
|
|
53
48
|
return;
|
|
54
49
|
}
|
|
55
50
|
const pkg = await readJson(pkgPath);
|
|
56
|
-
if (!
|
|
51
|
+
if (!checkPackageFields(pkg)) return;
|
|
57
52
|
const mainFile = path.join(cwd, pkg.main);
|
|
58
53
|
if (!fs.existsSync(mainFile)) {
|
|
59
54
|
logger.error(`未找到 ${colors.bold("package.json")} 中 ${colors.bold("main")} 字段值路径: ${colors.green(mainFile)}`);
|
|
60
55
|
return;
|
|
61
56
|
}
|
|
57
|
+
const packFilters = Array.isArray(pkg.files) && pkg.files.length ? pkg.files : [
|
|
58
|
+
"dist",
|
|
59
|
+
"resources",
|
|
60
|
+
"package.json",
|
|
61
|
+
"LICENSE"
|
|
62
|
+
];
|
|
63
|
+
const pkgFiles = await glob(packFilters.filter((s) => !s.startsWith("!")), {
|
|
64
|
+
cwd,
|
|
65
|
+
ignore: packFilters.filter((s) => s.startsWith("!")).map((s) => s.slice(1)).concat(["node_modules/**"])
|
|
66
|
+
});
|
|
67
|
+
console.log(pkgFiles);
|
|
62
68
|
logger.info(`${colors.blue(pkg.name)} 插件打包开始`);
|
|
63
69
|
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
64
70
|
archive.on("error", (err) => {
|
|
@@ -74,7 +80,7 @@ async function packExtension(opts) {
|
|
|
74
80
|
});
|
|
75
81
|
const output = fs.createWriteStream(path.join(cwd, `${pkg.name}.zip`));
|
|
76
82
|
archive.pipe(output);
|
|
77
|
-
|
|
83
|
+
pkgFiles.forEach((file) => {
|
|
78
84
|
const filePath = path.join(cwd, file);
|
|
79
85
|
if (!fs.existsSync(filePath)) return;
|
|
80
86
|
if (fs.lstatSync(filePath).isDirectory()) archive.directory(filePath, file);
|
|
@@ -82,7 +88,7 @@ async function packExtension(opts) {
|
|
|
82
88
|
});
|
|
83
89
|
archive.finalize();
|
|
84
90
|
}
|
|
85
|
-
function
|
|
91
|
+
function checkPackageFields(pkg) {
|
|
86
92
|
if (!pkg) {
|
|
87
93
|
logger.error("package.json 文件格式错误");
|
|
88
94
|
return false;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* cli 参数
|
|
4
|
+
*/
|
|
5
|
+
interface CliOptions {
|
|
6
|
+
/**
|
|
7
|
+
* 监听文件变化
|
|
8
|
+
*/
|
|
9
|
+
watch?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 打包插件,根据 package.json 中的 files 字段打包,如果未设置,默认取 dist,resources,package.json,LICENSE 文件夹或文件。
|
|
12
|
+
*/
|
|
13
|
+
pack?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 当前工作目录/根目录
|
|
16
|
+
*/
|
|
17
|
+
cwd?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 配置文件
|
|
20
|
+
*/
|
|
21
|
+
config?: string;
|
|
22
|
+
/**
|
|
23
|
+
* 生成 d.ts 文件路径
|
|
24
|
+
* @default 'hbuilderx.d.ts'
|
|
25
|
+
*/
|
|
26
|
+
dts?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 添加到生成的 d.ts 中的命令,如用到的内置命令
|
|
29
|
+
*/
|
|
30
|
+
commands?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* verbose 模式
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
verbose?: boolean;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { CliOptions };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/hbuilderx-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"description": "为 HBuilderX 开发插件提供便利的 cli 工具,根据 package.json 中的 contributes 配置,为 hbuilderx 的命令、视图等 API 提供 id 提示",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Tom Gao",
|
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
"extension",
|
|
20
20
|
"webview"
|
|
21
21
|
],
|
|
22
|
+
"exports": {
|
|
23
|
+
"./types": {
|
|
24
|
+
"types": "./dist/types.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"types": "./dist/types.d.ts",
|
|
22
28
|
"bin": {
|
|
23
29
|
"hx-cli": "./dist/index.js"
|
|
24
30
|
},
|
|
@@ -34,6 +40,7 @@
|
|
|
34
40
|
"archiver": "^7.0.1",
|
|
35
41
|
"chokidar": "^5.0.0",
|
|
36
42
|
"cosmiconfig": "^9.0.0",
|
|
43
|
+
"glob": "^13.0.0",
|
|
37
44
|
"meow": "^14.0.0",
|
|
38
45
|
"picocolors": "^1.1.1"
|
|
39
46
|
},
|
|
@@ -42,7 +49,7 @@
|
|
|
42
49
|
},
|
|
43
50
|
"scripts": {
|
|
44
51
|
"dev": "tsdown --watch",
|
|
45
|
-
"build": "tsdown",
|
|
52
|
+
"build": "rimraf ./dist && tsdown",
|
|
46
53
|
"lint": "eslint --fix"
|
|
47
54
|
}
|
|
48
55
|
}
|