
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@brandingbrand/code-plugin-env
Advanced tools
Code plugin that handles environment setup for supported app env providers
A plugin designed to manage multi-tenant environment configurations for Flagshipβ’ Code projects. This plugin automates the process of validating the required dependencies, and linking environment configuration files to your chosen environment provider.
@brandingbrand/code-app-env, or @brandingbrand/fsapp's project_env_index.js file based on project dependencies..ts environment configuration files.To install and use this plugin, you need to have the necessary dependencies installed. You can add this plugin to your project as follows:
yarn add -D @brandingbrand/code-plugin-env
Ensure your project has the necessary setup to run plugins from @brandingbrand/code-cli & @brandingbrand/code-cli-kit.
This plugin is executed as part of the @brandingbrand/code-cli-kit plugin system. Once configured, it will manage environment configuration linking automatically.
flagship-code.config.tsYou need to specify the envPath in your projectβs flagship-code.config.ts file, which points to the directory containing environment configuration files.
Additionally, if you are not using @brandingbrand/code-preset-react-native, you will need to specify @brandingbrand/code-plugin-env in the plugins array.
With @brandingbrand/code-preset-react-native:
export default {
preset: '@brandingbrand/code-preset-react-native',
envPath: 'path/to/your/env/configs', // Path to the environment configuration
// ... other configurations
}
Without @brandingbrand/code-preset-react-native:
export default {
envPath: 'path/to/your/env/configs', // Path to the environment configuration files
plugins: [
'@brandingbrand/code-plugin-env', // Include the environment plugin
// ... other plugins
],
};
build.<mode>.tsIf in certain build modes you wish to hide specific app environments, You may also specify a hiddenEnvs array in your build.<mode>.ts file.
When using:
@brandingbrand/fsapp - Hidden environments are filtered out, and will not be linked to the project_env_index.js file.@brandingbrand/code-app-env - The hidden environment array is copied to the .flagshipappenvrc file. When code-app-env loads the environment configurations via it's transformer, it will filter out the hidden environments according to this array.In all cases, hidden environments are ignored when --release mode is enabled during prebuild.
// build.uat.ts
import type { CodePluginEnvironment } from '@brandingbrand/code-plugin-env';
export default defineBuild<CodePluginEnvironment>({
// ... other build configurations ...
codePluginEnvironment: {
plugin: {
// For example, hiding your internal 'env.dev.ts' environment when building for QA teams
hiddenEnvs: ['dev'],
},
},
});
The plugin expects environment configuration files to follow the naming convention env.<mode>.ts. For example:
env.dev.tsenv.prod.tsenv.staging.tsThese files should export the environment-specific configuration.
Once the configuration is in place, execute the plugin as part of your build or CLI workflow. The plugin performs the following steps:
package.json:
@brandingbrand/fsapp or @brandingbrand/code-app-env.@brandingbrand/fsapp is found:
envPath directory that match the naming convention env.<mode>.ts.hiddenEnvs, matching environment modes are filtered out.--release mode, only the mode supplied to the --env arg will be linked, and all other modes will be ignored.project_env_index.js:
exports.default.exports.@brandingbrand/code-app-env is found:
envPath and confirms that the configured --env mode is valid..flagshipappenvrc file in the root of the project to link the environment configurations.android/app/src/main/res/values/strings.xml is modified to include:
flagship_env - The initial environment mode, specified by the --env argument.flagship_dev_menu - Indicates if the dev menu should be enabled, true unless --release is specified.ios/app/Info.plist is modified to include:
FlagshipEnv - The initial environment mode, specified by the --env argument.FlagshipDevMenu - Indicates if the dev menu should be enabled, true unless --release is specified.After configuring the environment file paths and dependencies, simply run the plugin with the desired options for your environment:
yarn flagship-code prebuild --build <build_mode> --env <env_mode>
Here is an overview of the file structure for this plugin:
plugin-env/
βββ src/
β βββ packages/
β β βββ <package>.ts
| | βββ index.ts
| βββ utils/
β β βββ code-config.ts
β β βββ package-plugin.ts
β β βββ validators.ts
β βββ index.ts
β βββ types.ts
βββ .eslintrc.js
βββ package.json
βββ tsconfig.json
βββ __tests__/
βββ index.ts
plugin-env/src/index.tsThis is the main entry point of the plugin, which contains the logic for enabling package-specific plugin functionality.
plugin-env/src/types.tsDefines the CodePluginEnvironment type to be extend the code project's build config with the plugin's specific properties, such as hiddenEnvs.
plugin-env/src/packages/<package>.tsEach <package>.ts file contains the logic for handling specific environment configurations. The plugin dynamically runs these files based on the project's installed packages
code-env.ts: Links environment configurations to @brandingbrand/code-app-env through its .flagshipappenvrc file, and configures the necessary native code properties for Android and iOS.fsapp-env.ts: Links environment configurations to @brandingbrand/fsapp through its project_env_index.js file.plugin-env/src/packages/index.tsProvides all package plugins as an array, which is filtered based on installed packages, and executed accordingly.
plugin-env/src/utils/Contains utility functions for the plugin:
code-config.ts: Contains functions to retrieve and validate the Flagshipβ’ Code configuration file.package-plugin.ts: Defines the special package-plugin structure for this plugin, and provides a purpose-built define function.validators.ts: Contains validation functions to ensure the environment paths and configurations exist as expected on the local filesystem.plugin-env/package.jsonContains the dependencies required for the plugin, such as bundle-require, magicast, and the development dependencies for eslint, jest, and typescript.
plugin-env/.eslintrc.jsDefines the ESLint configuration to maintain code quality across the pluginβs source files.
plugin-env/tsconfig.jsonProvides TypeScript configuration for compiling the pluginβs source code.
bundle-require: Used to dynamically load environment configuration files.magicast: Used for manipulating and writing the final project_env_index.js.@brandingbrand/code-cli-kit: Required for defining and running the plugin.To contribute to the development of this plugin, follow these steps:
Clone the repository.
Install the dependencies using yarn install.
Run linting and tests:
yarn lint
yarn test
Make your changes and submit a pull request.
FAQs
Code plugin that handles environment setup for supported app env providers
The npm package @brandingbrand/code-plugin-env receives a total of 261 weekly downloads. As such, @brandingbrand/code-plugin-env popularity was classified as not popular.
We found that @brandingbrand/code-plugin-env demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 18 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.