-
Notifications
You must be signed in to change notification settings - Fork 3
/
slushfile.js
68 lines (63 loc) · 1.83 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
/*
* slush-ng
* https://github.com/arvindr21/slush-ng
*
* Copyright (c) 2014, Arvind Ravulavaru
* Licensed under the MIT license.
*/
'use strict';
var gulp = require('gulp'),
install = require('gulp-install'),
conflict = require('gulp-conflict'),
template = require('gulp-template'),
rename = require('gulp-rename'),
_ = require('underscore.string'),
inquirer = require('inquirer');
function format(string) {
var username = string ? string.toLowerCase() : '';
return username.replace(/\s/g, '');
}
var defaults = (function() {
var homeDir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
workingDirName = process.cwd().split('/').pop().split('\\').pop(),
osUserName = homeDir && homeDir.split('/').pop() || 'root',
configFile = homeDir + '/.gitconfig',
user = {};
if (require('fs').existsSync(configFile)) {
user = require('iniparser').parseSync(configFile).user;
}
return {
appName: workingDirName,
userName: format(user.name) || osUserName,
authorEmail: user.email || ''
};
})();
gulp.task('default', function(done) {
var prompts = [{
name: 'appName',
message: 'What is the name of your project?',
default: defaults.appName
}];
//Ask
inquirer.prompt(prompts,
function(answers) {
if (!answers.appName) {
return done();
}
answers.appNameSlug = _.slugify(answers.appName);
answers.isWin = /^win/.test(process.platform);
gulp.src(__dirname + '/templates/**')
.pipe(template(answers))
.pipe(rename(function(file) {
if (file.basename.indexOf('__') == 0) {
file.basename = '.' + file.basename.slice(2);
}
}))
.pipe(conflict('./'))
.pipe(gulp.dest('./'))
.pipe(install())
.on('end', function() {
done();
});
});
});