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');
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;
};

4
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));
}
}

10
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;
}
}),
};

2
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', '*');

Loading…
Cancel
Save