-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
generator.js
86 lines (71 loc) · 1.96 KB
/
generator.js
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
85
'use strict';
var isValid = require('is-valid-app');
var choices = require('./tasks/choices');
var choose = require('./lib/choose');
var tasks = require('./tasks');
module.exports = function(app) {
if (!isValid(app, 'generate-license')) return;
/**
* Plugins
*/
app.use(require('generate-defaults'));
app.use(require('./tasks'));
/**
* The `default` task prompts you to choose the `LICENSE` to generate. All licenses
* from [github/choosealicense.com](https://github.com/github/choosealicense.com) are
* available.
*
* ```sh
* $ gen license
* $ gen license --dest ./docs
* # or
* $ gen license:choose
* $ gen license:choose --dest ./docs
* ```
* @name default
* @api public
*/
app.task('default', ['license']);
app.task('license', function(cb) {
app.build(app.options.defaultLicense || ['choose'], cb);
});
/**
* Prompt the user to choose the license to generate.
*/
app.task('license-choose', ['choose']);
app.task('license-prompt', ['choose']);
app.task('choose', function(cb) {
var options = {
message: 'Which license would you like to generate?',
choices: choices,
filter: function(str, choice) {
var re = new RegExp(str, 'i');
return re.test(choice.name[0]) || re.test(choice.id);
}
};
choose(app, options)
.then(function(name) {
app.build(name, cb);
})
.catch(cb);
});
/**
* Generate `tasks.js` file
*/
app.task('create-tasks', function(cb) {
return app.src('templates/*.tmpl')
.pipe(tasks({template: 'tasks/support/tasks.tmpl'}))
.pipe(app.renderFile('*'))
.pipe(app.dest(app.cwd));
});
/**
* Generate `choices.js` file
*/
app.task('create-choices', function(cb) {
return app.src('templates/*.tmpl')
.pipe(tasks({template: 'tasks/support/choices.tmpl'}))
.pipe(app.renderFile('*'))
.pipe(app.dest(app.cwd));
});
app.task('create', ['create-*']);
};