Skip to content

Commit 816703b

Browse files
author
Patrick Mueller
committed
started using electron-packager and standard
Lots of changes due to standard, but no new function. Build now builds for Mac, Linux 32- and 64-bit and Windows 32- and 64-bit.
1 parent 63f218b commit 816703b

File tree

20 files changed

+461
-748
lines changed

20 files changed

+461
-748
lines changed

.eslintrc

Lines changed: 0 additions & 22 deletions
This file was deleted.

Cakefile

Lines changed: 76 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# Licensed under the Apache License. See footer for details.
2-
31
require "cakex"
42

53
plist = require "plist"
64

75
pkg = require "./package.json"
8-
ePkg = require "./node_modules/electron-prebuilt/package.json"
6+
7+
electronVersion = "1.3.5"
8+
9+
year = 1900 + new Date().getYear()
910

1011
#-------------------------------------------------------------------------------
1112
task "watch", "watch for source file changes, build", -> taskWatch()
@@ -19,43 +20,88 @@ mkdir "-p", "tmp"
1920

2021
#-------------------------------------------------------------------------------
2122
taskBuild = ->
22-
log "build starting."
23+
log "build starting"
2324

24-
log "linting ..."
25-
eslint "app", {silent: true}, (code, output) =>
26-
console.log(output)
25+
cd process.cwd()
2726

28-
platArch = "#{process.platform}-#{process.arch}"
27+
process.exit(1) if runStandard() != 0
2928

30-
if platArch is "darwin-x64"
31-
mkdir "-p", "build/#{platArch}"
29+
log "doing some setup"
30+
mkdir "-p", "tmp/app"
31+
cp "-R", "app/*", "tmp/app"
3232

33-
build_darwin_x64 "build/#{platArch}", "AnyViewer-build"
34-
build_darwin_x64 "build/#{platArch}", "AnyViewer"
33+
fixAboutFile "tmp/app/renderer/about.md"
34+
cp "README.md", "tmp/app/renderer/README.md"
3535

36-
origDir = pwd()
37-
log "building distribution archive"
38-
cd "build/#{platArch}"
39-
exec "zip -q -y -r ../AnyViewer-#{platArch}-#{pkg.version}.zip AnyViewer.app"
40-
cd origDir
36+
log "running npm install on app"
37+
cd "tmp/app"
38+
exec "npm install --production"
39+
cd "../.."
40+
41+
options = [
42+
"--overwrite"
43+
"--out build"
44+
"--version #{electronVersion}"
45+
"--app-copyright 'Copyright 2015-#{year} AnyViewer contributors. All Rights Reserved.'"
46+
"--app-version #{pkg.version}"
47+
].join(" ")
48+
49+
optionsMac = [
50+
"--icon app/renderer/images/AnyViewer.icns"
51+
"--app-bundle-id org.muellerware.anyviewer"
52+
"--app-category-type public.app-category.utilities"
53+
"--protocol anyviewer"
54+
"--protocol-name AnyViewer"
55+
].join(" ")
56+
57+
optionsLinux = [
58+
].join(" ")
59+
60+
optionsWin = [
61+
"--win32metadata.CompanyName 'AnyViewer contributors'"
62+
"--win32metadata.ProductName AnyViewer"
63+
].join(" ")
64+
65+
log "building executables"
66+
electron_packager "tmp/app --platform darwin --arch x64 #{options} #{optionsMac}"
67+
electron_packager "tmp/app --platform linux --arch ia32 #{options} #{optionsLinux}"
68+
electron_packager "tmp/app --platform linux --arch x64 #{options} #{optionsLinux}"
69+
electron_packager "tmp/app --platform win32 --arch ia32 #{options} #{optionsWin}"
70+
electron_packager "tmp/app --platform win32 --arch x64 #{options} #{optionsWin}"
71+
72+
cfBundleFix "AnyViewer", "build/AnyViewer-darwin-x64/AnyViewer.app/Contents/Info.plist"
73+
74+
buildDirs = [
75+
"darwin-x64"
76+
"linux-ia32"
77+
"linux-x64"
78+
"win32-ia32"
79+
"win32-x64"
80+
]
4181

