cli-react-router
Version:
CLI to generate a project with react-router v7
78 lines • 3.51 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import chalk from 'chalk';
import path from 'path';
import { exec } from 'child_process';
import { askProjectInfo } from './prompts.js';
import { createStructure } from './utils.js';
import { structure } from "./structure.js";
import fs from 'fs';
export function runCreator() {
return __awaiter(this, void 0, void 0, function* () {
const { projectName, projectPath, initializeGit } = yield askProjectInfo();
const fullPath = path.join(projectPath, projectName);
console.log(chalk.blue(`Creando proyecto: ${projectName} en ${fullPath}`));
createStructure(fullPath, structure);
const packageJson = {
name: projectName,
version: "1.0.0",
main: "index.js",
type: "module",
scripts: {
dev: "react-router dev",
build: "react-router build",
start: "react-router-serve ./build/server/index.js"
},
dependencies: {
"@react-router/node": "^7.4.0",
"@react-router/serve": "^7.4.0",
isbot: "^5",
react: "^19.0.0",
"react-dom": "^19.0.0",
"react-router": "^7.4.0"
},
devDependencies: {
"@react-router/dev": "^7.4.0",
"@tailwindcss/vite": "^4.0.15",
"@types/node": "^22.13.10",
"@types/react": "^19.0.12",
"@types/react-dom": "^19.0.4",
typescript: "^5.8.2",
vite: "^6.2.2",
"vite-tsconfig-paths": "^5.1.4"
}
};
fs.writeFileSync(path.join(fullPath, 'package.json'), JSON.stringify(packageJson, null, 2));
process.chdir(fullPath);
console.log(chalk.blue('Instalando dependencias...'));
exec('npm install', (err, stdout, stderr) => {
if (err) {
console.error(chalk.red(`Error instalando dependencias: ${stderr}`));
process.exit(1);
}
console.log(chalk.green('Dependencias instaladas correctamente'));
if (initializeGit) {
console.log(chalk.blue('Inicializando repositorio Git...'));
exec('git init', (err, stdout, stderr) => {
if (err) {
console.error(chalk.red(`Error inicializando Git: ${stderr}`));
process.exit(1);
}
console.log(chalk.green('Repositorio Git inicializado correctamente'));
console.log(chalk.blue('¡Proyecto listo!'));
});
}
else {
console.log(chalk.blue('¡Proyecto listo!'));
}
});
});
}
//# sourceMappingURL=createProject.js.map