forked from teleport/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
189 lines (147 loc) · 4.13 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
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
/* eslint-env node */
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import del from 'del';
import assign from 'core-js/library/fn/object/assign';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import { spawn } from 'child_process';
import es from 'event-stream';
import browserify from 'browserify';
import watchify from 'watchify';
import browserSync from 'browser-sync';
const bs = browserSync.create();
const gp = gulpLoadPlugins();
import pkg from './package.json';
const BANNER = `/*! ${pkg.name} - v${pkg.version} | ${pkg.homepage} | ${pkg.license} */
`;
// ----------------------------- BROWSERIFY ------------------------------------
// Browserify params
const browserifyArgs = assign({}, watchify.args, {
standalone: 'TeleportAutocomplete',
transform: [
"babelify",
["ractivate", { "extensions": [".rac"] }]
],
debug: true,
});
// Browserify bundle command
const rebundle = (bundler, entry) => {
return bundler.bundle()
.on('error', gp.util.log)
.pipe(source(entry))
.pipe(gp.derequire())
.pipe(buffer())
.pipe(gp.rename({
dirname: '',
prefix: 'teleport-',
}))
.pipe(gp.sourcemaps.init({ loadMaps: true, debug: true }))
.pipe(gp.sourcemaps.write('./', { sourceRoot: '..' }))
.pipe(gp.if('*.js', gp.header(BANNER)))
.pipe(gulp.dest('dist'))
.pipe(bs.reload({ stream: true }));
};
/**
* Browserify + Babel with watchify
*/
gulp.task('watchify', () => {
const tasks = ['js/autocomplete.js', 'js/autocomplete-ractive.js'].map(entry => {
const bundler = watchify(browserify(assign(browserifyArgs, { entries: [entry] })));
bundler.on('update', rebundle.bind(this, bundler, entry));
bundler.on('log', gp.util.log);
return rebundle(bundler, entry);
});
return es.merge.apply(null, tasks);
});
/**
* Plain browserify
*/
gulp.task('browserify', () => {
const tasks = ['js/autocomplete.js', 'js/autocomplete-ractive.js'].map(entry => {
return rebundle(browserify(assign(browserifyArgs, { entries: [entry] })), entry);
});
return es.merge.apply(null, tasks);
});
// -----------------------------------------------------------------------------
/**
* Compile SASS and prefix it
*/
gulp.task('sass', () => {
return gulp.src('scss/autocomplete.scss')
.pipe(gp.sourcemaps.init())
.pipe(gp.sass().on('error', gp.sass.logError))
// Prefix CSS
.pipe(gp.autoprefixer())
.pipe(gp.rename({
prefix: 'teleport-',
}))
.pipe(gp.sourcemaps.write('.', { sourceRoot: '../scss' }))
.pipe(gp.if('*.css', gp.header(BANNER)))
.pipe(gulp.dest('dist'))
.pipe(gp.if('*.css', bs.reload({ stream: true })));
});
/**
* Concat and minify JS
*/
gulp.task('dist:js', ['browserify'], () => {
return gulp.src('dist/teleport-autocomplete.js')
.pipe(gp.sourcemaps.init({ loadMaps: true }))
.pipe(gp.uglify({ preserveComments: 'license' }))
.pipe(gp.rename({
extname: '.min.js',
}))
.pipe(gp.sourcemaps.write('.', { sourceRoot: '..' }))
.pipe(gulp.dest('dist'));
});
/**
* Minify CSS
*/
gulp.task('dist:css', ['sass'], () => {
return gulp.src('dist/teleport-autocomplete.css')
.pipe(gp.sourcemaps.init({ loadMaps: true, debug: true }))
.pipe(gp.minifyCss({ sourceMap: false }))
.pipe(gp.rename({
extname: '.min.css',
}))
.pipe(gp.sourcemaps.write('.', { sourceRoot: 'scss' }))
.pipe(gulp.dest('dist'));
});
/**
* Build package
*/
gulp.task('build', ['dist:js', 'dist:css']);
/**
* Release package
*/
gulp.task('release', ['build'], (done) => {
spawn('npm', ['publish'], { stdio: 'inherit' }).on('close', done);
});
/**
* Clean up generated folder
*/
gulp.task('clean', () => del('dist'));
/**
* Recompile and Livereload for dev
*/
gulp.task('watch', () => {
// Recompile CSS
gulp.watch('scss/**', ['sass']);
});
/**
* Dev Server
*/
gulp.task('serve', () => {
bs.init({
server: {
baseDir: './examples',
directory: true,
routes: { '/dist': 'dist' },
},
});
});
/**
* By default:
* Compile SASS, ES6, run devserver and watch files
*/
gulp.task('default', ['watch', 'watchify', 'sass', 'serve']);