Skip to content

Commit

Permalink
Merge pull request #2784 from crherman7/feat/fsapp_plugin
Browse files Browse the repository at this point in the history
feat(fsapp): add fsapp plugin
  • Loading branch information
NickBurkhartBB authored Jan 15, 2025
2 parents 76cda37 + f20d7bc commit 632e384
Show file tree
Hide file tree
Showing 68 changed files with 1,131 additions and 1,300 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ apps/example/ios
apps/example/android

!**/plugin-native-navigation/__tests__/**/node_modules
!**/plugin-fsapp/__tests__/**/node_modules
96 changes: 0 additions & 96 deletions apps/docs/src/content/docs/packages/cli-kit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -719,24 +719,6 @@ const gemfilePath = path.ios.gemfile;

##### Constant

###### `path.ios.envSwitcher`

Generates the absolute path to the iOS EnvSwitcher.m.

**type:** `string`

##### Usage

Below is an illustrative example demonstrating the utilization of the `path.ios.envSwitcher` to generate the absolute path to the EnvSwitcher.m.

```ts
import {path} from '@brandingbrand/code-cli-kit';

const envSwitcherPath = path.ios.envSwitcher;
```

##### Constant

###### `path.ios.entitlements`

Generates the absolute path to the iOS app.entitlements.
Expand Down Expand Up @@ -773,24 +755,6 @@ const privacyManifestPath = path.ios.privacyManifest;

##### Constant

###### `path.ios.nativeConstants`

Generates the absolute path to the iOS NativeConstants.m.

**type:** `string`

##### Usage

Below is an illustrative example demonstrating the utilization of the `path.ios.nativeConstants` to generate the absolute path to the NativeConstants.m.

```ts
import {path} from '@brandingbrand/code-cli-kit';

const nativeConstantsPath = path.ios.nativeConstants;
```

##### Constant

###### `path.ios.projectPbxProj`

Generates the absolute path to the iOS project.pbxproj.
Expand Down Expand Up @@ -1029,66 +993,6 @@ import {path} from '@brandingbrand/code-cli-kit';
const mainActivityPath = path.android.mainActivity(config);
```

##### Function

###### `path.android.envSwitcher`

Generates the absolute path to the Android EnvSwitcher.java.

**type:** `function (config: BuildConfig): string`

##### Options

###### `config`

**type:** [BuildConfig](/guides/build)

_required_

The build configuration consumed by Flagship Code represented by `build.<mode>.ts`.

##### Usage

Below is an illustrative example demonstrating the utilization of the `path.android.envSwitcher` to generate the absolute path to the EnvSwitcher.java.

```ts
import {path} from '@brandingbrand/code-cli-kit';

// config aggregated from @brandingbrand/cli

const envSwitcherPath = path.android.envSwitcher(config);
```

##### Function

###### `path.android.nativeConstants`

Generates the absolute path to the Android NativeConstants.java.

**type:** `function (config: BuildConfig): string`

##### Options

###### `config`

**type:** [BuildConfig](/guides/build)

_required_

The build configuration consumed by Flagship Code represented by `build.<mode>.ts`.

##### Usage

Below is an illustrative example demonstrating the utilization of the `path.android.nativeConstants` to generate the absolute path to the NativeConstants.java.

```ts
import {path} from '@brandingbrand/code-cli-kit';

// config aggregated from @brandingbrand/cli

const nativeConstantsPath = path.android.nativeConstants(config);
```

### string

A comprehensive suite of string-related utility functions facilitating efficient error handling and warning notifications.
Expand Down
158 changes: 158 additions & 0 deletions apps/docs/src/content/docs/packages/plugin-fsapp.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
title: plugin-fsapp
---

# plugin-fsapp

The `@brandingbrand/code-plugin-fsapp` is a specialized plugin for Flagship Code that manages environment configurations and native module setup for React Native applications using @brandingbrand/fsapp. It handles the complexities of environment switching, native constants, and platform-specific implementations.

## Key Features

- Environment switching capabilities for development, staging, and production
- Automated native module configuration for iOS and Android
- Native constants management
- Support for React Native 0.72 and 0.73
- Type-safe environment configuration

## Install

Add `@brandingbrand/code-plugin-fsapp` as a development dependency to your React Native project.

import {Tabs, TabItem} from '@astrojs/starlight/components';

<Tabs>
<TabItem label="yarn">

```sh
yarn add --dev @brandingbrand/code-plugin-fsapp
```

</TabItem>
<TabItem label="npm">

```sh
npm install --save-dev @brandingbrand/code-plugin-fsapp
```

</TabItem>
<TabItem label="pnpm">

```sh
pnpm add --save-dev @brandingbrand/code-plugin-fsapp
```

</TabItem>
<TabItem label="bun">

```sh
bun add --dev @brandingbrand/code-plugin-fsapp
```

</TabItem>
</Tabs>

Your package.json should now be updated, `@brandingbrand/code-plugin-fsapp` should be listed as a `devDependency`.

```json title="package.json" ins={10}
{
"name": "my-awesome-app",
"version": "1.0.0",
"author": "Your Name <[email protected]>",
"dependencies": {
"react": "^18.2.0",
"react-native": "~0.72.0"
},
"devDependencies": {
"@brandingbrand/code-plugin-fsapp": "1.0.0"
}
}
```

## Configure

### Flagship Code Configuration

Upon installing the dependency, it is imperative to update the `flagship-code.config.ts` file. Specifically, ensure that the `plugins` array includes the newly installed dependency. This step is crucial, as Flagship Code will only invoke the plugin if it is listed within this array.

```ts title="flagship-code.config.ts" ins={9}
import {defineConfig} from '@brandingbrand/code-cli-kit';

