1 | 'use strict';
|
2 |
|
3 | var path = require('path');
|
4 | var templates = path.resolve.bind(path, __dirname, 'templates');
|
5 | var matchFile = require('match-file');
|
6 | var through = require('through2');
|
7 |
|
8 | module.exports = function(app) {
|
9 | if (app.isRegistered('generate-license')) return;
|
10 |
|
11 | if (typeof app.ask === 'undefined') {
|
12 | throw new Error('expected the base-questions plugin to be registered');
|
13 | }
|
14 |
|
15 | app.use(require('generate-defaults'));
|
16 |
|
17 | app.task('mit', function(cb) {
|
18 | app.question('author.name', 'Author\'s name?');
|
19 | app.data('argv', app.get('cache.argv.orig'));
|
20 |
|
21 | app.src('*.tmpl', {cwd: templates()})
|
22 | .on('error', cb)
|
23 | .pipe(app.renderFile('*'))
|
24 | .on('error', cb)
|
25 | .pipe(filter('mit.tmpl'))
|
26 | .on('error', cb)
|
27 | .pipe(app.dest(function(file) {
|
28 | file.basename = app.option('license.basename') || 'LICENSE';
|
29 | return app.option('dest') || app.cwd;
|
30 | }))
|
31 | .on('error', cb)
|
32 | .on('end', cb)
|
33 | });
|
34 |
|
35 |
|
36 | app.task('license', ['mit']);
|
37 | app.task('default', ['license']);
|
38 | };
|
39 |
|
40 | function filter(pattern, options) {
|
41 | var isMatch = matchFile.matcher(pattern, options);
|
42 |
|
43 | return through.obj(function(file, enc, next) {
|
44 | if (file.isNull()) {
|
45 | next();
|
46 | return;
|
47 | }
|
48 |
|
49 | if (isMatch(file)) {
|
50 | next(null, file);
|
51 | } else {
|
52 | next();
|
53 | }
|
54 | });
|
55 | }
|