Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #121 from UnleashedMind/master
Browse files Browse the repository at this point in the history
appsync apiId check before pull
  • Loading branch information
UnleashedMind authored May 4, 2018
2 parents d8ecce1 + 1f35727 commit 944c506
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ describe('appsync update', () => {
}

beforeAll(() => {
// global.console = {log: jest.fn()}
global.console = {log: jest.fn()}
fs.__setMockFiles(MOCK_FILE_INFO)

appsyncManager.getAppSyncInfo = jest.fn((projectPath)=>{return appsyncInfo})
Expand Down
25 changes: 20 additions & 5 deletions __tests__/lib/utils/dependency-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,34 @@ describe('project info manager functions', () => {
fs.writeFileSync.mockClear()
})

test('npmInstall', () => {
test('installDependencies', () => {
fs.__setMockFiles(MOCK_FILE_INFO)
let mock_callback = jest.fn()
dependencyManager.npmInstall(projectPath, mock_callback)
let projectInfo = {
ProjectPath: projectPath
}
dependencyManager.installDependencies(projectInfo, mock_callback)
expect(mock_callback).toBeCalled()
})

test('installDependencies react', () => {
fs.__setMockFiles(MOCK_FILE_INFO)
let mock_callback = jest.fn()
let projectInfo = {
ProjectPath: projectPath,
Framework: 'react'
}
dependencyManager.installDependencies(projectInfo, mock_callback)
expect(mock_callback).toBeCalled()
})

test('npmInstall no packagejson', () => {
test('installDependencies no packagejson', () => {
fs.__setMockFiles({})
let mock_callback = jest.fn()
dependencyManager.npmInstall(projectPath, mock_callback)

let projectInfo = {
ProjectPath: projectPath
}
dependencyManager.installDependencies(projectInfo, mock_callback)
expect(mock_callback).toBeCalled()
})

Expand Down
3 changes: 3 additions & 0 deletions __tests__/lib/utils/press-enter-to-continue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
const pressKeyToContinue = require('../../../lib/utils/press-enter-to-continue.js')

describe('press-enter-to-continue', () => {
beforeAll(() => {
global.console = {log: jest.fn()}
})
test('run', () => {
let mockData = 'mock-data'
let handle = {message: 'mock-message'}
Expand Down
11 changes: 9 additions & 2 deletions lib/backend-operations/ops-appsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,18 @@ function preBackendUpdate(projectInfo, awsDetails, backendProjectDetails, callba

//////////////////// sync backend project ////////////////////
function syncCurrentBackendInfo(projectInfo, backendDetails, awsDetails, callback){
return appsyncRetrieve.run(projectInfo, awsDetails).then(()=>{
let appsyncInfo = appsyncManager.getAppSyncInfo(projectInfo.ProjectPath)
if(appsyncInfo && appsyncInfo.apiId){
return appsyncRetrieve.run(projectInfo, awsDetails).then(()=>{
if(callback){
callback()
}
})
}else{
if(callback){
callback()
}
})
}
}

function syncToDevBackend(projectInfo, backendProject, enabledFeatures, isConfirmed){
Expand Down
4 changes: 3 additions & 1 deletion lib/command-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const awsmobileBaseManager = require('./awsm-base-manager.js')
const starterManager = require('./awsm-starter-manager.js')
const backendCreate = require('./backend-create.js')
const starterRepoMapping = require('./utils/starter-repo-mapping.js')
const starterFrameworkMapping = require('./utils/starter-framework-mapping.js')
const nameManager = require('./utils/awsmobilejs-name-manager.js')
const pathManager = require('./utils/awsmobilejs-path-manager.js')
const dependencyManager = require('./utils/dependency-manager')
Expand Down Expand Up @@ -74,14 +75,15 @@ function setupStarterProject(projectPath, contentZipFilePath, callback){
function initialize(projectPath, callback)
{
let projectInfo = projectInfoManager.initialize(projectPath, starterManager.getProjectConfig(_starterName))
projectInfo.Framework = starterFrameworkMapping[_starterName]
if(callback){
callback(projectInfo)
}
}

function setupBackend(projectInfo, contentZipFilePath, callback){
backendCreate.createBackendProject(projectInfo, {contentZipFilePath: contentZipFilePath, yesFlag: _yesFlag, syncToDevFlag: 2}, function(){
dependencyManager.npmInstall(projectInfo.ProjectPath, function(){
dependencyManager.installDependencies(projectInfo, function(){
gitManager.insertAwsmobilejs(projectInfo.ProjectPath)
printWelcomeMessage(projectInfo)
if(callback){
Expand Down
19 changes: 13 additions & 6 deletions lib/utils/dependency-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ const dfOps = require('./directory-file-ops.js')
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm"
const yarn = /^win/.test(process.platform) ? "yarn.cmd" : "yarn"

function npmInstall(projectPath, callback){
let packageJsonFilePath = path.normalize(path.join(projectPath, 'package.json'))
function installDependencies(projectInfo, callback){
let packageJsonFilePath = path.normalize(path.join(projectInfo.ProjectPath, 'package.json'))
if(fs.existsSync(packageJsonFilePath)){
console.log()
console.log('Executing ' + npm + ' install...')
let childProcess = spawn(npm, ['install'], {cwd: projectPath, env: process.env, stdio: 'inherit'})
let command = npm
if(projectInfo.Framework=='react' || projectInfo.Framework == 'react-native'){
if(isYarnInstalled()){
command = yarn
}
}
console.log('Executing ' + command + ' install...')
let childProcess = spawn(command, ['install'], {cwd: projectInfo.ProjectPath, env: process.env, stdio: 'inherit'})

childProcess.on('exit', function(code) {
let codeString = code.toString()
if(code != 0){
codeString = chalk.red(code.toString())
}
console.log(npm + ' install returned ' + codeString)
console.log(command + ' install returned ' + codeString)
console.log()
if(callback){
callback()
Expand Down Expand Up @@ -157,7 +164,7 @@ function spawnChildProcess(command, args, cwd){
}

module.exports = {
npmInstall,
installDependencies,
setupAmplifyDependency,
isYarnInstalled
}
20 changes: 20 additions & 0 deletions lib/utils/starter-framework-mapping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
"use strict";
module.exports = {
'react': "react",
'react-native': "react-native",
// 'angular': "angular"
// 'ionic': "ionic",
// 'vue': "vue"
}

0 comments on commit 944c506

Please sign in to comment.