diff options
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib/build.js')
| -rwxr-xr-x | StoneIsland/platforms/ios/cordova/lib/build.js | 79 |
1 files changed, 71 insertions, 8 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(''); |
