调整代码生成和分包列入热更新开发范围
This commit is contained in:
20
bin/clean.js
Normal file
20
bin/clean.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const fs = require("fs");
|
||||
const fse = require("fs-extra")
|
||||
const path = require("path");
|
||||
const getDirs = (dir, list = [], cb) => {
|
||||
const dirs = fs.readdirSync(dir, {withFileTypes: true})
|
||||
dirs.map(d => {
|
||||
if (d.isDirectory()) {
|
||||
let p = path.join(dir, d.name)
|
||||
list.push(p)
|
||||
if (cb(d, p)) getDirs(p, list, cb)
|
||||
}
|
||||
})
|
||||
return list
|
||||
}
|
||||
getDirs(path.join(__dirname, '..', 'src'), [], (dir, path) => {
|
||||
if (dir.name == "apps") {
|
||||
fse.remove(path)
|
||||
}
|
||||
return dir.name != "apps"
|
||||
})
|
||||
@@ -69,6 +69,16 @@ const copyFiles = (dir, source = 'src/mods') => {
|
||||
})
|
||||
})
|
||||
}
|
||||
const setPageStyle = (app, file) => {
|
||||
let vue = fs.readFileSync(file).toString()
|
||||
if (/customNavigation/.test(vue)) {
|
||||
app.style = {navigationStyle: "custom"}
|
||||
} else if (/appName/.test(vue)) {
|
||||
let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1'),
|
||||
title = appName.replace(/(appName:|["'])/g, '')
|
||||
app.style = {navigationBarTitleText: title}
|
||||
}
|
||||
}
|
||||
const start = () => {
|
||||
chalkTag.info('开始生成pages.json...')
|
||||
let json = {
|
||||
@@ -81,7 +91,8 @@ const start = () => {
|
||||
],
|
||||
subPackages: [
|
||||
{root: "mods/", pages: []},
|
||||
{root: "components/pages/", pages: []}
|
||||
{root: "components/pages/", pages: []},
|
||||
{root: "project/", pages: []},
|
||||
],
|
||||
globalStyle: {
|
||||
pageOrientation: "auto",
|
||||
@@ -90,42 +101,41 @@ const start = () => {
|
||||
backgroundColor: "#4181FF"
|
||||
}
|
||||
}
|
||||
copyFiles('src/mods/project', 'project').then(() => findApp('src/components/pages', file => {
|
||||
if (/.+\\[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
||||
let app = {
|
||||
path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||
Promise.all([
|
||||
findApp('src/components/pages', file => {
|
||||
if (/.+\\[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
||||
let app = {
|
||||
path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||
}
|
||||
setPageStyle(app, file)
|
||||
return json.subPackages[1].pages.push(app)
|
||||
}
|
||||
let vue = fs.readFileSync(file).toString()
|
||||
if (/appName/.test(vue)) {
|
||||
let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1'),
|
||||
title = appName.replace(/(appName:|["'])/g, '')
|
||||
app.style = {navigationBarTitleText: title}
|
||||
}
|
||||
json.subPackages[1].pages.push(app)
|
||||
}
|
||||
}).then(() => {
|
||||
return findApp('src/mods', file => {
|
||||
}),
|
||||
findApp('src/mods', file => {
|
||||
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
||||
let app = {
|
||||
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
||||
path: file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||
}
|
||||
let vue = fs.readFileSync(file).toString()
|
||||
if (/appName/.test(vue)) {
|
||||
let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1'),
|
||||
title = appName.replace(/(appName:|["'])/g, '')
|
||||
app.style = {navigationBarTitleText: title}
|
||||
}
|
||||
json.subPackages[0].pages.push(app)
|
||||
setPageStyle(app, file)
|
||||
return json.subPackages[0].pages.push(app)
|
||||
}
|
||||
}),
|
||||
findApp('src/project', file => {
|
||||
if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) {
|
||||
let app = {
|
||||
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
||||
path: file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||
}
|
||||
setPageStyle(app, file)
|
||||
return json.subPackages[2].pages.push(app)
|
||||
}
|
||||
}).then(() => {
|
||||
fsExtra.outputJson('src/pages.json', json, () => {
|
||||
chalkTag.done('生成pages.json')
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
||||
|
||||
]).then(() => {
|
||||
fsExtra.outputJson('src/pages.json', json, () => {
|
||||
chalkTag.done('生成pages.json')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
start();
|
||||
Reference in New Issue
Block a user