|
| 1 | +// Create a dummy netcreate-config.js file |
| 2 | +// for first time setup. It needs to do two things: |
| 3 | +// 1. Create app-config/netcreate-config.js file |
| 4 | +// 2. Copy the _default.template.toml file to runtime directory |
| 5 | + |
| 6 | +const shell = require('shelljs'); |
| 7 | +const fs = require('fs'); |
| 8 | +const path = require('path'); |
| 9 | + |
| 10 | +const dataset = 'dummy'; |
| 11 | +const port = '3000'; |
| 12 | + |
| 13 | +let script = ` |
| 14 | +// this file generated by "init-netcreate-config.js" |
| 15 | +const NC_CONFIG = { |
| 16 | + dataset: "${dataset}", |
| 17 | + port: "${port}" |
| 18 | +}; |
| 19 | +if (typeof process === "object") module.exports = NC_CONFIG; |
| 20 | +if (typeof window === "object") window.NC_CONFIG = NC_CONFIG; |
| 21 | +`; |
| 22 | + |
| 23 | +const nccPath = 'app-config'; |
| 24 | +if (!fs.existsSync(nccPath)) fs.mkdirSync(nccPath, { recursive: true }); |
| 25 | +shell.ShellString(script).to(`${nccPath}/netcreate-config.js`); |
| 26 | + |
| 27 | +// Copy template TOML file |
| 28 | +const templateSrc = 'app-templates/_default.template.toml'; |
| 29 | +const destDir = path.join('runtime'); |
| 30 | +const destFile = path.join(destDir, `${dataset}.template.toml`); |
| 31 | +if (!fs.existsSync(destDir)) shell.mkdir('-p', destDir); |
| 32 | +shell.cp(templateSrc, destFile); |
| 33 | + |
| 34 | +console.log('init-netcreate-config.js'); |
| 35 | +console.log('1. Created app-config/netcreate-config.js file'); |
| 36 | +console.log(` with ${dataset} and ${port}`); |
| 37 | +console.log(`2. Created a ${dataset}.template.toml file`); |
| 38 | +console.log(' based on _default.template.toml'); |
| 39 | +console.log('You can now run the server with "./nc.js" or nc-multiplex.'); |
0 commit comments