UNPKG

@appshuttle.io/turing

Version:
95 lines (76 loc) 4.26 kB
const fs = require('fs') const path = require('path'); const TRStringManagement = require('../../Mixins/StringManagement/StringManagement') const BuildGradleMotor = require('./GenerationMotors/BuildGradle-Motor') const BuildGradleAppMotor = require('./GenerationMotors/BuildGradleApp-Motor') const GradleWrapperMotor = require('./GenerationMotors/GradleWrapper-Motor') const MainActivityMotor = require('./GenerationMotors/MainActivity-Motor') const MainActivityViewMotor = require('./GenerationMotors/MainActivityView-Motor') const LocalPropertiesMotor = require('./GenerationMotors/LocalProperties-Motor') const AppManifestMotor = require('./GenerationMotors/AppManifest-Motor') class AndroidMainProjectGenerator { 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.buildGradleMotor = new BuildGradleMotor(path + '/build.gradle', project, screenPointers, screens) this.buildGradleAppMotor = new BuildGradleAppMotor(path + '/app/build.gradle', project, screenPointers, screens) this.gradleWrapperMotor = new GradleWrapperMotor(path + '/gradle/wrapper/gradle-wrapper.properties', project, screenPointers, screens) this.localPropertiesMotor = new LocalPropertiesMotor(path + '/local.properties', project, screenPointers, screens) if (!fs.existsSync(path + '/app/src/main/java/com/appshuttle/' + this.StringManagement.alfanumericString(project.appInformation.appName).toLowerCase() +'/')) { mkdirpath(path + '/app/src/main/java/com/appshuttle/' + this.StringManagement.alfanumericString(project.appInformation.appName).toLowerCase() +'/'); } this.mainActivityMotor = new MainActivityMotor(path + '/app/src/main/java/com/appshuttle/'+project.appInformation.appName+'/MainActivity.java', project, screenPointers, screens) this.mainActivityViewMotor = new MainActivityViewMotor(path + '/app/src/main/res/layout/main.xml', project, screenPointers, screens) this.appManifestMotor = new AppManifestMotor(path + '/app/src/main/AndroidManifest.xml', project, screenPointers, screens) this.generateMainProject = function () { try { if (!fs.existsSync(this.path)) { fs.mkdirSync(this.path); } } catch (err) { return } var generatePromises = [] generatePromises.push(this.buildGradleMotor.generateBuildGradle()) generatePromises.push(this.buildGradleAppMotor.generateBuildGradleApp()) generatePromises.push(this.gradleWrapperMotor.generateGradleWrapper()) generatePromises.push(this.localPropertiesMotor.generateLocalProperties()) generatePromises.push(this.mainActivityMotor.generateMainActivity()) generatePromises.push(this.mainActivityViewMotor.generateMainActivityView()) generatePromises.push(this.appManifestMotor.generateAppManifest()) //TODO Build the rest of the views const context = this return new Promise((resolve, reject) => { Promise.all(generatePromises).then(function (values) { try { resolve() } catch (error) { reject(error) } resolve() }).catch(function (error) { reject(error) }) }) } } } mkdirpath = function (dirPath) { if (!fs.existsSync(dirPath)) { try { fs.mkdirSync(dirPath); } catch (e) { mkdirpath(path.dirname(dirPath)); mkdirpath(dirPath); } } } module.exports = AndroidMainProjectGenerator