Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ A CLI tool that simplifies creating React Native modules powered by Nitro Module
- 📚 TypeScript support out of the box
- 🔧 Zero configuration required
- ⚙️ Automated ios/android build with GitHub Actions
- 🧪 Optional React Native Harness setup for native Android and iOS tests
- 📦 Semantic Release

## 📖 Documentation
Expand Down
1 change: 1 addition & 0 deletions docs/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Options:
--platforms <platforms> comma-separated platforms to target
--langs <langs> comma-separated languages to generate
-d, --module-dir <moduleDirectory> directory to create the module in
--include-harness include React Native Harness setup in the example app
-e, --skip-example skip example app generation
-i, --skip-install skip installing dependencies
--ci run in CI mode
Expand Down
29 changes: 29 additions & 0 deletions docs/docs/usage/create-a-nitro-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ To create a Nitro Module along with an example app, use the following command. T
</TabItem>
</Tabs>

## With React Native Harness

If you want the generated example app to include React Native Harness for native Android and iOS tests, pass the `--include-harness` flag.

<Tabs groupId="cli">
<TabItem value="bun" label="Bun" default>
```bash
bun create nitro-module@latest my-awesome-module --include-harness
```
</TabItem>
<TabItem value="npx" label="Npx">
```bash
npx create-nitro-module@latest my-awesome-module --include-harness
```
</TabItem>
<TabItem value="yarn" label="Yarn">
```bash
yarn create nitro-module@latest my-awesome-module --include-harness
```
</TabItem>
<TabItem value="pnpm" label="Pnpm">
```bash
pnpm create nitro-module@latest my-awesome-module --include-harness
```
</TabItem>
</Tabs>

The generated `example` app will include Harness config, sample native test files, package scripts, and a GitHub Actions workflow for the selected platforms.

## Without example app

If you prefer to create a Nitro Module without an example app, use the following command. This will generate only the module, without any additional example app.
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig([
js.configs.recommended,
nodePlugin.configs['flat/recommended-script'],
{
files: ['src/*.ts'],
files: ['src/**/*.ts'],
languageOptions: {
parser: tsParser,
parserOptions: {
Expand Down
27 changes: 27 additions & 0 deletions src/cli/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ export const createModule = async (
}
}

if (options.skipExample && options.includeHarness) {
throw new Error(
'React Native Harness requires the generated example app. Remove --skip-example or omit --include-harness.'
)
}

if (
options.packageType &&
![Nitro.Module, Nitro.View].includes(options.packageType)
Expand Down Expand Up @@ -213,6 +219,7 @@ export const createModule = async (
spinner,
packageType,
finalPackageName: 'react-native-' + packageName.toLowerCase(),
includeHarness: answers.includeHarness,
skipInstall: options.skipInstall,
skipExample: options.skipExample,
})
Expand Down Expand Up @@ -254,8 +261,10 @@ export const createModule = async (

console.log(
generateInstructions({
includeHarness: answers.includeHarness,
moduleName: `react-native-${packageName.toLowerCase()}`,
pm: answers.pm,
platforms: answers.platforms,
skipExample: options.skipExample,
skipInstall: options.skipInstall,
})
Expand Down Expand Up @@ -350,6 +359,7 @@ const getUserAnswers = async (
description: `${kleur.yellow(`react-native-${name}`)} is a react native package built with Nitro`,
platforms,
packageType,
includeHarness: options.includeHarness === true,
platformLangs: parsePlatformLangsOption(
options.langs,
platforms,
Expand Down Expand Up @@ -479,6 +489,22 @@ const getUserAnswers = async (
],
})
},
includeHarness: async () => {
if (options?.skipExample) {
return false
}

if (options?.includeHarness === true) {
return true
}

return p.confirm({
message: kleur.cyan(
'Include React Native Harness for native Android and iOS tests?'
),
initialValue: false,
})
},
packageNameConfirmation: async ({ results }) => {
const packageName = results.packageName
if (!packageName) {
Expand Down Expand Up @@ -511,6 +537,7 @@ const getUserAnswers = async (
packageType: group.packageType,
platforms: group.platforms,
platformLangs: group.platformLangs as PlatformLangMap,
includeHarness: group.includeHarness as boolean,
pm: group.pm,
description: group.description as string,
}
Expand Down
4 changes: 4 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ program
'-d, --module-dir <moduleDirectory>',
'directory to create the module in'
)
.option(
'--include-harness',
'include React Native Harness setup in the example app'
)
.option('-e, --skip-example', 'skip example app generation')
.option('-i, --skip-install', 'skip installing dependencies')
.option('--ci', 'run in CI mode')
Expand Down
Loading
Loading