create-dexter-rn-app
Version:
Create a React Native app pre configured with Redux Toolkit, Persist, React Query, React Native Paper, SVG transformer, and Dexter's starter template.
79 lines (62 loc) • 2.2 kB
JavaScript
const { execSync } = require("child_process");
const path = require("path");
const fs = require("fs");
const prompts = require("prompts");
function runCommand(cmd) {
console.log(`\n▶️ ${cmd}\n`);
execSync(cmd, { stdio: "inherit" });
}
async function run() {
console.log("\n🚀Script started create-dexter-rn-app\n");
const response = await prompts(
{
type: "text",
name: "name",
message: "Project name?",
initial: "AwesomeProject",
validate: (value) =>
value && value.trim().length > 0 ? true : "Project name is required"
},
{
onCancel: () => {
console.log("\n👋 Setup cancelled.");
process.exit(1);
}
}
);
const projectName = (response.name || "").trim();
if (!projectName) {
console.log("❌ No project name provided. Exiting.");
process.exit(1);
}
const projectDir = path.resolve(process.cwd(), projectName);
if (fs.existsSync(projectDir)) {
console.error(`❌ Folder "${projectName}" already exists. Choose another name.`);
process.exit(1);
}
console.log(`\n📦 Creating React Native app: ${projectName}\n`);
try {
runCommand(`npx @react-native-community/cli@latest init ${projectName}`);
} catch (e) {
console.error("\n❌ Failed to initialize React Native app.");
process.exit(1);
}
process.chdir(projectDir);
const fullSetupCmd = "npx degit AakashThakur23102000/rn-cli-starter-template/template . --force && npm i @reduxjs/toolkit react-redux redux-persist @react-native-async-storage/async-storage react-native-safe-area-context react-native-size-matters @tanstack/react-query && npm i -D @types/react-redux reactotron-react-native && adb reverse tcp:9090 tcp:9090";
try {
runCommand(fullSetupCmd);
} catch (e) {
console.error("\n⚠️ One or more steps in the setup command failed.");
console.error(" You can re-run parts of it manually inside the project folder:\n");
console.error(" " + fullSetupCmd + "\n");
}
console.log(`
✅ Completed
Now run:
cd ${projectName}
npx react-native start
npx react-native run-android OR npx react-native run-ios
`);
}
run();