summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin/src
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
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')
-rw-r--r--packages/gitbook-plugin/src/cli.js29
-rw-r--r--packages/gitbook-plugin/src/create.js50
2 files changed, 79 insertions, 0 deletions
diff --git a/packages/gitbook-plugin/src/cli.js b/packages/gitbook-plugin/src/cli.js
index 20ceed5..33790c2 100644
--- a/packages/gitbook-plugin/src/cli.js
+++ b/packages/gitbook-plugin/src/cli.js
@@ -3,9 +3,11 @@
const program = require('commander');
const path = require('path');
const winston = require('winston');
+const inquirer = require('inquirer');
const pkg = require('../package.json');
const compile = require('./compile');
+const create = require('./create');
const resolve = (input => path.resolve(process.cwd(), input));
@@ -23,6 +25,33 @@ program
);
});
+program
+ .command('create [output]')
+ .description('create a new plugin')
+ .action(function(output, options) {
+ inquirer.prompt([
+ {
+ name: 'name',
+ message: 'name:'
+ },
+ {
+ name: 'desc',
+ message: 'description:'
+ },
+ {
+ name: 'github',
+ message: 'github url:'
+ }
+ ])
+ .then(answers => {
+ output = resolve(output || answers.name);
+ return create(output, answers);
+ })
+ .then(
+ () => winston.info(`Plugin created successfully in "${output}"`),
+ (err) => winston.error('Error: ', err)
+ );
+ });
program
.command('test [plugin]')
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;