SmallStone
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
16 additions and
7 deletions
-
packages/cli/src/cmd/dev/extractCodes.js
-
packages/cli/src/cmd/dev/index.js
-
packages/cli/src/cmd/dev/simplifyDSL.js
-
packages/cli/src/utils/server/index.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; |
|
|
}; |
|
|
}; |
|
|
|
@ -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)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
@ -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; |
|
|
} |
|
|
} |
|
|
}), |
|
|
}), |
|
|
}; |
|
|
}; |
|
|
|
@ -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', '*'); |
|
|