UNPKG

@appshuttle.io/turing

Version:
61 lines (46 loc) 2.97 kB
const fs = require('fs') const TRDateManagement = require('../../../../Mixins/DateManagement/DateManagement') const TRStringManagement = require('../../../../Mixins/StringManagement/StringManagement') const ViewControllerTemplates = require('../TemplateContent/ViewController-Templates') const IBActionMotor = require('./IBActions/IBAction-Motor') class ViewControllerMotor { constructor(path, project, screen) { if (!path) throw new Error('No app delegate path is specified') if (!project) throw new Error('No project is specified') if (!screen) throw new Error('No screen specified') this.path = path this.project = project this.screen = screen this.viewControllerContent = '' this.templates = new ViewControllerTemplates() this.DateManagement = new TRDateManagement() this.StringManagement = new TRStringManagement() this.IBActionMotor = new IBActionMotor(path, project, screen) this.generateViewController = function () { this.generateViewControllerStructure() this.generateViewControllerIBActions() const context = this return new Promise((resolve, reject) => { try { fs.writeFileSync(context.path, context.viewControllerContent) resolve() } catch (error) { reject(error) } }) } this.generateViewControllerStructure = function () { this.viewControllerContent = this.templates.getViewControllerStructure() this.viewControllerContent = this.viewControllerContent.replace(new RegExp(this.templates.FILE_NAME_HOLDER, 'g'), this.StringManagement.alfanumericString(this.screen.name) + 'ViewController') this.viewControllerContent = this.viewControllerContent.replace(new RegExp(this.templates.APPNAME_HOLDER, 'g'), this.project.appInformation.appName) this.viewControllerContent = this.viewControllerContent.replace(new RegExp(this.templates.CREATOR_NAME_HOLDER, 'g'), this.project.creatorInformation.name) this.viewControllerContent = this.viewControllerContent.replace(new RegExp(this.templates.DATE_HOLDER, 'g'), this.DateManagement.formatDateToUSLocale(new Date())) this.viewControllerContent = this.viewControllerContent.replace(new RegExp(this.templates.COPYRIGHT_YEAR_HOLDER, 'g'), this.DateManagement.getYearFromDate(new Date())) this.viewControllerContent = this.viewControllerContent.replace(new RegExp(this.templates.ORGANIZATION_NAME_HOLDER, 'g'), this.project.creatorInformation.name) } this.generateViewControllerIBActions = function () { this.viewControllerContent = this.viewControllerContent.replace(new RegExp(this.templates.IB_ACTIONS_HOLDER, 'g'), this.IBActionMotor.generateIBAction()) } } } module.exports = ViewControllerMotor