forked from yhatt/marp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
210 lines (186 loc) · 6.23 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
module.exports = gulp = require('gulp')
$ = do require('gulp-load-plugins')
config = require('./package.json')
del = require('del')
packager = require('electron-packager')
runSequence = require('run-sequence')
Path = require('path')
extend = require('extend')
mkdirp = require('mkdirp')
packageOpts =
asar: true
dir: 'dist'
out: 'packages'
name: config.name
version: config.devDependencies['electron']
prune: true
overwrite: true
'app-bundle-id': 'jp.yhatt.marp'
'app-version': config.version
'version-string':
ProductName: config.name
InternalName: config.name
FileDescription: config.name
CompanyName: 'yhatt'
LegalCopyright: ''
OriginalFilename: "#{config.name}.exe"
packageElectron = (opts = {}, done) ->
packager extend(packageOpts, opts), (err) ->
if err
if err.syscall == 'spawn wine'
$.util.log 'Packaging failed. Please install wine.'
else
throw err
done() if done?
globFolders = (pattern, func, callback) ->
doneTasks = 0
g = new (require("glob").Glob) pattern, (err, pathes) ->
throw err if err
done = ->
doneTasks++
callback() if callback? and doneTasks >= pathes.length
if pathes.length > 0
func(path, done) for path in pathes
else
callback()
gulp.task 'clean', ['clean:js', 'clean:css', 'clean:dist', 'clean:packages']
gulp.task 'clean:js', -> del ['js/**/*', 'js']
gulp.task 'clean:css', -> del ['css/**/*', 'css']
gulp.task 'clean:dist', -> del ['dist/**/*', 'dist']
gulp.task 'clean:packages', -> del ['packages/**/*', 'packages']
gulp.task 'clean:releases', -> del ['releases/**/*', 'releases']
gulp.task 'compile', ['compile:coffee', 'compile:sass']
gulp.task 'compile:production', ['compile:coffee:production', 'compile:sass:production']
gulp.task 'compile:coffee', ->
gulp.src 'coffee/**/*.coffee'
.pipe $.plumber()
.pipe $.sourcemaps.init()
.pipe $.coffee
bare: true
.pipe $.uglify()
.pipe $.sourcemaps.write()
.pipe gulp.dest('js')
gulp.task 'compile:sass', ->
gulp.src ['sass/**/*.scss', 'sass/**/*.sass']
.pipe $.plumber()
.pipe $.sourcemaps.init()
.pipe $.sass()
.pipe $.sourcemaps.write()
.pipe gulp.dest('css')
gulp.src ['resources/katex/fonts/*']
.pipe gulp.dest('css/fonts')
gulp.task 'compile:coffee:production', ['clean:js'], ->
gulp.src 'coffee/**/*.coffee'
.pipe $.coffee
bare: true
.pipe $.uglify()
.pipe gulp.dest('js')
gulp.task 'compile:sass:production', ['clean:css'], ->
gulp.src ['sass/**/*.scss', 'sass/**/*.sass']
.pipe $.sass()
.pipe $.cssnano
zindex: false
.pipe gulp.dest('css')
gulp.src ['resources/katex/fonts/*']
.pipe gulp.dest('css/fonts')
gulp.task 'dist', ['clean:dist'], ->
gulp.src([
'js/**/*'
'css/**/*'
'images/**/*'
'examples/**/*'
'*.js'
'!gulpfile.js'
'*.html'
'package.json'
'example.md'
'LICENSE'
], { base: '.' })
.pipe gulp.dest('dist')
.pipe $.install
production: true
gulp.task 'package', ['clean:packages', 'dist'], (done) ->
runSequence 'package:win32', 'package:darwin', 'package:linux', done
gulp.task 'package:win32', (done) ->
packageElectron {
platform: 'win32'
arch: 'ia32,x64'
icon: Path.join(__dirname, 'resources/windows/marp.ico')
}, done
gulp.task 'package:linux', (done) ->
packageElectron {
platform: 'linux'
arch: 'ia32,x64'
}, done
gulp.task 'package:darwin', (done) ->
packageElectron {
platform: 'darwin'
arch: 'x64'
icon: Path.join(__dirname, 'resources/darwin/marp.icns')
}, ->
gulp.src ["packages/*-darwin-*/#{config.name}.app/Contents/Info.plist"], { base: '.' }
.pipe $.plist
CFBundleDocumentTypes: [
{
CFBundleTypeExtensions: ['md', 'mdown']
CFBundleTypeIconFile: ''
CFBundleTypeName: 'Markdown file'
CFBundleTypeRole: 'Editor'
LSHandlerRank: 'Owner'
}
]
.pipe gulp.dest('.')
.on 'end', done
gulp.task 'build', (done) -> runSequence 'compile:production', 'package', done
gulp.task 'build:win32', (done) -> runSequence 'compile:production', 'dist', 'package:win32', done
gulp.task 'build:linux', (done) -> runSequence 'compile:production', 'dist', 'package:linux', done
gulp.task 'build:darwin', (done) -> runSequence 'compile:production', 'dist', 'package:darwin', done
gulp.task 'archive', ['archive:win32', 'archive:darwin', 'archive:linux']
gulp.task 'archive:win32', (done) ->
globFolders 'packages/*-win32-*', (path, globDone) ->
gulp.src ["#{path}/**/*"]
.pipe $.zip("#{config.version}-#{Path.basename(path, '.*')}.zip")
.pipe gulp.dest('releases')
.on 'end', globDone
, done
gulp.task 'archive:darwin', (done) ->
appdmg = try
require('appdmg')
catch err
null
unless appdmg
$.util.log 'Archiving for darwin is supported only OSX.'
$.util.log 'In OSX, please install appdmg (`npm install appdmg`)'
return done()
globFolders 'packages/*-darwin-*', (path, globDone) ->
release_to = Path.join(__dirname, "releases/#{config.version}-#{Path.basename(path, '.*')}.dmg")
mkdirp Path.dirname(release_to), (err) ->
del(release_to)
.then ->
running_appdmg = appdmg {
target: release_to
basepath: Path.join(__dirname, path)
specification:
title: config.name
background: Path.join(__dirname, "resources/darwin/dmg-background.png")
'icon-size': 80
window: {
position: { x: 90, y: 90 }
size: { width: 624, height: 412 }
}
contents: [
{ x: 210, y: 300, type: 'file', path: "#{config.name}.app" }
{ x: 410, y: 300, type: 'link', path: '/Applications' }
]
}
running_appdmg.on 'finish', globDone
, done
gulp.task 'archive:linux', (done) ->
globFolders 'packages/*-linux-*', (path, globDone) ->
gulp.src ["#{path}/**/*"]
.pipe $.tar("#{config.version}-#{Path.basename(path, '.*')}.tar")
.pipe $.gzip()
.pipe gulp.dest('releases')
.on 'end', globDone
, done
gulp.task 'release', (done) -> runSequence 'build', 'archive', 'clean', done