调整代码生成和分包列入热更新开发范围
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();
|
||||
@@ -4,17 +4,18 @@
|
||||
"private": false,
|
||||
"author": "Kubbo",
|
||||
"scripts": {
|
||||
"dev": "node bin/serve.js&&cross-env NODE_ENV=development VUE_APP_CW_MODE=dev UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch --minimize",
|
||||
"dev": "node bin/pages.js&&cross-env NODE_ENV=development VUE_APP_CW_MODE=dev UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch --minimize",
|
||||
"pages": "node bin/pages.js",
|
||||
"lib": "npm unpublish --force&&npm publish",
|
||||
"pages": "node bin/serve.js",
|
||||
"lib:all": "node project/build.js&&npm unpublish --workspaces --force&&npm publish --workspaces"
|
||||
"lib:all": "node src/project/build.js&&npm unpublish --workspaces --force&&npm publish --workspaces&&node bin/clean.js",
|
||||
"clean": "node bin/clean.js"
|
||||
},
|
||||
"files": [
|
||||
"src/mods"
|
||||
],
|
||||
"workspaces": [
|
||||
"src/components",
|
||||
"project/*"
|
||||
"src/project/*"
|
||||
],
|
||||
"publishConfig": {
|
||||
"registry": "http://cli.sinoecare.net"
|
||||
|
||||
@@ -69,13 +69,15 @@ export default {
|
||||
},
|
||||
getApps() {
|
||||
this.apps = []
|
||||
let applications = require.context('../mods', true, /\.(\/.+)\/App[^\/]+\.vue$/)
|
||||
applications.keys().map(path => {
|
||||
if (applications(path).default) {
|
||||
let {name: key, appName: name} = applications(path).default
|
||||
this.apps.push({key, name, path: path.replace(/^\.(.+).vue$/g, '$1')})
|
||||
}
|
||||
})
|
||||
// let applications = require.context('../', true, /\.(\/.+)\/App[^\/]+\.vue$/, 'lazy')
|
||||
// applications.keys().map(path => {
|
||||
// applications(path).then(file => {
|
||||
// if (file.default) {
|
||||
// let {name: key, appName: name} = file.default
|
||||
// this.apps.push({key, name, path: path.replace(/^\.(.+).vue$/g, '$1')})
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
},
|
||||
getAuth() {
|
||||
this.$nextTick(() => {
|
||||
|
||||
@@ -77,7 +77,7 @@ const copyFiles = (dir, source = 'src/mods') => {
|
||||
*/
|
||||
const init = () => {
|
||||
chalkTag.info('开始运行项目打包工具...')
|
||||
return new Promise(resolve => fs.readdir('./project', (err, files) => {
|
||||
return new Promise(resolve => fs.readdir('./src/project', (err, files) => {
|
||||
resolve(files.filter(e => e.indexOf('.') < 0))
|
||||
}))
|
||||
}
|
||||
@@ -88,12 +88,12 @@ const generateMain = project => {
|
||||
const getApps = new Promise(resolve => {
|
||||
const appLib = path.join(__dirname, project.toString(), 'apps.import.json')
|
||||
fsExtra.readJson(appLib, (err, data) => {
|
||||
fsExtra.emptyDirSync(`project/${project}/apps`)
|
||||
fsExtra.emptyDirSync(`src/project/${project}/apps`)
|
||||
let apps = []
|
||||
if (data) {
|
||||
chalkTag.info(project + '加载业务应用配置...')
|
||||
Promise.all([
|
||||
findApp(`project/${project}`, file => {
|
||||
findApp(`src/project/${project}`, file => {
|
||||
let reg = new RegExp(/.+(App[^\\\/]+)$/)
|
||||
if (reg.test(file)) {
|
||||
data[file.replace(reg, '$1')] = file.replace(reg, '$1')
|
||||
@@ -104,7 +104,7 @@ const generateMain = project => {
|
||||
]).then(() => Promise.all(Object.keys(data).map(e => {
|
||||
let app = [...new Set(apps)].find(s => s.indexOf(e) > -1)
|
||||
if (app) {
|
||||
return copyFiles(`project/${project}/apps/${e}`, app)
|
||||
return copyFiles(`src/project/${project}/apps/${e}`, app)
|
||||
}
|
||||
}))).then(() => {
|
||||
chalkTag.done(project + '业务应用加载完成')
|
||||
Reference in New Issue
Block a user