forked from Gisto/Gisto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
176 lines (162 loc) · 5.26 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
var gulp = require('gulp');
var gutil = require('gulp-util');
var pkg_json = require('./package.json');
var fs = require('fs');
var argv = require('yargs').argv;
var concat = require('gulp-concat-sourcemap');
var strip_log = require('gulp-strip-debug');
var connect = require('gulp-connect');
var NwBuilder = require('node-webkit-builder');
// Options to switch environment (dev/prod)
var env_option = {
env_dev: 'env:dev',
env_prod: 'env:prod',
blocking_char: '#'
};
/**
* version
*
* Get Gisto version
* Use: gulp version
*/
gulp.task('version', function () {
gutil.log('Version', gutil.colors.green(pkg_json.version));
});
/**
* version_bump
*
* Change Gisto version
* Use: gulp version_bump --to=0.2.4b
*/
gulp.task('version_bump', function () {
var files = ['./package.json', './app/package.json'];
files.forEach(function (file) {
var content = JSON.parse(fs.readFileSync(file));
content.version = argv.to;
fs.writeFileSync(file, JSON.stringify(content, null, 4));
});
});
/**
* dev
*
* Change Gisto environment to "development"
* Use: gulp dev
*/
gulp.task('dev', function () {
var files = ['./app/index.html'];
files.forEach(function (file) {
var content = fs.readFileSync(file, "utf8")
.replace('<!-- ' + env_option.env_dev + ' --' + env_option.blocking_char + '>', '<!-- ' + env_option.env_dev + ' -->')
.replace('<!-- ' + env_option.env_prod + ' -->', '<!-- ' + env_option.env_prod + ' --' + env_option.blocking_char + '>')
.replace('/* ' + env_option.env_dev + ' *' + env_option.blocking_char + '/', '/* ' + env_option.env_dev + ' */')
.replace('/* ' + env_option.env_prod + ' */', '/* ' + env_option.env_prod + ' *' + env_option.blocking_char + '/');
fs.writeFileSync(file, content);
});
// Toggle "toolbar"
var file = './app/package.json';
var content = JSON.parse(fs.readFileSync(file));
content.window.toolbar = true;
fs.writeFileSync(file, JSON.stringify(content, null, 4));
});
/**
* prod
*
* Change Gisto environment to "production", also concatenates files and remove console logs
* Use: gulp prod
*/
gulp.task('prod', ['concat'], function () {
var files = ['./app/index.html'];
files.forEach(function (file) {
var content = fs.readFileSync(file, "utf8")
.replace('<!-- ' + env_option.env_prod + ' --' + env_option.blocking_char + '>', '<!-- ' + env_option.env_prod + ' -->')
.replace('<!-- ' + env_option.env_dev + ' -->', '<!-- ' + env_option.env_dev + ' --' + env_option.blocking_char + '>')
.replace('/* ' + env_option.env_prod + ' *' + env_option.blocking_char + '/', '/* ' + env_option.env_prod + ' */')
.replace('/* ' + env_option.env_dev + ' */', '/* ' + env_option.env_dev + ' *' + env_option.blocking_char + '/');
fs.writeFileSync(file, content);
});
// Toggle "toolbar"
var file = './app/package.json';
var content = JSON.parse(fs.readFileSync(file));
content.window.toolbar = false;
fs.writeFileSync(file, JSON.stringify(content, null, 4));
});
/**
* server
*
* Serves the app on specified port or 8080 if --port parameter omitted
* Use: gulp server OR gulp server --port=80 (defalts to 8080)
*/
gulp.task('server', function () {
connect.server({
root: './app',
port: argv.port || '8080',
livereload: true
});
});
/**
* concat
*
* concatenates files and remove console logs, also used by other functions here
* Use: gulp concat
*/
gulp.task('concat', function () {
gulp.src([
'app/lib/jquery/dist/jquery.min.js',
'app/lib/socket.io-client/socket.io.js',
'app/lib/angular/angular.js',
'app/lib/angular-route/angular-route.js',
'app/lib/angular-animate/angular-animate.js',
'app/lib/angular-sanitize/angular-sanitize.js',
'app/lib/angular-ui-utils/ui-utils.min.js',
'app/lib/angular-socket-io/socket.min.js',
'app/lib/showdown/compressed/showdown.js',
'app/js/*.js',
'!app/js/gisto.min.js'
])
.pipe(strip_log())
.pipe(concat('gisto.min.js'))
.pipe(gulp.dest('./app/js/'));
});
/**
* build
*
* Build binaries for specified platform
* Use: gulp build --os=win|osx|linux32|linux64|all
*/
gulp.task('build', ['prod'], function () {
var os = argv.os;
if (!os) {
return gutil.log(gutil.colors.red('NOTE'), gutil.colors.white('Please specify platform (Use: gulp build --os=win|osx|linux32|linux64|all)'));
}
if (os === 'all') {
os = 'win,osx,linux32,linux64';
}
os.split(',');
var nw = new NwBuilder({
files: './app/**',
buildDir: "./bin",
winIco: "./app/icon.ico",
version: '0.9.2',
platforms: os
});
gutil.log(gutil.colors.green('Building for: ' + os));
var pathToNwsnapshot = nw.options.cacheDir + '/' + nw.options.version + '/' + os + '/nwsnapshot';
//return gutil.log(gutil.colors.green('XXXX: ' + pathToNwsnapshot));
nw.build().then(function () {
// Build OK
}).
catch(function (error) {
console.error(error);
});
});
/**
* release
*
* Will be used for releases
* Use: gulp release
*/
gulp.task('release', ['concat'], function () {
// Do stuff
});
// Default task
gulp.task('default', ['version', 'dev', 'server']);