-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support modelgen without an amplify backend
- Loading branch information
1 parent
9337382
commit 3fdfdff
Showing
4 changed files
with
137 additions
and
50 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
35 changes: 35 additions & 0 deletions
35
packages/amplify-codegen/src/utils/getModelSchemaPathParam.js
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const path = require('path'); | ||
|
||
const modelSchemaParamKey = 'model-schema'; | ||
/** | ||
* Retrieve the specified model schema path parameter, returning as an absolute path. | ||
* @param {!import('@aws-amplify/amplify-cli-core').$TSContext} context the CLI invocation context | ||
* @returns {string | null} the absolute path to the model schema path | ||
*/ | ||
const getModelSchemaPathParam = (context) => { | ||
const modelSchemaPathParam = context.parameters?.options?.[modelSchemaParamKey]; | ||
if ( !modelSchemaPathParam ) { | ||
return null; | ||
} | ||
let projectRoot; | ||
try { | ||
context.amplify.getProjectMeta(); | ||
projectRoot = context.amplify.getEnvInfo().projectPath; | ||
} catch (e) { | ||
projectRoot = process.cwd(); | ||
} | ||
return path.isAbsolute(modelSchemaPathParam) ? modelSchemaPathParam : path.join(projectRoot, modelSchemaPathParam); | ||
}; | ||
|
||
/** | ||
* Retrieve whether or not a model schema path param was specified during invocation. | ||
* @param {!import('@aws-amplify/amplify-cli-core').$TSContext} context the CLI invocation context | ||
* @returns {!boolean} whether or not a model schema path param is specified via the CLI | ||
*/ | ||
const hasModelSchemaPathParam = (context) => context?.parameters?.options | ||
&& Object.keys(context.parameters.options).find((optionKey) => optionKey === modelSchemaParamKey) !== undefined; | ||
|
||
module.exports = { | ||
getModelSchemaPathParam, | ||
hasModelSchemaPathParam, | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Find the project root. | ||
* @param {!import('@aws-amplify/amplify-cli-core').$TSContext} context the amplify runtime context | ||
* @returns {!string} the project root, or cwd | ||
*/ | ||
const getProjectRoot = (context) => { | ||
try { | ||
return context.amplify.getEnvInfo().projectPath; | ||
} catch (_) { | ||
return process.cwd(); | ||
} | ||
}; | ||
|
||
module.exports = getProjectRoot; |