Skip to content
Draft
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
4 changes: 2 additions & 2 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pre-commit:
- "*.json"
- "*.ts"
- "*.tsx"
run: bun lint {staged_files}
run: bun lint {staged_files} && git add {staged_files}
format:
glob:
- "*.json"
- "*.ts"
- "*.tsx"
run: bun format {staged_files}
run: bun format {staged_files} && git add {staged_files}
18 changes: 17 additions & 1 deletion src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:'),
Expand Down Expand Up @@ -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,
}
}
22 changes: 16 additions & 6 deletions src/generate-nitro-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -224,15 +225,24 @@ export class NitroModuleFactory {
private async createExampleApp() {
const packageManager = this.config.pm === 'bun' ? 'bunx' : 'npx -y'

const args = `${packageManager} \
// TODO: generate expo example app
const expoCmd = 'npx create-expo-app@latest'

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(
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export enum Nitro {
View = 'view',
}

export enum ExampleType {
Expo = 'expo',
CLI = 'cli',
}

export type GenerateModuleConfig = {
pm: PackageManager
cwd: string
Expand All @@ -41,6 +46,7 @@ export type GenerateModuleConfig = {
moduleType: Nitro
moduleName: string
finalModuleName: string
exampleType: ExampleType
} & Omit<CreateModuleOptions, 'moduleDir'>

export interface FileGenerator {
Expand All @@ -62,4 +68,4 @@ export type InstructionsParams = {
pm: string
skipInstall?: boolean
skipExample?: boolean
}
}
Loading