@appshuttle.io/turing
Version:
Code Generation Library used in Shuttle
97 lines (80 loc) • 3.82 kB
JavaScript
var shell = require('shelljs')
var nodePath = process.execPath ? process.execPath
: (which('node') || which('nodejs'))
shell.config.execPath = nodePath.stdout
const TRStringManagement = require('../../Mixins/StringManagement/StringManagement')
class iOSAppBuilder {
constructor(projectPath, project, screenPointers, screens) {
if (!projectPath) throw new Error('No shuttle project path is specified')
if (!project) throw new Error('No project is specified')
if (!screenPointers) throw new Error('No screen pointers were specified')
if (!screens) throw new Error('No screens were specified')
this.path = projectPath
this.project = project
this.screenPointers = screenPointers
this.screens = screens
this.StringManagement = new TRStringManagement()
this.IOS_SDKS_COMMAND = 'xcodebuild --showsdks'
this.buildiOSApp = function () {
const thisRef = this
this.checkiOSBuildEnvironment()
return new Promise((resolve, reject) => {
Promise.all([this.checkiOSBuildEnvironment(), this.generateAppSimulator()]).then(function (values) {
resolve(values[1])
}).catch(function (error) {
reject(error)
})
})
}
this.checkiOSBuildEnvironment = function () {
return new Promise((resolve, reject) => {
if (!shell.which('xcode-select')) {
shell.echo('Sorry, this script requires xcode-select select to install Xcode Dependencies')
shell.exit(1)
reject({
code: -1,
message: 'Sorry, this script requires xcode-select to install Xcode Dependencies'
})
return
}
// Install XcodeBuild if necessary
if (!shell.which('xcodebuild')) {
shell.echo('Sorry, this script requires xcodebuild to build iOS projects.')
shell.exit(1)
reject({
code: -1,
message: 'Sorry, this script requires xcodebuild to build iOS projects.'
})
return
}
// Check Available SDKs
// var sdksExec = shell.exec(this.IOS_SDKS_COMMAND, {silent:true})
// if (sdksExec.stderr) {
// error('Error getting iOS SDKs. Error: ' + sdksExec.stderr)
// return
// } else {
// console.log(sdksExec.stdout)
// }
resolve({
code: 200,
message: 'All iOS Build Environment OK'
})
})
}
this.generateAppSimulator = function () {
return new Promise((resolve, reject) => {
shell.exec('xcodebuild -scheme '+ this.StringManagement.alfanumericString(this.project.appInformation.appName) +' -project '+ this.path + '/' + this.StringManagement.alfanumericString(this.project.appInformation.appName) +'.xcodeproj/ -sdk iphonesimulator12.0 build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO', function(code, stdout, stderr) {
if (code === 0) {
resolve(stdout.split('Touch ')[1].split(' ')[0])
} else {
reject({
code: -1,
message: 'Error executing command to build app with error message: ' + stderr
})
}
})
})
}
}
}
module.exports = iOSAppBuilder