-
Notifications
You must be signed in to change notification settings - Fork 6
/
Cakefile
198 lines (154 loc) · 5.89 KB
/
Cakefile
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
require "cakex"
plist = require "plist"
pkg = require "./package.json"
electronVersion = "1.3.5"
year = 1900 + new Date().getYear()
#-------------------------------------------------------------------------------
task "watch", "watch for source file changes, build", -> taskWatch()
task "build", "run a build", -> taskBuild()
task "buildIcns", "build the OS X icns file", -> taskBuildIcns()
WatchSpec = "app/**/* .eslintrc package.json"
#-------------------------------------------------------------------------------
mkdir "-p", "tmp"
#-------------------------------------------------------------------------------
taskBuild = ->
log "build starting"
cd process.cwd()
process.exit(1) if runStandard() != 0
log "doing some setup"
mkdir "-p", "tmp/app"
cp "-R", "app/*", "tmp/app"
fixAboutFile "tmp/app/renderer/about.md"
cp "README.md", "tmp/app/renderer/README.md"
log "running npm install on app"
cd "tmp/app"
exec "npm install --production"
cd "../.."
options = [
"--overwrite"
"--out build"
"--version #{electronVersion}"
"--app-copyright 'Copyright 2015-#{year} AnyViewer contributors. All Rights Reserved.'"
"--app-version #{pkg.version}"
].join(" ")
optionsMac = [
"--icon app/renderer/images/AnyViewer.icns"
"--app-bundle-id org.muellerware.anyviewer"
"--app-category-type public.app-category.utilities"
"--protocol anyviewer"
"--protocol-name AnyViewer"
].join(" ")
optionsLinux = [
].join(" ")
optionsWin = [
"--win32metadata.CompanyName 'AnyViewer contributors'"
"--win32metadata.ProductName AnyViewer"
].join(" ")
log "building executables"
electron_packager "tmp/app --platform darwin --arch x64 #{options} #{optionsMac}"
electron_packager "tmp/app --platform linux --arch ia32 #{options} #{optionsLinux}"
electron_packager "tmp/app --platform linux --arch x64 #{options} #{optionsLinux}"
electron_packager "tmp/app --platform win32 --arch ia32 #{options} #{optionsWin}"
electron_packager "tmp/app --platform win32 --arch x64 #{options} #{optionsWin}"
cfBundleFix "AnyViewer", "build/AnyViewer-darwin-x64/AnyViewer.app/Contents/Info.plist"
buildDirs = [
"darwin-x64"
"linux-ia32"
"linux-x64"
"win32-ia32"
"win32-x64"
]
log "building executable archives"
for buildDir in buildDirs
rm "build/AnyViewer-#{buildDir}/LICENSE"
rm "build/AnyViewer-#{buildDir}/LICENSES.chromium.html"
rm "build/AnyViewer-#{buildDir}/version"
origDir = pwd()
cd "build/AnyViewer-#{buildDir}"
exec "zip -q -y -r ../AnyViewer-#{buildDir}-#{pkg.version}.zip *"
cd origDir
log "build done."
#-------------------------------------------------------------------------------
runStandard = ->
log "standard: checking files"
rc = exec("node_modules/.bin/standard")
log "standard: A-OK!" if rc.code == 0
return rc.code
#-------------------------------------------------------------------------------
watchIter = ->
runStandard()
#-------------------------------------------------------------------------------
taskWatch = ->
watchIter()
watch
files: WatchSpec.split " "
run: watchIter
watch
files: "Cakefile"
run: (file) ->
return unless file == "Cakefile"
log "Cakefile changed, exiting"
exit 0
#-------------------------------------------------------------------------------
build_app = (oDir) ->
oDir = "#{oDir}/app"
mkdir oDir
cp "-R", "app/*", oDir
pushd oDir
exec "npm install --production"
popd()
fixAboutFile "#{oDir}/renderer/about.md"
cp "README.md", "#{oDir}/renderer/README.md"
#-------------------------------------------------------------------------------
fixAboutFile = (aboutFile)->
aboutContent = cat aboutFile
aboutContent = aboutContent.replace(/%%app-version%%/g, pkg.version)
aboutContent = aboutContent.replace(/%%electron-version%%/g, electronVersion)
aboutContent.to aboutFile
#-------------------------------------------------------------------------------
cfBundleFix = (name, iFile) ->
pObj = plist.parse( cat iFile )
pObj.CFBundleDocumentTypes = [
{
CFBundleTypeExtensions: [ "md" ],
CFBundleTypeIconFile: "AnyViewer.icns",
CFBundleTypeName: "public.markdown",
CFBundleTypeRole: "Viewer",
LSHandlerRank: "Alternate",
LSItemContentTypes: [ "public.markdown" ]
}
]
pObj.UTImportedTypeDeclarations = [
{
UTTypeConformsTo: [ "public.data" ],
UTTypeIdentifier: "public.markdown",
UTTypeTagSpecification: {
"com.apple.ostype": "markdown",
"public.filename-extension": [ "md" ],
"public.mime-type": "text/markdown"
}
}
]
plist.build(pObj).to iFile
#-------------------------------------------------------------------------------
taskBuildIcns = ->
log "building icns file from png"
iFile = "app/renderer/images/AnyViewer.png"
oFile = "app/renderer/images/AnyViewer.icns"
tDir = "tmp/icns.iconset"
cleanDir tDir
exec "sips -z 16 16 #{iFile} --out #{tDir}/icon_16x16.png"
exec "sips -z 32 32 #{iFile} --out #{tDir}/[email protected]"
exec "sips -z 32 32 #{iFile} --out #{tDir}/icon_32x32.png"
exec "sips -z 64 64 #{iFile} --out #{tDir}/[email protected]"
exec "sips -z 128 128 #{iFile} --out #{tDir}/icon_128x128.png"
exec "sips -z 256 256 #{iFile} --out #{tDir}/[email protected]"
exec "sips -z 256 256 #{iFile} --out #{tDir}/icon_256x256.png"
exec "sips -z 512 512 #{iFile} --out #{tDir}/[email protected]"
exec "sips -z 512 512 #{iFile} --out #{tDir}/icon_512x512.png"
exec "sips -z 1024 1024 #{iFile} --out #{tDir}/[email protected]"
exec "iconutil --convert icns --output #{oFile} #{tDir}"
#-------------------------------------------------------------------------------
cleanDir = (dir) ->
mkdir "-p", dir
rm "-rf", "#{dir}/*"