-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslushfile.js
67 lines (61 loc) · 3.05 KB
/
slushfile.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
'use strict';
var fs = require('fs'),
path = require('path'),
gulp = require('gulp'),
install = require('gulp-install'),
conflict = require('gulp-conflict'),
template = require('gulp-template'),
inquirer = require('inquirer'),
_ = require('lodash'),
chalk = require('chalk');
function spaceSeparatedStrToArray(str) {
return str.trim().split(/\s+/);
}
gulp.task('default', function(done) {
inquirer.prompt([
{ name: 'env', message: 'Environment:', type: 'list', choices: [
{ value: 'node', name: 'Node.js' },
new inquirer.Separator('(more environments coming soon)')
// { value: 'browser', name: 'Browser' }
]},
{ when: _.callback({ env: 'node' }), name: 'pkgName', message: 'Package name:', default: _.kebabCase(path.basename(process.cwd())) },
{ when: _.callback({ env: 'node' }), name: 'pkgDescription', message: 'Package description:', default: 'My awesome ES.next package' },
{ when: _.callback({ env: 'node' }), name: 'keywords', message: 'Keywords (space-separated):', default: 'es20xx hello-world' },
{ when: _.callback({ env: 'node' }), name: 'installFlags', default: '--save', message: function(answers) {
return 'Recommended flag(s) for ' + chalk.bgGreen(' npm install ' + answers.pkgName + ' ');
}},
{ when: _.callback({ env: 'node' }), name: 'enginesNode', message: 'Compatible Node.js versions:', default: '>= 0.10' },
{ when: _.callback({ env: 'node' }), name: 'travisNode', message: 'Node.js versions to use in Travis CI (space-separated):', default: '0.12 iojs' },
{ when: _.callback({ env: 'node' }), name: 'authorName', message: 'Author name:', default: 'Ult Combo' },
{ when: _.callback({ env: 'node' }), name: 'authorEmail', message: 'Author email:', default: '[email protected]' },
{ name: 'ghUser', message: 'GitHub repository owner username:', default: 'UltCombo' },
{ name: 'ghRepo', message: 'GitHub repository name:', default: function(answers) { return answers.pkgName; } },
{ name: 'homepage', message: 'Project homepage:', default: function(answers) { return 'https://github.com/' + answers.ghUser + '/' + answers.ghRepo; } },
{ name: 'license', message: 'License:', type: 'list', choices: fs.readdirSync(__dirname + '/tpl/licenses') },
{ type: 'confirm', name: 'moveon', message: 'Continue?' },
], function(answers) {
if (!answers.moveon) return done();
['keywords', 'travisNode'].forEach(function(prop) {
answers[prop] = spaceSeparatedStrToArray(answers[prop]);
});
answers.currentYear = new Date().getFullYear();
gulp.src([
__dirname + '/tpl/env/' + answers.env + '/**',
__dirname + '/tpl/licenses/' + answers.license + '/**'
], { dot: true })
// Set the interpolate option in order to not conflict with ES2015 template strings
.pipe(template(answers, { interpolate: /<%=([\s\S]+?)%>/g }))
.pipe(conflict('.'))
.pipe(gulp.dest('.'))
.pipe(install())
.on('end', function() {
console.log(chalk.green(
'All set!\n' +
'Run ' + chalk.white.bgGreen(' npm run dev ') + ' and hack the ' +
chalk.white.bgGreen(' src ') + ' directory!'
));
done();
})
.resume();
});
});