-
Notifications
You must be signed in to change notification settings - Fork 32
/
slushfile.js
83 lines (80 loc) · 2.5 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var gulp = require('gulp'),
install = require('gulp-install'),
conflict = require('gulp-conflict'),
template = require('gulp-template'),
rename = require('gulp-rename'),
inquirer = require('inquirer'),
_ = require('underscore.string');
var cssTypeData = {
'less': {
plugin: 'gulp-less',
pluginVersion: '^1.2.3',
pipeCommand: 'g.less()',
extension: 'less'
},
'sass': {
plugin: 'gulp-sass',
pluginVersion: '^0.7.1',
pipeCommand: 'g.sass()',
extension: 'scss'
},
'styl': {
plugin: 'gulp-stylus',
pluginVersion: '^1.0.2',
pipeCommand: 'g.stylus({use: [require(\'nib\')()]})',
extension: 'styl',
extraDependencies: {
'nib': '^1.0.2'
}
}
};
gulp.task('default', function (done) {
inquirer.prompt([
{type: 'input', name: 'name', message: 'What do you want to name your AngularJS app?', default: getNameProposal()},
{type: 'list', name: 'csstype', message: 'What CSS preprocessor do you want to use?', default: 'styl', choices: [
{name: 'Stylus', value: 'styl'},
{name: 'LESS', value: 'less'},
{name: 'Sass', value: 'sass'}
]},
{type: 'confirm', name: 'coffee', message: 'Do you want to use CoffeeScript in your app?', default: false},
{type: 'confirm', name: 'example', message: 'Do you want to include a Todo List example in your app?', default: true}
],
function (answers) {
answers.nameDashed = _.slugify(answers.name);
answers.modulename = _.camelize(answers.nameDashed);
var files = [__dirname + '/templates/**'];
if (answers.coffee) {
files.push('!' + __dirname + '/templates/src/**/*.js')
}
else {
files.push('!' + __dirname + '/templates/src/**/*.coffee')
}
if (!answers.example) {
files.push('!' + __dirname + '/templates/src/app/todo/**');
}
answers.styleData = cssTypeData[answers.csstype];
return gulp.src(files)
.pipe(template(answers))
.pipe(rename(function (file) {
if (file.extname === '.css') {
file.extname = '.' + answers.styleData.extension;
} else if (file.basename[0] === '_') {
file.basename = '.' + file.basename.slice(1);
}
}))
.pipe(conflict('./'))
.pipe(gulp.dest('./'))
.pipe(install())
.on('finish', function () {
done();
});
});
});
function getNameProposal () {
var path = require('path');
try {
return require(path.join(process.cwd(), 'package.json')).name;
} catch (e) {
return path.basename(process.cwd());
}
}