summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/cordova/lib
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-12-03 00:23:09 -0500
committerJules Laplace <jules@okfoc.us>2015-12-03 00:23:09 -0500
commite760f95dc843cf11367d1aea0ed832991964584a (patch)
treecf03b343ef830c58f2b12aa0c76135fca58489c9 /StoneIsland/platforms/ios/cordova/lib
parent0a55602cb98fea35632f8f11e840c65cc9011018 (diff)
rebuild project
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib')
-rwxr-xr-xStoneIsland/platforms/ios/cordova/lib/build.js79
-rwxr-xr-xStoneIsland/platforms/ios/cordova/lib/check_reqs.js112
-rwxr-xr-xStoneIsland/platforms/ios/cordova/lib/copy-www-build-step.js69
-rwxr-xr-xStoneIsland/platforms/ios/cordova/lib/copy-www-build-step.sh87
-rwxr-xr-xStoneIsland/platforms/ios/cordova/lib/list-devices24
-rwxr-xr-xStoneIsland/platforms/ios/cordova/lib/list-emulator-images3
-rwxr-xr-xStoneIsland/platforms/ios/cordova/lib/run.js4
7 files changed, 247 insertions, 131 deletions
diff --git a/StoneIsland/platforms/ios/cordova/lib/build.js b/StoneIsland/platforms/ios/cordova/lib/build.js
index 153a4ec3..2213ef8c 100755
--- a/StoneIsland/platforms/ios/cordova/lib/build.js
+++ b/StoneIsland/platforms/ios/cordova/lib/build.js
@@ -24,9 +24,11 @@ var Q = require('q'),
path = require('path'),
shell = require('shelljs'),
spawn = require('./spawn'),
- check_reqs = require('./check_reqs');
+ check_reqs = require('./check_reqs'),
+ fs = require('fs');
var projectPath = path.join(__dirname, '..', '..');
+var projectName = null;
module.exports.run = function (argv) {
@@ -36,6 +38,10 @@ module.exports.run = function (argv) {
'release': Boolean,
'device': Boolean,
'emulator': Boolean,
+ 'codeSignIdentity': String,
+ 'codeSignResourceRules': String,
+ 'provisioningProfile': String,
+ 'buildConfig' : String
}, {'-r': '--release'}, argv);
if (args.debug && args.release) {
@@ -45,10 +51,42 @@ module.exports.run = function (argv) {
if (args.device && args.emulator) {
return Q.reject('Only one of "device"/"emulator" options should be specified');
}
+
+ if(args.buildConfig) {
+ if(!fs.existsSync(args.buildConfig)) {
+ return Q.reject('Build config file does not exist:' + args.buildConfig);
+ }
+ console.log('Reading build config file:', path.resolve(args.buildConfig));
+ var buildConfig = JSON.parse(fs.readFileSync(args.buildConfig, 'utf-8'));
+ if(buildConfig.ios) {
+ var buildType = args.release ? 'release' : 'debug';
+ var config = buildConfig.ios[buildType];
+ if(config) {
+ ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile'].forEach(
+ function(key) {
+ args[key] = args[key] || config[key];
+ });
+ }
+ }
+ }
return check_reqs.run().then(function () {
return findXCodeProjectIn(projectPath);
- }).then(function (projectName) {
+ }).then(function (name) {
+ projectName = name;
+ var extraConfig = '';
+ if (args.codeSignIdentity) {
+ extraConfig += 'CODE_SIGN_IDENTITY = ' + args.codeSignIdentity + '\n';
+ extraConfig += 'CODE_SIGN_IDENTITY[sdk=iphoneos*] = ' + args.codeSignIdentity + '\n';
+ }
+ if (args.codeSignResourceRules) {
+ extraConfig += 'CODE_SIGN_RESOURCE_RULES_PATH = ' + args.codeSignResourceRules + '\n';
+ }
+ if (args.provisioningProfile) {
+ extraConfig += 'PROVISIONING_PROFILE = ' + args.provisioningProfile + '\n';
+ }
+ return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
+ }).then(function () {
var configuration = args.release ? 'Release' : 'Debug';
console.log('Building project : ' + path.join(projectPath, projectName + '.xcodeproj'));
@@ -57,6 +95,23 @@ module.exports.run = function (argv) {
var xcodebuildArgs = getXcodeArgs(projectName, projectPath, configuration, args.device);
return spawn('xcodebuild', xcodebuildArgs, projectPath);
+ }).then(function () {
+ if (!args.device) {
+ return;
+ }
+ var buildOutputDir = path.join(projectPath, 'build', 'device');
+ var pathToApp = path.join(buildOutputDir, projectName + '.app');
+ var pathToIpa = path.join(buildOutputDir, projectName + '.ipa');
+ var xcRunArgs = ['-sdk', 'iphoneos', 'PackageApplication',
+ '-v', pathToApp,
+ '-o', pathToIpa];
+ if (args.codeSignIdentity) {
+ xcRunArgs.concat('--sign', args.codeSignIdentity);
+ }
+ if (args.provisioningProfile) {
+ xcRunArgs.concat('--embed', args.provisioningProfile);
+ }
+ return spawn('xcrun', xcRunArgs, projectPath);
});
};
@@ -128,19 +183,27 @@ function getXcodeArgs(projectName, projectPath, configuration, isDevice) {
// help/usage function
module.exports.help = function help() {
console.log('');
- console.log('Usage: build [ --debug | --release ] [--archs=\"<list of architectures...>\"] [--device | --simulator]');
- console.log(' --help : Displays this dialog.');
- console.log(' --debug : Builds project in debug mode. (Default)');
- console.log(' --release : Builds project in release mode.');
- console.log(' -r : Shortcut :: builds project in release mode.');
+ console.log('Usage: build [--debug | --release] [--archs=\"<list of architectures...>\"]');
+ console.log(' [--device | --simulator] [--codeSignIdentity=\"<identity>\"]');
+ console.log(' [--codeSignResourceRules=\"<resourcerules path>\"]');
+ console.log(' [--provisioningProfile=\"<provisioning profile>\"]');
+ console.log(' --help : Displays this dialog.');
+ console.log(' --debug : Builds project in debug mode. (Default)');
+ console.log(' --release : Builds project in release mode.');
+ console.log(' -r : Shortcut :: builds project in release mode.');
// TODO: add support for building different archs
// console.log(" --archs : Builds project binaries for specific chip architectures (`anycpu`, `arm`, `x86`, `x64`).");
console.log(' --device, --simulator');
- console.log(' : Specifies, what type of project to build');
+ console.log(' : Specifies, what type of project to build');
+ console.log(' --codeSignIdentity : Type of signing identity used for code signing.');
+ console.log(' --codeSignResourceRules : Path to ResourceRules.plist.');
+ console.log(' --provisioningProfile : UUID of the profile.');
+ console.log('');
console.log('examples:');
console.log(' build ');
console.log(' build --debug');
console.log(' build --release');
+ console.log(' build --codeSignIdentity="iPhone Distribution" --provisioningProfile="926c2bd6-8de9-4c2f-8407-1016d2d12954"');
// TODO: add support for building different archs
// console.log(" build --release --archs=\"armv7\"");
console.log('');
diff --git a/StoneIsland/platforms/ios/cordova/lib/check_reqs.js b/StoneIsland/platforms/ios/cordova/lib/check_reqs.js
index 6b4cce56..d1f6333c 100755
--- a/StoneIsland/platforms/ios/cordova/lib/check_reqs.js
+++ b/StoneIsland/platforms/ios/cordova/lib/check_reqs.js
@@ -17,34 +17,30 @@
under the License.
*/
-/* jshint node:true, bitwise:true, undef:true, trailing:true, quotmark:true,
- indent:4, unused:vars, latedef:nofunc,
- sub:true, laxcomma:true, laxbreak:true
-*/
-
-var Q = require('Q'),
- os = require('os'),
+var Q = require('q'),
shell = require('shelljs'),
versions = require('./versions');
var XCODEBUILD_MIN_VERSION = '4.6.0';
+var XCODEBUILD_NOT_FOUND_MESSAGE =
+ 'Please install version ' + XCODEBUILD_MIN_VERSION + ' or greater from App Store';
var IOS_SIM_MIN_VERSION = '3.0.0';
-var IOS_SIM_NOT_FOUND_MESSAGE = 'ios-sim was not found. Please download, build and install version ' + IOS_SIM_MIN_VERSION +
- ' or greater from https://github.com/phonegap/ios-sim into your path.' +
- ' Or \'npm install -g ios-sim\' using node.js: http://nodejs.org';
+var IOS_SIM_NOT_FOUND_MESSAGE =
+ 'Please download, build and install version ' + IOS_SIM_MIN_VERSION + ' or greater' +
+ ' from https://github.com/phonegap/ios-sim into your path, or do \'npm install -g ios-sim\'';
-var IOS_DEPLOY_MIN_VERSION = '1.2.0';
-var IOS_DEPLOY_NOT_FOUND_MESSAGE = 'ios-deploy was not found. Please download, build and install version ' + IOS_DEPLOY_MIN_VERSION +
- ' or greater from https://github.com/phonegap/ios-deploy into your path.' +
- ' Or \'npm install -g ios-deploy\' using node.js: http://nodejs.org';
+var IOS_DEPLOY_MIN_VERSION = '1.4.0';
+var IOS_DEPLOY_NOT_FOUND_MESSAGE =
+ 'Please download, build and install version ' + IOS_DEPLOY_MIN_VERSION + ' or greater' +
+ ' from https://github.com/phonegap/ios-deploy into your path, or do \'npm install -g ios-deploy\'';
/**
* Checks if xcode util is available
* @return {Promise} Returns a promise either resolved with xcode version or rejected
*/
module.exports.run = module.exports.check_xcodebuild = function () {
- return checkTool('xcodebuild', XCODEBUILD_MIN_VERSION);
+ return checkTool('xcodebuild', XCODEBUILD_MIN_VERSION, XCODEBUILD_NOT_FOUND_MESSAGE);
};
/**
@@ -63,6 +59,13 @@ module.exports.check_ios_sim = function () {
return checkTool('ios-sim', IOS_SIM_MIN_VERSION, IOS_SIM_NOT_FOUND_MESSAGE);
};
+module.exports.check_os = function () {
+ // Build iOS apps available for OSX platform only, so we reject on others platforms
+ return process.platform === 'darwin' ?
+ Q.resolve(process.platform) :
+ Q.reject('Cordova tooling for iOS requires Apple OS X');
+};
+
module.exports.help = function () {
console.log('Usage: check_reqs or node check_reqs');
};
@@ -71,24 +74,87 @@ module.exports.help = function () {
* Checks if specific tool is available.
* @param {String} tool Tool name to check. Known tools are 'xcodebuild', 'ios-sim' and 'ios-deploy'
* @param {Number} minVersion Min allowed tool version.
- * @param {String} optMessage Message that will be used to reject promise.
+ * @param {String} message Message that will be used to reject promise.
* @return {Promise} Returns a promise either resolved with tool version or rejected
*/
-function checkTool (tool, minVersion, optMessage) {
- if (os.platform() !== 'darwin'){
- // Build iOS apps available for OSX platform only, so we reject on others platforms
- return Q.reject('Cordova tooling for iOS requires Apple OS X');
- }
+function checkTool (tool, minVersion, message) {
// Check whether tool command is available at all
var tool_command = shell.which(tool);
if (!tool_command) {
- return Q.reject(optMessage || (tool + 'command is unavailable.'));
+ return Q.reject(tool + ' was not found. ' + (message || ''));
}
// check if tool version is greater than specified one
return versions.get_tool_version(tool).then(function (version) {
+ version = version.trim();
return versions.compareVersions(version, minVersion) >= 0 ?
Q.resolve(version) :
Q.reject('Cordova needs ' + tool + ' version ' + minVersion +
- ' or greater, you have version ' + version + '.');
+ ' or greater, you have version ' + version + '. ' + (message || ''));
});
}
+
+/**
+ * Object that represents one of requirements for current platform.
+ * @param {String} id The unique identifier for this requirements.
+ * @param {String} name The name of requirements. Human-readable field.
+ * @param {Boolean} isFatal Marks the requirement as fatal. If such requirement will fail
+ * next requirements' checks will be skipped.
+ */
+var Requirement = function (id, name, isFatal) {
+ this.id = id;
+ this.name = name;
+ this.installed = false;
+ this.metadata = {};
+ this.isFatal = isFatal || false;
+};
+
+/**
+ * Methods that runs all checks one by one and returns a result of checks
+ * as an array of Requirement objects. This method intended to be used by cordova-lib check_reqs method
+ *
+ * @return Promise<Requirement[]> Array of requirements. Due to implementation, promise is always fulfilled.
+ */
+module.exports.check_all = function() {
+
+ var requirements = [
+ new Requirement('os', 'Apple OS X', true),
+ new Requirement('xcode', 'Xcode'),
+ new Requirement('ios-deploy', 'ios-deploy'),
+ new Requirement('ios-sim', 'ios-sim')
+ ];
+
+ var result = [];
+ var fatalIsHit = false;
+
+ var checkFns = [
+ module.exports.check_os,
+ module.exports.check_xcodebuild,
+ module.exports.check_ios_deploy,
+ module.exports.check_ios_sim
+ ];
+
+ // Then execute requirement checks one-by-one
+ return checkFns.reduce(function (promise, checkFn, idx) {
+ return promise.then(function () {
+ // If fatal requirement is failed,
+ // we don't need to check others
+ if (fatalIsHit) return Q();
+
+ var requirement = requirements[idx];
+ return checkFn()
+ .then(function (version) {
+ requirement.installed = true;
+ requirement.metadata.version = version;
+ result.push(requirement);
+ }, function (err) {
+ if (requirement.isFatal) fatalIsHit = true;
+ requirement.metadata.reason = err;
+ result.push(requirement);
+ });
+ });
+ }, Q())
+ .then(function () {
+ // When chain is completed, return requirements array to upstream API
+ return result;
+ });
+};
diff --git a/StoneIsland/platforms/ios/cordova/lib/copy-www-build-step.js b/StoneIsland/platforms/ios/cordova/lib/copy-www-build-step.js
new file mode 100755
index 00000000..7a81b93e
--- /dev/null
+++ b/StoneIsland/platforms/ios/cordova/lib/copy-www-build-step.js
@@ -0,0 +1,69 @@
+#!/usr/bin/env node
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+// This script copies the www directory into the Xcode project.
+
+// This script should not be called directly.
+// It is called as a build step from Xcode.
+
+var BUILT_PRODUCTS_DIR = process.env.BUILT_PRODUCTS_DIR,
+ FULL_PRODUCT_NAME = process.env.FULL_PRODUCT_NAME,
+ COPY_HIDDEN = process.env.COPY_HIDDEN,
+ PROJECT_FILE_PATH = process.env.PROJECT_FILE_PATH;
+
+var path = require('path'),
+ fs = require('fs'),
+ shell = require('shelljs'),
+ glob = require('glob'),
+ srcDir = 'www',
+ dstDir = path.join(BUILT_PRODUCTS_DIR, FULL_PRODUCT_NAME),
+ dstWwwDir = path.join(dstDir, 'www');
+
+if(!BUILT_PRODUCTS_DIR) {
+ console.error('The script is meant to be run as an Xcode build step and relies on env variables set by Xcode.');
+ process.exit(1);
+}
+
+try {
+ fs.statSync(srcDir);
+} catch (e) {
+ console.error('Path does not exist: ' + srcDir);
+ process.exit(1);
+}
+
+// Code signing files must be removed or else there are
+// resource signing errors.
+shell.rm('-rf', dstWwwDir);
+shell.rm('-rf', path.join(dstDir, '_CodeSignature'));
+shell.rm('-rf', path.join(dstDir, 'PkgInfo'));
+shell.rm('-rf', path.join(dstDir, 'embedded.mobileprovision'));
+
+// Copy www dir recursively
+if(!!COPY_HIDDEN) {
+ shell.mkdir('-p', dstWwwDir);
+ shell.cp('-r', glob.sync(srcDir + '/**', { dot: true }), dstWwwDir);
+} else {
+ shell.cp('-r', srcDir, dstDir);
+}
+
+// Copy the config.xml file.
+shell.cp('-f', path.join(path.dirname(PROJECT_FILE_PATH), path.basename(PROJECT_FILE_PATH, '.xcodeproj'), 'config.xml'),
+ dstDir);
diff --git a/StoneIsland/platforms/ios/cordova/lib/copy-www-build-step.sh b/StoneIsland/platforms/ios/cordova/lib/copy-www-build-step.sh
deleted file mode 100755
index 7b934d5f..00000000
--- a/StoneIsland/platforms/ios/cordova/lib/copy-www-build-step.sh
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/bin/sh
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-#
-# This script copies the www directory into the Xcode project.
-#
-# This script should not be called directly.
-# It is called as a build step from Xcode.
-
-SRC_DIR="www/"
-DST_DIR="$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/www"
-COPY_HIDDEN=
-ORIG_IFS=$IFS
-IFS=$(echo -en "\n\b")
-
-if [[ -z "$BUILT_PRODUCTS_DIR" ]]; then
- echo "The script is meant to be run as an Xcode build step and relies on env variables set by Xcode."
- exit 1
-fi
-if [[ ! -e "$SRC_DIR" ]]; then
- echo "Path does not exist: $SRC_DIR"
- exit 1
-fi
-
-# Use full path to find to avoid conflict with macports find (CB-6383).
-if [[ -n $COPY_HIDDEN ]]; then
- alias do_find='/usr/bin/find "$SRC_DIR"'
-else
- alias do_find='/usr/bin/find -L "$SRC_DIR" -name ".*" -prune -o'
-fi
-
-time (
-# Code signing files must be removed or else there are
-# resource signing errors.
-rm -rf "$DST_DIR" \
- "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/_CodeSignature" \
- "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/PkgInfo" \
- "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/embedded.mobileprovision"
-
-# Directories
-for p in $(do_find -type d -print); do
- subpath="${p#$SRC_DIR}"
- mkdir "$DST_DIR$subpath" || exit 1
-done
-
-# Symlinks
-for p in $(do_find -type l -print); do
- subpath="${p#$SRC_DIR}"
- source=$(readlink $SRC_DIR$subpath)
- sourcetype=$(stat -f "%HT%SY" $source)
- if [ "$sourcetype" = "Directory" ]; then
- mkdir "$DST_DIR$subpath" || exit 2
- else
- rsync -a "$source" "$DST_DIR$subpath" || exit 3
- fi
-done
-
-# Files
-for p in $(do_find -type f -print); do
- subpath="${p#$SRC_DIR}"
- if ! ln "$SRC_DIR$subpath" "$DST_DIR$subpath" 2>/dev/null; then
- rsync -a "$SRC_DIR$subpath" "$DST_DIR$subpath" || exit 4
- fi
-done
-
-# Copy the config.xml file.
-cp -f "${PROJECT_FILE_PATH%.xcodeproj}/config.xml" "$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME"
-
-)
-IFS=$ORIG_IFS
-
diff --git a/StoneIsland/platforms/ios/cordova/lib/list-devices b/StoneIsland/platforms/ios/cordova/lib/list-devices
index a12abd74..3fa3e6da 100755
--- a/StoneIsland/platforms/ios/cordova/lib/list-devices
+++ b/StoneIsland/platforms/ios/cordova/lib/list-devices
@@ -21,7 +21,7 @@
/*jshint node: true*/
-var Q = require('Q'),
+var Q = require('q'),
exec = require('child_process').exec;
/**
@@ -36,14 +36,20 @@ function listDevices() {
];
// wrap al lexec calls into promises and wait until they're fullfilled
- return Q.all(commands).then(function (promises) {
+ return Q.all(commands).then(function (results) {
var accumulator = [];
- promises.forEach(function (promise) {
- if (promise.state === 'fulfilled') {
- // Each command promise resolves with array [stout, stderr], and we need stdout only
- // Append stdout lines to accumulator
- accumulator.concat(promise.value[0].trim().split('\n'));
- }
+ results.forEach(function (result) {
+ var devicefound;
+ // Each command promise resolves with array [stout, stderr], and we need stdout only
+ // Append stdout lines to accumulator
+ devicefound = result[0].trim().split('\n');
+ if(devicefound && devicefound.length) {
+ devicefound.forEach(function(device) {
+ if (device) {
+ accumulator.push(device);
+ }
+ });
+ }
});
return accumulator;
});
@@ -59,4 +65,4 @@ if (!module.parent) {
console.log(device);
});
});
-}
+} \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/cordova/lib/list-emulator-images b/StoneIsland/platforms/ios/cordova/lib/list-emulator-images
index 0c7f0c55..07dd1a48 100755
--- a/StoneIsland/platforms/ios/cordova/lib/list-emulator-images
+++ b/StoneIsland/platforms/ios/cordova/lib/list-emulator-images
@@ -32,8 +32,7 @@ var Q = require('q'),
function listEmulatorImages () {
return check_reqs.check_ios_sim().then(function () {
return Q.nfcall(exec, 'ios-sim showdevicetypes 2>&1 | ' +
- 'sed "s/com.apple.CoreSimulator.SimDeviceType.//g" | ' +
- 'awk -F\',\' \'{print $1}\'');
+ 'sed "s/com.apple.CoreSimulator.SimDeviceType.//g"');
}).then(function (stdio) {
// Exec promise resolves with array [stout, stderr], and we need stdout only
return stdio[0].trim().split('\n');
diff --git a/StoneIsland/platforms/ios/cordova/lib/run.js b/StoneIsland/platforms/ios/cordova/lib/run.js
index 151cad2a..fcd39015 100755
--- a/StoneIsland/platforms/ios/cordova/lib/run.js
+++ b/StoneIsland/platforms/ios/cordova/lib/run.js
@@ -50,7 +50,7 @@ module.exports.run = function (argv) {
// Valid values for "--target" (case sensitive):
var validTargets = ['iPhone-4s', 'iPhone-5', 'iPhone-5s', 'iPhone-6-Plus', 'iPhone-6',
'iPad-2', 'iPad-Retina', 'iPad-Air', 'Resizable-iPhone', 'Resizable-iPad'];
- if (args.target && validTargets.indexOf(args.target) < 0 ) {
+ if (!(args.device) && args.target && validTargets.indexOf(args.target.split(',')[0]) < 0 ) {
return Q.reject(args.target + ' is not a valid target for emulator');
}
@@ -174,4 +174,4 @@ module.exports.help = function () {
console.log(' run --emulator --debug');
console.log('');
process.exit(0);
-}; \ No newline at end of file
+};