diff --git a/create-app.js b/create-app.js index b010e83..2619677 100644 --- a/create-app.js +++ b/create-app.js @@ -1,14 +1,15 @@ -#!/usr/bin/env node -import { cpSync, renameSync, rmSync } from 'fs' -import { join } from 'path' import { execSync } from 'child_process' +import { cpSync, readFileSync, renameSync, rmSync, mkdirSync } from 'fs' +import { join, resolve } from 'path' +import Arborist from '@npmcli/arborist' +import packlist from 'npm-packlist' // Enhances source files inside /app with a fresh RN project template. const appName = 'ReactigationApp' console.log('⌛ Initializing a fresh RN project...') -execSync(`npx react-native init ${appName} --skip-git-init true --install-pods true`, { +execSync(`bunx @react-native-community/cli init ${appName} --skip-git-init true --install-pods true`, { // Write output to cnosole. stdio: 'inherit', }) @@ -26,11 +27,18 @@ execSync('npm run build', { stdio: 'inherit', }) -// Install this package locally, avoiding symlinks. -execSync('npm install $(npm pack .. | tail -1) --legacy-peer-deps', { - cwd: join(process.cwd(), 'app'), - stdio: 'inherit', -}) +const packageName = JSON.parse(readFileSync('./package.json')).name +const packageDirectory = resolve(`app/node_modules/${packageName}`) + +// Package files and copy them to app node_modules. +// Couldn't get symlinks to work with metro. +const arborist = new Arborist({ path: process.cwd() }) +const tree = await arborist.loadActual() +const files = await packlist(tree) + +mkdirSync(packageDirectory, { recursive: true }) + +files.forEach((file) => cpSync(join(process.cwd(), file), join(packageDirectory, file), { recursive: true })) console.log('') console.log('🍞 React Native App created inside /app.') diff --git a/package.json b/package.json index a6d51e3..ed988a1 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "./package.json": "./package.json" }, "scripts": { - "app": "node create-app.js", + "app": "bun create-app.js", "app:install": "npm i --no-save $(npm pack . | tail -1) --prefix app", "build": "esbuild index.tsx --outdir=dist --bundle --format=esm --platform=neutral --sourcemap --external:react-native --external:react && tsc", "watch": "npm-run-all --parallel build:watch copy", @@ -32,28 +32,30 @@ "react-native": ">= 0.70" }, "devDependencies": { - "@react-native-community/cli": "^13.6.9", - "@react-native/babel-preset": "^0.74.84", - "@react-native/eslint-config": "^0.74.84", - "@react-native/typescript-config": "^0.74.84", + "@npmcli/arborist": "^7.5.4", + "@react-native-community/cli": "^14.0.1", + "@react-native/babel-preset": "^0.75.2", + "@react-native/eslint-config": "^0.75.2", + "@react-native/typescript-config": "^0.75.2", "@types/jest": "^29.5.12", - "@types/node": "^20.14.2", - "@types/react": "^18.3.3", + "@types/node": "^22.5.2", + "@types/react": "^18.3.5", "@types/react-native": "^0.73.0", "@types/react-test-renderer": "^18.3.0", "babel-jest": "^29.7.0", "cpx": "^1.5.0", - "esbuild": "^0.21.5", + "esbuild": "^0.23.1", "eslint": "8.57.0", "eslint-plugin-flowtype": "^8.0.3", - "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-prettier": "^5.2.1", "jest": "^29.7.0", + "npm-packlist": "^8.0.2", "npm-run-all": "^4.1.5", - "prettier": "^3.3.1", + "prettier": "^3.3.3", "react": "^18.3.1", - "react-native": "^0.74.2", + "react-native": "^0.75.2", "react-test-renderer": "^18.3.1", - "typescript": "^5.4.5" + "typescript": "^5.5.4" }, "files": [ "dist"