smallstonesk
4 years ago
3 changed files with 30 additions and 1 deletions
@ -0,0 +1,24 @@ |
|||
const path = require('path'); |
|||
const fs = require('fs-extra'); |
|||
|
|||
const INSERT_IMPORT_PLUGINS_COMMENT = '\/\/ import plugins here'; |
|||
const INSERT_USE_PLUGINS_COMMENT = '\/\/ use plugins here'; |
|||
|
|||
const setup = async (plugins, logicBasePath) => { |
|||
const entryFilePath = path.join(logicBasePath, 'index.js'); |
|||
const codes = await fs.readFile(entryFilePath); |
|||
const modifiedContent = codes |
|||
.replace(new RegExp(INSERT_IMPORT_PLUGINS_COMMENT), () => { |
|||
return plugins |
|||
.map((plugin, index) => `import plugin${index} from '${plugin}';`) |
|||
.join('\n'); |
|||
}) |
|||
.replace(new RegExp(INSERT_USE_PLUGINS_COMMENT), () => { |
|||
return plugins |
|||
.map((_, index) => `logic.use(plugin${index});`) |
|||
.join('\n'); |
|||
}); |
|||
await fs.outputFile(entryFilePath, modifiedContent); |
|||
}; |
|||
|
|||
module.exports = setup; |
@ -1,6 +1,10 @@ |
|||
import Logic from './logic'; |
|||
import dsl from './dsl.json'; |
|||
// import plugins here
|
|||
|
|||
|
|||
const logic = new Logic({dsl}); |
|||
|
|||
// use plugins here
|
|||
|
|||
export default logic; |
|||
|
Loading…
Reference in new issue