42-
if platArch is "linux-x64"
43-
mkdir "-p", "build/#{platArch}"
82+
log "building executable archives"
83+
for buildDir in buildDirs
84+
rm "build/AnyViewer-#{buildDir}/LICENSE"
85+
rm "build/AnyViewer-#{buildDir}/LICENSES.chromium.html"
86+
rm "build/AnyViewer-#{buildDir}/version"
4487

45-
build_linux_x64 "build/#{platArch}", "AnyViewer-build"
46-
build_linux_x64 "build/#{platArch}", "AnyViewer"
88+
origDir = pwd()
89+
cd "build/AnyViewer-#{buildDir}"
90+
exec "zip -q -y -r ../AnyViewer-#{buildDir}-#{pkg.version}.zip *"
91+
cd origDir
4792

48-
origDir = pwd()
49-
log "building distribution archive"
50-
cd "build/#{platArch}"
51-
exec "zip -q -y -r ../AnyViewer-#{platArch}-#{pkg.version}.zip AnyViewer"
52-
cd origDir
93+
log "build done."
5394

54-
log "build done."
95+
#-------------------------------------------------------------------------------
96+
runStandard = ->
97+
log "standard: checking files"
98+
rc = exec("node_modules/.bin/standard")
99+
log "standard: A-OK!" if rc.code == 0
100+
return rc.code
55101

56102
#-------------------------------------------------------------------------------
57103
watchIter = ->
58-
taskBuild()
104+
runStandard()
59105

60106
#-------------------------------------------------------------------------------
61107
taskWatch = ->
@@ -90,80 +136,14 @@ build_app = (oDir) ->
90136
fixAboutFile = (aboutFile)->
91137
aboutContent = cat aboutFile
92138
aboutContent = aboutContent.replace(/%%app-version%%/g, pkg.version)
93-
aboutContent = aboutContent.replace(/%%electron-version%%/g, ePkg.version)
139+
aboutContent = aboutContent.replace(/%%electron-version%%/g, electronVersion)
94140

95141
aboutContent.to aboutFile
96142

97-
#-------------------------------------------------------------------------------
98-
build_darwin_x64 = (dir, name)->
99-
log "building #{path.relative process.cwd(), path.join(dir, name)} ..."
100-
101-
iDir = "node_modules/electron-prebuilt/dist"
102-
oDir = dir
103-
104-
eiDir = "#{iDir}/Electron.app"
105-
eoDir = "#{oDir}/Electron.app"
106-
107-
rm "-Rf", eoDir
108-
109-
# copy electron, swizzle license/version names, locations
110-
cp "-R", eiDir, oDir
111-
cp "#{iDir}/LICENSE", "#{eoDir}/LICENSE-electron"
112-
cp "#{iDir}/version", "#{eoDir}/version-electron"
113-
114-
# copy icns
115-
cp "app/renderer/images/AnyViewer.icns", "#{eoDir}/Contents/Resources"
116-
117-
# fix the Info.plist
118-
cfBundleFix name, "#{eoDir}/Contents/Info.plist"
119-
120-
# remove default_app
121-
rm "-rf", "#{eoDir}/Contents/Resources/default_app"
122-
123-
# rename the binary executable
124-
mv "#{eoDir}/Contents/MacOS/Electron", "#{eoDir}/Contents/MacOS/#{name}"
125-
126-
# build the app directory
127-
build_app "#{eoDir}/Contents/Resources"
128-
129-
# rename the .app file
130-
rm "-Rf", "#{oDir}/#{name}.app"
131-
mv eoDir, "#{oDir}/#{name}.app"
132-
133-
#-------------------------------------------------------------------------------
134-
build_linux_x64 = (dir, name)->
135-
log "building #{path.relative process.cwd(), path.join(dir, name)} ..."
136-
137-
iDir = "node_modules/electron-prebuilt/dist"
138-
oDir = "#{dir}/#{name}"
139-
140-
rm "-Rf", oDir
141-
142-
# copy electron, swizzle license/version names, locations
143-
cp "-R", "#{iDir}/*", oDir
144-
cp "#{iDir}/LICENSE", "#{oDir}/LICENSE-electron"
145-
cp "#{iDir}/version", "#{oDir}/version-electron"
146-
147-
# remove default_app
148-
rm "-rf", "#{oDir}/resources/default_app"
149-
150-
# build the app directory
151-
build_app "#{oDir}/resources"
152-
153-
# rename the .app file
154-
mv "#{oDir}/electron", "#{oDir}/#{name}"
155-
156143
#-------------------------------------------------------------------------------
157144
cfBundleFix = (name, iFile) ->
158145
pObj = plist.parse( cat iFile )
159146

