create.js
6.2 KB
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
213
214
215
216
217
218
219
/*******************************
Create Distributions
*******************************/
/*
This will create individual distribution repositories for each SUI distribution
* copy distribution files to release
* update package.json file
*/
var
gulp = require('gulp'),
// node dependencies
console = require('better-console'),
del = require('del'),
fs = require('fs'),
path = require('path'),
runSequence = require('run-sequence'),
mergeStream = require('merge-stream'),
// admin dependencies
concatFileNames = require('gulp-concat-filenames'),
debug = require('gulp-debug'),
flatten = require('gulp-flatten'),
git = require('gulp-git'),
jsonEditor = require('gulp-json-editor'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
tap = require('gulp-tap'),
// config
config = require('../../config/user'),
release = require('../../config/admin/release'),
project = require('../../config/project/release'),
// shorthand
version = project.version,
output = config.paths.output
;
module.exports = function(callback) {
var
stream,
index,
tasks = []
;
for(index in release.distributions) {
var
distribution = release.distributions[index]
;
// streams... designed to save time and make coding fun...
(function(distribution) {
var
distLowerCase = distribution.toLowerCase(),
outputDirectory = path.join(release.outputRoot, distLowerCase),
packageFile = path.join(outputDirectory, release.files.npm),
repoName = release.distRepoRoot + distribution,
regExp = {
match : {
files : '{files}',
version : '{version}'
}
},
task = {
all : distribution + ' copying files',
repo : distribution + ' create repo',
meteor : distribution + ' create meteor package.js',
package : distribution + ' create package.json'
},
gatherFiles,
createList
;
// get files for meteor
gatherFiles = function(dir) {
var
dir = dir || path.resolve('.'),
list = fs.readdirSync(dir),
omitted = [
'.git',
'node_modules',
'package.js',
'LICENSE',
'README.md',
'package.json',
'bower.json',
'.gitignore'
],
files = []
;
list.forEach(function(file) {
var
isOmitted = (omitted.indexOf(file) > -1),
filePath = path.join(dir, file),
stat = fs.statSync(filePath)
;
if(!isOmitted) {
if(stat && stat.isDirectory()) {
files = files.concat(gatherFiles(filePath));
}
else {
files.push(filePath.replace(outputDirectory + path.sep, ''));
}
}
});
return files;
};
// spaces out list correctly
createList = function(files) {
var filenames = '';
for(var file in files) {
if(file == (files.length - 1) ) {
filenames += "'" + files[file] + "'";
}
else {
filenames += "'" + files[file] + "',\n ";
}
}
return filenames;
};
gulp.task(task.meteor, function() {
var
files = gatherFiles(outputDirectory),
filenames = createList(files)
;
gulp.src(release.templates.meteor[distLowerCase])
.pipe(plumber())
.pipe(flatten())
.pipe(replace(regExp.match.version, version))
.pipe(replace(regExp.match.files, filenames))
.pipe(rename(release.files.meteor))
.pipe(gulp.dest(outputDirectory))
;
});
if(distribution == 'CSS') {
gulp.task(task.repo, function() {
var
themes,
components,
releases
;
themes = gulp.src('dist/themes/default/**/*', { base: 'dist/' })
.pipe(gulp.dest(outputDirectory))
;
components = gulp.src('dist/components/*', { base: 'dist/' })
.pipe(gulp.dest(outputDirectory))
;
releases = gulp.src('dist/*', { base: 'dist/' })
.pipe(gulp.dest(outputDirectory))
;
return mergeStream(themes, components, releases);
});
}
else if(distribution == 'LESS') {
gulp.task(task.repo, function() {
var
definitions,
themeImport,
themeConfig,
siteTheme,
themes
;
definitions = gulp.src('src/definitions/**/*', { base: 'src/' })
.pipe(gulp.dest(outputDirectory))
;
themeImport = gulp.src('src/semantic.less', { base: 'src/' })
.pipe(gulp.dest(outputDirectory))
;
themeImport = gulp.src('src/theme.less', { base: 'src/' })
.pipe(gulp.dest(outputDirectory))
;
themeConfig = gulp.src('src/theme.config.example', { base: 'src/' })
.pipe(gulp.dest(outputDirectory))
;
siteTheme = gulp.src('src/_site/**/*', { base: 'src/' })
.pipe(gulp.dest(outputDirectory))
;
themes = gulp.src('src/themes/**/*', { base: 'src/' })
.pipe(gulp.dest(outputDirectory))
;
return mergeStream(definitions, themeImport, themeConfig, siteTheme, themes);
});
}
// extend package.json
gulp.task(task.package, function() {
return gulp.src(packageFile)
.pipe(plumber())
.pipe(jsonEditor(function(package) {
if(version) {
package.version = version;
}
return package;
}))
.pipe(gulp.dest(outputDirectory))
;
});
tasks.push(task.meteor);
tasks.push(task.repo);
tasks.push(task.package);
})(distribution);
}
runSequence(tasks, callback);
};