This commit is contained in:
parent
97614a9079
commit
d93316be15
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
build.json
|
build.json
|
||||||
kit/.kit/modules/*
|
kit/.kit/modules/*
|
||||||
|
kit/publish/*
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
"bin": "src/index.js",
|
"bin": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun src/index.js",
|
"test": "bun src/index.js",
|
||||||
|
"publish": "node publish.js",
|
||||||
"linux": "bun build.js && bun build ./src/index.js --compile --bytecode --minify --target=bun-linux-x64-baseline --outfile=./dist/linux/kit",
|
"linux": "bun build.js && bun build ./src/index.js --compile --bytecode --minify --target=bun-linux-x64-baseline --outfile=./dist/linux/kit",
|
||||||
"windows": "bun build.js && bun build ./src/index.js --compile --bytecode --minify --target=bun-windows-x64-baseline --outfile=./dist/windows/kit.exe",
|
"windows": "bun build.js && bun build ./src/index.js --compile --bytecode --minify --target=bun-windows-x64-baseline --outfile=./dist/windows/kit.exe",
|
||||||
"pkg-alpine": "bun build.js && pkg --compress GZip . -t node14-alpine-arm64 -o ./dist/alpine/kit",
|
"pkg-alpine": "bun build.js && pkg --compress GZip . -t node14-alpine-arm64 -o ./dist/alpine/kit",
|
||||||
@ -27,3 +28,4 @@
|
|||||||
"webdav": "^5.3.1"
|
"webdav": "^5.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
116
kit/publish.js
Normal file
116
kit/publish.js
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const { spawnSync } = require('child_process');
|
||||||
|
const JSON5 = require('json5');
|
||||||
|
|
||||||
|
const root = __dirname;
|
||||||
|
const publishDir = path.resolve(root, 'publish');
|
||||||
|
const artifacts = [
|
||||||
|
{
|
||||||
|
script: 'pkg-windows',
|
||||||
|
source: path.resolve(root, 'dist/windows/kit.exe'),
|
||||||
|
target: path.resolve(publishDir, 'windows/x86_64/kit.exe'),
|
||||||
|
localPath: 'publish/windows/x86_64/kit.exe',
|
||||||
|
os: 'windows',
|
||||||
|
arch: 'x86_64',
|
||||||
|
filename: 'kit.exe'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
script: 'pkg-linux',
|
||||||
|
source: path.resolve(root, 'dist/linux/kit'),
|
||||||
|
target: path.resolve(publishDir, 'linux/x86_64/kit'),
|
||||||
|
localPath: 'publish/linux/x86_64/kit',
|
||||||
|
os: 'linux',
|
||||||
|
arch: 'x86_64',
|
||||||
|
filename: 'kit'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
function run(command, args) {
|
||||||
|
console.log(`> ${command} ${args.join(' ')}`);
|
||||||
|
const result = spawnSync(command, args, {
|
||||||
|
cwd: root,
|
||||||
|
stdio: 'inherit',
|
||||||
|
shell: process.platform === 'win32'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
throw result.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status !== 0) {
|
||||||
|
process.exit(result.status || 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readJson(file) {
|
||||||
|
return JSON5.parse(fs.readFileSync(file, 'utf-8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function readPackage() {
|
||||||
|
return readJson(path.resolve(root, 'package.json'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function readSourceMeta() {
|
||||||
|
const candidates = [
|
||||||
|
path.resolve(root, 'meta.json'),
|
||||||
|
path.resolve(root, '..', 'meta.json')
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const file of candidates) {
|
||||||
|
if (fs.existsSync(file)) {
|
||||||
|
return readJson(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyFile(source, target) {
|
||||||
|
if (!fs.existsSync(source)) {
|
||||||
|
throw new Error(`Build artifact not found: ${source}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
||||||
|
fs.copyFileSync(source, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeMeta() {
|
||||||
|
const pkg = readPackage();
|
||||||
|
const sourceMeta = readSourceMeta();
|
||||||
|
const meta = {
|
||||||
|
id: sourceMeta.id || pkg.name || 'kit',
|
||||||
|
name: sourceMeta.name || pkg.name || 'kit',
|
||||||
|
desc: sourceMeta.desc || sourceMeta.description || '',
|
||||||
|
group: sourceMeta.group || '/modules',
|
||||||
|
dist: artifacts.map((artifact) => ({
|
||||||
|
path: artifact.localPath,
|
||||||
|
os: artifact.os,
|
||||||
|
arch: artifact.arch,
|
||||||
|
filename: artifact.filename,
|
||||||
|
type: 'executable'
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.mkdirSync(publishDir, { recursive: true });
|
||||||
|
fs.writeFileSync(path.resolve(publishDir, 'meta.json'), JSON.stringify(meta, null, 4), 'utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
function preparePublishDir() {
|
||||||
|
fs.rmSync(publishDir, { recursive: true, force: true });
|
||||||
|
|
||||||
|
for (const artifact of artifacts) {
|
||||||
|
copyFile(artifact.source, artifact.target);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const artifact of artifacts) {
|
||||||
|
run('npm', ['run', artifact.script]);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparePublishDir();
|
||||||
|
run('kit3', ['publish', './publish']);
|
||||||
|
|
||||||
|
console.log('Publish completed.');
|
||||||
@ -172,7 +172,7 @@ parser.addCmdLine("freem [level]", "释放内存", function (cli) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
parser.addCmdLine("docker runsh <container> [--file]", "反向获取 docker 容器启动脚本", function (cli) {
|
parser.addCmdLine("dockersh <container> [--file]", "反向获取 docker 容器启动脚本", function (cli) {
|
||||||
let container = cli.getParamValue("container")
|
let container = cli.getParamValue("container")
|
||||||
let file = cli.getParamValue("file")
|
let file = cli.getParamValue("file")
|
||||||
import("./docker/index.js").then(psl => psl.main(container, file))
|
import("./docker/index.js").then(psl => psl.main(container, file))
|
||||||
|
|||||||
@ -144,6 +144,7 @@ async function main(){
|
|||||||
}
|
}
|
||||||
await remote.publish(localFile, remotePath);
|
await remote.publish(localFile, remotePath);
|
||||||
$logger.info("发布成功");
|
$logger.info("发布成功");
|
||||||
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.addCmdLine("install [module]", "安装/更新模块; 支持 myapp、myapp@1.0、/docker/net/myapp", async function (cli) {
|
parser.addCmdLine("install [module]", "安装/更新模块; 支持 myapp、myapp@1.0、/docker/net/myapp", async function (cli) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user