-
Notifications
You must be signed in to change notification settings - Fork 115
/
gulpfile.js
138 lines (121 loc) · 5.1 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
'use strict';
const gulp = require('gulp'),
async = require('async'),
fs = require('fs'),
rimraf = require('rimraf'),
zip = require('gulp-zip'),
util = require('gulp-util'),
packageElectron = require('gulp-atom-electron'),
symdest = require('gulp-symdest'),
git = require('gulp-git'),
exec = require('child_process').exec,
grimraf = require('gulp-rimraf'),
debug = require('gulp-debug'),
vfs = require('vinyl-fs'),
imagemin = require ('gulp-imagemin'),
sass = require('gulp-sass'),
rseq = require('run-sequence'),
merge = require('merge2'),
electron = require('electron-connect');
//CONFIG
const BUILD_DIR = 'build',
RELEASE_DIR = 'release',
BOT_DIR = `${BUILD_DIR}/gofbot`,
PACKAGES_DIR = `${BOT_DIR}/packages`,
PACKAGE_SRC = [`${BUILD_DIR}/**/*`, `!${BUILD_DIR}/{packages,packages/**}`],
server = electron.server.create({path: BUILD_DIR, verbose: true});
gulp.task('python:install', callback => {
async.waterfall([
cb => rimraf(PACKAGES_DIR, cb),
cb => async.concat(fs.readFileSync('build/gofbot/requirements.txt')
.toString()
.split('\n')
.map(dep => dep.trim().replace('-e ', '')), (cmd, _) => exec(`pip install ${cmd} --target ${PACKAGES_DIR}`, _), err => cb(err)),
cb => fs.open(`${PACKAGES_DIR}/google/__init__.py`, 'wx', cb),
(file, cb) => fs.close(file, cb)
], callback);
});
gulp.task('python:associate', callback => {
async.waterfall([
_ => fs.readFile(`${BOT_DIR}/pokecli.py`, _),
(data, cb) => {
let parsed = data.toString().split('\n');
var targetIndex = 0;
for (let i = 0; i <= parsed.length; i++) {
let line = parsed[i];
if (line.toLowerCase().indexOf('import sys') == 0) {
targetIndex = i;
break;
}
}
parsed.splice(targetIndex + 1, 0, 'sys.path.insert(0, \'packages\')');
cb(null, new Buffer(parsed.join('\n')));
},
(data, _) => fs.writeFile(`${BOT_DIR}/pokecli.py`, data, _)
], callback);
});
gulp.task('python', _ => rseq('python:install', 'python:associate', _));
gulp.task('electron:osx', () => {
return gulp.src(PACKAGE_SRC, {base: 'build'})
.pipe(packageElectron({
version: '1.3.3',
platform: 'darwin',
darwinIcon: 'src/assets/resources/image/icons/pokemon.icns',
darwinBundleIdentifier: 'com.github.pokemongof'
})).pipe(symdest(RELEASE_DIR));
});
gulp.task('electron:windows', () => {
return gulp.src(PACKAGE_SRC.concat(`${BUILD_DIR}pywin/**/*`), {base: 'build'})
.pipe(packageElectron({
version: '1.3.3',
platform: 'win32',
arch: 'ia32',
winIcon: 'src/assets/resources/image/icons/pokemon.ico',
companyName: 'PokemonGoF',
copyright: '2016 PokemonGOF, All Rights Reserved.'
}))
.pipe(zip('app-windows.exe'))
.pipe(gulp.dest(RELEASE_DIR));
});
gulp.task('electron', ['electron:windows', 'electron:osx']);
gulp.task('gofbot:update', (callback) => {
async.series([
_ => git.exec({args: `submodule deinit -f ${BOT_DIR}`}, _),
_ => git.updateSubmodule({ args: '--init --recursive' }, _)
], callback);
});
gulp.task('gofbot:prune', (callback) => {
//TODO - Switch to grimraf
async.parallel([
_ => rimraf(`${BOT_DIR}/docs`, _),
_ => rimraf(`${BOT_DIR}/.github`, _),
_ => rimraf(`${BOT_DIR}/tests`, _),
_ => async.concat(['ws_server.py', 'run.sh', 'setup.sh', 'README.md', 'pylint-recursive.py', 'run.bat',
'LICENSE', 'Dockerfile', 'install.sh', 'CONTRIBUTORS.md', 'docker-compose.yml', '.travis.yml', '.styles.yapf',
'.pylintrc', '.mention-bot', '.pullapprove.yml', '.dockerignore', '.gitignore'].map(x => `${BOT_DIR}/${x}`), fs.unlink, _)
], callback);
});
gulp.task('gofbot', _ => rseq('gofbot:update', ['gofbot:prune', 'python'], _));
gulp.task('clean', () => vfs.src([`${BUILD_DIR}/*`, `!${BUILD_DIR}/{gofbot,gofbot/*,pywin,pywin/*}`]).pipe(grimraf()));
gulp.task('build:node', () => {
const getNodeModules = () => Object.keys(JSON.parse(fs.readFileSync('package.json').toString()).dependencies).map(_ => `node_modules/${_}/**/*`);
return merge(
vfs.src(getNodeModules(), {base: '.'})
.pipe(gulp.dest(BUILD_DIR)),
gulp.src('package.json')
.pipe(gulp.dest(BUILD_DIR))
);
});
gulp.task('build:src', () => {
return merge(
gulp.src(['src/**/*', '!src/{styles,styles/**}'])
.pipe(gulp.dest(BUILD_DIR)),
gulp.src('src/**/*.{scss,sass}')
.pipe(sass({ includePaths: ['node_modules/materialize-css/sass'] }).on('error', sass.logError))
.pipe(gulp.dest(BUILD_DIR))
);
});
gulp.task('run', () => server.start());
gulp.task('build', _ => rseq('clean', ['gofbot', 'build:node', 'build:src'], _));
gulp.task('develop', _ => rseq('build', 'run', _));
gulp.task('release', _ => rseq('build', 'electron', _));