在仓库制作打包脚本
This commit is contained in:
36
bin/build.js
Normal file
36
bin/build.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const axios = require('axios')
|
||||
const {fsExtra, copyFiles} = require("./tools");
|
||||
const getBuildConfig = id => {
|
||||
axios.post('/ns/node/custom/detail', null, {params: {id}}).then(res => {
|
||||
if (res?.data) {
|
||||
const config = res.data.data
|
||||
fsExtra.outputJson('src/config.json', config.extra)
|
||||
createPages(config)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const createPages = (config = {}) => {
|
||||
fsExtra.emptyDir("src/apps", err => {
|
||||
if (!err) {
|
||||
const {customPath, appList} = config
|
||||
const stdApps = {}
|
||||
appList.filter(e => !/project/.test(e.id))?.forEach(e => {
|
||||
const paths = e.libPath.split('/').filter(Boolean) || []
|
||||
paths.pop()
|
||||
stdApps[paths.join("/")] = 1
|
||||
})
|
||||
Promise.all([
|
||||
copyFiles("src/apps/core", "packages/core"),
|
||||
copyFiles("src/apps/custom", `project/${customPath}`),
|
||||
...Object.keys(stdApps).map(e => copyFiles(`src/apps/${e.replace(/^packages[\\\/]/, '')}`, e)),
|
||||
]).then(() => fsExtra.ensureFile("src/apps/actions.js"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const start = () => {
|
||||
const buildId = process.argv[2] || 'f670cc46-7cf7-4a0f-86ee-3077044c0b17'
|
||||
getBuildConfig(buildId)
|
||||
}
|
||||
start()
|
||||
33
bin/mods.js
33
bin/mods.js
@@ -1,33 +0,0 @@
|
||||
const {chalkTag, findApp, fs, fsExtra} = require("./tools");
|
||||
const compiler = require('vue-template-compiler')
|
||||
const getAppInfo = (file, apps) => {
|
||||
if (/[\\\/](App[A-Z][^\\\/]+)\.vue$/g.test(file)) {
|
||||
const name = file.replace(/.+[\\\/](App[^\\\/]+)\.vue$/, '$1'),
|
||||
source = fs.readFileSync(file).toString(),
|
||||
parsed = compiler.parseComponent(source),
|
||||
script = parsed.script?.content || "",
|
||||
label = script.match(/label:[^,]+/)?.[0]?.replace(/.+["']([^"']+).+/, '$1')
|
||||
const paths = file.split(/[\\\/]/)
|
||||
apps.push({
|
||||
id: file.replace(/\.vue$/, '').replace(/[\\\/]/g, '_'),
|
||||
label: label || name,
|
||||
path: `/${file.replace(/\.vue$/, '').replace(/[\\\/]/g, '/')}`,
|
||||
workspace: paths.at(0),
|
||||
esm: ['.', paths.slice(1)].flat().join("/"),
|
||||
name
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const start = () => {
|
||||
chalkTag.info("开始扫描库工程...")
|
||||
const list = []
|
||||
Promise.all([
|
||||
findApp('packages', app => getAppInfo(app, list)),
|
||||
findApp('project', app => getAppInfo(app, list)),
|
||||
]).then(() => {
|
||||
fsExtra.outputJson('examples/modules.json', {apps: list})
|
||||
chalkTag.done("扫描完毕")
|
||||
})
|
||||
}
|
||||
start()
|
||||
Reference in New Issue
Block a user