首页 / 操作系统 / Linux / Linux shell 实现node-webkit的自动跨平台打包
今天下午发现了个好玩的东西(node-webkit),这东西有一直是我想实现的功能:使用html编写桌面应用,实现跨平台;具体实现方法:结合chrome浏览器内核和node.js搭建一个跨平台的应用运行环境(node-webkit is an app runtime based on Chromium and node.js.)可是这东西好像还没有一个像样的IDE,没有自动打包成应用的功能,虽然手动打包的步骤也不麻烦,但作为程序猿的我,不得不用更“高级”方法实现啦~~O(∩_∩)O哈哈~先说说手动打包吧:windows:将你的app文件用zip压缩打包,更名为成app.nw,然后直接将nw.exe和app.nw合并为app.exe即可(注意nw.exe文件夹下的库和nw.pak不能删)。linux:将你的app文件用zip压缩打包,更名为成app.nw,然后直接将nw和app.nw合并为app即可(注意要给app文件加上运行权限:chmod +x app)mac:node-webkit.app/Contents/Resources/,将system-info打包成app.nw后,放入该目录即可(还有一些图标文件也要处理,由于我还没在mac平台上测试,就先不详述了,等我上我的黑苹果测试通过了再说吧)我是在Ubuntu上打包的,不喜欢用windows的命令行,在windows下工作的伙伴们可以试试cygwin.当然我不是啥linux大神啦,我是菜鸟级的,之前写过最长的shell代码应该没有超过30行,今天破纪录了,空了好多空行,看了下有90行了,O(∩_∩)O哈哈~废话不多说了,先直接上代码了:#!/bin/bash # by VellBibi # init your app info app_name="vview" app_dir="/files/Web/Projects/vview/"
if [ ${o} = true ]; then #remove old file [ ${w} = true ] && rm -rf ${app_name}_win [ ${l} = true ] && rm -rf ${app_name}_linux [ ${m} = true ] && rm -rf ${app_name}_mac fi
# create app.nw file cd $app_dir zip app.nw ./* app_nwfile=${app_dir}/app.nw
if [ ${w} = true ]; then echo "creating windows *.exe file..." unzip $win_nw_zipfile -d ${app_name}_win && cd ${app_name}_win cat nw.exe $app_nwfile > ${app_name}.exe rm -rf nw.exe nwsnapshot.exe credits.html cd .. echo "create windows app success!" else echo "ignore windows app" fi
if [ ${l} = true ]; then echo "creating linux execute file..." tar -xvf $linux_nw_tarfile -C ./ tardir=${linux_nw_tarfile%.tar*} && tardir=${tardir##*/} # rename tardir mv $tardir ${app_name}_linux && cd ${app_name}_linux cat nw $app_nwfile > ${app_name} && chmod +x ${app_name} rm -rf nw nwsnapshot credits.html cd .. echo "create linux app success!" else echo "ignore linux app" fi
if [ ${m} = true ]; then echo "creating mac execute file..." unzip $mac_nw_zipfile -d ${app_name}_mac && cd ${app_name}_mac if [ -f ${app_dir}/Info.plist ];then cp ${app_dir}/Info.plist node-webkit.app/Contents/ fi cp $app_nwfile node-webkit.app/Contents/Resources/ if [ -f ${app_dir}/app.icns ];then cp ${app_dir}/app.icns node-webkit.app/Contents/Resources/ fi mv node-webkit.app ${app_name}.app rm -rf nwsnapshot credits.html cd .. echo "create mac app success!" else echo "ignore mac app" fi