UNPKG

1.15 kBJavaScriptView Raw
1'use strict';
2
3var path = require('path');
4var templates = path.resolve.bind(path, __dirname, 'templates');
5var matchFile = require('match-file');
6var through = require('through2');
7
8module.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() {
18 app.question('author.name', 'Author\'s name?');
19 app.data('argv', app.get('cache.argv.orig'));
20
21 return app.src('*.tmpl', {cwd: templates()})
22 .pipe(app.renderFile('*'))
23 .pipe(filter('mit.tmpl'))
24 .pipe(app.dest(function(file) {
25 file.basename = app.option('license.basename') || 'LICENSE';
26 return app.option('dest');
27 }));
28 });
29
30 // aliases
31 app.task('license', ['mit']);
32 app.task('default', ['license']);
33};
34
35function filter(pattern, options) {
36 var isMatch = matchFile.matcher(pattern, options);
37
38 return through.obj(function(file, enc, next) {
39 if (isMatch(file)) {
40 next(null, file);
41 } else {
42 next();
43 }
44 });
45}