-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Init :: Sanitize name and paths #193
base: master
Are you sure you want to change the base?
Changes from 5 commits
3ed28a6
48445e8
3bfe59f
52cbcfb
4a07d69
f6036f3
a95e5e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ import logger from 'loglevel' | |
import { existsSync, writeFileSync } from 'node:fs' | ||
import { basename, join } from 'node:path' | ||
import { userInfo } from 'os' | ||
import { ENTER, createFolderIfNotExists } from '../utils' | ||
import { ENTER, createFolderIfNotExists, sanitizeName } from '../utils' | ||
import { PROGRAM_FILE_EXTENSION, TEST_FILE_EXTENSION, WOLLOK_FILE_EXTENSION } from 'wollok-ts' | ||
import kebabCase from 'lodash/kebabCase' | ||
import { execSync } from 'node:child_process' | ||
|
||
export type Options = { | ||
|
@@ -35,24 +36,27 @@ export default function (folder: string | undefined, { project: _project, name, | |
} | ||
|
||
// Creating files | ||
const exampleName = name ?? 'example' | ||
logger.info(`Creating definition file ${exampleName}.${WOLLOK_FILE_EXTENSION}`) | ||
writeFileSync(join(project, `${exampleName}.${WOLLOK_FILE_EXTENSION}`), wlkDefinition) | ||
const exampleName = name && name.length > 0 ? name : 'example' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 |
||
const exampleFilename = sanitizeName(exampleName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmm tengo dudas sobre esto... A mí me gusta que los programas entiendan lo que quiero hacer y, o bien lo hagan, o bien me tiren un error. Si me la estoy mandando en el nombre que elegí, tal vez sea mejor tirar un error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bueno, bien. Esta es la discusión interesante que quería tener. Recordando lo frustrante que es elegir una contraseña en un banco y que te la vaya rechazando hasta que le pegás a cuántas mayúsculas y números quiere que tengas, y recordando la premisa que usamos en otros lugares de desburocratizar la UX (como cuando establecimos que el creador de desafíos de Pilas Bloques debía siempre armar desafíos válidos, en lugar de tirar popups de "te falta el personaje" o "no se puede poner un personaje encima de...." etc.), se me ocurrió la propuesta de "dejame pasar todo, corregí lo que quieras, sólo dame mi proyecto Wollok" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pero no me vuelvo loco si quieren mostrar un error del estilo "recordá que los nombres de proyecto deben empezar con minúscula, no incluir caracteres raros. Pueden tener letras, números y guiones bajos pero no espacios o eñes". y listo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sí, yo prefiero no tomar decisiones por el usuario. Si elegís un nombre incorrecto, que falle es lo más sano (salvo en el package.json que no me interesa mucho que tenga un nombre porque esa validación no es nuestra ni tampoco la queremos) |
||
|
||
const wollokDefinitionFile = `${exampleFilename}.${WOLLOK_FILE_EXTENSION}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ver comentario más abajo |
||
logger.info(`Creating definition file ${wollokDefinitionFile}`) | ||
writeFileSync(join(project, wollokDefinitionFile), wlkDefinition) | ||
|
||
if (!noTest) { | ||
const testFile = `test${capitalizeFirstLetter(exampleName)}.${TEST_FILE_EXTENSION}` | ||
const testFile = `test${capitalizeFirstLetter(exampleFilename)}.${TEST_FILE_EXTENSION}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ojo que deberíamos dejar |
||
logger.info(`Creating test file ${testFile}`) | ||
writeFileSync(join(project, testFile), testDefinition(exampleName)) | ||
writeFileSync(join(project, testFile), testDefinition(exampleFilename)) | ||
} | ||
|
||
if (game) { | ||
const gameFile = `main${capitalizeFirstLetter(exampleName)}.${PROGRAM_FILE_EXTENSION}` | ||
const gameFile = `main${capitalizeFirstLetter(exampleFilename)}.${PROGRAM_FILE_EXTENSION}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lo mismo acá: es |
||
logger.info(`Creating program file ${gameFile}`) | ||
writeFileSync(join(project, `${gameFile}`), gameDefinition(exampleName)) | ||
writeFileSync(join(project, gameFile), gameDefinition(exampleFilename)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lo mismo: |
||
} | ||
|
||
logger.info('Creating package.json') | ||
writeFileSync(join(project, 'package.json'), packageJsonDefinition(project, game)) | ||
writeFileSync(join(project, 'package.json'), packageJsonDefinition(name ?? project, game)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmm... no, yo quiero |
||
|
||
if (!noCI) { | ||
logger.info('Creating CI files') | ||
|
@@ -75,7 +79,7 @@ export default function (folder: string | undefined, { project: _project, name, | |
} | ||
|
||
// Finish | ||
logger.info(green('✨ Project succesfully created. Happy coding!')) | ||
logger.info(green('✨ Project successfully created. Happy coding!')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bien por el typo corregido! |
||
} | ||
|
||
|
||
|
@@ -131,7 +135,7 @@ program PepitaGame { | |
` | ||
|
||
const packageJsonDefinition = (projectName: string, game: boolean) => `{ | ||
"name": "${basename(projectName)}", | ||
"name": "${kebabCase(basename(projectName))}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahí tenemos una biblioteca para kebabCase |
||
"version": "1.0.0", | ||
${game ? assetsConfiguration() : ''}"wollokVersion": "4.0.0", | ||
PalumboN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"author": "${userInfo().username}", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhhh polémico 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esto se usa para las funciones
camelCase
ykebabCase
.Quizá podemos encontrar alguna implementación por ahí y evitar la dependencia.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encontré estas bibliotecas
@nmigueles