-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
128 lines (112 loc) · 3.44 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import del from 'del';
import globby from 'globby';
import through from 'through2';
import log from 'gulplog';
import sourcemaps from 'gulp-sourcemaps';
import babelify from 'babelify';
import browserify from 'browserify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import embedTemplates from 'gulp-angular-embed-templates';
//paths
const urls = {
js: 'src/Preserver/backoffice/*.js',
html: 'src/Preserver/backoffice/*.html',
css: 'src/Preserver/backoffice/*.css',
lang: 'src/Preserver/lang/*.xml',
manifest: 'src/Preserver/package.manifest',
dest: './dist/App_Plugins/Preserver',
dev: '../Umbraco-CMS/src/Umbraco.Web.UI/App_Plugins/Preserver'
};
//config
const config = {
prod: process.argv.indexOf('--prod') > -1
};
function to(path) {
const to = config.prod ? urls.dest : urls.dev;
return path ? to + '/' + path : to;
}
function clean() {
return del([`${urls.dest}/**`, `${urls.dev}/**`], { force: true });
}
function js() {
// gulp expects tasks to return a stream, so we create one here.
var bundledStream = through();
bundledStream
// turns the output bundle stream into a stream containing
// the normal attributes gulp plugins expect.
.pipe(source('preserver.min.js'))
// the rest of the gulp task, as you would normally write it.
// here we're copying from the Browserify + Uglify2 recipe.
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true
}))
// Add gulp plugins to the pipeline here.
.pipe(embedTemplates({
basePath: './'
}))
.on('error', log.error)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(to('backoffice')));
// "globby" replaces the normal "gulp.src" as Browserify
// creates it's own readable stream.
globby(urls.js).then(entries => {
// create the Browserify instance.
const b = browserify({
entries: entries,
debug: !config.prod,
transform: [babelify]
});
// pipe the Browserify stream into the stream we created earlier
// this starts our gulp pipeline.
b.bundle()
.pipe(bundledStream);
}).catch(err => bundledStream.emit('error', err));
// finally, we return the stream, so gulp knows when this task is done.
return bundledStream;
}
function manifest() {
return gulp.src(urls.manifest)
.pipe(gulp.dest(to()))
}
function html() {
return gulp.src(urls.html)
.pipe(gulp.dest(to('backoffice')))
}
function lang() {
return gulp.src(urls.lang)
.pipe(gulp.dest(to('lang')))
}
function css() {
return gulp.src(urls.css)
.pipe(gulp.dest(to('backoffice')))
}
export const dev = gulp.task('dev',
gulp.series(clean,
gulp.parallel(
js,
html,
css,
lang,
manifest,
done => {
console.log('starting watchers');
gulp.watch(urls.js, js);
gulp.watch(urls.html, html);
gulp.watch(urls.css, css);
gulp.watch(urls.lang, lang);
gulp.watch(urls.manifest, manifest);
done();
}
)));
export const build = gulp.task('build',
gulp.series(clean,
gulp.parallel(
js,
html,
css,
lang,
manifest
)));