-
Notifications
You must be signed in to change notification settings - Fork 6
/
slushfile.js
44 lines (43 loc) · 1.52 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
var gulp = require('gulp'),
aside = require('gulp-aside'),
conflict = require('gulp-conflict'),
install = require('gulp-install'),
template = require('gulp-template'),
inquirer = require('inquirer'),
path = require('path');
gulp.task('default', function (cb) {
inquirer.prompt([
{
type: 'input',
message: 'Name your project:',
name: 'project',
validate: function (input) { return /\w/g.test(input) || 'Seriously, name it:'; },
filter: function (input) { return input.toString().trim(); },
default: 'slushy' || gulp.args
}, {
type: 'confirm',
message: function (input) { return 'Create project ' + input['project'] + '?'; },
name: 'good',
default: true
}
]).then(function (answers) {
if (!answers.good) { return cb(); }
answers.slug = slugify(answers.project);
answers.camel = camelize(answers.project);
gulp.src(path.join(__dirname, 'templates/app/**'))
.pipe(aside('!**/*.{ico,png}', template(answers, { interpolate: /<%=([\s\S]+?)%>/g })))
.pipe(conflict(path.join(process.cwd(), answers.slug)))
.pipe(gulp.dest(path.join(process.cwd(), answers.slug)))
.pipe(install())
.on('end', function () { cb(); }).resume();
});
});
function camelize (str) {
return str.charAt(0).toLowerCase() + str.slice(1).replace(/[-_\s]+(.)?/g, function(m, c) { return c ? c.toUpperCase() : ''; });
}
function classable (str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function slugify (str) {
return str.toLowerCase().replace(/\s/g, '-');
}