160-
pObj.CFBundleDisplayName = name
161-
pObj.CFBundleExecutable = name
162-
pObj.CFBundleName = name
163-
pObj.CFBundleIconFile = "AnyViewer.icns"
164-
pObj.CFBundleIdentifier = "org.muellerware.#{name}"
165-
pObj.CFBundleVersion = pkg.version
166-
167147
pObj.CFBundleDocumentTypes = [
168148
{
169149
CFBundleTypeExtensions: [ "md" ],
@@ -191,7 +171,7 @@ cfBundleFix = (name, iFile) ->
191171

192172
#-------------------------------------------------------------------------------
193173
taskBuildIcns = ->
194-
log "build icns file..."
174+
log "building icns file from png"
195175

196176
iFile = "app/renderer/images/AnyViewer.png"
197177
oFile = "app/renderer/images/AnyViewer.icns"
@@ -216,17 +196,3 @@ taskBuildIcns = ->
216196
cleanDir = (dir) ->
217197
mkdir "-p", dir
218198
rm "-rf", "#{dir}/*"
219-
220-
#-------------------------------------------------------------------------------
221-
# Licensed under the Apache License, Version 2.0 (the "License");
222-
# you may not use this file except in compliance with the License.
223-
# You may obtain a copy of the License at
224-
#
225-
# http://www.apache.org/licenses/LICENSE-2.0
226-
#
227-
# Unless required by applicable law or agreed to in writing, software
228-
# distributed under the License is distributed on an "AS IS" BASIS,
229-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
230-
# See the License for the specific language governing permissions and
231-
# limitations under the License.
232-
#-------------------------------------------------------------------------------

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ install
4747
You can download a pre-built binary from the
4848
[releases page](https://github.com/pmuellr/AnyViewer/releases).
4949

50+
5051
Mac OS X notes
5152
--------------------------------------------------------------------------------
5253

@@ -66,6 +67,24 @@ You can associate AnyViewer with other file extensions, by [following these
6667
instructions](http://www.imore.com/how-change-default-apps-os-x).
6768

6869

70+
Windows notes
71+
--------------------------------------------------------------------------------
72+
73+
Windows builds are not tested, they are the build outputs of
74+
[`electron-packager`](https://npmjs.org/package/electron-packager).
75+
Please [create an issue](https://github.com/pmuellr/AnyViewer/issues) for
76+
problems encountered.
77+
78+
79+
Linux notes
80+
--------------------------------------------------------------------------------
81+
82+
Linux builds are not tested, they are the build outputs of
83+
[`electron-packager`](https://npmjs.org/package/electron-packager).
84+
Please [create an issue](https://github.com/pmuellr/AnyViewer/issues) for
85+
problems encountered.
86+
87+
6988
plugins
7089
================================================================================
7190

@@ -172,9 +191,7 @@ building
172191
* run `npm install` to install dependencies
173192
* run `npm run build` to build the execute
174193

175-
A "build" version of the executable is available in the `build` directory,
176-
to make it easier to test a development version while you have a stable version
177-
installed at the same time, on your boxen.
194+
Executables and archives for all platforms will be in the `build` directory.
178195

179196

180197
hacking
@@ -205,10 +222,6 @@ Awesome! We're happy that you want to contribute.
205222
Make sure that you're read and understand the
206223
[Code of Conduct](CODE_OF_CONDUCT.md).
207224

208-
At this time, there are no builds for Windows or Linux, but if someone would
209-
like to contribute those, that would be awesome. It's expected that changes
210-
would need to be changed to the build scripts, and possibly the runtime code.
211-
212225

213226
license
214227
================================================================================

app/AnyViewer.desktop

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)