@appshuttle.io/turing
Version:
Code Generation Library used in Shuttle
58 lines (43 loc) • 1.88 kB
JavaScript
const fs = require('fs')
const TRStringManagement = require('../../../Mixins/StringManagement/StringManagement')
const ViewControllerMotor = require('./GenerationMotors/ViewController-Motor')
class iOSViewControllerGenerator {
constructor(path, project, screenPointers, screens) {
if (!path) throw new Error('No pbxproj 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 = path
this.project = project
this.screenPointers = screenPointers
this.screens = screens
this.StringManagement = new TRStringManagement()
this.generateViewControllers = function () {
try {
if (!fs.existsSync(this.path)){
fs.mkdirSync(this.path);
}
} catch (err) {
return
}
var generatePromises = []
for (const screen of this.screens) {
const viewControllerMotor = new ViewControllerMotor(this.path + '/' + this.StringManagement.alfanumericString(screen.name) + 'ViewController.swift', this.project, screen)
generatePromises.push(viewControllerMotor.generateViewController())
}
const context = this
return new Promise((resolve, reject) => {
Promise.all(generatePromises).then(function (values) {
try {
resolve()
} catch (error) {
reject(error)
}
}).catch(function (error) {
reject(error)
})
})
}
}
}
module.exports = iOSViewControllerGenerator