-
Notifications
You must be signed in to change notification settings - Fork 141
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
Showing
25 changed files
with
705 additions
and
121 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,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>", | ||
"description": "Defines the directory path where environment configuration files are stored (relative or absolute path).", | ||
"required": true, | ||
"example": "--app-env-dir ./config/environments" | ||
}, | ||
{ | ||
"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.