{"id":785,"date":"2013-09-23T17:30:56","date_gmt":"2013-09-23T17:30:56","guid":{"rendered":"http:\/\/psyphi.net\/blog\/?p=785"},"modified":"2013-09-24T18:57:03","modified_gmt":"2013-09-24T18:57:03","slug":"cross-platform-automated-builds-for-node-webkit-applications","status":"publish","type":"post","link":"https:\/\/psyphi.net\/blog\/2013\/09\/cross-platform-automated-builds-for-node-webkit-applications\/","title":{"rendered":"Cross-platform automated builds for node-webkit applications"},"content":{"rendered":"<p>Recently I&#8217;ve been extending my &#8220;classic&#8221; JavaScript knowledge by learning NodeJS. I&#8217;m sad to say that writing cross-platform, Desktop-class applications in Perl is just way too much hassle. However, having also discovered node-webkit I&#8217;ve been able to accelerate my desktop application development using classic HTML &amp; CSS knowledge and improving my JavaScript techniques, mostly trying to better understand fully asynchronous, non-blocking programming. Apart from some initial mind-bending scoping experiences which maybe I&#8217;ll come back to another day, it&#8217;s generally been a breeze.<\/p>\n<p>One of the useful things I&#8217;ve been able to do is to automate cross-platform application builds for Windows and Mac (Linux to come, not a priority right now but should be easy &#8211; feel free to comment). It&#8217;s not compilation, but more like application packaging.<\/p>\n<p>My project has the node-webkit distributable zips in &#8220;src\/&#8221;. The target folder is &#8220;dist\/&#8221; and I&#8217;m also using a few DOS tools (zip.exe &amp; unzip.exe and the commandline Anolis Resource editor) which live in dist\/tools. The targets are built with timestamped filenames, a .exe in &#8220;dist\/win\/&#8221; for Windows and a .dmg in &#8220;dist\/mac\/&#8221; for OSX. I don&#8217;t do anything clever with Info.plist on Mac though I know I should, but the icons are set on both platforms, assuming they&#8217;ve been pre-generated and saved in the right places (resources\/).<\/p>\n<p>On OSX I&#8217;m using system <em>make<\/em> which presumably came with XCode. On Windows I&#8217;m using <em>gmake<\/em> which on my system came with a previous installation of Strawberry Perl but is also available in a Windows binary\/installer.<\/p>\n<p>My Makefile looks something like below (&#8220;make&#8221; not being one of my strongest skills &#8211; apologies for the ugly stuff). It might not be 100% complete as it&#8217;s been excised out of the original, much more complicated Makefile, so use with caution. If anyone has any tips on stuffing it all into NSIS automatically as well, please comment.<\/p>\n<pre><code>NW    := node-webkit-v0.7.3\r\nNWWIN := $(NW)-win-ia32\r\nNWMAC := $(NW)-osx-ia32\r\nNWLIN := $(NW)-linux-x64\r\n\r\ndeps:\r\n\trm -rf node_modules\r\n\tnpm install\r\n\r\nwindeps:\r\n\tif exist node_modules rmdir node_modules \/s \/q\r\n\tnpm install\r\n\r\n# zip.exe &amp;amp; unzip.exe from http:\/\/stahlworks.com\/dev\/?tool=zipunzip\r\n# Resourcer.exe from http:\/\/anolis.codeplex.com\/\r\nwin: windeps\r\n\tif exist mdc.nw del mdc.nw \/q\r\n\tif exist dist\\win rmdir dist\\win \/s \/q\r\n\tif exist tmp rmdir tmp \/s \/q\r\n\tdist\\tools\\zip -r mdc.nw mdc package.json node_modules\r\n\tmkdir dist\\win tmp\r\n\tdist\\tools\\unzip -d tmp -o src\\$(NWWIN).zip\r\n\tdist\\tools\\Resourcer -op:del -src:tmp\\nw.exe -type:14 -name:IDR_MAINFRAME\r\n\tdist\\tools\\Resourcer -op:add -src:tmp\\nw.exe -type:14 -name:IDR_MAINFRAME -file:resources\\mdc72x72.ico -lang:1033\r\n\tcopy \/b tmp\\nw.exe+mdc.nw dist\\win\\mdc.exe\r\n\tcopy tmp\\icudt.dll dist\\win\r\n\tcopy tmp\\nw.pak dist\\win\r\n\tif exist mdc.nw del mdc.nw \/q\r\n\tif exist tmp rmdir tmp \/q \/s\r\n\tdist\\tools\\zip -r dist\\win\\mdc-$(shell echo %date:~-4,4%%date:~3,2%%date:~0,2%-%time:~0,2%%time:~3,2%).zip dist\\win\r\n\r\nmac: deps\r\n\t[ ! -f mdc.nw ] || rm mdc.nw\r\n\tzip -r mdc.nw mdc package.json resources\/mdc72x72.png node_modules\r\n\ttouch node-webkit.app\r\n\trm -rf node-webkit.app dist\/mdc.app dist\/mac\r\n\tmkdir dist\/mac\r\n\tunzip -o src\/$(NWMAC).zip\r\n\tmv node-webkit.app dist\/mac\/mdc.app\r\n\tmv mdc.nw dist\/mac\/mdc.app\/Contents\/Resources\/app.nw\r\n\trm dist\/mac\/mdc.app\/Contents\/Resources\/nw.icns\r\n\tsips -s format icns resources\/mdc512x512.png --out dist\/mac\/mdc.app\/Contents\/Resources\/mdc.icns\r\n\tperl -i -pe 's{nw[.]icns}{mdc.icns}smxg' dist\/mac\/mdc.app\/Contents\/Info.plist\r\n\tperl -i -pe 's{node[-]webkit[ ]App}{MDC}smxg' dist\/mac\/mdc.app\/Contents\/Info.plist\r\n\thdiutil create dist\/mac\/mdc-$(shell date +'%Y%m%d-%H%M').dmg -ov -volname \"MDC\" -fs HFS+ -srcfolder dist\/mac\/mdc.app\r\n\trm -rf dist\/mac\/mdc.app\r\n\r\ntest:\r\n\t@.\/node_modules\/.bin\/mocha\r\n\r\n.PHONY: test<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently I&#8217;ve been extending my &#8220;classic&#8221; JavaScript knowledge by learning NodeJS. I&#8217;m sad to say that writing cross-platform, Desktop-class applications in Perl is just way too much hassle. However, having also discovered node-webkit I&#8217;ve been able to accelerate my desktop application development using classic HTML &amp; CSS knowledge and improving my JavaScript techniques, mostly trying &hellip; <a href=\"https:\/\/psyphi.net\/blog\/2013\/09\/cross-platform-automated-builds-for-node-webkit-applications\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Cross-platform automated builds for node-webkit applications&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[11],"tags":[983,307,984,744,292,532,980,982,981,985],"class_list":["post-785","post","type-post","status-publish","format-standard","hentry","category-programming","tag-chrome","tag-css","tag-desktop-applications","tag-html","tag-javascript","tag-make","tag-node","tag-node-webkit","tag-nodejs","tag-software-packaging"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/comments?post=785"}],"version-history":[{"count":6,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/785\/revisions"}],"predecessor-version":[{"id":791,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/posts\/785\/revisions\/791"}],"wp:attachment":[{"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/media?parent=785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/categories?post=785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/psyphi.net\/blog\/wp-json\/wp\/v2\/tags?post=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}