-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.coffee
147 lines (130 loc) · 6.12 KB
/
gulpfile.coffee
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
POI_VERSION = '3.1.2'
ELECTRON_VERSION = '0.30.0'
SYSTEM_BIT =
win32: 'ia32'
linux: 'x64'
darwin: 'x64'
PLATFORM = process.env.BUILD_PLATFORM || process.platform
path = require 'path-extra'
BUILD_ROOT = path.join(path.tempdir(), "poi-v#{POI_VERSION}-#{PLATFORM}-#{SYSTEM_BIT[PLATFORM]}", 'resources', 'app')
Promise = require 'bluebird'
gulp = require 'gulp'
del = Promise.promisifyAll require 'del'
delAsync = Promise.promisify del
request = Promise.promisifyAll require 'request'
requestAsync = Promise.promisify request
fs = Promise.promisifyAll require 'fs-extra'
colors = require 'colors'
AdmZip = require 'adm-zip'
{execAsync} = Promise.promisifyAll require('child_process')
{log, warn, error} = require './lib/utils'
async = Promise.coroutine
gulp.task 'theme', async ->
themes =
darkly: 'https://bootswatch.com/darkly/bootstrap.css'
flatly: 'https://bootswatch.com/flatly/bootstrap.css'
lumen: 'https://bootswatch.com/lumen/bootstrap.css'
paper: 'https://bootswatch.com/paper/bootstrap.css'
slate: 'https://bootswatch.com/slate/bootstrap.css'
superhero: 'https://bootswatch.com/superhero/bootstrap.css'
united: 'https://bootswatch.com/united/bootstrap.css'
lumendark: 'https://raw.githubusercontent.com/PHELiOX/poi-theme-lumendark/master/lumendark.css'
paperdark: 'https://raw.githubusercontent.com/ruiii/poi_theme_paper_dark/master/paperdark.css'
for theme, url of themes
dir = path.join(__dirname, 'assets', 'themes', theme, 'css')
fs.ensureDirSync dir
log "Downloding #{theme} theme."
[res, data] = yield request.getAsync url,
encoding: null
yield fs.writeFileAsync path.join(dir, "#{theme}.css"), data
gulp.task 'flash', async ->
plugins =
win32: 'http://7xj6zx.com1.z0.glb.clouddn.com/poi/PepperFlash/win32.zip'
linux: 'http://7xj6zx.com1.z0.glb.clouddn.com/poi/PepperFlash/linux.zip'
darwin: 'http://7xj6zx.com1.z0.glb.clouddn.com/poi/PepperFlash/darwin.zip'
url = plugins[process.platform]
dir = path.join(__dirname, 'PepperFlash')
fs.ensureDirSync dir
try
yield fs.accessAsync path.join(path.tempdir(), "flashplayer-#{PLATFORM}.zip"), fs.R_OK
yield fs.removeSync path.join(path.tempdir(), "flashplayer-#{PLATFORM}.zip")
catch e
log "Downloading flash plugin #{PLATFORM}"
[response, body] = yield requestAsync
url: url
encoding: null
yield fs.writeFileAsync path.join(path.tempdir(), "flashplayer-#{PLATFORM}.zip"), body
log "Extract flash plugin"
zip = new AdmZip path.join(path.tempdir(), "flashplayer-#{PLATFORM}.zip")
zip.extractAllTo dir, true
gulp.task 'download-electron', async ->
electrons =
win32: "https://npm.taobao.org/mirrors/electron/#{ELECTRON_VERSION}/electron-v#{ELECTRON_VERSION}-win32-ia32.zip"
linux: "https://npm.taobao.org/mirrors/electron/#{ELECTRON_VERSION}/electron-v#{ELECTRON_VERSION}-linux-x64.zip"
darwin: "https://npm.taobao.org/mirrors/electron/#{ELECTRON_VERSION}/electron-v#{ELECTRON_VERSION}-darwin-x64.zip"
url = electrons[PLATFORM]
log url
dir = path.join(path.tempdir(), "poi-v#{POI_VERSION}-#{PLATFORM}-#{SYSTEM_BIT[PLATFORM]}")
fs.ensureDirSync dir
try
yield fs.accessAsync path.join(path.homedir(), "electron-v#{ELECTRON_VERSION}-#{PLATFORM}.zip")
catch e
log "Downloding Electron #{PLATFORM} #{ELECTRON_VERSION}"
[response, body] = yield requestAsync
url: url
encoding: null
yield fs.writeFileAsync path.join(path.homedir(), "electron-v#{ELECTRON_VERSION}-#{PLATFORM}.zip"), body
log "Extract Electron #{ELECTRON_VERSION}"
zip = new AdmZip path.join(path.homedir(), "electron-v#{ELECTRON_VERSION}-#{PLATFORM}.zip")
zip.extractAllTo dir, true
gulp.task 'copy-files', ['download-electron'], ->
gulp.src(['app.coffee', 'bower.json', 'default-config.cson', 'constant.cson', 'index.html', 'index.js', 'LICENSE', 'package.json'])
.pipe(gulp.dest(BUILD_ROOT))
gulp.src(['assets/**/*']).pipe(gulp.dest(path.join(BUILD_ROOT, 'assets')))
gulp.src(['components/**/*']).pipe(gulp.dest(path.join(BUILD_ROOT, 'components')))
gulp.src(['lib/**/*']).pipe(gulp.dest(path.join(BUILD_ROOT, 'lib')))
gulp.src(['views/**/*']).pipe(gulp.dest(path.join(BUILD_ROOT, 'views')))
gulp.src(['plugins/**/*']).pipe(gulp.dest(path.join(BUILD_ROOT, 'plugins')))
gulp.task 'install-dependencies', ['copy-files'], async ->
log BUILD_ROOT
fs.ensureDirSync BUILD_ROOT
process.chdir BUILD_ROOT
log 'Installing dependencies'
yield execAsync 'npm install --production'
gulp.task 'get-flash-player', ['install-dependencies'], async ->
plugins =
win32: 'http://7xj6zx.com1.z0.glb.clouddn.com/poi/PepperFlash/win32.zip'
linux: 'http://7xj6zx.com1.z0.glb.clouddn.com/poi/PepperFlash/linux.zip'
darwin: 'http://7xj6zx.com1.z0.glb.clouddn.com/poi/PepperFlash/darwin.zip'
url = plugins[PLATFORM]
dir = path.join(path.tempdir(), "poi-v#{POI_VERSION}-#{PLATFORM}-#{SYSTEM_BIT[PLATFORM]}", 'PepperFlash')
fs.ensureDirSync dir
try
yield fs.accessAsync path.join(path.homedir(), "flashplayer-#{PLATFORM}.zip"), fs.R_OK
catch e
log "Downloading flash plugin #{PLATFORM}"
[response, body] = yield requestAsync
url: url
encoding: null
yield fs.writeFileAsync path.join(path.homedir(), "flashplayer-#{PLATFORM}.zip"), body
log "Extract flash plugin"
zip = new AdmZip path.join(path.homedir(), "flashplayer-#{PLATFORM}.zip")
zip.extractAllTo dir, true
gulp.task 'build', ['get-flash-player'], async ->
fs.renameSync path.join(BUILD_ROOT, 'default-config.cson'), path.join(BUILD_ROOT, 'config.cson')
process.chdir path.join(path.tempdir(), "poi-v#{POI_VERSION}-#{PLATFORM}-#{SYSTEM_BIT[PLATFORM]}")
if PLATFORM == 'linux'
yield execAsync 'mv ./electron ./poi'
yield execAsync 'chmod +x ./poi'
else if PLATFORM == 'win32'
yield execAsync 'mv ./electron.exe ./poi.exe'
log "Build OK: #{path.join(path.tempdir(), "poi-v#{POI_VERSION}-#{PLATFORM}-#{SYSTEM_BIT[PLATFORM]}")}"
###
gulp.task 'electron-all', ->
gulp.task 'build', ['prepare-build', 'flash', 'electron'], ->
gulp.start 'pack'
gulp.task 'build-all', ['prepare-build', 'flash-all', 'electron-all'], ->
gulp.start 'pack-all'
gulp.task 'clean-build'
###
gulp.task 'default', ['theme', 'flash']