@hlw-midway/plugin-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.
- package/README.md +0 -0
- package/package.json +35 -0
- package/scripts/build.js +47 -0
- package/scripts/index.js +12 -0
- package/scripts/release.js +48 -0
package/README.md
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hlw-midway/plugin-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "hlw-admin midway plugin",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"hlw",
|
|
11
|
+
"hlw-admin"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://www.baidu.com"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"hlw-plugin-cli": "scripts/index.js"
|
|
19
|
+
},
|
|
20
|
+
"author": "HLW",
|
|
21
|
+
"readme": "README.md",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@hlw-midway/cache-manager-fs-hash": "file:../cache-manager-fs-hash",
|
|
25
|
+
"@midwayjs/cache-manager": "^3.20.3",
|
|
26
|
+
"@midwayjs/core": "^3.20.3",
|
|
27
|
+
"archiver": "^7.0.1",
|
|
28
|
+
"esbuild": "^0.25.0",
|
|
29
|
+
"esbuild-plugin-copy": "^2.1.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^22.13.9",
|
|
33
|
+
"typescript": "^5.8.2"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/scripts/build.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
console.log("hlw-plugin-cli run build");
|
|
2
|
+
|
|
3
|
+
const esbuild = require('esbuild');
|
|
4
|
+
const copyPlugin = require('esbuild-plugin-copy').default;
|
|
5
|
+
const packageJson = require('../package.json');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
const projectRoot = process.cwd();
|
|
10
|
+
|
|
11
|
+
// 输出目录
|
|
12
|
+
const outdir = path.join(projectRoot, 'dist');
|
|
13
|
+
|
|
14
|
+
// 删除 dist 目录
|
|
15
|
+
if (fs.existsSync(outdir)) {
|
|
16
|
+
fs.rmdirSync(outdir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 构建
|
|
20
|
+
module.exports.result = esbuild.build({
|
|
21
|
+
entryPoints: [path.join(projectRoot, 'src', 'index.ts'), path.join(projectRoot, 'test', 'index.ts')],
|
|
22
|
+
external: Object.keys(packageJson.devDependencies),
|
|
23
|
+
bundle: true,
|
|
24
|
+
platform: 'node',
|
|
25
|
+
outdir,
|
|
26
|
+
plugins: [
|
|
27
|
+
copyPlugin({
|
|
28
|
+
assets: [{
|
|
29
|
+
from: ['./README.md'],
|
|
30
|
+
to: ['./README.md']
|
|
31
|
+
},{
|
|
32
|
+
from: ['./package.json'],
|
|
33
|
+
to: ['./package.json']
|
|
34
|
+
},{
|
|
35
|
+
from: ['./plugin.json'],
|
|
36
|
+
to: ['./plugin.json']
|
|
37
|
+
},{
|
|
38
|
+
from: ['./assets/*'],
|
|
39
|
+
to: ['./assets']
|
|
40
|
+
},{
|
|
41
|
+
from: ['./src/*'],
|
|
42
|
+
to: ['./source']
|
|
43
|
+
}]
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
}).catch(() => process.exit(1));
|
|
47
|
+
|
package/scripts/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
console.log("hlw-plugin-cli run release");
|
|
2
|
+
|
|
3
|
+
const projectRoot = process.cwd();
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const archiver = require('archiver');
|
|
8
|
+
const pluginJson = require(path.join(projectRoot, 'plugin.json'));
|
|
9
|
+
|
|
10
|
+
const packFolder = (folderPath, outputPath) => {
|
|
11
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
12
|
+
// 创建文件写入流
|
|
13
|
+
const output = fs.createWriteStream(outputPath);
|
|
14
|
+
const archive = archiver('zip', {
|
|
15
|
+
zlib: { level: 9 } // 设置压缩级别
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// 监听关闭事件
|
|
19
|
+
output.on('close', function() {
|
|
20
|
+
console.log(`hlw plugin package successfully. Total size: ${archive.pointer()} bytes`);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// 监听错误事件
|
|
24
|
+
archive.on('error', function(err) {
|
|
25
|
+
throw err;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// 将压缩内容流连接到文件写入流
|
|
29
|
+
archive.pipe(output);
|
|
30
|
+
|
|
31
|
+
// 添加文件夹
|
|
32
|
+
archive.directory(folderPath, false);
|
|
33
|
+
|
|
34
|
+
// 完成归档
|
|
35
|
+
archive.finalize();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 打包
|
|
39
|
+
const folderPath = path.join(projectRoot, 'dist'); // 替换为你的文件夹路径
|
|
40
|
+
const outputPath = path.join(projectRoot, 'release', `${pluginJson.name}_v${pluginJson.version}.hlw`); // 替换为你希望创建的 .hlw 文件路径
|
|
41
|
+
|
|
42
|
+
const { result } = require('./build.js');
|
|
43
|
+
|
|
44
|
+
result.then(()=>{
|
|
45
|
+
packFolder(folderPath, outputPath);
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
|