summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin/src/cli.js
blob: 06e421d3602d1ef56fae874cc085a3355e36d303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env node

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));

program.version(pkg.version);
winston.cli();

program
    .command('build [input] [output]')
    .description('build a browser plugin')
    .action(function(input, output, options) {
        compile(resolve(input), resolve(output))
        .then(
            () => winston.info('Plugin compiled successfully'),
            (err) => winston.error('Error: ', err)
        );
    });

program
    .command('create [output]')
    .description('create a new plugin')
    .action(function(output, options) {
        inquirer.prompt([
            {
                name: 'title',
                message: 'Title (as displayed on GitBook.com):'
            },
            {
                name: 'name',
                message: 'Name (unique identifier for the plugin):'
            },
            {
                name: 'desc',
                message: 'Description:'
            },
            {
                name: 'github',
                message: 'GitHub repository URL:'
            },
            {
                name: 'categories',
                message: 'Categories (as displayed on GitBook.com):',
                type: 'checkbox',
                choices: [
                    'analytics',
                    'search',
                    'content',
                    'structure',
                    'social',
                    'visual'
                ]
            }
        ])
        .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]')
    .description('test specs for a plugin')
    .action(function(plugin, options) {

    });


program.parse(process.argv);

// Display help if no arguments
if (!program.args.length) program.help();