2015-04-02 54 views
5

我想用Phonegap Build编译我的Ionic应用程序(我正在使用Mac,因此我无法编译到iOS)。Ionic Framework + Phonegap构建:工作流程

什么是最佳工作流程?

感谢

+0

我无法相信这个问题是越来越缺乏关注。 – 2015-06-01 22:51:31

回答

2

这是我自己尝试回答这个(请帮我更新这个所以每个人都可以受益):

构建应用程序与离子:

ionic start myApp sidemenu 
etc... 

在默认离子app config.xml文件位于www/文件夹上方的根目录中,因此将它移动到Phonegap Build的www/文件夹中即可找到它。

mv config.xml www/ 

然后zipwww/文件夹或git push它从本地计算机到已与PhoneGap的建立链接的远程混帐回购协议。只能压缩或推送此目录,因为如果让其他目录位于Ionic根目录(如node_modules)中,则您的应用程序将太大而无法在Phonegap Build上编译。

然后在Phonegap Build上编译。

5

经过这整个晚上和整个上午的战斗,我想出了一个hackish的解决方案。
希望它可以帮助别人。

由于离子V1.0,至少我简单的项目,最大的区别就是

  • config.xml中
  • 所有图像资产是./resources

我做了什么:
config.xml更改:

  • 创建在.www/config_phonegap.xml新文件基于config.xml中
  • 在插件节点改变了命名空间的PhoneGap(的xmlns:间隙= “http://phonegap.com/ns/1.0”)
  • 使用正则表达式搜索替换所有图标和飞溅标签改变成相应的PhoneGap等效
  • 手动创建必要的“间隙:插件”标签为任何插件

吞加法:

  • 创建一饮而尽任务复制.www /成./phonegap文件夹
  • 一饮而尽任务也是对资源的副本
  • 一饮而尽任务coipies超过config_phonegap.xml并将其重命名为config.xml中
  • 一饮而尽任务压缩建立我们新的www文件夹。 (在zip文件中应该没有顶级www。我们只是想压缩WWW的内容)

这意味着,我的工作流程建设(直到我需要改变的东西的config.xml)现在看起来是这样的:

  1. gulp phonegap
  2. 上传phonegap.zip到https://build.phonegap.com

显然很多地区的改进在这里,但我需要的东西我可以用现在进行发布。在创建一个静态config_phonegap.xml之前,我探索了一些想法,比如用JS解析xml或制作XSLT文件。对于努力量来说,这一点似乎是低回报,所以我没有遵循。

下面是相关的代码位参考
正则表达式:

### icon regex 
# android 
<icon src="([\.\w\\-]+)" density="([\w-]+)"/> 
<icon src="$1" gap:platform="android" gap:qualifier="$2"/> 

# ios 
<icon src="([@\.\w\\-]+)" width="([\d]+)" height="([\d]+)"/> 
<icon src="$1" gap:platform="ios" width="$2" height="$3" /> 


### splash regex 
# android 
<splash src="([\.\w\\-]+)" density="([\w-]+)"/> 
<gap:splash src="$1" gap:platform="android" gap:qualifier="$2" /> 

#ios 
<splash src="([[email protected]\.\w\\-]+)" width="([\d]+)" height="([\d]+)"/> 
<gap:splash src="$1" gap:platform="ios" width="$2" height="$3" /> 

样品的PhoneGap兼容的config.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<widget id="com.yadda.yadda" version="2.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0"> 
    <name>my app name</name> 
    <description> 
     la di da desc 
    </description> 
    <author email="[email protected]" href="https://harhar.com/">w--</author> 

    <content src="index.html"/> 
    <access origin="*"/> 

    <preference name="webviewbounce" value="false"/> 
    <preference name="UIWebViewBounce" value="false"/> 
    <preference name="DisallowOverscroll" value="true"/> 
    <preference name="BackupWebStorage" value="none"/> 
    <preference name="SplashScreen" value="screen"/> 
    <preference name="SplashScreenDelay" value="1500"/> 

    <icon src="resources/android/icon/drawable-ldpi-icon.png" gap:platform="android" gap:qualifier="ldpi"/> 
    <icon src="resources/android/icon/drawable-mdpi-icon.png" gap:platform="android" gap:qualifier="mdpi"/> 
    <icon src="resources/android/icon/drawable-hdpi-icon.png" gap:platform="android" gap:qualifier="hdpi"/> 
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" gap:platform="android" gap:qualifier="xhdpi"/> 
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" gap:platform="android" gap:qualifier="xxhdpi"/> 
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" gap:platform="android" gap:qualifier="xxxhdpi"/> 
    <gap:splash src="resources/android/splash/drawable-land-ldpi-screen.png" gap:platform="android" gap:qualifier="land-ldpi" /> 
    <gap:splash src="resources/android/splash/drawable-land-mdpi-screen.png" gap:platform="android" gap:qualifier="land-mdpi" /> 
    <gap:splash src="resources/android/splash/drawable-land-hdpi-screen.png" gap:platform="android" gap:qualifier="land-hdpi" /> 
    <gap:splash src="resources/android/splash/drawable-land-xhdpi-screen.png" gap:platform="android" gap:qualifier="land-xhdpi" /> 
    <gap:splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" gap:platform="android" gap:qualifier="land-xxhdpi" /> 
    <gap:splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" gap:platform="android" gap:qualifier="land-xxxhdpi" /> 
    <gap:splash src="resources/android/splash/drawable-port-ldpi-screen.png" gap:platform="android" gap:qualifier="port-ldpi" /> 
    <gap:splash src="resources/android/splash/drawable-port-mdpi-screen.png" gap:platform="android" gap:qualifier="port-mdpi" /> 
    <gap:splash src="resources/android/splash/drawable-port-hdpi-screen.png" gap:platform="android" gap:qualifier="port-hdpi" /> 
    <gap:splash src="resources/android/splash/drawable-port-xhdpi-screen.png" gap:platform="android" gap:qualifier="port-xhdpi" /> 
    <gap:splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" gap:platform="android" gap:qualifier="port-xxhdpi" /> 
    <gap:splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" gap:platform="android" gap:qualifier="port-xxxhdpi" /> 

    <icon src="resources/ios/icon/icon.png" gap:platform="ios" width="57" height="57" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="114" height="114" /> 
    <icon src="resources/ios/icon/icon-40.png" gap:platform="ios" width="40" height="40" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="80" height="80" /> 
    <icon src="resources/ios/icon/icon-50.png" gap:platform="ios" width="50" height="50" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="100" height="100" /> 
    <icon src="resources/ios/icon/icon-60.png" gap:platform="ios" width="60" height="60" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="120" height="120" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="180" height="180" /> 
    <icon src="resources/ios/icon/icon-72.png" gap:platform="ios" width="72" height="72" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="144" height="144" /> 
    <icon src="resources/ios/icon/icon-76.png" gap:platform="ios" width="76" height="76" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="152" height="152" /> 
    <icon src="resources/ios/icon/icon-small.png" gap:platform="ios" width="29" height="29" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="58" height="58" /> 
    <icon src="resources/ios/icon/[email protected]" gap:platform="ios" width="87" height="87" /> 
    <gap:splash src="resources/ios/splash/[email protected]~iphone.png" gap:platform="ios" width="640" height="1136" /> 
    <gap:splash src="resources/ios/splash/Default-667h.png" gap:platform="ios" width="750" height="1334" /> 
    <gap:splash src="resources/ios/splash/Default-736h.png" gap:platform="ios" width="1242" height="2208" /> 
    <gap:splash src="resources/ios/splash/Default-Landscape-736h.png" gap:platform="ios" width="2208" height="1242" /> 
    <gap:splash src="resources/ios/splash/[email protected]~ipad.png" gap:platform="ios" width="2048" height="1536" /> 
    <gap:splash src="resources/ios/splash/Default-Landscape~ipad.png" gap:platform="ios" width="1024" height="768" /> 
    <gap:splash src="resources/ios/splash/[email protected]~ipad.png" gap:platform="ios" width="1536" height="2048" /> 
    <gap:splash src="resources/ios/splash/Default-Portrait~ipad.png" gap:platform="ios" width="768" height="1024" /> 
    <gap:splash src="resources/ios/splash/[email protected]~iphone.png" gap:platform="ios" width="640" height="960" /> 
    <gap:splash src="resources/ios/splash/Default~iphone.png" gap:platform="ios" width="320" height="480" /> 

    <icon src="icon.png"/> 
    <gap:splash src="splash.png" /> 

<!-- so android doesnt' go bat shit crazy --> 
    <preference name="permissions" value="none"/> 

<!-- plugins --> 
    <feature name="StatusBar"> 
    <param name="ios-package" value="CDVStatusBar" onload="true"/> 
    </feature> 
<gap:plugin name="cordova-plugin-statusbar" source="npm" version="1.0.0"> 
    <param name="onload" value="true" /> 
</gap:plugin> 
<gap:plugin name="cordova-plugin-splashscreen" source="npm" version="2.0.0" /> 
</widget> 

一饮而尽任务:

// **** Build phonegap *****/ 
var PHONEGAP_BUILD_FOLDER = '../phonegap', 
     PHONEGAP_RAW_FOLDER = 'www', 
     IONIC_SOURCE_FOLDER = './www', 
     IONIC_RESOURCE_FOLDER = './resources' 
     PHONEGAP_ZIP_FILE = 'phonegap_build.zip'; 

gulp.task('phonegap', function(cb){ 
    runSequence('clean_phonegap', 
       'copy_www', 
       'copy_resources', 
       'copy_phonegap_config_xml', 
       'copy_default_icon', 
       'copy_default_splash', 
       'zip_phonegap', 
       cb); 
}); 

gulp.task('clean_phonegap', function(cb){ 
    // clean our folder first 
    var phonegap_del_pattern = PHONEGAP_BUILD_FOLDER + '/*'; 
    del([phonegap_del_pattern], {force: true}, cb); 
}) 

gulp.task('copy_www', function(){ 
    var target_phonegap_folder = PHONEGAP_BUILD_FOLDER + '/' + PHONEGAP_RAW_FOLDER 
    return gulp.src([IONIC_SOURCE_FOLDER + '/**']) 
       .on('error', swallowError) 
       .pipe(gulp.dest(target_phonegap_folder)) 
}) 

gulp.task('copy_phonegap_config_xml', function(){ 
    var target_phonegap_folder = PHONEGAP_BUILD_FOLDER + '/' + PHONEGAP_RAW_FOLDER 
    return gulp.src(['config_phonegap.xml']) 
       .on('error', swallowError) 
       .pipe(rename('config.xml')) 
       .pipe(gulp.dest(target_phonegap_folder)); 
}) 

gulp.task('copy_resources', function(){ 
    var target_phonegap_folder = PHONEGAP_BUILD_FOLDER + '/' + PHONEGAP_RAW_FOLDER + '/resources', 
     exclude_pattern = '!' + IONIC_RESOURCE_FOLDER + '/_source_assets{,/**}' 

    // exclude pattern needs to go first. mother fucker. 
    return gulp.src([exclude_pattern, IONIC_RESOURCE_FOLDER + '/**']) 
       .on('error', swallowError) 
       .pipe(gulp.dest(target_phonegap_folder)); 
}) 

gulp.task('copy_default_icon', function(){ 
    var target_phonegap_folder = PHONEGAP_BUILD_FOLDER + '/' + PHONEGAP_RAW_FOLDER; 
    return gulp.src([IONIC_RESOURCE_FOLDER + '/ios/icon.png' ]) 
       .on('error', swallowError) 
       .pipe(gulp.dest(target_phonegap_folder)); 
}) 

gulp.task('copy_default_splash', function(){ 
    var target_phonegap_folder = PHONEGAP_BUILD_FOLDER + '/' + PHONEGAP_RAW_FOLDER; 
    return gulp.src([IONIC_RESOURCE_FOLDER + '/splash.png' ]) 
       .on('error', swallowError) 
       .pipe(gulp.dest(target_phonegap_folder)); 
}) 


gulp.task('zip_phonegap', function(){ 
    var sourcephonegap_folder = PHONEGAP_BUILD_FOLDER + '/' + PHONEGAP_RAW_FOLDER 
    return gulp.src(sourcephonegap_folder + '/**') 
     .pipe(zip('phonegap.zip')) 
     .on('error', swallowError) 
     .pipe(gulp.dest(PHONEGAP_BUILD_FOLDER)); 
}) 
0

w--的帖子很有帮助,但我真的不需要那么多阶段来完成我的任务。另外,我的config.xml似乎可以在PhoneGap Build中正常工作。因此,这种单一饮而尽任务将拉链拉上www和config.xml中为.zip文件:

gulp.task('phonegap_zip', function(){ 
    return gulp.src(['./www/**', './config.xml']) 
     .pipe(zip('phonegap.zip')) 

     .pipe(gulp.dest('./phonegap/')); 
}); 
0

如果你想自动生成的PhoneGap构建配置文件,使用:

npm install pgb-config-maker --save 

./make-config-xml.sh 

下一个命令:

phonegap remote build ios