-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
152 lines (127 loc) · 3.04 KB
/
gulpfile.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
const gulp = require('gulp');
const gutil = require('gulp-util');
const webpack = require('webpack-stream');
const uglify = require('gulp-uglify');
const header = require('gulp-header');
const path = require('path');
const fs = require('fs-extra');
const config = require('./src/conf.js');
const webpackConfig = {
module: {
loaders: [
{
test: /.js?$/,
loader: 'babel-loader',
query: {
presets: ['es2015'],
plugins: ['transform-object-assign']
}
}
]
},
resolve: {
modulesDirectories: ['node_modules', 'bower_components'],
extensions: ['', '.js', '.jsx']
},
plugins: [
new webpack.webpack.ProvidePlugin({
Promise: 'es6-promise-promise'
})
]
};
gulp.task('clean', () => {
['dist','temp','temp/screenshots'].map((dir)=>{
fs.removeSync(dir);
fs.mkdirSync(dir);
});
});
gulp.task('test', ['make'], function () {
const through = require('through2');
const mochaPhantomJS = require('gulp-mocha-phantomjs');
return gulp
.src('test/index.html')
.pipe(mochaPhantomJS({
reporter: 'nyan',
suppressStderr: false,
phantomjs: {
viewportSize: {
width: 1440,
height: 900
},
settings: {
webSecurityEnabled: false,
localToRemoteUrlAccessEnabled: true
}
}
}))
.pipe(through.obj((chunk, enc, cb) => {
const screenshotPath = 'temp/screenshots/';
const screenshots = fs.readdirSync(screenshotPath);
let uploadCount = 0;
const isDoneMaybe = () => {
uploadCount++;
if(uploadCount >= screenshots.length) {
cb(null, chunk);
}
};
screenshots.map((screenshot)=>{
let spawn = require('child_process').spawn;
let child = spawn('curl',[
'--upload-file',
`./${screenshotPath+screenshot}`,
'https://transfer.sh/'
]);
child.stdout.on('data', (buffer) => {
gutil.log('Look at it!!!', gutil.colors.magenta(buffer.toString().replace('\n','')));
});
child.stdout.on('end', isDoneMaybe);
});
}));
});
gulp.task('default', function() {
return gulp.src('src/app.js')
.pipe(webpack({
watch: true,
devtool: 'source-map',
output: {
filename: config.webpack.filename.dev,
library: config.webpack.library,
libraryTarget: 'umd'
},
plugins: webpackConfig.plugins,
module: webpackConfig.module,
resolve: {
root: path.resolve('./src')
}
}))
.pipe(header(config.webpack.header+'\n'))
.pipe(gulp.dest('dist/'));
});
gulp.task('make', ['clean'], function() {
return gulp.src('src/app.js')
.pipe(webpack({
output: {
filename: config.webpack.filename.dist,
library: config.webpack.library,
libraryTarget: 'umd'
},
plugins: webpackConfig.plugins,
module: webpackConfig.module,
resolve: {
root: path.resolve('./src')
}
}))
.pipe(uglify())
.pipe(header(config.webpack.header+'\n'))
.pipe(gulp.dest('dist/'));
});
gulp.task('release', function(){
const release = require('gulp-github-release');
return gulp.src('dist/'+config.webpack.filename.dist)
.pipe(release({
manifest: require('./package.json')
}).on('error',function(e){
console.error(e);
this.emit('end');
}));
});