1- # Licensed under the Apache License. See footer for details.
2-
31require " cakex"
42
53plist = require " plist"
64
75pkg = 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# -------------------------------------------------------------------------------
1112task " watch" , " watch for source file changes, build" , -> taskWatch ()
@@ -19,43 +20,88 @@ mkdir "-p", "tmp"
1920
2021# -------------------------------------------------------------------------------
2122taskBuild = ->
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# -------------------------------------------------------------------------------
57103watchIter = ->
58- taskBuild ()
104+ runStandard ()
59105
60106# -------------------------------------------------------------------------------
61107taskWatch = ->
@@ -90,80 +136,14 @@ build_app = (oDir) ->
90136fixAboutFile = (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# -------------------------------------------------------------------------------
157144cfBundleFix = (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# -------------------------------------------------------------------------------
193173taskBuildIcns = ->
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 = ->
216196cleanDir = (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- # -------------------------------------------------------------------------------
0 commit comments