This repository has been archived by the owner on Aug 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
153 lines (136 loc) · 4.96 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
153
/* Global */
var autoprefixer = require('gulp-autoprefixer')
var browserify = require('browserify')
var buffer = require('vinyl-buffer')
var cssnano = require('gulp-cssnano')
var gulpConcat = require('gulp-concat')
var less = require('gulp-less')
var notify = require('gulp-notify')
var plumber = require('gulp-plumber')
var rename = require('gulp-rename')
var source = require('vinyl-source-stream')
var sourcemaps = require('gulp-sourcemaps')
var uglify = require('gulp-uglify')
var gulp = require('gulp')
var NwBuilder = require('nw-builder')
var src = './src/'
var app = './app/'
/* Errors */
function onError(error) {
console.log(error)
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
icon: src + "images/icon.png",
sound: "Beep"
})(error)
this.emit('end')
}
function onSuccess(msg) {
return {
message: msg + " Complete! ",
icon: src + "images/icon.png",
onLast: true
}
}
// styles: Compile and Minify Less / CSS Files
var styles_watchFolder = src + 'styles/**/*.less'
var styles_srcFile = src + 'styles/mewify-master.less'
var styles_destFolder = app + 'styles'
var styles_destFile = 'mewify-master.css'
var styles_destFileMin = 'mewify-master.min.css'
gulp.task('styles', function() {
return gulp.src(styles_srcFile)
.pipe(plumber({ errorHandler: onError }))
.pipe(sourcemaps.init())
.pipe(less({ compress: false }))
.pipe(autoprefixer({ browsers: ['last 3 versions', 'iOS > 7'], remove: false }))
.pipe(rename(styles_destFile))
.pipe(gulp.dest(styles_destFolder))
.pipe(cssnano({ autoprefixer: false, safe: true }))
.pipe(rename(styles_destFileMin))
.pipe(sourcemaps.write('/maps'))
.pipe(gulp.dest(styles_destFolder))
.pipe(notify(onSuccess('Styles')))
})
// js: concat native
var jsNative_watchFolder = src + 'scripts-native/**/*.js'
var jsNative_SrcFiles = src + 'scripts-native/*.js'
var jsNative_DestFolder = app + 'js/'
var jsNative_DestFile = 'mewify-native.js'
var jsNative_DestFileMin = 'mewify-native.min.js'
/* Concat & Uglify Native JS */
gulp.task('jsNative', function() {
return gulp.src(jsNative_SrcFiles)
.pipe(plumber({ errorHandler: onError }))
.pipe(sourcemaps.init())
.pipe(gulpConcat(jsNative_DestFile))
.pipe(gulp.dest(jsNative_DestFolder))
.pipe(uglify())
.pipe(rename(jsNative_DestFileMin))
.pipe(sourcemaps.write('/maps'))
.pipe(gulp.dest(jsNative_DestFolder))
.pipe(notify(onSuccess('Native JS')))
});
// js: Browserify
var js_watchFolder = src + 'scripts/**/*.js'
var js_srcFile = src + 'scripts/main.js'
var js_destFolder = app + 'js/'
var js_destFile = 'mewify-master.js'
var js_destFileMin = 'mewify-master.min.js'
var babelOpts = { presets: ['es2015'], compact: false, global: true }
function bundle_js(bundler) {
return bundler.bundle()
.pipe(plumber({ errorHandler: onError }))
.pipe(source('main.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(rename(js_destFile))
.pipe(gulp.dest(js_destFolder))
.pipe(uglify())
.pipe(rename(js_destFileMin))
.pipe(sourcemaps.write('/maps'))
.pipe(gulp.dest(js_destFolder))
.pipe(notify(onSuccess('JS')))
}
gulp.task('js', function() {
var bundler = browserify(js_srcFile)
bundle_js(bundler)
})
// Copy
var imgSrcFolder = src + 'images/**/*'
var fontSrcFolder = src + 'fonts/**/*'
var htmlFiles = src + '*.html'
gulp.task('copy', function() {
gulp.src(imgSrcFolder).pipe(gulp.dest(app + 'images'))
gulp.src(fontSrcFolder).pipe(gulp.dest(app + 'fonts'))
gulp.src(htmlFiles).pipe(gulp.dest(app))
.pipe(notify(onSuccess('Copy')))
})
gulp.task('buildApp', function() {
var nw = new NwBuilder({
files: ['./**/**', '!./src/**/**', '!./build/**/**', '!./cache/**/**'], // use the glob format
platforms: ['osx64', 'win64', 'linux64'],
version: '0.21.3',
buildDir: './build',
forceDownload: true
});
nw.build().then(function() {
console.error("executables done");
notify(onSuccess('executables building'));
}).catch(function(error) {
console.error(error);
notify(onError(error));
});
});
// Watch Tasks
gulp.task('watchJS', function() { gulp.watch(js_watchFolder, ['js']) })
gulp.task('watchjsNative', function() { gulp.watch(jsNative_watchFolder, ['jsNative']) })
gulp.task('watchLess', function() { gulp.watch(styles_watchFolder, ['styles']) })
gulp.task('watchHTML', function() { gulp.watch(htmlFiles, ['copy']) })
gulp.task('watchImages', function() { gulp.watch(imgSrcFolder, ['copy']) })
gulp.task('watchFonts', function() { gulp.watch(fontSrcFolder, ['copy']) })
gulp.task('watch', ['watchJS', 'watchjsNative', 'watchLess', 'watchHTML', 'watchImages', 'watchFonts'])
gulp.task('build', ['js', 'jsNative', 'styles', 'copy'])
gulp.task('default', ['build', 'watch'])