1 Star 0 Fork 0

AAAlex(做饭中) / MG-Linker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pack.js 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
邓圣砚 提交于 2024-01-05 16:37 . 第一次push
/**
* 打包成单独小组件
* 用法:
* node pack.js Scripts/「源码」小组件示例.js
* 将会在`Dist`目录生成「小件件」小组件示例.js 文件,这个文件可以发送给用户单独使用
*/
const process = require('process')
const os = require('os')
const fs = require('fs')
const path = require('path')
if (process.argv.length !== 3) {
console.log('[!] 用法:node pack Scripts/「源码」xxx.js')
process.exit(0)
}
const SAVE_PATH = path.join(__dirname, "Publish")
const file_name = process.argv[2]
const out_name = file_name.replace("「源码」", "").replace("Scripts", "Publish");
// 创建目录
if (!fs.existsSync(SAVE_PATH)) {
fs.mkdirSync(SAVE_PATH)
}
// 组合文件
const runtime_file = fs.readFileSync(path.join(__dirname, "Scripts", "「砚哥」开发环境.js"))
const runtime_code = runtime_file.toString("utf-8").split("// @running.end")[0]
const widget_file = fs.readFileSync(path.join(__dirname, file_name))
const widget_code = widget_file.toString("utf-8");
const widget_class = widget_code.split("// @组件代码开始")[1].split("// @组件代码结束")[0]
const widget_header = widget_code.split('// icon-color:')[1].split('\n')[0];
let result_code = `// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color:${widget_header}
${runtime_code}
${widget_class}
await Running(Widget)`
// 写入文件
fs.writeFileSync(path.join(__dirname, out_name), result_code)
console.log('[*] 文件已经保存到:' + out_name)
1
https://gitee.com/alexxyan/mg-linker.git
git@gitee.com:alexxyan/mg-linker.git
alexxyan
mg-linker
MG-Linker
master

搜索帮助