linux下node-webkit自动跨平台打包shell

来源:互联网 发布:深圳网络出租屋牌照 编辑:程序博客网 时间:2024/06/01 10:20

前言

node-webkit可谓是webapp开发神器,支持windows、mac、linux,但是打包是个问题,总不能在三个系统里面打包吧。

官方也有打包工具,但是总觉得挺麻烦的。

于是想着linux可不可以通过shell来实现跨平台打包。

实现

http://www.linuxidc.com/Linux/2014-03/97933.htm

发现一位大神写的脚本,但是由于node-webkit改名为nwjs,且该脚本windows、mac下的脚本有问题,因此对它进行了一些修改。

#!/bin/bash# by minghuazhou# init your app infoapp_name="toopos"app_dir="/home/qiqi/toopos_/trunk/tooposWeb/build"win_nw_zipfile="/home/qiqi/toopos_/trunk/tooposBuilder/codes/nwjs-v0.12.3-win-ia32.zip"linux_nw_tarfile="/home/qiqi/toopos_/trunk/tooposBuilder/codes/nwjs-v0.12.3-linux-x64.tar.gz"mac_nw_zipfile="/home/qiqi/toopos_/trunk/tooposBuilder/codes/nwjs-v0.12.3-osx-ia32.zip"# read pack_flagw=false && l=false && m=false && o=falsewhile getopts "wlmo" arg # -w:windows -l:linux -m:mac -o:overwritedocase $arg in            w)                w=true                ;;            l)                l=true                ;;            m)                m=true                ;;o)o=true;;            ?)            echo "unkonw argument"        exit 1        ;;    esacdoneif [ ${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}_macfi# create app.nw filecd $app_dirzip -r app.nw ./* app_nwfile=${app_dir}/app.nwif [ ${w} = true ]; thenecho "creating windows *.exe file..."unzip $win_nw_zipfile -d ${app_name}_win && cd ${app_name}_winwinzipdir=$(ls  -ad */)mv ${winzipdir}* ./cat nw.exe $app_nwfile > ${app_name}.exerm -rf ${winzipdir} nw.exe nwsnapshot.exe credits.htmlcd ..echo "create windows app success!"elseecho "ignore windows app"fiif [ ${l} = true ]; thenecho "creating linux execute file..."tar -xf $linux_nw_tarfile -C ./tardir=${linux_nw_tarfile%.tar*} && tardir=${tardir##*/} # rename tardirmv  $tardir ${app_name}_linux && cd ${app_name}_linuxcat nw $app_nwfile > ${app_name} && chmod +x ${app_name}rm -rf nw nwsnapshot credits.htmlcd ..echo "create linux app success!"elseecho "ignore linux app"fiif [ ${m} = true ]; thenecho "creating mac execute file..."unzip $mac_nw_zipfile -d ${app_name}_mac && cd ${app_name}_macmaczipdir=$(ls  -ad */)mv ${maczipdir}* ./if [ -f ${app_dir}/Info.plist ];then    cp ${app_dir}/Info.plist nwjs.app/Contents/ficp $app_nwfile nwjs.app/Contents/Resources/if [ -f ${app_dir}/app.icns ];then    cp ${app_dir}/app.icns nwjs.app/Contents/Resources/fimv nwjs.app ${app_name}.apprm -rf ${maczipdir} nwsnapshot credits.htmlcd ..echo "create mac app success!"elseecho "ignore mac app"fi# remove app.nwrm -f app.nw

使用方法

一.从nwjs官网上下载三个平台的包

这里取了win32、linux64、mac32的包

二.修改shell脚本中app名称、路径、各平台包文件地址

app_name="toopos"app_dir="/home/qiqi/toopos_/trunk/tooposWeb/build"win_nw_zipfile="/home/qiqi/toopos_/trunk/tooposBuilder/codes/nwjs-v0.12.3-win-ia32.zip"linux_nw_tarfile="/home/qiqi/toopos_/trunk/tooposBuilder/codes/nwjs-v0.12.3-linux-x64.tar.gz"mac_nw_zipfile="/home/qiqi/toopos_/trunk/tooposBuilder/codes/nwjs-v0.12.3-osx-ia32.zip"
三.终端运行你的.sh文件,如sh yourshell.sh,有四个参数可以给定:

1.-w : 打包windows下的运行文件到 [your_app_name]_win文件夹下

2.-l : 打包linux下的运行文件到[your_app_name]_linux文件夹下

3.-m : 打包mac下的运行文件到[your_app_name]_mac文件夹下

4.-o : 覆盖之前打包过的文件(没有加这一项的话中间会有提示是否覆盖文件)

四.效果图(mac上没有试过,穷逼一个)


0 0