Skip to content

Commit

Permalink
Fix IDE integrations for Windows
Browse files Browse the repository at this point in the history
The verifyNode task only worked on macOS and Linux, and really isn't
necessary anyway. Kill it, and instead just try to run the command. If
it's missing, throw an error.

Also, throw an exception instead of printing the error. This has two
advantages: 1) the error is red and angry and obvious 2) the user can
try again via Android Studio without modifying the gradle.build file
  • Loading branch information
jpignata committed May 26, 2020
1 parent 59d876a commit 448b62b
Showing 1 changed file with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,34 @@ import groovy.json.JsonOutput

class AmplifyTools implements Plugin<Project> {
void apply(Project project) {
def doesNodeExist = true
def doesGradleConfigExist

// profile name can be changed in amplify-gradle-config
def profile = 'default'
def accessKeyId = null
def secretAccessKey = null
def region = null
def envName = 'amplify'
def syncEnabled = 'true'
def gradleConfigFileName = 'amplify-gradle-config.json'

project.task('createAmplifyApp') {
def npx = 'npx'

if (project.file(gradleConfigFileName).exists()) {
return
}

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
npx += '.cmd'
}

project.task('verifyNode') {
try {
project.exec {
commandLine 'npx', '-v'
standardOutput = new ByteArrayOutputStream()
commandLine npx, 'amplify-app', '--platform', 'android'
}
} catch (commandLineFailure) {
doesNodeExist = false
println("Node is not installed. Visit https://nodejs.org/en/download/ to install it")
}
}

project.task('createAmplifyApp') {
doesGradleConfigExist = project.file('amplify-gradle-config.json').isFile()
if (doesNodeExist && !doesGradleConfigExist) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
project.exec {
commandLine 'npx.cmd', 'amplify-app', '--platform', 'android'
}
} else {
project.exec {
commandLine 'npx', 'amplify-app', '--platform', 'android'
}
}
throw new Exception('Node.js is not installed. Visit https://nodejs.org/en/download/ to install it.')
}
}
project.createAmplifyApp.dependsOn('verifyNode')

project.task('getConfig') {
def inputConfigFile = project.file('amplify-gradle-config.json')
Expand Down

0 comments on commit 448b62b

Please sign in to comment.