summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin/src/create.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-09-29 13:15:41 +0200
committerSamy Pesse <samypesse@gmail.com>2016-09-29 13:15:41 +0200
commit42d53ec0323956c1536666793823f41ee874d2ce (patch)
tree20107cc323de6c6c732fa4f5d2043b994ee2ea14 /packages/gitbook-plugin/src/create.js
parent287c80b2e116572669f2a7073731ba7350e3619a (diff)
downloadgitbook-42d53ec0323956c1536666793823f41ee874d2ce.zip
gitbook-42d53ec0323956c1536666793823f41ee874d2ce.tar.gz
gitbook-42d53ec0323956c1536666793823f41ee874d2ce.tar.bz2
Add gitbook-plugin command to create a plugin
Diffstat (limited to 'packages/gitbook-plugin/src/create.js')
-rw-r--r--packages/gitbook-plugin/src/create.js50
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;