This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathslushfile.js
208 lines (190 loc) · 6.1 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* slush-marklogic-spring-boot
* https://github.com/rjrudin/slush-marklogic-spring-boot
*
* Copyright (c) 2016, Rob Rudin
* Licensed under the MIT license.
*/
'use strict';
var gulp = require('gulp'),
gulpif = require('gulp-if'),
conflict = require('gulp-conflict'),
chmod = require('gulp-chmod'),
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,
userName: osUserName || format((user && user.name) || ''),
authorName: (user && user.name) || '',
authorEmail: (user && user.email) || ''
};
})();
gulp.task('default', function (done) {
var prompts = [
{
name: 'appName',
message: 'What is the name of your application?',
default: defaults.appName
},
{
name: 'appHost',
message: 'What MarkLogic host do you want to deploy to?',
default: 'localhost'
},
{
name: 'appAdminUsername',
message: 'What MarkLogic admin user do you want to deploy with?',
default: 'admin'
},
{
name: 'appAdminPassword',
message: 'What is the MarkLogic admin user password? (Or keep blank and modify in gradle.properties afterwards)',
default: ''
},
{
name: 'appRestPort',
message: 'What port do you want the MarkLogic application REST API server to use?',
default: '8003'
},
{
name: 'appTestRestPort',
message: '(Optional) What port do you want a MarkLogic REST API server for testing to use? (zero means no test server)',
default: '0'
},
{
name: 'appBootPort',
message: 'What port do you want the Spring Boot server to use?',
default: '8080'
},
{
type: 'list',
name: 'template',
message: 'Select Template',
choices: [{
name: 'default',
value: 'default'
}, {
name: '3-columns',
value: '3column'
}, {
name: 'Cards',
value: 'cards'
}, {
name: 'Dashboard',
value: 'dashboard'
}, {
name: 'Full-screen map',
value: 'map'
}, {
name: 'I don\'t know',
value: 'unsure'
}]
},
{
type: 'list',
name: 'theme',
message: 'What is the main focus?',
when: function(ans) {
return ans.template === 'unsure';
},
choices: [{
name: 'Semantics',
value: '3column'
}, {
name: 'Charts',
value: 'dashboard'
}, {
name: 'Map/Graph',
value: 'map'
}, {
name: 'Data records',
value: 'cards'
}, {
name: 'Documents',
value: '3column'
}, {
name: 'Other',
value: 'default'
}]
}
];
// gulp-template bombs on certain font files, so using gulpif to not process them
var isTemplateable = function(file) {
var rel = file.relative;
var result =
rel.indexOf('fonts') == -1 &&
rel.indexOf('images') == -1 &&
rel.indexOf('gradle-wrapper') == -1 &&
!rel.endsWith('.zip');
console.log (rel);
return result;
};
// Need to make the gradlew scripts executable
var isExecutable = function(file) {
return file.relative.indexOf('gulp-chmod') > -1;
};
// Tell lodash to only interpolate <%= and %>; we need to ignore ${ and } as
// those are used by Thymeleaf
var templateOptions = {
interpolate: /<%=([\s\S]+?)%>/g
};
inquirer.prompt(prompts,
function (answers) {
answers.appNameSlug = _.slugify(answers.appName);
var srcPaths = [
__dirname + '/templates/**',
__dirname + '/templates/.bowerrc',
__dirname + '/templates/.editorconfig',
__dirname + '/templates/.gitignore',
'!' + __dirname + '/templates/.gradle',
'!' + __dirname + '/templates/bin',
'!' + __dirname + '/templates/bin/**',
'!' + __dirname + '/templates/build',
'!' + __dirname + '/templates/build/**'
];
if (answers.appTestRestPort == 0) {
srcPaths.push('!' + __dirname + '/templates/src/test');
srcPaths.push('!' + __dirname + '/templates/src/test/**');
}
var theme = answers.theme || answers.template || clArgs.theme || 'default';
if (theme !== 'default') { // overlay the theme if not the default theme chosen
srcPaths.push(__dirname + '/themes/' + theme + '/**');
}
gulp.src(srcPaths)
.pipe(gulpif(isTemplateable, template(answers, templateOptions)))
.pipe(rename(function (file) {
if (file.basename[0] === '_') {
file.basename = '.' + file.basename.slice(1);
}
}))
.pipe(gulpif(isExecutable, chmod(755)))
.pipe(conflict('./', {defaultChoice: 'y'}))
.pipe(gulp.dest('./'))
.on('end', function () {
done();
});
});
});