1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var
|
18 | gulp = require('gulp'),
|
19 |
|
20 |
|
21 | fs = require('fs'),
|
22 | path = require('path'),
|
23 |
|
24 |
|
25 | concatFileNames = require('gulp-concat-filenames'),
|
26 | flatten = require('gulp-flatten'),
|
27 | jsonEditor = require('gulp-json-editor'),
|
28 | plumber = require('gulp-plumber'),
|
29 | rename = require('gulp-rename'),
|
30 | replace = require('gulp-replace'),
|
31 | tap = require('gulp-tap'),
|
32 |
|
33 |
|
34 | config = require('../../config/user'),
|
35 | release = require('../../config/admin/release'),
|
36 | project = require('../../config/project/release'),
|
37 |
|
38 |
|
39 | version = project.version,
|
40 | output = config.paths.output
|
41 |
|
42 | ;
|
43 |
|
44 |
|
45 | module.exports = function(callback) {
|
46 | var
|
47 | stream,
|
48 | index,
|
49 | tasks = []
|
50 | ;
|
51 |
|
52 | for(index in release.components) {
|
53 |
|
54 | var
|
55 | component = release.components[index]
|
56 | ;
|
57 |
|
58 |
|
59 | (function(component) {
|
60 |
|
61 | var
|
62 | outputDirectory = path.join(release.outputRoot, component),
|
63 | isJavascript = fs.existsSync(output.compressed + component + '.js'),
|
64 | isCSS = fs.existsSync(output.compressed + component + '.css'),
|
65 | capitalizedComponent = component.charAt(0).toUpperCase() + component.slice(1),
|
66 | packageName = release.packageRoot + component,
|
67 | repoName = release.componentRepoRoot + capitalizedComponent,
|
68 | gitURL = 'https://github.com/' + release.org + '/' + repoName + '.git',
|
69 | repoURL = 'https://github.com/' + release.org + '/' + repoName + '/',
|
70 | concatSettings = {
|
71 | newline : '',
|
72 | root : outputDirectory,
|
73 | prepend : " '",
|
74 | append : "',"
|
75 | },
|
76 | regExp = {
|
77 | match : {
|
78 |
|
79 | name : '{component}',
|
80 | titleName : '{Component}',
|
81 | version : '{version}',
|
82 | files : '{files}',
|
83 |
|
84 | spacedVersions : /(###.*\n)\n+(?=###)/gm,
|
85 | spacedLists : /(^- .*\n)\n+(?=^-)/gm,
|
86 | trim : /^\s+|\s+$/g,
|
87 | unrelatedNotes : new RegExp('^((?!(^.*(' + component + ').*$|###.*)).)*$', 'gmi'),
|
88 | whitespace : /\n\s*\n\s*\n/gm,
|
89 |
|
90 | componentExport : /(.*)\$\.fn\.\w+\s*=\s*function\(([^\)]*)\)\s*{/g,
|
91 | componentReference: '$.fn.' + component,
|
92 | settingsExport : /\$\.fn\.\w+\.settings\s*=/g,
|
93 | settingsReference : /\$\.fn\.\w+\.settings/g,
|
94 | trailingComma : /,(?=[^,]*$)/,
|
95 | jQuery : /jQuery/g,
|
96 | },
|
97 | replace : {
|
98 |
|
99 | name : component,
|
100 | titleName : capitalizedComponent,
|
101 |
|
102 | spacedVersions : '',
|
103 | spacedLists : '$1',
|
104 | trim : '',
|
105 | unrelatedNotes : '',
|
106 | whitespace : '\n\n',
|
107 |
|
108 | componentExport : 'var _module = module;\n$1module.exports = function($2) {',
|
109 | componentReference: '_module.exports',
|
110 | settingsExport : 'module.exports.settings =',
|
111 | settingsReference : '_module.exports.settings',
|
112 | jQuery : 'require("jquery")'
|
113 | }
|
114 | },
|
115 | task = {
|
116 | all : component + ' creating',
|
117 | repo : component + ' create repo',
|
118 | bower : component + ' create bower.json',
|
119 | readme : component + ' create README',
|
120 | npm : component + ' create NPM Module',
|
121 | notes : component + ' create release notes',
|
122 | composer : component + ' create composer.json',
|
123 | package : component + ' create package.json',
|
124 | meteor : component + ' create meteor package.js',
|
125 | },
|
126 |
|
127 | manifest = {
|
128 | assets : outputDirectory + '/assets/**/' + component + '?(s).*',
|
129 | component : outputDirectory + '/' + component + '+(.js|.css)'
|
130 | }
|
131 | ;
|
132 |
|
133 |
|
134 | function copyDist() {
|
135 | return gulp.src(release.source + component + '.*')
|
136 | .pipe(plumber())
|
137 | .pipe(flatten())
|
138 | .pipe(replace(release.paths.source, release.paths.output))
|
139 | .pipe(gulp.dest(outputDirectory))
|
140 | ;
|
141 | }
|
142 |
|
143 |
|
144 | function createNpmModule() {
|
145 | return gulp.src(release.source + component + '!(*.min|*.map).js')
|
146 | .pipe(plumber())
|
147 | .pipe(flatten())
|
148 | .pipe(replace(regExp.match.componentExport, regExp.replace.componentExport))
|
149 | .pipe(replace(regExp.match.componentReference, regExp.replace.componentReference))
|
150 | .pipe(replace(regExp.match.settingsExport, regExp.replace.settingsExport))
|
151 | .pipe(replace(regExp.match.settingsReference, regExp.replace.settingsReference))
|
152 | .pipe(replace(regExp.match.jQuery, regExp.replace.jQuery))
|
153 | .pipe(rename('index.js'))
|
154 | .pipe(gulp.dest(outputDirectory))
|
155 | ;
|
156 | }
|
157 |
|
158 |
|
159 | function createReadme() {
|
160 | return gulp.src(release.templates.readme)
|
161 | .pipe(plumber())
|
162 | .pipe(flatten())
|
163 | .pipe(replace(regExp.match.name, regExp.replace.name))
|
164 | .pipe(replace(regExp.match.titleName, regExp.replace.titleName))
|
165 | .pipe(gulp.dest(outputDirectory))
|
166 | ;
|
167 | }
|
168 |
|
169 |
|
170 | function extendBower() {
|
171 | return gulp.src(release.templates.bower)
|
172 | .pipe(plumber())
|
173 | .pipe(flatten())
|
174 | .pipe(jsonEditor(function(bower) {
|
175 | bower.name = packageName;
|
176 | bower.description = capitalizedComponent + ' - Semantic UI';
|
177 | if(isJavascript) {
|
178 | if(isCSS) {
|
179 | bower.main = [
|
180 | component + '.js',
|
181 | component + '.css'
|
182 | ];
|
183 | }
|
184 | else {
|
185 | bower.main = [
|
186 | component + '.js'
|
187 | ];
|
188 | }
|
189 | bower.dependencies = {
|
190 | jquery: '>=1.8'
|
191 | };
|
192 | }
|
193 | else {
|
194 | bower.main = [
|
195 | component + '.css'
|
196 | ];
|
197 | }
|
198 | return bower;
|
199 | }))
|
200 | .pipe(gulp.dest(outputDirectory))
|
201 | ;
|
202 | }
|
203 |
|
204 |
|
205 | function extendPackage() {
|
206 | return gulp.src(release.templates.package)
|
207 | .pipe(plumber())
|
208 | .pipe(flatten())
|
209 | .pipe(jsonEditor(function(npm) {
|
210 | if(isJavascript) {
|
211 | npm.dependencies = {
|
212 | jquery: 'x.x.x'
|
213 | };
|
214 | npm.main = 'index.js';
|
215 | }
|
216 | npm.name = packageName;
|
217 | if(version) {
|
218 | npm.version = version;
|
219 | }
|
220 | npm.title = 'Semantic UI - ' + capitalizedComponent;
|
221 | npm.description = 'Single component release of ' + component;
|
222 | npm.repository = {
|
223 | type : 'git',
|
224 | url : gitURL
|
225 | };
|
226 | return npm;
|
227 | }))
|
228 | .pipe(gulp.dest(outputDirectory))
|
229 | ;
|
230 | }
|
231 |
|
232 |
|
233 | function extendComposer(){
|
234 | return gulp.src(release.templates.composer)
|
235 | .pipe(plumber())
|
236 | .pipe(flatten())
|
237 | .pipe(jsonEditor(function(composer) {
|
238 | if(isJavascript) {
|
239 | composer.dependencies = {
|
240 | jquery: 'x.x.x'
|
241 | };
|
242 | composer.main = component + '.js';
|
243 | }
|
244 | composer.name = 'semantic/' + component;
|
245 | if(version) {
|
246 | composer.version = version;
|
247 | }
|
248 | composer.description = 'Single component release of ' + component;
|
249 | return composer;
|
250 | }))
|
251 | .pipe(gulp.dest(outputDirectory))
|
252 | ;
|
253 | }
|
254 |
|
255 |
|
256 | function createReleaseNotes() {
|
257 | return gulp.src(release.templates.notes)
|
258 | .pipe(plumber())
|
259 | .pipe(flatten())
|
260 |
|
261 | .pipe(replace(regExp.match.unrelatedNotes, regExp.replace.unrelatedNotes))
|
262 | .pipe(replace(regExp.match.whitespace, regExp.replace.whitespace))
|
263 | .pipe(replace(regExp.match.spacedVersions, regExp.replace.spacedVersions))
|
264 | .pipe(replace(regExp.match.spacedLists, regExp.replace.spacedLists))
|
265 | .pipe(replace(regExp.match.trim, regExp.replace.trim))
|
266 | .pipe(gulp.dest(outputDirectory))
|
267 | ;
|
268 | }
|
269 |
|
270 |
|
271 | function createMeteorPackage() {
|
272 | var
|
273 | filenames = ''
|
274 | ;
|
275 | return gulp.src(manifest.component)
|
276 | .pipe(concatFileNames('empty.txt', concatSettings))
|
277 | .pipe(tap(function(file) {
|
278 | filenames += file.contents;
|
279 | }))
|
280 | .on('end', function() {
|
281 | gulp.src(manifest.assets)
|
282 | .pipe(concatFileNames('empty.txt', concatSettings))
|
283 | .pipe(tap(function(file) {
|
284 | filenames += file.contents;
|
285 | }))
|
286 | .on('end', function() {
|
287 |
|
288 | filenames = filenames.replace(regExp.match.trailingComma, '').trim();
|
289 | gulp.src(release.templates.meteor.component)
|
290 | .pipe(plumber())
|
291 | .pipe(flatten())
|
292 | .pipe(replace(regExp.match.name, regExp.replace.name))
|
293 | .pipe(replace(regExp.match.titleName, regExp.replace.titleName))
|
294 | .pipe(replace(regExp.match.version, version))
|
295 | .pipe(replace(regExp.match.files, filenames))
|
296 | .pipe(rename(release.files.meteor))
|
297 | .pipe(gulp.dest(outputDirectory))
|
298 | ;
|
299 | })
|
300 | ;
|
301 | })
|
302 | ;
|
303 | }
|
304 |
|
305 | tasks.push(gulp.series(
|
306 | copyDist,
|
307 | createNpmModule,
|
308 | extendBower,
|
309 | createReadme,
|
310 | extendPackage,
|
311 | extendComposer,
|
312 | createReleaseNotes,
|
313 | createMeteorPackage
|
314 | ));
|
315 | })(component);
|
316 | }
|
317 |
|
318 | gulp.series(...tasks)(callback);
|
319 | };
|