-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Edward Foyle
committed
Sep 23, 2020
1 parent
c1c3ed5
commit a924a48
Showing
2 changed files
with
103 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,36 @@ | ||
import { AddApiRequest, UpdateApiRequest } from 'amplify-headless-interface'; | ||
import { AddApiRequest, AddAuthRequest, UpdateApiRequest, UpdateAuthRequest } from 'amplify-headless-interface'; | ||
import execa from 'execa'; | ||
import { getCLIPath } from '..'; | ||
|
||
export const addHeadlessApi = (cwd: string, request: AddApiRequest) => { | ||
return executeHeadlessCommand(cwd, 'api', 'add', request); | ||
export const addHeadlessApi = async (cwd: string, request: AddApiRequest) => { | ||
await executeHeadlessCommand(cwd, 'api', 'add', request); | ||
}; | ||
|
||
export const updateHeadlessApi = async (cwd: string, request: UpdateApiRequest) => { | ||
return executeHeadlessCommand(cwd, 'api', 'update', request); | ||
await executeHeadlessCommand(cwd, 'api', 'update', request); | ||
}; | ||
|
||
export const removeHeadlessApi = async (cwd: string, apiName: string) => { | ||
await execa(getCLIPath(), ['remove', 'api', apiName, '--yes'], { cwd }); | ||
await headlessRemoveResource(cwd, 'api', apiName); | ||
}; | ||
|
||
export const addHeadlessAuth = async (cwd: string, request: AddAuthRequest) => { | ||
await executeHeadlessCommand(cwd, 'auth', 'add', request); | ||
}; | ||
|
||
export const updateHeadlessAuth = async (cwd: string, request: UpdateAuthRequest) => { | ||
await executeHeadlessCommand(cwd, 'auth', 'update', request); | ||
}; | ||
|
||
export const removeHeadlessAuth = async (cwd: string, authName: string) => { | ||
await headlessRemoveResource(cwd, 'auth', authName); | ||
}; | ||
|
||
const headlessRemoveResource = async (cwd: string, category: string, resourceName: string) => { | ||
await execa(getCLIPath(), ['remove', category, resourceName, '--yes'], { cwd }); | ||
}; | ||
const executeHeadlessCommand = async (cwd: string, category: string, operation: string, request: AnyHeadlessRequest) => { | ||
await execa(getCLIPath(), [operation, category, '--headless'], { input: JSON.stringify(request), cwd }); | ||
}; | ||
|
||
type AnyHeadlessRequest = AddApiRequest | UpdateApiRequest; | ||
type AnyHeadlessRequest = AddApiRequest | UpdateApiRequest | AddAuthRequest | UpdateAuthRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters