diff options
Diffstat (limited to 'packages/gitbook-plugin/src/create.js')
-rw-r--r-- | packages/gitbook-plugin/src/create.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/packages/gitbook-plugin/src/create.js b/packages/gitbook-plugin/src/create.js new file mode 100644 index 0000000..5b218c2 --- /dev/null +++ b/packages/gitbook-plugin/src/create.js @@ -0,0 +1,50 @@ +const fs = require('fs-extra'); +const path = require('path'); + +const TEMPLATE_DIR = path.resolve(__dirname, '../template'); + +/** + * Create a new plugin + * @param {String} outputDir + * @param {String} spec.name + * @param {String} spec.desc + */ +function create(outputDir, spec) { + const pkg = { + 'name': `gitbook-plugin-${spec.name}`, + 'description': `${spec.desc}`, + 'main': 'index.js', + 'version': '0.0.0', + 'dependencies': { + 'gitbook-core': '^0.0.0' + }, + 'devDependencies': { + 'gitbook-plugin': '*' + }, + 'engines': { + 'gitbook': '>=3.0.0' + }, + 'scripts': { + 'build-js': 'gitbook-plugin build ./src/index.js ./_assets/theme.js', + 'prepublish': 'npm run build-js' + }, + 'homepage': `${spec.github}`, + 'repository': { + 'type': 'git', + 'url': `${spec.github}.git` + }, + 'bugs': { + 'url': `${spec.github}/issues` + } + }; + + fs.copySync(TEMPLATE_DIR, outputDir, { + clobber: true + }); + + fs.outputJsonSync(path.resolve(outputDir, 'package.json'), pkg, { + spaces: 2 + }); +} + +module.exports = create; |