-
Notifications
You must be signed in to change notification settings - Fork 20
/
slushfile.js
212 lines (182 loc) · 6.56 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
209
210
211
212
var gulp = require('gulp'),
gutil = require('gulp-util'),
install = require('gulp-install'),
template = require('gulp-template'),
gulpif = require('gulp-if'),
rename = require('gulp-rename'),
path = require('path'),
url = require('url'),
inquirer = require('inquirer');
function isUndefined(obj) {
return obj === void 0;
};
function fixUrl(urlString, prefix, endfix) {
if (!urlString) return '/';
endfix = isUndefined(endfix) ? true : endfix;
prefix = isUndefined(prefix) ? true : prefix;
if (prefix) {
urlString = urlString.indexOf('http://') < 0 ? 'http://' + urlString : urlString;
}
if (endfix) {
urlString = urlString[urlString.length - 1] == '/' ? urlString : urlString + '/';
}
return urlString;
};
gulp.task('default', function(done) {
gutil.log('slush-alloyteam-simple');
var tplFiles = function(file) {
var basename = path.basename(file.path);
return (basename === 'project.js') || (basename === 'livefile.js');
};
inquirer.prompt([{
type: 'input',
name: 'name',
message: '项目名称 -> '
}, {
type: 'input',
name: 'webServer',
message: '项目html路径,如: http://find.qq.com/qqun/search/ -> '
}, {
type: 'input',
name: 'cdn',
message: '项目cdn路径,如: http://s.url.cn/qqun/qqfind/search/ -> '
}, {
type: 'input',
name: 'subModule',
message: '子项目名字(可直接enter留空),如: 双十一活动子项目 qiqi_1111 -> '
}, {
type: 'confirm',
name: 'moveon',
message: '开始初始化项目? -> '
}],
function(answers) {
if (!answers.moveon) {
return done();
}
if (!answers.webServer) {
gutil.log('html根目录不能为空!');
return done();
}
// set cdn default webserver
answers.cdn = answers.cdn || answers.webServer;
answers.subModule = answers.subModule || '';
// fix url
answers.cdn = fixUrl(answers.cdn);
answers.webServer = fixUrl(answers.webServer);
answers.subModule = fixUrl(answers.subModule, false, true);
// alloydist mapping setting suggestion
var cdnUrlObj = url.parse(answers.cdn);
var webUrlObj = url.parse(answers.webServer);
answers.distCdnDir = '/data/sites/cdn.qplus.com' + cdnUrlObj.pathname;
answers.distHtmlDir = '/data/sites/' + webUrlObj.hostname + webUrlObj.pathname;
// for livefile.js
var webServer = (answers.subModule === '/') ? answers.webServer : answers.webServer + answers.subModule;
var cdn = (answers.subModule === '/') ? answers.cdn : answers.cdn + answers.subModule;
answers.webServerResolve = webServer.replace('http://', '');
answers.cdnResolve = cdn.replace('http://', '');
gulp.src(__dirname + '/templates/**')
.pipe(gulpif(tplFiles, template(answers)))
.pipe(rename(function(file) {
if (file.basename[0] === '_' && file.basename[1] === '_') {
file.basename = '.' + file.basename.slice(2);
}
}))
.pipe(gulp.dest('./'))
// .pipe(install())
.on('finish', function() {
done();
});
});
});
gulp.task('page', function(done) {
var pageName = gulp.args[0];
if (!pageName) {
console.log('page name require');
done();
return;
}
var data = {
pageName: pageName
};
gulp.src(__dirname + '/components/page/index.html')
.pipe(template(data))
.pipe(rename(function(file) {
file.basename = file.basename.replace('index', pageName);
}))
.pipe(gulp.dest('./src'));
gulp.src(__dirname + '/components/page/index.js')
.pipe(rename(function(file) {
file.basename = file.basename.replace('index', pageName);
}))
.pipe(gulp.dest('./src/js/'));
gulp.src(__dirname + '/components/page/index.scss')
.pipe(rename(function(file) {
file.basename = file.basename.replace('index', pageName);
}))
.pipe(gulp.dest('./src/css/'));
gulp.src(__dirname + '/components/page/index.jade')
.pipe(gulp.dest('./src/tpl/' + pageName + '/'));
done();
});
gulp.task('autosprite', function(done) {
var spriteName = gulp.args[0];
if (!spriteName) {
console.log('sprite name require');
done();
return;
}
var data = {
spriteName: spriteName
};
gulp.src(__dirname + '/components/sprite/autosprite.scss')
.pipe(template(data))
.pipe(rename(function(file) {
file.basename = file.basename.replace('autosprite', '_' + spriteName);
}))
.pipe(gulp.dest('./src/css/common'));
gulp.src(__dirname + '/components/sprite/icon.png')
.pipe(gulp.dest('./src/img/sprite/' + spriteName + '/'));
done();
});
gulp.task('sprite', function(done) {
var spriteName = gulp.args[0];
if (!spriteName) {
console.log('sprite name require');
done();
return;
}
var data = {
spriteName: spriteName
};
gulp.src(__dirname + '/components/sprite/sprite.scss')
.pipe(template(data))
.pipe(rename(function(file) {
file.basename = file.basename.replace('sprite', '_' + spriteName);
}))
.pipe(gulp.dest('./src/css/common'));
gulp.src(__dirname + '/components/sprite/icon.png')
.pipe(gulp.dest('./src/img/sprite/' + spriteName + '/'));
done();
});
gulp.task('retina', function(done) {
var spriteName = gulp.args[0];
if (!spriteName) {
console.log('sprite name require');
done();
return;
}
var data = {
spriteName: spriteName
};
gulp.src(__dirname + '/components/sprite/retina.scss')
.pipe(template(data))
.pipe(rename(function(file) {
file.basename = file.basename.replace('retina', '_' + spriteName);
}))
.pipe(gulp.dest('./src/css/common'));
gulp.src(__dirname + '/components/sprite/icon.png')
.pipe(gulp.dest('./src/img/sprite/' + spriteName + '/'));
gulp.src(__dirname + '/components/sprite/icon.png')
.pipe(gulp.dest('./src/img/sprite/' + spriteName + '@2x/'));
done();
});