Skip to content

Commit

Permalink
Merge pull request #2760 from crherman7/feat/ENG-5744
Browse files Browse the repository at this point in the history
feat(env): ENG-5744 app-env package
  • Loading branch information
NickBurkhartBB authored Dec 6, 2024
2 parents 64bf3c9 + 62e03ce commit bd46273
Show file tree
Hide file tree
Showing 49 changed files with 4,903 additions and 143 deletions.
4 changes: 4 additions & 0 deletions apps/example/.flagshipappenvrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"hiddenEnvs": [],
"dir": "./coderc/env"
}
113 changes: 0 additions & 113 deletions apps/example/App.tsx

This file was deleted.

1 change: 1 addition & 0 deletions apps/example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: ['@brandingbrand/code-app-env/plugin'],
};
30 changes: 30 additions & 0 deletions apps/example/coderc/plugins/plugin-env/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @jest-environment-options {"requireTemplate": true}
*/

/// <reference types="@brandingbrand/code-jest-config" />

import {fs, path} from '@brandingbrand/code-cli-kit';
import plugin from '../src';

describe('plugin', () => {
it('ios', async () => {
await plugin.ios?.({} as any, {} as any);

const infoPlist = await fs.readFile(path.ios.infoPlist, 'utf-8');

expect(infoPlist).toContain(`<key>FlagshipEnv</key>
<string>prod</string>
<key>FlagshipDevMenu</key>
<true/>`);
});

it('android', async () => {
await plugin.android?.({} as any, {} as any);

const strings = await fs.readFile(path.android.strings, 'utf-8');

expect(strings).toContain('<string name="flagship_env">prod</string>');
expect(strings).toContain('<string name="flagship_dev_menu">true</string>');
});
});
19 changes: 19 additions & 0 deletions apps/example/coderc/plugins/plugin-env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "plugin-env",
"version": "0.0.0",
"license": "UNLICENSED",
"private": true,
"main": "src/index.ts",
"scripts": {
"lint": "eslint . --max-warnings 0",
"test": "jest"
},
"jest": {
"preset": "@brandingbrand/code-jest-config"
},
"types": "src/index.ts",
"devDependencies": {
"eslint": "^8.0.0",
"jest": "^29.0.0"
}
}
49 changes: 49 additions & 0 deletions apps/example/coderc/plugins/plugin-env/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Defines a plugin for @brandingbrand/code-cli-kit.
* @module Plugin
*/

import {
definePlugin,
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.
*/
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,
};
});
},

/**
* 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'});

return xml;
});
},
});
Loading

0 comments on commit bd46273

Please sign in to comment.