-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b2d98d
commit 88a93f0
Showing
14 changed files
with
795 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |
Oops, something went wrong.