Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
owellandry committed Sep 14, 2024
1 parent 4b2d98d commit 88a93f0
Show file tree
Hide file tree
Showing 14 changed files with 795 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# PyRex
Pyre

npm uninstall -g pyrex-cli
npm install -g .
pyx create-pyrex-app app
31 changes: 31 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node

// index.js

const { Command } = require('commander');
const { createApp } = require('./modules/createApp');
const { promptStructure } = require('./modules/promptStructure');
const { execSync } = require('child_process');

const program = new Command();

program
.version('1.0.0')
.command('create-pyrex-app <appName>')
.description('Crea una nueva aplicación Pyrex')
.action(async (appName) => {
await createApp(appName, promptStructure);
});

program
.command('start')
.description('Inicia el servidor de desarrollo')
.action(() => {
try {
execSync('node modules/server.js', { stdio: 'inherit' });
} catch (error) {
console.error('Error al iniciar el servidor:', error.message);
}
});

program.parse(process.argv);
63 changes: 63 additions & 0 deletions modules/createApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const { createPublicFiles } = require('./fileManager');
const { createReadme } = require('./readme');

async function createApp(appName, promptStructure) {
const appDir = path.join(process.cwd(), appName);
if (fs.existsSync(appDir)) {
console.error('El directorio ya existe.');
process.exit(1);
}

// Crear el directorio principal
fs.mkdirSync(appDir);

// Preguntar al usuario sobre la estructura del proyecto
const answers = await promptStructure();

// Crear la estructura de carpetas según la elección del usuario
if (answers.structure === 'src') {
fs.mkdirSync(path.join(appDir, 'src'));
fs.writeFileSync(path.join(appDir, 'src', 'index.js'), '// Tu código aquí');
} else if (answers.structure === 'app') {
fs.mkdirSync(path.join(appDir, 'app'));
fs.writeFileSync(path.join(appDir, 'app', 'index.js'), '// Tu código aquí');
} else if (answers.structure === 'page') {
fs.mkdirSync(path.join(appDir, 'pages'));
fs.writeFileSync(path.join(appDir, 'pages', 'index.js'), '// Tu código aquí');
}

// Crear archivos públicos y README
createPublicFiles(appDir);
createReadme(appDir);

// Ejecutar npm init -y para crear package.json
try {
execSync('npm init -y', { cwd: appDir, stdio: 'inherit' });
console.log('Proyecto inicializado con npm.');
} catch (error) {
console.error('Error al ejecutar npm init:', error.message);
}

// Instalar TypeScript
try {
execSync('npm install typescript --save-dev', { cwd: appDir, stdio: 'inherit' });
console.log('TypeScript instalado.');
} catch (error) {
console.error('Error al instalar TypeScript:', error.message);
}

// Inicializar Git
try {
execSync('git init', { cwd: appDir, stdio: 'inherit' });
console.log('Repositorio Git inicializado.');
} catch (error) {
console.error('Error al inicializar Git:', error.message);
}

console.log(`Aplicación Pyrex creada en ${appDir}`);
}

module.exports = { createApp };
15 changes: 15 additions & 0 deletions modules/fileManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//modules/fileManager.js

const fs = require('fs');
const path = require('path');

function createPublicFiles(appDir) {
const publicDir = path.join(appDir, 'public');
fs.mkdirSync(publicDir);

fs.copyFileSync(path.join(__dirname, '../pages/public/index.html.js'), path.join(publicDir, 'index.html'));
fs.copyFileSync(path.join(__dirname, '../pages/public/style.css.js'), path.join(publicDir, 'style.css'));
fs.copyFileSync(path.join(__dirname, '../pages/public/favicon.ico'), path.join(publicDir, 'favicon.ico'));
}

module.exports = { createPublicFiles };
18 changes: 18 additions & 0 deletions modules/promptLanguage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// modules/promptLanguage.js

const inquirer = require('inquirer').default;

async function promptLanguage() {
const answer = await inquirer.prompt([
{
type: 'list',
name: 'language',
message: '¿Qué lenguaje de programación prefieres?',
choices: ['javascript', 'typescript'],
},
]);

return answer;
}

module.exports = { promptLanguage };
22 changes: 22 additions & 0 deletions modules/promptStructure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const inquirer = require('inquirer').default;

async function promptStructure() {
const answers = await inquirer.prompt([
{
type: 'list',
name: 'structure',
message: 'Elige la estructura del proyecto:',
choices: ['src', 'app', 'page'],
},
{
type: 'list',
name: 'language',
message: 'Elige el lenguaje del proyecto:',
choices: ['JavaScript', 'TypeScript'],
},
]);

return answers;
}

module.exports = { promptStructure };
31 changes: 31 additions & 0 deletions modules/readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//modules/readme.md

const fs = require('fs');
const path = require('path');

function createReadme(appDir) {
const readmeContent = `
# Pyrex App
Este es un proyecto creado con Pyrex.
## Estructura del Proyecto
Elige una estructura para tu proyecto:
1. **src**: Carpeta para el código fuente.
2. **app**: Carpeta para la aplicación principal.
3. **page**: Carpeta para las páginas del proyecto.
Usa los siguientes comandos para iniciar tu aplicación:
\`\`\`
npm install
npm start
\`\`\`
`;

fs.writeFileSync(path.join(appDir, 'README.md'), readmeContent);
}

module.exports = { createReadme };
19 changes: 19 additions & 0 deletions modules/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// modules/server.js

const express = require('express');
const path = require('path');
const app = express();
const port = 3000;

// Configura el directorio de archivos estáticos
app.use(express.static(path.join(__dirname, '../pages/public')));

// Ruta principal
app.get('/', (req, res) => {
res.send('<h1>Bienvenido a tu primer framework</h1>');
});

// Inicia el servidor
app.listen(port, () => {
console.log(`Servidor escuchando en http://localhost:${port}`);
});
Loading

0 comments on commit 88a93f0

Please sign in to comment.