-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
271 lines (237 loc) · 8.78 KB
/
gulpfile.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
var gulp = require("gulp"),
del = require("del"),
include = require("gulp-include"),
rename = require("gulp-rename"),
uglify = require("gulp-uglify"),
sass = require("gulp-sass"),
sourcemaps = require('gulp-sourcemaps'),
plumber = require('gulp-plumber'),
cssnano = require('gulp-cssnano'),
replace = require('gulp-replace'),
log = require('fancy-log'),
through2 = require('through2'),
runner = require('child_process'),
fs = require('fs'),
babel = require('gulp-babel'),
concat = require('gulp-concat')
;
// Variables de chemins
var source = './src'; // dossier de travail
var doc = './doc/assets'; // dossier de travail
var destination = './dist'; // dossier à livrer
var build = './build'; // dossier de ocmpilation
gulp.task("clean-dest", function(done) {
del.sync([
destination + '/**/*'
]);
done();
});
gulp.task("clean-build", function(done) {
del.sync([
build + '/**/*'
]);
done();
});
gulp.task("clean", gulp.series("clean-dest", "clean-build"));
gulp.task('make-sass', function () {
var scssList = [];
fs.readdirSync(doc+ '/scss/', { withFileTypes: true })
.filter(dirent => !dirent.name.startsWith('_'))
.filter(dirent => dirent.name.endsWith('.scss'))
.map(dirent => scssList.push(doc+ '/scss/' +dirent.name));
fs.readdirSync(source+ '/core/scss/', { withFileTypes: true })
.filter(dirent => !dirent.name.startsWith('_'))
.filter(dirent => dirent.name.endsWith('.scss'))
.map(dirent => scssList.push(source+ '/core/scss/' +dirent.name));
return gulp.src(scssList)
.pipe(plumber(function(e){log.error('Erreur lors de la compilation SASS !', e);}))
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write())
.pipe(gulp.dest(build + '/css/dev'))
.pipe(cssnano({zindex: false}))
.pipe(gulp.dest(build + '/css/min'))
;
});
gulp.task("scripts", function() {
return gulp.src([
source + "/core/js/closest-polyfill.js",
source + "/core/js/sipaui.js"
])
.pipe(concat('sipaui.min.js', {newLine: ';'}))
.pipe(include({
extensions: "js",
hardFail: true,
includePaths: [
__dirname + "/src/core/js"
]
}))
.pipe(babel({
"presets": [
[
"@babel/preset-env",
{
"targets": {
"firefox": "51",
"chrome": "56",
"ie": "10"
}
}
]
]
}))
.on('error', console.log)
.pipe(gulp.dest(build + '/js/dev'))
;
});
gulp.task("images", function() {
return gulp.src([
source + "/core/images/**/*",
source + "/components/**/images/**/*",
])
.pipe(gulp.dest(destination + '/images'))
;
});
gulp.task("make-scripts-dev", gulp.series("scripts", function() {
return gulp.src([build + '/js/dev/**/*'])
.pipe(gulp.dest(destination + '/js'))
;
}));
gulp.task("make-scripts-prod", gulp.series("scripts", function() {
return gulp.src([build + '/js/dev/**/*'])
.pipe(uglify()
.on('error', console.log))
.pipe(rename('sipaui.min.js'))
.pipe(gulp.dest(destination + '/js'))
;
}));
gulp.task("make-css-dev", gulp.series("make-sass", function() {
return gulp.src([build + '/css/dev/**/*'])
.pipe(gulp.dest(destination + '/css'));
}));
gulp.task("make-css-prod", gulp.series("make-sass", function() {
return gulp.src([build + '/css/min/**/*'])
.pipe(gulp.dest(destination + '/css'));
}));
gulp.task("make-assets", function() {
return gulp.src([source + '/core/fonts/**/*'])
.pipe(gulp.dest(destination + '/fonts'));
});
gulp.task("copy-storybook", function() {
return gulp.src(['./doc/storybook/**/*'])
.pipe(gulp.dest(build + '/storybook'));
});
gulp.task("copy-stories", gulp.series("copy-storybook", function() {
return gulp.src([source + '/components/**/*'])
.pipe(gulp.dest(destination + '/components'));
}));
gulp.task("build-stories", gulp.series("copy-stories", function(done) {
var components = fs.readdirSync('dist/components/', {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.forEach(dirent => {
gulp.src('dist/components/' + dirent.name + '/**/*.md')
.pipe(replace(/\]\((design\/[^.]+\..{3,4})\)/g, '](components/' + dirent.name + '/$1)'))
.pipe(gulp.dest('dist/components/' + dirent.name));
});
;
done();
}));
gulp.task("loader-storybook", gulp.series("build-stories", function() {
var components = [];
function _liste(dirPath, name) {
var liste = fs.readdirSync(dirPath, {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.forEach(dirent => {
if(
fs.readdirSync(dirPath + dirent.name, {withFileTypes: true})
.filter(dirent => dirent.isFile())
.filter(dirent => dirent.name.indexOf('doc-') !== -1).length > 1
) {
components.push({
path: dirPath + dirent.name,
fullname: name + dirent.name,
name: dirent.name
});
} else {
_liste(dirPath + dirent.name + '/', name + dirent.name + '/');
}
})
}
_liste('src/components/', '');
// console.log(components);
var imports = components.map(component =>
['design', 'html', 'vuejs']
.map(type => {
if(fs.existsSync('./dist/components/' + component.fullname + '/doc-' + type + '.md'))
return 'import doc_' + type + '_' + component.name.replace('-', '_') + ' from \'../../../dist/components/' + component.fullname + '/doc-' + type + '.md\';';
else return '';
})
.join(`
`)
)
.join(`
`)
;
var stories = components.map(component => {
return `storiesOf(\'`+ component.fullname +`\', module)
.addDecorator(withKnobs)
` + ['design', 'html', 'vuejs']
.map(type => {
if(fs.existsSync('./dist/components/' + component.fullname + '/doc-' + type + '.md'))
return '.add(\'' + type + '\', doc(doc_' + type + '_' + component.name.replace('-', '_') + '))';
else return '';
})
.join(`
`) + `
;
`
})
.join(`
`)
;
return gulp.src(build + '/storybook/stories/load-stories.js')
.pipe(replace('##imports##', imports))
.pipe(replace('##stories##', stories))
.pipe(gulp.dest(build + '/storybook/stories/'));
;
}));
function myPhp2Html(file, enc, cb) {
runner.exec('php ' + file.path, function(err, phpResponse, stderr) {
if(err) console.log(err); /* log error */
file.contents = new Buffer(phpResponse
.replace(/\/dist\//g, '\/')
.replace(/\/doc\//g, '\/')
.replace(/\.php/g, '.html')
);
return cb(null, file);
});
}
gulp.task("php2html", function(glob, dest) {
return gulp.src(["./doc/*.php"])
.pipe(through2.obj(myPhp2Html))
.pipe(rename(function (path) {
path.extname = ".html"
}))
.pipe(gulp.dest(build + "/"));
});
//
// Commandes utiles ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
gulp.task("make-dev-assets", gulp.series("make-assets", "make-css-dev", "images", "make-scripts-dev"));
gulp.task("make-prod-assets", gulp.series("make-assets", "make-css-prod", "images", "make-scripts-prod"));
gulp.task("generate-doc", gulp.series("make-prod-assets", "php2html"));
gulp.task("generate-html", gulp.series("generate-doc", function() {
// replace html
return gulp.src([build + '/**/*.html'])
.pipe(gulp.dest(destination + '/'));
}));
gulp.task("watch", function(){
gulp.watch([source+ '/core/scss/**/*.scss',source+ '/components/**/*.scss',source+ '/core/**/*.js',doc+ '/scss/**/*.scss'], gulp.series('generate-html'));
gulp.watch([source+ '/components/**/*.md'], gulp.series(() => {
return gulp.src([source + '/components/**/*.md'])
.pipe(gulp.dest(destination + '/components'));
}));
});
gulp.task("html", gulp.series("clean", "generate-html", "loader-storybook"));
gulp.task("build", gulp.series("html"));
gulp.task("default", gulp.series("html"));