Compare commits

...

3 Commits

Author SHA1 Message Date
Cheney
5ff621c05b publish 功能 2025-03-13 11:27:11 +08:00
Cheney
5f5e73e1c9 更新 platform 打印格式 2025-03-12 11:23:44 +08:00
Cheney
77e610b38b 添加脚本和 meta 2025-03-12 10:27:24 +08:00
9 changed files with 205 additions and 100 deletions

2
kit.sh Normal file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
bun /app/kit.program/kit/src/index.js $@

View File

@ -125,6 +125,27 @@ parser.addCmdLine("platform", "平台信息", function (cli) {
// 调用主函数并打印结果
getAllDeviceInfo().then(info => {
console.log('Device Information:');
var table = []
for ( let k in info.os ){
table.push({ '项' : 'OS ' + k, '值' : info.os[k]})
}
for ( let k in info.cpu ){
table.push({ '项' : 'CPU ' + k, '值' : info.cpu[k]})
}
for ( let k in info.memory ){
if ( k.endsWith("Size") ) {
continue;
}
table.push({ '项' : 'Mem ' + k, '值' : info.memory[k]})
}
for ( let k in info.disk ){
if ( k.endsWith("Size") ) {
continue;
}
table.push({ '项' : 'Disk' + k, '值' : info.disk[k]})
}
console.table(table);
console.log( JSON.stringify(info, null, 4));
}).catch(error => {
console.error('Error getting device information:', error);

View File

@ -45,7 +45,7 @@ async function main(){
const projectScript = fs.readFileSync("./kit.js", "utf-8");
const vm = require('node:vm');
const vm = require('vm');
const script = new vm.Script(projectScript + ";" + step + "()");
const context = {
animal: 'cat', count: 2, $logger, shell
@ -82,7 +82,24 @@ async function main(){
}
});
parser.addCmdLine("publish", "发布到远程仓库;", async function () {
parser.addCmdLine("publish [localFile] [remotePath]", "发布到远程仓库;", async function (cli) {
const fs = require("fs");
let localFile = cli.getParamValue("localFile");
if ( ! fs.existsSync(localFile) ) {
$logger.error("本地文件不存在")
return
}
let remotePath = cli.getParamValue("remotePath");
if ( ! remotePath ) {
$logger.info("使用本地配置路径")
if ( ! fs.existsSync("meta.json") ) {
$logger.error("没有找到本地配置")
return
}
} else {
$logger.info("发布到远程路径" + remotePath)
}
let remote = await $context.get("remote")
if (!(await remote.check())) {
$logger.error("远程仓库不可用")
@ -90,7 +107,7 @@ async function main(){
} else {
$logger.info("远程仓库可用")
}
remote.publish()
await remote.publish(localFile, remotePath)
});
parser.addCmdLine("install [module]", "安装/更新模块;", async function (cli) {
let remote = await $context.get("remote")

View File

@ -1,7 +1,7 @@
require("./init")
const osutil = require("./util/osutil")
const killer = require('cross-port-killer');
const net = require('node:net');
const net = require('net');
/**

View File

@ -4,12 +4,12 @@
const path = require("path")
const fs = require("fs")
const JSON5 = require('json5')
const { pipeline, Transform} = require("node:stream/promises");
const { pipeline, Transform} = require("stream/promises");
module.exports = class Remote {
constructor() {
this.init()
// this.__init()
this.func_publish = require("./publish")
this.func_install = require("./install")
}
@ -21,12 +21,14 @@ module.exports = class Remote {
const uConfig = await $context.get("uConfig");
if ( uConfig.get("remoteServer") ){
let server = uConfig.get("remoteServer");
$logger.info("server " + server)
if ( server.startsWith("webdav") ) {
server = "http" + server.substring(6)
}
if ( uConfig.get("remoteAuth") ) {
let up = uConfig.get("remoteAuth");
$logger.info("remoteAuth " + up)
up = up.split(":", 2)
this.client = this.webdav.createClient(
server,
@ -155,29 +157,31 @@ module.exports = class Remote {
return false;
}
async publish(){
return this.func_publish( this )
async publish(localFile, remotePath){
return await this.func_publish( this , localFile, remotePath )
}
async install(id){
return this.func_install( this, id )
}
async wUpload(from, to){
async wUpload(from, to, debug){
const totalSize = fs.statSync(from).size;
debug ? console.log("totalSize", totalSize) : null
const rs = fs.createReadStream( from );
let wSize = 0;
let rSize = 0;
rs.on("data", (r)=>{
rSize += r.length;
// console.log("r", rSize * 100 / totalSize)
debug ? console.log("r", rSize * 100 / totalSize + "%") : null
})
const ws = this.client.createWriteStream(to)
ws.on("data", (r)=>{
wSize += r.length;
// console.log("w", wSize * 100 / totalSize)
debug ? console.log("w ", wSize * 100 / totalSize + "%") : null
})
return pipeline( rs, ws);
await pipeline( rs, ws);
debug ? console.log("finish") : null
}
async wDownload(from, to){
@ -198,7 +202,7 @@ module.exports = class Remote {
wSize += r.length;
// console.log("w", wSize * 100 / totalSize)
})
return pipeline(
return await pipeline(
rs, ws
)
}

View File

@ -1,9 +1,35 @@
const path = require("path")
const fs = require("fs")
const JSON5 = require('json5')
const { pipeline } = require('node:stream/promises');
const { pipeline } = require('stream/promises');
const objutil = require("../util/objutil")
module.exports = async function publish(remote, meta){
const datautil = require("../util/datautil")
module.exports = async function publish(remote, localFile, remotePath) {
if( remotePath ) {
// 如果有 meta
// 如果没有 meta
$logger.info("远程路径没有 meta, 按照默认规则上传");
// 确认目录
let folder = path.posix.resolve("/" + remotePath + "/data/" + datautil.now() );
if ( ! await remote.client.exists( folder ) ) {
// 创建文件夹
await remote.client.createDirectory(folder, {
recursive: true
});
}
let filename = path.basename(localFile);
// 上传文件
await remote.wUpload( localFile , path.posix.resolve(folder , filename ), true);
} else {
let curPath = process.cwd();
const metaFilePath = path.resolve( curPath, "meta.json" );
@ -75,5 +101,7 @@ module.exports = async function publish(remote, meta){
await remote.client.putFileContents("/modules/" + localMeta.id + "/meta.json", JSON5.stringify(remoteMeta, null, 4) , { overwrite: true });
}
$logger.info("发布成功")
}

27
kit/src/util/datautil.js Normal file
View File

@ -0,0 +1,27 @@
module.exports = {
// 定义格式化日期的函数
formatDate : function (date){
// 获取年份
const year = date.getFullYear();
// 获取月份,注意月份是从 0 开始的,所以要加 1
const month = String(date.getMonth() + 1).padStart(2, '0');
// 获取日期
const day = String(date.getDate()).padStart(2, '0');
// 获取小时
const hours = String(date.getHours()).padStart(2, '0');
// 获取分钟
const minutes = String(date.getMinutes()).padStart(2, '0');
// 获取秒数
const seconds = String(date.getSeconds()).padStart(2, '0');
// 按照 yyyyMMddHHmmss 的格式拼接字符串
return `${year}${month}${day}${hours}${minutes}${seconds}`;
},
now : function (){
// 获取当前日期和时间
const currentDate = new Date();
// 调用格式化函数
const formattedDate = this.formatDate(currentDate);
return formattedDate
}
}

View File

@ -105,7 +105,7 @@ async function main(){
// }
// );
const client = webdav.createClient(
"http://172.16.18.45:5244/dav",
"http://baishe.fullstack.club:5244/dav",
{
username: "kit",
password: "kitkit"
@ -117,7 +117,7 @@ async function main(){
console.log(directoryItems)
// 下载测试
await wDownload(client, "/kit")
// await wDownload(client, "/kit")
// let rs = fs.createReadStream("D:\\fullstack\\TDevOps\\kit\\dist\\windows\\kit.exe")
// rs.on("data", (r)=>{
@ -136,7 +136,7 @@ async function main(){
// console.log("end")
// await wUpload( client, "./kit", "/kit" )
await wUpload( client, "D:\\fullstack\\TDevOps\\Readme.md", "/test/case1/data/20250313111818/Readme.md2" )
// await wUpload( client, "../dist/windows/kit.exe", "/modules/kit/0.1.20240227094429/Windows/X86_64/kit.exe" )
console.log("over")
}

View File

@ -7,15 +7,21 @@
"version": "0.1", //
// "platform" : "cross", // cross=[X86_64, ARM64]
// "os" : "cross", // cross=[Windows, Linux, Alpine]
"dist": [{
platform : "X86_64",
os : "Windows",
path: "kit/dist/windows/kit.exe", //
"versions": [{
"version" : "0.1",
"match" : {
"x64|win32" : {
"path": "data/windows/kit.exe",
"filename" : "kit.exe"
}, {
platform : "X86_64",
os : "Linux",
path: "kit/dist/linux/kit", //
},
"x64|linux" : {
"path": "data/linux/kit",
"filename" : "kit"
},
"x64|linux|kylin V10" : {
"path": "data/kylin/kit.zip",
"filename" : "kit"
}
}
}]
}