UNPKG

@appshuttle.io/turing

Version:
85 lines (69 loc) 5.04 kB
var shell = require('shelljs') var nodePath = process.execPath ? process.execPath : (which('node') || which('nodejs')) shell.config.execPath = nodePath.stdout var fs = require('fs') const TRStringManagement = require('../Mixins/StringManagement/StringManagement') const TRFileManagement = require('../Mixins/FileManagement/FileManagement') const iOSMainProjectGenerator = require('./iOSGenerators/iOSMainProjectGenerator/iOSMainProjectGenerator') const iOSAppDelegateGenerator = require('./iOSGenerators/iOSAppDelegateGenerator/iOSAppDelegateGenerator') const iOSInfoPlistGenerator = require('./iOSGenerators/iOSInfoPlistGenerator/iOSInfoPlistGenerator') const iOSAssetsGenerator = require('./iOSGenerators/iOSAssetsGenerator/iOSAssetsGenerator') const iOSViewControllerGenerator = require('./iOSGenerators/iOSViewControllerGenerator/iOSViewControllerGenerator') const iOSStoryboardGenerator = require('./iOSGenerators/iOSStoryboardGenerator/iOSStoryboardGenerator') const iOSLaunchScreenGenerator = require('./iOSGenerators/iOSStoryboardGenerator/iOSLaunchScreenGenerator') const iOSAppBuilder = require('./iOSAppBuilders/iOSAppBuilder') class iOSBuilder { constructor (exportPath, project, screenPointers, screens) { if (!exportPath) throw new Error('No shuttle project export 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 = exportPath + '/iOS' this.project = project this.screenPointers = screenPointers this.screens = screens this.StringManagement = new TRStringManagement() this.FileManagement = new TRFileManagement() this.iOSMainProjectGenerator = new iOSMainProjectGenerator(this.path + '/'+ this.StringManagement.alfanumericString(this.project.appInformation.appName) +'_xcodeproj', this.project, this.screenPointers, this.screens) this.iOSAppDelegateGenerator = new iOSAppDelegateGenerator(this.path + '/' + this.StringManagement.alfanumericString(this.project.appInformation.appName), this.project, this.screenPointers, this.screens) this.iOSInfoPlistGenerator = new iOSInfoPlistGenerator(this.path + '/' + this.StringManagement.alfanumericString(this.project.appInformation.appName), this.project, this.screenPointers, this.screens) this.iOSAssetsGenerator = new iOSAssetsGenerator(this.path + '/' + this.StringManagement.alfanumericString(this.project.appInformation.appName) + '/Assets.xcassets', this.project, this.screenPointers, this.screens) this.iOSViewControllerGenerator = new iOSViewControllerGenerator(this.path + '/' + this.StringManagement.alfanumericString(this.project.appInformation.appName), this.project, this.screenPointers, this.screens) this.iOSStoryboardGenerator = new iOSStoryboardGenerator(this.path + '/' + this.StringManagement.alfanumericString(this.project.appInformation.appName), this.project, this.screenPointers, this.screens) this.iOSLaunchScreenGenerator = new iOSLaunchScreenGenerator(this.path + '/' + this.StringManagement.alfanumericString(this.project.appInformation.appName), this.project, this.screenPointers, this.screens) this.iOSAppBuilder = new iOSAppBuilder(this.path + '/', this.project, this.screenPointers, this.screens) this.generateiOSProject = function (success, errorBlock) { const thisRef = this this.FileManagement.methods.deleteDirIfExistsSync(this.path).then(function() { try { if (!fs.existsSync(thisRef.path)){ fs.mkdirSync(thisRef.path); } } catch (err) { errorBlock(err) return } var generationPromises = [] generationPromises.push(thisRef.iOSMainProjectGenerator.generateMainProject()) generationPromises.push(thisRef.iOSAppDelegateGenerator.generateAppDelegate()) generationPromises.push(thisRef.iOSInfoPlistGenerator.generateInfoPlist()) generationPromises.push(thisRef.iOSAssetsGenerator.generateAssets()) generationPromises.push(thisRef.iOSViewControllerGenerator.generateViewControllers()) generationPromises.push(thisRef.iOSStoryboardGenerator.generateMainStoryboard()) generationPromises.push(thisRef.iOSLaunchScreenGenerator.generateLaunchScreenStoryboard()) Promise.all(generationPromises).then(function (values) { success() }).catch(function (err) { errorBlock(err) }) }).catch(function (err) { errorBlock(err) }) } this.buildiOS = function () { return this.iOSAppBuilder.buildiOSApp() } } } module.exports = iOSBuilder