@appshuttle.io/turing
Version:
Code Generation Library used in Shuttle
51 lines (39 loc) • 2.29 kB
JavaScript
const fs = require('fs')
const TRDateManagement = require('../../../../Mixins/DateManagement/DateManagement')
const AppDelegateTemplates = require('../TemplateContent/AppDelegate-Templates')
class AppDelegateMotor {
constructor(path, project, screenPointers, screens) {
if (!path) throw new Error('No app delegate 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.appDelegateContent = ''
this.templates = new AppDelegateTemplates()
this.DateManagement = new TRDateManagement()
this.generateAppDelegate = function () {
this.generateAppDelegateStructure()
const context = this
return new Promise((resolve, reject) => {
try {
fs.writeFileSync(context.path, context.appDelegateContent)
resolve()
} catch (error) {
reject(error)
}
})
}
this.generateAppDelegateStructure = function () {
this.appDelegateContent = this.templates.getAppDelegateStructure()
this.appDelegateContent = this.appDelegateContent.replace(new RegExp(this.templates.APPNAME_HOLDER, 'g'), this.project.appInformation.appName)
this.appDelegateContent = this.appDelegateContent.replace(new RegExp(this.templates.CREATOR_NAME_HOLDER, 'g'), this.project.creatorInformation.name)
this.appDelegateContent = this.appDelegateContent.replace(new RegExp(this.templates.DATE_HOLDER, 'g'), this.DateManagement.formatDateToUSLocale(new Date()))
this.appDelegateContent = this.appDelegateContent.replace(new RegExp(this.templates.COPYRIGHT_YEAR_HOLDER, 'g'), this.DateManagement.getYearFromDate(new Date()))
this.appDelegateContent = this.appDelegateContent.replace(new RegExp(this.templates.ORGANIZATION_NAME_HOLDER, 'g'), this.project.creatorInformation.name)
}
}
}
module.exports = AppDelegateMotor