Compare commits
No commits in common. "5ff621c05b500cc4d511270a905528324ddc8f7d" and "97a76195c2bcba23b49b4c7d051a2c3a48109c90" have entirely different histories.
5ff621c05b
...
97a76195c2
@ -125,27 +125,6 @@ parser.addCmdLine("platform", "平台信息", function (cli) {
|
|||||||
// 调用主函数并打印结果
|
// 调用主函数并打印结果
|
||||||
getAllDeviceInfo().then(info => {
|
getAllDeviceInfo().then(info => {
|
||||||
console.log('Device Information:');
|
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));
|
console.log( JSON.stringify(info, null, 4));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Error getting device information:', error);
|
console.error('Error getting device information:', error);
|
||||||
|
|||||||
@ -45,7 +45,7 @@ async function main(){
|
|||||||
|
|
||||||
|
|
||||||
const projectScript = fs.readFileSync("./kit.js", "utf-8");
|
const projectScript = fs.readFileSync("./kit.js", "utf-8");
|
||||||
const vm = require('vm');
|
const vm = require('node:vm');
|
||||||
const script = new vm.Script(projectScript + ";" + step + "()");
|
const script = new vm.Script(projectScript + ";" + step + "()");
|
||||||
const context = {
|
const context = {
|
||||||
animal: 'cat', count: 2, $logger, shell
|
animal: 'cat', count: 2, $logger, shell
|
||||||
@ -82,24 +82,7 @@ async function main(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.addCmdLine("publish [localFile] [remotePath]", "发布到远程仓库;", async function (cli) {
|
parser.addCmdLine("publish", "发布到远程仓库;", async function () {
|
||||||
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")
|
let remote = await $context.get("remote")
|
||||||
if (!(await remote.check())) {
|
if (!(await remote.check())) {
|
||||||
$logger.error("远程仓库不可用")
|
$logger.error("远程仓库不可用")
|
||||||
@ -107,7 +90,7 @@ async function main(){
|
|||||||
} else {
|
} else {
|
||||||
$logger.info("远程仓库可用")
|
$logger.info("远程仓库可用")
|
||||||
}
|
}
|
||||||
await remote.publish(localFile, remotePath)
|
remote.publish()
|
||||||
});
|
});
|
||||||
parser.addCmdLine("install [module]", "安装/更新模块;", async function (cli) {
|
parser.addCmdLine("install [module]", "安装/更新模块;", async function (cli) {
|
||||||
let remote = await $context.get("remote")
|
let remote = await $context.get("remote")
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
require("./init")
|
require("./init")
|
||||||
const osutil = require("./util/osutil")
|
const osutil = require("./util/osutil")
|
||||||
const killer = require('cross-port-killer');
|
const killer = require('cross-port-killer');
|
||||||
const net = require('net');
|
const net = require('node:net');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -4,12 +4,12 @@
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const JSON5 = require('json5')
|
const JSON5 = require('json5')
|
||||||
const { pipeline, Transform} = require("stream/promises");
|
const { pipeline, Transform} = require("node:stream/promises");
|
||||||
|
|
||||||
module.exports = class Remote {
|
module.exports = class Remote {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// this.__init()
|
this.init()
|
||||||
this.func_publish = require("./publish")
|
this.func_publish = require("./publish")
|
||||||
this.func_install = require("./install")
|
this.func_install = require("./install")
|
||||||
}
|
}
|
||||||
@ -21,14 +21,12 @@ module.exports = class Remote {
|
|||||||
const uConfig = await $context.get("uConfig");
|
const uConfig = await $context.get("uConfig");
|
||||||
if ( uConfig.get("remoteServer") ){
|
if ( uConfig.get("remoteServer") ){
|
||||||
let server = uConfig.get("remoteServer");
|
let server = uConfig.get("remoteServer");
|
||||||
$logger.info("server " + server)
|
|
||||||
if ( server.startsWith("webdav") ) {
|
if ( server.startsWith("webdav") ) {
|
||||||
server = "http" + server.substring(6)
|
server = "http" + server.substring(6)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( uConfig.get("remoteAuth") ) {
|
if ( uConfig.get("remoteAuth") ) {
|
||||||
let up = uConfig.get("remoteAuth");
|
let up = uConfig.get("remoteAuth");
|
||||||
$logger.info("remoteAuth " + up)
|
|
||||||
up = up.split(":", 2)
|
up = up.split(":", 2)
|
||||||
this.client = this.webdav.createClient(
|
this.client = this.webdav.createClient(
|
||||||
server,
|
server,
|
||||||
@ -157,31 +155,29 @@ module.exports = class Remote {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async publish(localFile, remotePath){
|
async publish(){
|
||||||
return await this.func_publish( this , localFile, remotePath )
|
return this.func_publish( this )
|
||||||
}
|
}
|
||||||
|
|
||||||
async install(id){
|
async install(id){
|
||||||
return this.func_install( this, id )
|
return this.func_install( this, id )
|
||||||
}
|
}
|
||||||
|
|
||||||
async wUpload(from, to, debug){
|
async wUpload(from, to){
|
||||||
const totalSize = fs.statSync(from).size;
|
const totalSize = fs.statSync(from).size;
|
||||||
debug ? console.log("totalSize", totalSize) : null
|
|
||||||
const rs = fs.createReadStream( from );
|
const rs = fs.createReadStream( from );
|
||||||
let wSize = 0;
|
let wSize = 0;
|
||||||
let rSize = 0;
|
let rSize = 0;
|
||||||
rs.on("data", (r)=>{
|
rs.on("data", (r)=>{
|
||||||
rSize += r.length;
|
rSize += r.length;
|
||||||
debug ? console.log("r", rSize * 100 / totalSize + "%") : null
|
// console.log("r", rSize * 100 / totalSize)
|
||||||
})
|
})
|
||||||
const ws = this.client.createWriteStream(to)
|
const ws = this.client.createWriteStream(to)
|
||||||
ws.on("data", (r)=>{
|
ws.on("data", (r)=>{
|
||||||
wSize += r.length;
|
wSize += r.length;
|
||||||
debug ? console.log("w ", wSize * 100 / totalSize + "%") : null
|
// console.log("w", wSize * 100 / totalSize)
|
||||||
})
|
})
|
||||||
await pipeline( rs, ws);
|
return pipeline( rs, ws);
|
||||||
debug ? console.log("finish") : null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async wDownload(from, to){
|
async wDownload(from, to){
|
||||||
@ -202,7 +198,7 @@ module.exports = class Remote {
|
|||||||
wSize += r.length;
|
wSize += r.length;
|
||||||
// console.log("w", wSize * 100 / totalSize)
|
// console.log("w", wSize * 100 / totalSize)
|
||||||
})
|
})
|
||||||
return await pipeline(
|
return pipeline(
|
||||||
rs, ws
|
rs, ws
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,35 +1,9 @@
|
|||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const JSON5 = require('json5')
|
const JSON5 = require('json5')
|
||||||
const { pipeline } = require('stream/promises');
|
const { pipeline } = require('node:stream/promises');
|
||||||
const objutil = require("../util/objutil")
|
const objutil = require("../util/objutil")
|
||||||
const datautil = require("../util/datautil")
|
module.exports = async function publish(remote, meta){
|
||||||
|
|
||||||
|
|
||||||
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();
|
let curPath = process.cwd();
|
||||||
const metaFilePath = path.resolve( curPath, "meta.json" );
|
const metaFilePath = path.resolve( curPath, "meta.json" );
|
||||||
@ -101,7 +75,5 @@ module.exports = async function publish(remote, localFile, remotePath) {
|
|||||||
|
|
||||||
await remote.client.putFileContents("/modules/" + localMeta.id + "/meta.json", JSON5.stringify(remoteMeta, null, 4) , { overwrite: true });
|
await remote.client.putFileContents("/modules/" + localMeta.id + "/meta.json", JSON5.stringify(remoteMeta, null, 4) , { overwrite: true });
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$logger.info("发布成功")
|
$logger.info("发布成功")
|
||||||
}
|
}
|
||||||
@ -1,27 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -105,7 +105,7 @@ async function main(){
|
|||||||
// }
|
// }
|
||||||
// );
|
// );
|
||||||
const client = webdav.createClient(
|
const client = webdav.createClient(
|
||||||
"http://baishe.fullstack.club:5244/dav",
|
"http://172.16.18.45:5244/dav",
|
||||||
{
|
{
|
||||||
username: "kit",
|
username: "kit",
|
||||||
password: "kitkit"
|
password: "kitkit"
|
||||||
@ -117,7 +117,7 @@ async function main(){
|
|||||||
console.log(directoryItems)
|
console.log(directoryItems)
|
||||||
|
|
||||||
// 下载测试
|
// 下载测试
|
||||||
// await wDownload(client, "/kit")
|
await wDownload(client, "/kit")
|
||||||
|
|
||||||
// let rs = fs.createReadStream("D:\\fullstack\\TDevOps\\kit\\dist\\windows\\kit.exe")
|
// let rs = fs.createReadStream("D:\\fullstack\\TDevOps\\kit\\dist\\windows\\kit.exe")
|
||||||
// rs.on("data", (r)=>{
|
// rs.on("data", (r)=>{
|
||||||
@ -136,7 +136,7 @@ async function main(){
|
|||||||
|
|
||||||
// console.log("end")
|
// console.log("end")
|
||||||
|
|
||||||
await wUpload( client, "D:\\fullstack\\TDevOps\\Readme.md", "/test/case1/data/20250313111818/Readme.md2" )
|
// await wUpload( client, "./kit", "/kit" )
|
||||||
// await wUpload( client, "../dist/windows/kit.exe", "/modules/kit/0.1.20240227094429/Windows/X86_64/kit.exe" )
|
// await wUpload( client, "../dist/windows/kit.exe", "/modules/kit/0.1.20240227094429/Windows/X86_64/kit.exe" )
|
||||||
console.log("over")
|
console.log("over")
|
||||||
}
|
}
|
||||||
|
|||||||
22
meta.json
22
meta.json
@ -7,21 +7,15 @@
|
|||||||
"version": "0.1", // 当前版本号,只包含两位,其他部分自动生成
|
"version": "0.1", // 当前版本号,只包含两位,其他部分自动生成
|
||||||
// "platform" : "cross", // cross=跨平台;[X86_64, ARM64]
|
// "platform" : "cross", // cross=跨平台;[X86_64, ARM64]
|
||||||
// "os" : "cross", // cross=跨操作系统;[Windows, Linux, Alpine]
|
// "os" : "cross", // cross=跨操作系统;[Windows, Linux, Alpine]
|
||||||
"versions": [{
|
"dist": [{
|
||||||
"version" : "0.1",
|
platform : "X86_64",
|
||||||
"match" : {
|
os : "Windows",
|
||||||
"x64|win32" : {
|
path: "kit/dist/windows/kit.exe", // 本地存储路径
|
||||||
"path": "data/windows/kit.exe",
|
|
||||||
"filename" : "kit.exe"
|
"filename" : "kit.exe"
|
||||||
},
|
}, {
|
||||||
"x64|linux" : {
|
platform : "X86_64",
|
||||||
"path": "data/linux/kit",
|
os : "Linux",
|
||||||
|
path: "kit/dist/linux/kit", // 本地存储路径
|
||||||
"filename" : "kit"
|
"filename" : "kit"
|
||||||
},
|
|
||||||
"x64|linux|kylin V10" : {
|
|
||||||
"path": "data/kylin/kit.zip",
|
|
||||||
"filename" : "kit"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user