From f925173c3847cdb581b446727b62d454ea4c7abd Mon Sep 17 00:00:00 2001 From: Patrick Kabwe Date: Mon, 24 Feb 2025 14:00:05 +0200 Subject: [PATCH 1/5] feat: generate expo example app with nitro --- src/generate-nitro-module.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/generate-nitro-module.ts b/src/generate-nitro-module.ts index 4cd9ec46..9cec7dd5 100644 --- a/src/generate-nitro-module.ts +++ b/src/generate-nitro-module.ts @@ -224,6 +224,8 @@ export class NitroModuleFactory { private async createExampleApp() { const packageManager = this.config.pm === 'bun' ? 'bunx' : 'npx -y' + // TODO: generate expo example app + const args = `${packageManager} \ @react-native-community/cli@latest init ${toPascalCase(this.config.moduleName)}Example \ --package-name com.${replaceHyphen(this.config.moduleName)}example \ From d70c8570d154c49044c0a54335379bd78ac1baad Mon Sep 17 00:00:00 2001 From: Patrick Kabwe Date: Mon, 24 Feb 2025 14:01:17 +0200 Subject: [PATCH 2/5] feat: generate expo example app with nitro --- src/generate-nitro-module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generate-nitro-module.ts b/src/generate-nitro-module.ts index 9cec7dd5..f9a346dd 100644 --- a/src/generate-nitro-module.ts +++ b/src/generate-nitro-module.ts @@ -225,7 +225,7 @@ export class NitroModuleFactory { const packageManager = this.config.pm === 'bun' ? 'bunx' : 'npx -y' // TODO: generate expo example app - + const args = `${packageManager} \ @react-native-community/cli@latest init ${toPascalCase(this.config.moduleName)}Example \ --package-name com.${replaceHyphen(this.config.moduleName)}example \ From 3e168ae5549c369aca21ad098ca4af78e5be1d37 Mon Sep 17 00:00:00 2001 From: Patrick Kabwe Date: Sun, 2 Mar 2025 09:28:55 +0200 Subject: [PATCH 3/5] feat: add support for creating Expo and CLI example apps --- src/create.ts | 18 +++++++++++++++++- src/generate-nitro-module.ts | 20 ++++++++++++++------ src/types.ts | 6 ++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/create.ts b/src/create.ts index b4e56750..44508e21 100644 --- a/src/create.ts +++ b/src/create.ts @@ -6,7 +6,12 @@ import path from 'path' import projectPackageJsonFile from '../package.json' import { generateInstructions, SUPPORTED_PLATFORMS } from './constants' import { NitroModuleFactory } from './generate-nitro-module' -import { CreateModuleOptions, Nitro, PLATFORM_LANGUAGE_MAP } from './types' +import { + CreateModuleOptions, + ExampleType, + Nitro, + PLATFORM_LANGUAGE_MAP, +} from './types' import { detectPackageManager, dirExist } from './utils' export const createModule = async ( @@ -42,6 +47,7 @@ export const createModule = async ( finalModuleName: 'react-native-' + name.toLowerCase(), skipInstall: options.skipInstall, skipExample: options.skipExample, + exampleType: answers.exampleType, }) await moduleFactory.createNitroModule() @@ -92,6 +98,14 @@ const getUserAnswers = async (name: string, usedPm?: string) => { }, }) + const exampleType = await inquirer.prompt({ + type: 'list', + message: kleur.cyan('What type of module would you like to create?'), + name: 'name', + choices: ['expo', 'cli', 'both'], // Thinking if i should have this? + default: 'cli', + }) + const platforms = await inquirer.prompt({ type: 'checkbox', message: kleur.cyan('🎯 Select target platforms:'), @@ -194,5 +208,7 @@ const getUserAnswers = async (name: string, usedPm?: string) => { pm: pm.name, moduleType: moduleType.name === 'Nitro View' ? Nitro.View : Nitro.Module, + exampleType: + exampleType.name === 'expo' ? ExampleType.Expo : ExampleType.CLI, } } diff --git a/src/generate-nitro-module.ts b/src/generate-nitro-module.ts index f9a346dd..e16f67c5 100644 --- a/src/generate-nitro-module.ts +++ b/src/generate-nitro-module.ts @@ -25,6 +25,7 @@ import { CppFileGenerator } from './file-generators/cpp-file-generator' import { IOSFileGenerator } from './file-generators/ios-file-generator' import { JSFileGenerator } from './file-generators/js-file-generator' import { + ExampleType, FileGenerator, GenerateModuleConfig, Nitro, @@ -225,16 +226,23 @@ export class NitroModuleFactory { const packageManager = this.config.pm === 'bun' ? 'bunx' : 'npx -y' // TODO: generate expo example app + const expoCmd = 'npx create-expo-app@latest' - const args = `${packageManager} \ + const cliCmd = `${packageManager} \ @react-native-community/cli@latest init ${toPascalCase(this.config.moduleName)}Example \ --package-name com.${replaceHyphen(this.config.moduleName)}example \ - --directory example --skip-install --skip-git-init --version latest` - - await execAsync(args, { cwd: this.config.cwd }) + --directory example --skip-install --skip-git-init --version 0.78.0` + + let appPath = '' + if (this.config.exampleType === ExampleType.Expo) { + await execAsync(expoCmd, { cwd: this.config.cwd }) + appPath = path.join(this.config.cwd, 'example', 'App.tsx') + } else { + await execAsync(cliCmd, { cwd: this.config.cwd }) + // Setup App.tsx + appPath = path.join(this.config.cwd, 'example', 'App.tsx') + } - // Setup App.tsx - const appPath = path.join(this.config.cwd, 'example', 'App.tsx') await writeFile( appPath, appExampleCode( diff --git a/src/types.ts b/src/types.ts index 9f31f5ea..46a08dde 100644 --- a/src/types.ts +++ b/src/types.ts @@ -30,6 +30,11 @@ export enum Nitro { View = 'view', } +export enum ExampleType { + Expo = 'expo', + CLI = 'cli', +} + export type GenerateModuleConfig = { pm: PackageManager cwd: string @@ -41,6 +46,7 @@ export type GenerateModuleConfig = { moduleType: Nitro moduleName: string finalModuleName: string + exampleType: ExampleType } & Omit export interface FileGenerator { From 1f89297b16ed186a93180c9ba97c98e59c95834a Mon Sep 17 00:00:00 2001 From: Patrick Kabwe Date: Sun, 2 Mar 2025 09:30:41 +0200 Subject: [PATCH 4/5] chore: update lefthook config and minor type file cleanup --- lefthook.yml | 2 +- src/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lefthook.yml b/lefthook.yml index 62cd254f..0df431db 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -12,4 +12,4 @@ pre-commit: - "*.json" - "*.ts" - "*.tsx" - run: bun format {staged_files} \ No newline at end of file + run: bun format {staged_files} && git add {staged_files} \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 46a08dde..2fa27561 100644 --- a/src/types.ts +++ b/src/types.ts @@ -68,4 +68,4 @@ export type InstructionsParams = { pm: string skipInstall?: boolean skipExample?: boolean -} \ No newline at end of file +} From 33cf93b55f0a6f6bd1b1143aad46ad2c743c5d90 Mon Sep 17 00:00:00 2001 From: Patrick Kabwe Date: Sun, 2 Mar 2025 09:31:42 +0200 Subject: [PATCH 5/5] chore: update lefthook linting to auto-stage files --- lefthook.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lefthook.yml b/lefthook.yml index 0df431db..53b06f80 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -6,7 +6,7 @@ pre-commit: - "*.json" - "*.ts" - "*.tsx" - run: bun lint {staged_files} + run: bun lint {staged_files} && git add {staged_files} format: glob: - "*.json"