Browse Source

Merge pull request #22 from qilei0529/perf/dsl-fix

修复若干问题
master
SmallStone 4 years ago
committed by GitHub
parent
commit
08f701b1f3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      packages/cli/src/cmd/dev/extractCodes.js
  2. 4
      packages/cli/src/cmd/dev/index.js
  3. 10
      packages/cli/src/cmd/dev/simplifyDSL.js
  4. 2
      packages/cli/src/utils/server/index.js

7
packages/cli/src/cmd/dev/extractCodes.js

@ -24,11 +24,14 @@ const writeNodeCodes = async (basePath, dsl) => {
const nodes = cells.filter((cell) => cell.shape !== 'edge'); const nodes = cells.filter((cell) => cell.shape !== 'edge');
for (const { for (const {
id, id,
data: { code }, shape,
data: { label, code },
} of nodes) { } of nodes) {
fileIds.push(id); fileIds.push(id);
const filePath = path.join(basePath, id + '.js'); 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; return fileIds;
}; };

4
packages/cli/src/cmd/dev/index.js

@ -50,8 +50,8 @@ class Dev extends Base {
run() { run() {
const app = createServer(); const app = createServer();
app.post('/api/save', this.save); app.post('/api/save', this.save.bind(this));
app.get('/api/connect', this.connect); app.get('/api/connect', this.connect.bind(this));
} }
} }

10
packages/cli/src/cmd/dev/simplifyDSL.js

@ -3,7 +3,11 @@ const fs = require('fs-extra');
const extractObj = (obj = {}, keys = []) => { const extractObj = (obj = {}, keys = []) => {
const ret = {}; const ret = {};
keys.forEach((key) => (ret[key] = obj[key])); keys.forEach((key) => {
if (obj[key]) {
ret[key] = obj[key];
}
});
return ret; return ret;
}; };
@ -14,7 +18,9 @@ const simplify = (dsl) => {
if (cell.shape === 'edge') { if (cell.shape === 'edge') {
return extractObj(cell, ['id', 'shape', 'source', 'target']); return extractObj(cell, ['id', 'shape', 'source', 'target']);
} else { } else {
return extractObj(cell, ['id', 'shape', 'data']); const newCell = extractObj(cell, ['id', 'shape']);
newCell.data = extractObj(cell.data, ['trigger', 'configData']);
return newCell;
} }
}), }),
}; };

2
packages/cli/src/utils/server/index.js

@ -3,7 +3,7 @@ const bodyParser = require('body-parser');
const createServer = (port = 3500) => { const createServer = (port = 3500) => {
const app = express(); const app = express();
app.use(bodyParser.json()); app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({ extended: false }));
app.use((req, res, next) => { app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Origin', '*');

Loading…
Cancel
Save