diff --git a/bin/build.js b/bin/build.js new file mode 100644 index 00000000..7cdf7bd9 --- /dev/null +++ b/bin/build.js @@ -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() diff --git a/bin/mods.js b/bin/mods.js deleted file mode 100644 index d7d7b35f..00000000 --- a/bin/mods.js +++ /dev/null @@ -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() diff --git a/package.json b/package.json index 6affc94d..7c4843fa 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "vue-cli-service build", "oms": "vue-cli-service serve examples/main.js --mode oms", "sync": "node bin/appsSync.js", - "preview": "vue-cli-service serve", + "preview": "node bin/build.js && vue-cli-service serve", "predev": "node bin/scanApps.js", "preoms": "dotenv -e .env.oms node bin/scanApps.js" }, diff --git a/src/main.js b/src/main.js index c066ac2f..be3ac3d8 100644 --- a/src/main.js +++ b/src/main.js @@ -3,16 +3,14 @@ import App from './App.vue'; import ui from 'element-ui'; import router from './utils/router'; import utils from './utils'; -import vcUI from 'dui'; +import vcUI from 'dui/packages'; import appComp from 'dui/dv'; import store from './utils/store'; import autoRoutes from "./utils/autoRoutes"; import extra from "./config.json" import axios from "./utils/axios"; -//import ob from "dui/lib/js/observer" //备注底座信息,勿删 console.log("欢迎使用%s", extra.sysInfo?.name || "构建版本") -//new ob() window.Vue = Vue Vue.use(ui); Vue.use(vcUI); diff --git a/src/utils/autoRoutes.js b/src/utils/autoRoutes.js index 720db2a1..b9ce6410 100644 --- a/src/utils/autoRoutes.js +++ b/src/utils/autoRoutes.js @@ -20,7 +20,7 @@ const signOut = () => commit("signOut"), const loadApps = () => { //新App的自动化格式 waiting.init({innerHTML: '应用加载中..'}) - let apps = require.context('../../apps', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, "lazy") + let apps = require.context('../apps', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, "lazy") return Promise.all(apps.keys().map(path => apps(path).then(file => { if (file.default) { let {name} = file.default diff --git a/src/views/dvIndex.vue b/src/views/dvIndex.vue index ba9cc595..1931888a 100644 --- a/src/views/dvIndex.vue +++ b/src/views/dvIndex.vue @@ -57,7 +57,7 @@ export default { loadDvs() { //新App的自动化格式 waiting.init({innerHTML: '应用加载中..'}) - let apps = require.context('../../apps', true, /\.(\/.+)\/App[A-Z][^\/]+D[Vv]\.vue$/, "lazy") + let apps = require.context('../apps', true, /\.(\/.+)\/App[A-Z][^\/]+D[Vv]\.vue$/, "lazy") return Promise.all(apps.keys().map(path => apps(path).then(file => { if (file.default) { let {name} = file.default diff --git a/src/views/home.vue b/src/views/home.vue index 6a64b55b..667d4660 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -22,7 +22,7 @@ export default { useCopilot: () => !!configExtra?.copilot }, created() { - import("../../apps/actions").then(extra => { + import("../apps/actions").then(extra => { const actions = extra?.default || {} this.$store.hotUpdate({actions}) Object.keys(actions)?.map(action => this.$store.dispatch(action)) diff --git a/vue.config.js b/vue.config.js index dd04d191..e9f6fa47 100644 --- a/vue.config.js +++ b/vue.config.js @@ -22,6 +22,7 @@ module.exports = { .add(path.resolve(__dirname, 'packages')) .add(path.resolve(__dirname, 'project')) .add(path.resolve(__dirname, 'examples')) + .add(path.resolve(__dirname, 'src')) .add(path.resolve(__dirname, 'ui/packages')) .add(path.resolve(__dirname, 'ui/dv')) .add(path.resolve(__dirname, 'ui/lib/js'))