export default defineConfig({
buildPath: './coderc/build',
pluginPath: './coderc/plugins',
plugins: [
// other plugins
'@brandingbrand/code-plugin-fsapp',
],
});
```

### Environment Configuration

Create environment files following this structure:

```typescript title="env.development.ts"
import {defineEnv} from '@brandingbrand/code-cli-kit';

export default defineEnv({
API_URL: 'https://dev-api.example.com',
FEATURE_FLAGS: {
enableFeatureA: true,
},
});
```

### CLI Options

The plugin requires the following command-line options:

```sh
--env <environment> # Specifies the initial environment (development, staging, production)
```

Example usage:

```sh
flagship-code build --env development
```

### Platform-Specific Setup

The plugin automatically handles:

- iOS

- Configures EnvSwitcher and NativeConstants modules
- Updates Xcode project settings
- Manages environment variables

- Android
- Sets up Java modules for environment switching
- Configures MainActivity and MainApplication
- Handles build-time environment configuration

For more detailed guidance and information, please refer to the [Flagship Code Configuration](/guides/config) guide. This resource offers comprehensive instructions and insights to assist you in configuring Flagship Code effectively.

## Troubleshooting

Common issues and solutions:

1. Environment files not detected

- Ensure files follow the naming convention: `env.<environment>.ts`
- Verify files are in the correct directory

2. Build errors

- Check that all native dependencies are properly linked
- Verify React Native version compatibility

3. Environment switching issues
- Confirm proper CLI flag usage
- Check environment file syntax

## Additional Resources

- [Flagship Code Configuration Guide](/guides/config)
- [Environment Management](/guides/environments)
- [Native Module Setup](/guides/native-modules)
2 changes: 1 addition & 1 deletion packages/app-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"@types/babel__core": "^7.20.5",
"@types/node": "^22.3.0",
"@types/react": "18.2.6",
"react": "18.2.0",
"react-native": "0.73.11",
"react-native-sensitive-info": "^5.5.8",
"react": "18.2.0",
"typescript": "^5.5.4"
}
}
4 changes: 2 additions & 2 deletions packages/app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"@repo/typescript-config": "*",
"@types/eslint": "^8.56.1",
"@types/url-parse": "^1.4.11",
"typescript": "^5.3.3",
"react": "18.2.0",
"react-native": "0.73.11",
"react-native-navigation": "^7.40.1"
"react-native-navigation": "^7.40.1",
"typescript": "^5.3.3"
}
}
56 changes: 0 additions & 56 deletions packages/cli-kit/__tests__/path-0.72.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ describe('path', () => {
);
});

it('should have an ios.envSwitcher function that returns the path to ios/app/EnvSwitcher.m', () => {
const envSwitcherPath = path.ios.envSwitcher;
expect(envSwitcherPath).toEqual(
expect.stringMatching(/.*ios\/app\/EnvSwitcher\.m$/),
);
});

it('should have an ios.entitlements function that returns the path to ios/app/app.entitlements', () => {
const entitlementsPath = path.ios.entitlements;
expect(entitlementsPath).toEqual(
Expand All @@ -48,13 +41,6 @@ describe('path', () => {
expect(gemfilePath).toEqual(expect.stringMatching(/.*ios\/Gemfile$/));
});

it('should have an ios.nativeConstants function that returns the path to ios/app/NativeConstants.m', () => {
const nativeConstantsPath = path.ios.nativeConstants;
expect(nativeConstantsPath).toEqual(
expect.stringMatching(/.*ios\/app\/NativeConstants\.m$/),
);
});

it('should have an ios.appDelegate function that returns the path to ios/app/AppDelegate.mm', () => {
const appDelegatePath = path.ios.appDelegate;
expect(appDelegatePath).toEqual(
Expand Down Expand Up @@ -146,27 +132,6 @@ describe('path', () => {
);
});

it('should have an android.envSwitcher function that returns the path to android/app/src/main/java/com/example/app/EnvSwitcher.java', () => {
const config = {
android: {
name: 'example',
displayName: 'Example',
packageName: 'com.example.app',
},
ios: {
name: 'example',
displayName: 'Example',
bundleId: 'com.example.app',
},
};
const envSwitcherPath = path.android.envSwitcher(config);
expect(envSwitcherPath).toEqual(
expect.stringMatching(
/.*android\/app\/src\/main\/java\/com\/example\/app\/EnvSwitcher\.java$/,
),
);
});

it('should have an android.gemfile function that returns the path to android/Gemfile', () => {
const gemfilePath = path.android.gemfile;
expect(gemfilePath).toEqual(expect.stringMatching(/.*android\/Gemfile$/));
Expand All @@ -179,27 +144,6 @@ describe('path', () => {
);
});

it('should have an android.nativeConstants function that returns the path to android/app/src/main/java/com/example/app/NativeConstants.java', () => {
const config = {
android: {
name: 'example',
displayName: 'Example',
packageName: 'com.example.app',
},
ios: {
name: 'example',
displayName: 'Example',
bundleId: 'com.example.app',
},
};
const nativeConstantsPath = path.android.nativeConstants(config);
expect(nativeConstantsPath).toEqual(
expect.stringMatching(
/.*android\/app\/src\/main\/java\/com\/example\/app\/NativeConstants\.java$/,
),
);
});

it('should have an android.strings function that returns the path to android/app/src/main/res/values/strings.xml', () => {
const stringsPath = path.android.strings;
expect(stringsPath).toEqual(
Expand Down
Loading

0 comments on commit 632e384

Please sign in to comment.