diff --git a/packages/cli/src/cmd/dev/extractCodes.js b/packages/cli/src/cmd/dev/extractCodes.js index 339f53b..6bce61c 100644 --- a/packages/cli/src/cmd/dev/extractCodes.js +++ b/packages/cli/src/cmd/dev/extractCodes.js @@ -24,11 +24,14 @@ const writeNodeCodes = async (basePath, dsl) => { const nodes = cells.filter((cell) => cell.shape !== 'edge'); for (const { id, - data: { code }, + shape, + data: { label, code }, } of nodes) { fileIds.push(id); const filePath = path.join(basePath, id + '.js'); - await fs.outputFile(filePath, code, { encoding: 'utf8', flag: 'w' }); + const preData = `// ${shape}: ${label}\n`; + const saveData = `${preData}\n${code}`; + await fs.outputFile(filePath, saveData, { encoding: 'utf8', flag: 'w' }); } return fileIds; }; diff --git a/packages/cli/src/cmd/dev/index.js b/packages/cli/src/cmd/dev/index.js index e716a85..f313c9d 100644 --- a/packages/cli/src/cmd/dev/index.js +++ b/packages/cli/src/cmd/dev/index.js @@ -50,8 +50,8 @@ class Dev extends Base { run() { const app = createServer(); - app.post('/api/save', this.save); - app.get('/api/connect', this.connect); + app.post('/api/save', this.save.bind(this)); + app.get('/api/connect', this.connect.bind(this)); } } diff --git a/packages/cli/src/cmd/dev/simplifyDSL.js b/packages/cli/src/cmd/dev/simplifyDSL.js index 758e759..53867de 100644 --- a/packages/cli/src/cmd/dev/simplifyDSL.js +++ b/packages/cli/src/cmd/dev/simplifyDSL.js @@ -3,7 +3,11 @@ const fs = require('fs-extra'); const extractObj = (obj = {}, keys = []) => { const ret = {}; - keys.forEach((key) => (ret[key] = obj[key])); + keys.forEach((key) => { + if (obj[key]) { + ret[key] = obj[key]; + } + }); return ret; }; @@ -14,7 +18,9 @@ const simplify = (dsl) => { if (cell.shape === 'edge') { return extractObj(cell, ['id', 'shape', 'source', 'target']); } else { - return extractObj(cell, ['id', 'shape', 'data']); + const newCell = extractObj(cell, ['id', 'shape']); + newCell.data = extractObj(cell.data, ['trigger', 'configData']); + return newCell; } }), }; diff --git a/packages/cli/src/utils/server/index.js b/packages/cli/src/utils/server/index.js index bc9290e..afa4a76 100644 --- a/packages/cli/src/utils/server/index.js +++ b/packages/cli/src/utils/server/index.js @@ -3,7 +3,7 @@ const bodyParser = require('body-parser'); const createServer = (port = 3500) => { const app = express(); - app.use(bodyParser.json()); + app.use(bodyParser.json({ limit: '50mb' })); app.use(bodyParser.urlencoded({ extended: false })); app.use((req, res, next) => { res.header('Access-Control-Allow-Origin', '*');