forked from digitalbs/slush-anglify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slushfile.js
62 lines (56 loc) · 1.77 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
/*
* slush-anglify
* https://github.com/digitalbs/slush-anglify
*
* Copyright (c) 2014, Brian Schneider
* Licensed under the MIT license.
*/
/**
* Require in necessary modules
*/
var fs = require('fs'),
slushTasks = fs.readdirSync(__dirname + '/slush-tasks');
/**
* Setting globals to use for all slush tasks
*/
global.gulp = require('gulp');
global.install = require('gulp-install');
global.conflict = require('gulp-conflict');
global.global.template = require('gulp-template');
global.rename = require('gulp-rename');
global._ = require('underscore.string');
global.inquirer = require('inquirer');
global.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: formatUsername(user.name) || osUserName,
authorEmail: user.email || ''
};
})();
/**
* slush tasks loader. Loops through the files in the slush task directory to load in
* @param {Object} slushTask Slush task in each loop is the file that we read and bring in to require them into the slush file
*/
slushTasks.forEach(function(slushTask) {
if (slushTask.match(/.*\.js/)) {
require('./slush-tasks/' + slushTask);
}
});
//helper methods
/**
* Format the user name used in the github user name
* @param {String} string Github user name
* @return {String} retuns the formatted user name
*/
function formatUsername(string) {
var username = string.toLowerCase();
return username.replace(/\s/g, '');
}