-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.examples.ts
More file actions
61 lines (43 loc) · 1.64 KB
/
gulpfile.examples.ts
File metadata and controls
61 lines (43 loc) · 1.64 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
import * as path from 'path';
import * as fs from 'fs';
import * as webpack from 'webpack';
import * as gulp from 'gulp';
import * as gutil from 'gulp-util';
import * as sass from 'gulp-sass';
import * as concat from 'gulp-concat';
import {getExampleWebpackConfig} from './webpack.config';
const ROOT = path.join(__dirname, 'examples', 'examples');
const tasks = [];
fs.readdirSync(ROOT)
.map((file) => path.join(ROOT, file))
.filter((file) => fs.statSync(file).isDirectory() && path.basename(file) !== 'node_modules')
.forEach((directory: string) => {
const name = path.basename(directory);
const tsconfig = JSON.parse(<string>fs.readFileSync(path.join(directory, 'tsconfig.json'), {encoding: 'utf-8'}));
const exampleTasks = [];
if (fs.existsSync(path.join(directory, 'styles'))) {
exampleTasks.push(`compile:example:${name}:styles`);
gulp.task(`compile:example:${name}:styles`, () => {
return gulp.src(path.join(directory, 'styles', 'index.scss'))
.pipe(sass().on('error', sass.logError))
.pipe(concat('style.css'))
.pipe(gulp.dest(path.join(directory, 'public')));
});
}
exampleTasks.push(`compile:example:${name}:app`);
gulp.task(`compile:example:${name}:app`, (done) => {
const webpackConfig = getExampleWebpackConfig(directory);
webpack(webpackConfig, (err, stats) => {
if(err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString({
colors: true,
}));
done();
});
});
tasks.push(`compile:example:${name}`);
gulp.task(`compile:example:${name}`, gulp.series(exampleTasks));
});
gulp.task('compile:examples', gulp.parallel(tasks));