UNPKG

@appshuttle.io/turing

Version:
81 lines (59 loc) 2.48 kB
const fs = require('fs') const crypto = require('crypto') const MainActivityTemplates = require('../TemplateContent/MainActivity-Template') class MainActivityMotor { 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.mainActContent = '' this.templates = new MainActivityTemplates() this.generateMainActivity = function () { this.generateGradleStructure() const context = this return new Promise((resolve, reject) => { try { fs.writeFileSync(context.path, context.mainActContent) resolve() } catch (error) { reject(error) } }) } /* GENERATION METHODS */ this.generateGradleStructure = function () { this.mainActContent = this.templates.getMainActivityStructure() this.mainActContent = this.mainActContent.replace(new RegExp(this.templates.PACKAGE_HOLDER , 'g'), this.getPackage()) this.mainActContent = this.mainActContent.replace(this.templates.APP_NAME_MIN_HOLDER, this.getProjectName()) this.mainActContent = this.mainActContent.replace(this.templates.IMPORTS_HOLDER, this.getImports()) this.mainActContent = this.mainActContent.replace(this.templates.FIELDS_HOLDER, this.getFields()) this.mainActContent = this.mainActContent.replace(this.templates.FIELDS_INIT_HOLDER, this.getFieldsInit()) } /* CONTENT PRODUCERS */ this.getPackage = function () { return 'com.appshuttle.'+this.getProjectName() } this.getProjectName = function () { return this.project.name.trim().toLowerCase() } this.getImports = function () { return '' } this.getFields = function () { return '' } this.getFieldsInit = function () { return '' } } } module.exports = MainActivityMotor