-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): ENG-5881 dynamic cli options #2773
Merged
NickBurkhartBB
merged 3 commits into
brandingbrand:feature/app-router
from
crherman7:feat/ENG-5881
Dec 19, 2024
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,4 +1,5 @@ | ||
{ | ||
"hiddenEnvs": [], | ||
"singleEnv": false, | ||
"dir": "./coderc/env" | ||
} |
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,49 +1,84 @@ | ||
/** | ||
* Defines a plugin for @brandingbrand/code-cli-kit. | ||
* @module Plugin | ||
*/ | ||
|
||
import { | ||
definePlugin, | ||
fs, | ||
path, | ||
withInfoPlist, | ||
withStrings, | ||
} from '@brandingbrand/code-cli-kit'; | ||
|
||
/** | ||
* Defines a plugin with functions for both iOS and Android platforms. | ||
* @alias module:Plugin | ||
* @param {Object} build - The build configuration object. | ||
* @param {Object} options - The options object. | ||
* Custom error for missing required options. | ||
*/ | ||
class MissingOptionError extends Error { | ||
constructor(optionName: string) { | ||
super(`MissingOptionError: missing ${optionName} variable`); | ||
this.name = 'MissingOptionError'; | ||
} | ||
} | ||
|
||
/** | ||
* Type definition for the plugin options. | ||
*/ | ||
interface PluginOptions { | ||
appEnvInitial: string; | ||
appEnvDir: string; | ||
appEnvHide?: string[]; | ||
release: boolean; | ||
} | ||
|
||
/** | ||
* Helper function to validate required options. | ||
*/ | ||
function validateOptions(options: PluginOptions) { | ||
if (!options.appEnvInitial) { | ||
throw new MissingOptionError('appEnvInitial'); | ||
} | ||
if (!options.appEnvDir) { | ||
throw new MissingOptionError('appEnvDir'); | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to write the environment configuration file. | ||
*/ | ||
async function writeEnvConfig(options: PluginOptions) { | ||
const configPath = path.join(process.cwd(), '.flagshipappenvrc'); | ||
const configData = { | ||
hiddenEnvs: options.appEnvHide || [], | ||
singleEnv: options.release, | ||
dir: options.appEnvDir, | ||
}; | ||
|
||
await fs.writeFile(configPath, JSON.stringify(configData, null, 2) + '\n'); | ||
} | ||
|
||
/** | ||
* Defines a plugin for both iOS and Android platforms. | ||
*/ | ||
export default definePlugin({ | ||
/** | ||
* Function to be executed for iOS platform. | ||
* @param {Object} _build - The build configuration object for iOS. | ||
* @param {Object} _options - The options object for iOS. | ||
* @returns {Promise<void>} A promise that resolves when the process completes. | ||
*/ | ||
ios: async function (_build: object, _options: object): Promise<void> { | ||
await withInfoPlist(plist => { | ||
return { | ||
...plist, | ||
FlagshipEnv: 'prod', | ||
FlagshipDevMenu: true, | ||
}; | ||
}); | ||
ios: async (_build: object, options: any): Promise<void> => { | ||
validateOptions(options); | ||
|
||
await withInfoPlist(plist => ({ | ||
...plist, | ||
FlagshipEnv: options.appEnvInitial, | ||
FlagshipDevMenu: options.release, | ||
})); | ||
|
||
await writeEnvConfig(options); | ||
}, | ||
|
||
/** | ||
* Function to be executed for Android platform. | ||
* @param {Object} _build - The build configuration object for Android. | ||
* @param {Object} _options - The options object for Android. | ||
* @returns {Promise<void>} A promise that resolves when the process completes. | ||
*/ | ||
android: async function (_build: object, _options: object): Promise<void> { | ||
return withStrings(xml => { | ||
xml.resources.string?.push({$: {name: 'flagship_env'}, _: 'prod'}); | ||
xml.resources.string?.push({$: {name: 'flagship_dev_menu'}, _: 'true'}); | ||
android: async (_build: object, options: any): Promise<void> => { | ||
validateOptions(options); | ||
|
||
await withStrings(xml => { | ||
xml.resources.string?.push( | ||
{$: {name: 'flagship_env'}, _: options.appEnvInitial}, | ||
{$: {name: 'flagship_dev_menu'}, _: `${options.release}`}, | ||
); | ||
return xml; | ||
}); | ||
|
||
await writeEnvConfig(options); | ||
}, | ||
}); |
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,22 @@ | ||
{ | ||
"options": [ | ||
{ | ||
"flags": "--app-env-initial <value>", | ||
"description": "Specifies the initial environment to be used when the application starts (e.g., 'development', 'staging', or 'production').", | ||
"required": true, | ||
"example": "--app-env-initial development" | ||
}, | ||
{ | ||
"flags": "--app-env-dir <value>", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We technically could aggregate this with babel traversal and looking at imports etc. |
||
"description": "Defines the directory path where environment configuration files are stored (relative or absolute path).", | ||
"required": true, | ||
"example": "--app-env-dir ./config/environments" | ||
NickBurkhartBB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
"flags": "--app-env-hide <value>", | ||
"description": "Specifies one or more environments to hide from selection or visibility (comma-separated list).", | ||
"required": false, | ||
"example": "--app-env-hide staging,test" | ||
} | ||
] | ||
} |
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,5 @@ | ||
{ | ||
"dependencies": { | ||
"@brandingbrand/fsapp": "11.0.0" | ||
} | ||
} |
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
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
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,5 @@ | ||
{ | ||
"dependencies": { | ||
"@brandingbrand/fsapp": "11.0.0" | ||
} | ||
} |
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,74 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Flagship Code Commands Configuration", | ||
"description": "Schema for defining custom commander options in flagship-code.commands.json", | ||
"type": "object", | ||
"properties": { | ||
"options": { | ||
"type": "array", | ||
"description": "An array of custom options to be dynamically added to commander commands", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"flags": { | ||
"type": "string", | ||
"description": "The flag syntax for the option, following commander conventions (e.g., '--flag <value>').", | ||
"pattern": "^--[a-zA-Z0-9\\-_]+(\\s<[a-zA-Z0-9\\-_]+>|\\s\\[[a-zA-Z0-9\\-_]+\\])?$", | ||
"examples": [ | ||
"--custom-flag <value>", | ||
"--enable-feature", | ||
"--mode [type]" | ||
], | ||
"minLength": 2 | ||
}, | ||
"description": { | ||
"type": "string", | ||
"description": "A brief description of the option, including the expected value format or type.", | ||
"minLength": 1, | ||
"examples": [ | ||
"Specifies the initial environment to use, e.g., 'development', 'staging', or 'production'.", | ||
"Defines the path to the environments directory.", | ||
"A comma-separated list of environments to hide." | ||
] | ||
}, | ||
"example": { | ||
"type": "string", | ||
"description": "A concrete example showing how to use the option.", | ||
"examples": [ | ||
"--app-env-initial development", | ||
"--app-env-dir ./config/environments", | ||
"--app-env-hide staging,test" | ||
] | ||
}, | ||
"defaultValue": { | ||
"description": "The default value for the option if it is not specified by the user.", | ||
"anyOf": [ | ||
{"type": "string"}, | ||
{"type": "number"}, | ||
{"type": "boolean"}, | ||
{"type": "null"} | ||
] | ||
}, | ||
"choices": { | ||
"type": "array", | ||
"description": "Restrict the option's possible values to a predefined set.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"uniqueItems": true, | ||
"examples": [["debug", "release", "test"]] | ||
}, | ||
"required": { | ||
"type": "boolean", | ||
"description": "Indicates whether the option is mandatory.", | ||
"default": false | ||
} | ||
}, | ||
"required": ["flags", "description"], | ||
"additionalProperties": false | ||
} | ||
} | ||
}, | ||
"required": ["options"], | ||
"additionalProperties": false | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably also need to verify that these folders exist and the initial environment exists in the app environment directory. currently it seems like it works fine if I input invalid values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we could add additional validation of the directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed