forked from journey/template
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.9 KiB
138 lines
3.9 KiB
const fs = require('fs-extra')
|
|
const path = require('path');
|
|
const child_process = require("child_process");
|
|
const express = require('express');
|
|
const {createProxyMiddleware} = require('http-proxy-middleware');
|
|
const proxy = require('./config');
|
|
const {getDefaultSettings} = require('http2');
|
|
|
|
function getDirectories(path) {
|
|
return fs.readdirSync(path).filter(function (file) {
|
|
return fs.statSync(path + '/' + file).isDirectory();
|
|
});
|
|
}
|
|
|
|
const ROOT_DIR = __dirname
|
|
const SRC_DIR = path.join(ROOT_DIR, './src');
|
|
const FROM_PORT = 7000
|
|
|
|
// 获取所有src目录下的文件夹(文件夹名即appIdesignd)
|
|
const APP_IDS = getDirectories(SRC_DIR)
|
|
|
|
const LIST = APP_IDS.map((appId, i) => {
|
|
const workspace = path.join(SRC_DIR, `./${appId}`);
|
|
const devPort = FROM_PORT + i;
|
|
const devCmd = `cd ${workspace} && npm run serve -- --port ${devPort}`;
|
|
const buildCmd = `cd ${workspace} && npm run build`;
|
|
const installCmd = `cd ${workspace} && npm install`;
|
|
const manifest = require(path.join(workspace, './public/esplug.json'))
|
|
const entry = `http://localhost:${devPort}`
|
|
const icon = `http://localhost:${devPort}/icon.png`
|
|
return {
|
|
appId,
|
|
manifest: {
|
|
...manifest,
|
|
id: appId,
|
|
name: manifest.name || '未命名',
|
|
entry,
|
|
icon,
|
|
},
|
|
workspace,
|
|
devPort,
|
|
devCmd,
|
|
installCmd,
|
|
buildCmd,
|
|
}
|
|
}).filter((item) => {
|
|
return !item.manifest.disabled
|
|
});
|
|
|
|
// 安装依赖
|
|
function install() {
|
|
LIST.forEach((item) => {
|
|
console.log(`[appId:${item.appId} name:${item.manifest.name}] 开始安装依赖:`)
|
|
child_process.execSync(item.installCmd, {stdio: 'inherit'})
|
|
});
|
|
}
|
|
|
|
// 打包构建
|
|
function build() {
|
|
LIST.forEach((item) => {
|
|
console.log(`[appId:${item.appId} appName:${item.manifest.name}] 开始打包构建:`)
|
|
child_process.execSync(item.buildCmd, {stdio: 'inherit'})
|
|
fs.copySync(path.join(item.workspace, './dist'), path.join(ROOT_DIR, `./dist`)) //${item.appId}
|
|
});
|
|
console.log('全部打包构建完成')
|
|
}
|
|
|
|
// 开发模式运行
|
|
function dev() {
|
|
const apps_widgets = {
|
|
apps: [],
|
|
widgets: [],
|
|
components: [],
|
|
}
|
|
LIST.forEach((item) => {
|
|
if (item.manifest.type === 'widget') {
|
|
apps_widgets.widgets.push(item.manifest)
|
|
} else {
|
|
//过滤出system为true的组件
|
|
apps_widgets.apps.push(item.manifest);
|
|
const cps = item.manifest.components || [];
|
|
apps_widgets.components.push(...cps.filter(c => c.system));
|
|
}
|
|
})
|
|
fs.writeFileSync(path.join(ROOT_DIR, './lib/platform/dist/TIS_PLATFORM/manifest/apps_widgets.json'), JSON.stringify(apps_widgets, null, 2))
|
|
|
|
const cmd = LIST.reduce((acc, item) => {
|
|
acc += ` "${item.devCmd}"`
|
|
return acc;
|
|
}, 'concurrently');
|
|
child_process.execSync(cmd, {stdio: 'inherit'});
|
|
}
|
|
|
|
//运行框架依赖
|
|
function startPlatform() {
|
|
const app = express();
|
|
app.use(express.static('./lib/platform/dist'));
|
|
const port = 8001;
|
|
for (const key in proxy) {
|
|
app.use(createProxyMiddleware(key, proxy[key]))
|
|
}
|
|
app.listen(port, function (err) {
|
|
if (err) {
|
|
console.log(err);
|
|
return;
|
|
}
|
|
console.log(`listening at http://localhost:${port}/TIS_PLATFORM/"\n`);
|
|
})
|
|
}
|
|
|
|
//启动一站式开发平台
|
|
function design() {
|
|
const app = express();
|
|
app.use(express.static(path.join(__dirname, './lib/tis_design/examples/')))
|
|
app.listen(9988);
|
|
console.log(`listening at http://localhost:9988/"\n`);
|
|
}
|
|
|
|
const arg = process.argv[2]
|
|
switch (arg) {
|
|
case 'install':
|
|
install()
|
|
break;
|
|
case 'dev':
|
|
dev();
|
|
break;
|
|
case 'build':
|
|
build();
|
|
break;
|
|
case 'platform':
|
|
startPlatform();
|
|
break;
|
|
case 'design':
|
|
design();
|
|
break;
|
|
default:
|
|
console.error(`未知命令 ${arg}`)
|
|
}
|