forked from ng-harmony-zz/slush-angular-harmony-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slushfile.js
113 lines (103 loc) · 3.31 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* slush-node
* https://github.com/chrisenytc/slush-node
*
* Copyright (c) 2015, Christopher EnyTC
* 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"),
path = require("path"),
fs = require("fs");
function format(string) {
var username = string.toLowerCase();
return username.replace(/\s/g, "");
}
var defaults = (function () {
var workingDirName = path.basename(process.cwd()),
homeDir, includeSed, configFile, user;
if (process.platform === "win32") {
homeDir = process.env.USERPROFILE;
} else {
homeDir = process.env.HOME || process.env.HOMEPATH;
}
configFile = path.join(homeDir, ".gitconfig");
user = {};
if (require("fs").existsSync(configFile)) {
user = require("iniparser").parseSync(configFile).user;
}
return {
appName: workingDirName,
userName: "ng-harmony",
authorName: user.name || "",
authorEmail: user.email || ""
};
})();
gulp.task("default", function (done) {
var prompts = [{
name: "appName",
message: "What\"s the module name?",
default: defaults.appName
}, {
name: "appDescription",
message: "Please enter a short description?"
}, {
name: "appVersion",
message: "What\"s the module version?",
default: "0.1.0"
}, {
name: "authorName",
message: "What\"s the author name?",
default: defaults.authorName
}, {
name: "authorEmail",
message: "And the author\"s email?",
default: defaults.authorEmail
}, {
name: "userName",
message: "What\"s the github username?",
default: defaults.userName
}];
//Ask
inquirer.prompt(prompts,
function (answers) {
if (!answers.appName) {
return done();
}
answers.appNameSlug = _.slugify(answers.appName);
answers.appNameOnly = _.capitalize(answers.appNameSlug);
var d = new Date();
answers.year = d.getFullYear();
answers.date = d.getFullYear() + "-" + (d.getMonth() +
1) + "-" + d.getDate();
var files = [__dirname + "/templates/**"];
files.push("!" + __dirname + "/templates/LICENSE");
fs.mkdir("./src");
fs.mkdirSync("./build");
fs.mkdir("./build/modules");
gulp.src(files)
.pipe(template(answers))
.pipe(rename(function (file) {
var appReplace = file.basename.replace(
new RegExp("appName", "g"),
answers.appNameSlug);
file.basename = appReplace;
if (file.basename[0] === "_") {
file.basename = "." + file.basename
.slice(1);
}
}))
.pipe(conflict("./"))
.pipe(gulp.dest("./"))
.pipe(install())
.on("end", function () {
done();
});
});
});