UNPKG

2.67 kBJavaScriptView Raw
1'use strict';
2
3var utils = require('./utils');
4
5module.exports = function(app) {
6
7 // use `base-questions` plugin for user prompts
8 app.use(utils.questions());
9
10 /**
11 * Listend for `done` event
12 */
13
14 app.on('done', function() {
15 app.log.success('done');
16 process.exit();
17 });
18
19 /**
20 * Generate an `assemblefile.js`
21 */
22
23 app.task('init', function(cb) {
24 app.confirm('init', 'Welcome to assemble! Want to create an assemblefile.js?');
25 app.ask('init', {save: false}, function(err, answers) {
26 if (err) {
27 cb(err);
28 return;
29 }
30 if (!answers.init) {
31 app.log.time('Got it, we\'re all finished here. Run `assemble` to lean the next step.');
32 app.emit('done');
33 return;
34 }
35 app.build(['new', 'prompt-install'], cb);
36 });
37 });
38
39 /**
40 * Generate an `assemblefile.js`
41 */
42
43 app.task('new', function(cb) {
44 app.src('templates/assemblefile.js', {cwd: __dirname})
45 .pipe(app.dest(process.cwd()))
46 .on('end', function() {
47 app.log.success('created assemblefile.js');
48 cb();
49 });
50 });
51
52 /**
53 * Prompt to install assemble
54 */
55
56 app.task('prompt-install', function(cb) {
57 app.confirm('install', 'Want to install assemble to devDependencies now?');
58 app.ask('install', {save: false}, function(err, answers) {
59 if (err) {
60 cb(err);
61 return;
62 }
63 if (!answers.install) {
64 app.log.time('Got it, stopping');
65 app.emit('done');
66 return;
67 }
68 app.log.time('installing assemble');
69 install(['assemble'], cb);
70 });
71 });
72
73 /**
74 * Asks if you want to generate an `assemblefile.js`
75 */
76
77 app.task('prompt-new', function(cb) {
78 app.confirm('file', 'No assemblefile.js found, want to add one?');
79 app.ask('file', {save: false}, function(err, answers) {
80 if (err) {
81 cb(err);
82 return;
83 }
84 if (!answers.file) {
85 app.log.time('Got it, stopping');
86 app.emit('done');
87 return;
88 }
89 app.build(['new', 'prompt-install'], cb);
90 });
91 });
92
93 /**
94 * Display a help menu of available commands and flags.
95 *
96 * ```sh
97 * $ assemble help
98 * ```
99 * @name help
100 * @api public
101 */
102
103 app.task('help', { silent: true }, function(cb) {
104 app.base.cli.process({ help: true }, cb);
105 });
106
107 /**
108 * Default task
109 */
110
111 app.task('default', ['prompt-new']);
112};
113
114/**
115 * Install devDependencies
116 */
117
118function install(args, cb) {
119 args = ['install', '--save-dev'].concat(args);
120 utils.spawn('npm', args, {stdio: 'inherit'})
121 .on('error', cb)
122 .on('close', function(code, err) {
123 cb(err, code);
124 });
125}