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.
 
 
 
 

41 lines
1.2 KiB

const path = require('path');
const fs = require('fs-extra');
const mergePkg = require('./mergePkg');
const simplifyDSL = require('./simplifyDSL');
const extractCodes = require('./extractCodes');
const {createServer} = require('../../utils/server');
const PROJECT_ROOT_PATH = process.cwd();
const TPL_PATH = path.join(__dirname, './template');
const LOGIC_BASE_PATH = path.join(process.cwd(), './src/logic');
const setup = () => {
const app = createServer();
app.post('/api/save', async (req, res) => {
// check dsl whether existed
if (!req.body || !req.body.dsl) {
res.status(500).json({isCompiled: false}).end();
return;
}
// compile
try {
const {dsl} = req.body;
await mergePkg(dsl, PROJECT_ROOT_PATH);
await simplifyDSL(dsl, LOGIC_BASE_PATH);
await extractCodes(dsl, LOGIC_BASE_PATH);
await fs.copy(TPL_PATH, LOGIC_BASE_PATH);
res.status(200).json({isCompiled: true}).end();
console.log('compile successfully!');
} catch(err) {
res.status(500).json({isCompiled: false}).end();
console.log('compile failed! the error is:', err.message);
}
});
}
module.exports = function() {
fs.ensureDirSync(LOGIC_BASE_PATH);
setup();
};