-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslushfile.js
159 lines (146 loc) · 5.17 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* slush-slush-cmake
* https://github.com/julian-becker/slush-slush-cmake
*
* Copyright (c) 2018, Julian Becker
* Licensed under the MIT license.
*/
'use strict';
var gulp = require('gulp'),
install = require('gulp-install'),
conflict = require('gulp-conflict'),
replace = require('gulp-replace'),
template = require('gulp-template'),
rename = require('gulp-rename'),
_ = require('underscore.string'),
inquirer = require('inquirer'),
path = require('path');
function format(string) {
var username = string.toLowerCase();
return username.replace(/\s/g, '');
}
var defaults = (function () {
var workingDirName = path.basename(process.cwd()),
homeDir, osUserName, configFile, user;
if (process.platform === 'win32') {
homeDir = process.env.USERPROFILE;
osUserName = process.env.USERNAME || path.basename(homeDir).toLowerCase();
}
else {
homeDir = process.env.HOME || process.env.HOMEPATH;
osUserName = homeDir && homeDir.split('/').pop() || 'root';
}
configFile = path.join(homeDir, '.gitconfig');
user = {};
if (require('fs').existsSync(configFile)) {
user = require('iniparser').parseSync(configFile).user;
}
return {
appName: workingDirName,
libraryName1: 'mylibA',
libraryName2: 'mylibB',
authorName: user.name || '',
authorEmail: user.email || ''
};
})();
gulp.task('default', function (done) {
var prompts = [{
name: 'appName',
message: 'Name for the main application?',
default: defaults.appName
}, {
name: 'appDescription',
message: 'What is the description for this application?'
}, {
name: 'libraryName1',
message: 'Name of dummy component library 1?',
default: defaults.libraryName1
}, {
name: 'libraryName2',
message: 'Name of dummy component library 2?',
default: defaults.libraryName2
}, {
name: 'appVersion',
message: 'What is the version of your project?',
default: '0.1.0'
}, {
name: 'authorName',
message: 'What is the author name?',
default: defaults.authorName
}, {
name: 'authorEmail',
message: 'What is the author email?',
default: defaults.authorEmail
}, {
type: 'list',
name: 'license',
message: 'Choose your license type',
choices: ['MIT', 'BSD', 'UNLICENSE'],
default: 'UNLICENSE'
}, {
type: 'list',
name: 'testingFramework',
message: 'Choose your testing framework',
choices: ['GoogleTest', 'Catch2'],
default: 'Catch2'
}, {
type: 'confirm',
name: 'moveon',
message: 'Continue?'
}];
//Ask
inquirer
.prompt(prompts)
.then(function (answers) {
if (!answers.moveon) {
return done();
}
var d = new Date();
answers.year = d.getFullYear();
answers.date = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
answers.LIBRARYNAME1 = answers.libraryName1.toUpperCase();
answers.LIBRARYNAME2 = answers.libraryName2.toUpperCase();
answers.appNameSlug = _.slugify(answers.appName);
var files = [
__dirname + '/templates/**',
__dirname + '/templates_' + answers.testingFramework + '/**'
];
gulp.src(files)
.pipe(replace('${','_UGLY_OPENBRACE_'))
.pipe(replace('}','_UGLY_CLOSINGBRACE_'))
.pipe(template(answers))
.pipe(replace('_UGLY_OPENBRACE_','${'))
.pipe(replace('_UGLY_CLOSINGBRACE_','}'))
.pipe(rename(function (path) {
if (path.basename[0] === '_') {
path.basename = '.' + path.basename.slice(1);
}
path.dirname = path.dirname
.replace(/==(\s*appName\s*)==/g, answers.appName)
.replace(/==(\s*libraryName1\s*)==/g, answers.libraryName1)
.replace(/==(\s*libraryName2\s*)==/g, answers.libraryName2);
path.basename = path.basename
.replace(/==(\s*appName\s*)==/g, answers.appName)
.replace(/==(\s*libraryName1\s*)==/g, answers.libraryName1)
.replace(/==(\s*libraryName2\s*)==/g, answers.libraryName2);
}))
.pipe(conflict('./'))
.pipe(gulp.dest('./'))
.pipe(install())
.on('end', function () {
done();
});
gulp.src(__dirname + '/license_templates/LICENSE_'+answers.license)
.pipe(template(answers))
.pipe(rename(function (path) {
console.log('basename='+path.basename);
path.basename = 'LICENSE';
}))
.pipe(conflict('./'))
.pipe(gulp.dest('./'))
.pipe(install())
.on('end', function () {
done();
});
});
});