forked from krakenjs/post-robot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
179 lines (157 loc) · 5.04 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
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var webpack = require('webpack');
let gulpFlowtype = require('gulp-flowtype');
var gulpWebpack = require('webpack-stream');
var Server = require('karma').Server;
var argv = require('yargs').argv;
var UglifyJSPlugin = require('uglifyjs-webpack-plugin');
var yargs = require('yargs');
var qs = require('querystring');
var CircularDependencyPlugin = require('circular-dependency-plugin');
gulp.task('test', ['lint', 'typecheck', 'karma']);
gulp.task('build', ['test', 'webpack', 'webpack-min']);
var MODULE_NAME = 'postRobot';
function buildWebpackConfig({ filename, modulename, minify = false, globals = {} }) {
globals = {
__TEST__: false,
__IE_POPUP_SUPPORT__: false,
__ALLOW_POSTMESSAGE_POPUP__: true,
...globals
};
const PREPROCESSOR_OPTS = {
'ifdef-triple-slash': 'false',
...globals
};
return {
stats: {
hash: yargs.argv['debug'] ? true : false,
timings: yargs.argv['debug'] ? true : false,
chunks: yargs.argv['debug'] ? true : false,
chunkModules: yargs.argv['debug'] ? true : false,
modules: yargs.argv['debug'] ? true : false,
cached: yargs.argv['debug'] ? true : false,
cachedAssets: yargs.argv['debug'] ? true : false,
reasons: yargs.argv['debug'] ? true : false,
source: yargs.argv['debug'] ? true : false,
errorDetails: yargs.argv['debug'] ? true : false,
performance: yargs.argv['debug'] ? true : false,
warnings: yargs.argv['debug'] ? true : false
},
module: {
rules: [
{
test: /\.js$/,
loader: `ifdef-loader?${ qs.encode(PREPROCESSOR_OPTS) }`
},
{
test: /\.js$/,
loader: 'babel-loader'
}
]
},
resolve: {
modules: [
'node_modules',
'src',
'client'
]
},
output: {
filename,
libraryTarget: 'umd',
umdNamedDefine: true,
library: modulename
},
plugins: [
new webpack.DefinePlugin(globals),
new webpack.SourceMapDevToolPlugin({
filename: '[file].map'
}),
new UglifyJSPlugin({
test: /\.js$/,
beautify: !minify,
minimize: minify,
compress: { warnings: false },
mangle: minify,
sourceMap: true
}),
new CircularDependencyPlugin({
failOnError: true
})
],
bail: true
};
}
gulp.task('webpack', [ 'webpack-max', 'webpack-min', 'webpack-max-ie', 'webpack-min-ie' ]);
gulp.task('webpack-max', function() {
return gulp.src('src/index.js')
.pipe(gulpWebpack(buildWebpackConfig({
filename: `post-robot.js`,
modulename: MODULE_NAME
}), webpack))
.pipe(gulp.dest('dist'));
});
gulp.task('webpack-min', function() {
return gulp.src('src/index.js')
.pipe(gulpWebpack(buildWebpackConfig({
filename: `post-robot.min.js`,
modulename: MODULE_NAME,
minify: true
}), webpack))
.pipe(gulp.dest('dist'));
});
gulp.task('webpack-max-ie', function() {
return gulp.src('src/index.js')
.pipe(gulpWebpack(buildWebpackConfig({
filename: `post-robot.ie.js`,
modulename: MODULE_NAME,
globals: {
__IE_POPUP_SUPPORT__: true
}
}), webpack))
.pipe(gulp.dest('dist'));
});
gulp.task('webpack-min-ie', function() {
return gulp.src('src/index.js')
.pipe(gulpWebpack(buildWebpackConfig({
filename: `post-robot.ie.min.js`,
modulename: MODULE_NAME,
minify: true,
globals: {
__IE_POPUP_SUPPORT__: true
}
}), webpack))
.pipe(gulp.dest('dist'));
});
gulp.task('typecheck', [ 'lint' ], function() {
return gulp.src([ 'src/**/*.js', 'test/**/*.js' ])
.pipe(gulpFlowtype({
abort: true
}));
});
gulp.task('lint', function() {
return gulp.src('src/**').pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('karma', function (done) {
var server = new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: !Boolean(argv['keep-browser-open']),
client: {
captureConsole: Boolean(argv['capture-console'])
}
});
server.on('browser_error', function (browser, err) {
console.log('Karma Run Failed: ' + err.message);
throw err;
});
server.on('run_complete', function (browsers, results) {
if (results.failed) {
return done(new Error('Karma: Tests Failed'));
}
done();
});
return server.start();
});