UNPKG

@appshuttle.io/turing

Version:
81 lines (59 loc) 2.59 kB
const fs = require('fs') const crypto = require('crypto') const BuildGradleAppTemplates = require('../TemplateContent/BuildGradleApp-Template') class BuildGradleAppMotor { 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.gradleContent = '' this.templates = new BuildGradleAppTemplates() this.generateBuildGradleApp = function () { this.generateGradleStructure() const context = this return new Promise((resolve, reject) => { try { fs.writeFileSync(context.path, context.gradleContent) resolve() } catch (error) { reject(error) } }) } /* GENERATION METHODS */ this.generateGradleStructure = function () { this.gradleContent = this.templates.getBuildGradleAppStructure() this.gradleContent = this.gradleContent.replace(this.templates.MIN_SDK_HOLDER, this.getMinSdk()) this.gradleContent = this.gradleContent.replace(this.templates.NAME_HOLDER, this.getProjectName()) this.gradleContent = this.gradleContent.replace(this.templates.TARGET_SDK_HOLDER, this.getTargetSdk()) this.gradleContent = this.gradleContent.replace(this.templates.VERSION_CODE_HOLDER, this.getVersionCode()) this.gradleContent = this.gradleContent.replace(this.templates.VERSION_NAME_HOLDER, this.getVersionName()) } /* CONTENT PRODUCERS */ this.getMinSdk = function () { return this.templates.MIN_SDK_DEFAULT } this.getProjectName = function () { return this.project.name.trim().toLowerCase() } this.getTargetSdk = function () { return this.templates.TARGET_SDK_DEFAULT } this.getVersionCode = function () { return this.templates.VERSION_CODE_DEFAULT } this.getVersionName = function () { return this.templates.VERSION_NAME_DEFAULT } } } module.exports = BuildGradleAppMotor