forked from WhitestormJS/whs.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.js
74 lines (59 loc) · 1.77 KB
/
examples.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
import path from 'path';
import fs from 'fs';
import gulp from 'gulp';
import del from 'del';
import pug from 'pug';
import less from 'gulp-less';
import {ExampleCompilerInstance} from './compilers';
import {getTemplateData} from './config';
import {getPaths} from './utils';
gulp.task('less', () => {
return gulp.src('./examples/assets/less/*.less')
.pipe(less())
.pipe(gulp.dest('./examples/assets/css/'));
});
gulp.task('examples:build', ['examples:html', 'less']);
gulp.task('examples:html', callback => {
const wait = [];
const paths = getPaths();
const templateData = getTemplateData();
templateData.scriptname = 'bundle.js';
templateData.paths = paths[0];
templateData.categories = paths[1];
const exampleCompiler = new ExampleCompilerInstance({
path: {
ammojs: templateData.ammojs,
assets: templateData.assets
}
});
const compileFile = (inPath, outPath) =>
wait.push(new Promise(resolve => fs.writeFile(
path.resolve('./examples/', outPath),
pug.compileFile(path.resolve('./examples/', inPath), {})(templateData),
resolve
)));
compileFile('./index.pug', './index.html');
paths[0].forEach(p => {
compileFile(`${p}/index.pug`, `${p}/index.html`);
wait.push(
new Promise(resolve => {
exampleCompiler(p, false).run(() => {
resolve();
});
})
);
});
Promise.all(wait).then(() => callback());
});
// CLEANING
gulp.task('examples:clean', callback => {
const paths = getPaths();
const wait = [];
const delExample = inPath => del(path.resolve('./examples/', inPath)); // wait.push(
paths[0].forEach(p => {
delExample(`${p}/index.html`);
delExample(`${p}/bundle.js`);
});
delExample('./index.html');
Promise.all(wait).then(() => callback());
});