Skip to content

feat: add localization prompt #145

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

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 51 additions & 44 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { postOrderDirectoryTraverse, preOrderDirectoryTraverse } from './utils/d
import generateReadme from './utils/generateReadme'
import generateIndex from './utils/generateIndex'
import getCommand from './utils/getCommand'
import getLanguage from './utils/getLanguage'
import renderEslint from './utils/renderEslint'
import { FILES_TO_FILTER } from './utils/filterList'

Expand Down Expand Up @@ -118,7 +119,7 @@ async function init() {
const defaultProjectName = !targetDir ? 'vue-project' : targetDir

const forceOverwrite = argv.force

const language = getLanguage()
let result: {
projectName?: string
shouldOverwrite?: boolean
Expand Down Expand Up @@ -158,99 +159,105 @@ async function init() {
{
name: 'projectName',
type: targetDir ? null : 'text',
message: 'Project name:',
message: language.projectName.message,
initial: defaultProjectName,
onState: (state) => (targetDir = String(state.value).trim() || defaultProjectName)
},
{
name: 'shouldOverwrite',
type: () => (canSkipEmptying(targetDir) || forceOverwrite ? null : 'confirm'),
type: () => (canSkipEmptying(targetDir) || forceOverwrite ? null : 'toggle'),
message: () => {
const dirForPrompt =
targetDir === '.' ? 'Current directory' : `Target directory "${targetDir}"`
targetDir === '.'
? language.shouldOverwrite.dirForPrompts.current
: `${language.shouldOverwrite.dirForPrompts.target} "${targetDir}"`

return `${dirForPrompt} is not empty. Remove existing files and continue?`
}
return `${dirForPrompt} ${language.shouldOverwrite.message}`
},
initial: true,
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'overwriteChecker',
type: (prev, values) => {
if (values.shouldOverwrite === false) {
throw new Error(red('✖') + ' Operation cancelled')
throw new Error(red('✖') + ` ${language.errors.operationCancelled}`)
}
return null
}
},
{
name: 'packageName',
type: () => (isValidPackageName(targetDir) ? null : 'text'),
message: 'Package name:',
message: language.packageName.message,
initial: () => toValidPackageName(targetDir),
validate: (dir) => isValidPackageName(dir) || 'Invalid package.json name'
validate: (dir) => isValidPackageName(dir) || language.packageName.invalidMessage
},
{
name: 'needsTypeScript',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add TypeScript?',
message: language.needsTypeScript.message,
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsJsx',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add JSX Support?',
message: language.needsJsx.message,
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsRouter',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add Vue Router for Single Page Application development?',
message: language.needsRouter.message,
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsPinia',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add Pinia for state management?',
message: language.needsPinia.message,
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsVitest',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add Vitest for Unit Testing?',
message: language.needsVitest.message,
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsE2eTesting',
type: () => (isFeatureFlagsUsed ? null : 'select'),
message: 'Add an End-to-End Testing Solution?',
hint: language.needsE2eTesting.hint,
message: language.needsE2eTesting.message,
initial: 0,
choices: (prev, answers) => [
{ title: 'No', value: false },
{ title: language.needsE2eTesting.selectOptions.negative.title, value: false },
{
title: 'Playwright',
title: language.needsE2eTesting.selectOptions.playwright.title,
value: 'playwright'
},
{
title: 'Nightwatch',
title: language.needsE2eTesting.selectOptions.nightwatch.title,
description: answers.needsVitest
? undefined
: 'also supports unit testing with Nightwatch Component Testing',
: language.needsE2eTesting.selectOptions.nightwatch.desc,
value: 'nightwatch'
},
{
title: 'Cypress',
title: language.needsE2eTesting.selectOptions.cypress.title,
description: answers.needsVitest
? undefined
: 'also supports unit testing with Cypress Component Testing',
: language.needsE2eTesting.selectOptions.cypress.desc,
value: 'cypress'
}
]
Expand All @@ -260,24 +267,24 @@ async function init() {
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add VueUse - Collection of essential Composition Utilities?',
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsI18n',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add i18n - internationalization plugin?',
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsStorybook',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: 'Add Storybook?',
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsSonarQube',
Expand All @@ -289,22 +296,22 @@ async function init() {
},
message: 'Add SonarQube for code coverage?',
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
},
{
name: 'needsTanStackQuery',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message:
'Add TanStack Query - Hooks for fetching, caching and updating asynchronous data?',
initial: false,
active: 'Yes',
inactive: 'No'
active: language.defaultToggleOptions.active,
inactive: language.defaultToggleOptions.inactive
}
],
{
onCancel: () => {
throw new Error(red('✖') + ' Operation cancelled')
throw new Error(red('✖') + ` ${language.errors.operationCancelled}`)
}
}
)
Expand Down Expand Up @@ -346,7 +353,7 @@ async function init() {
fs.mkdirSync(root)
}

console.log(`\nScaffolding project in ${root}...`)
console.log(`\n${language.infos.scaffolding} ${root}...`)

const pkg = { name: packageName, version: '0.0.0' }
fs.writeFileSync(path.resolve(root, 'package.json'), JSON.stringify(pkg, null, 2))
Expand Down Expand Up @@ -552,7 +559,7 @@ async function init() {
})
)

console.log(`\nDone. Now run:\n`)
console.log(`\n${language.infos.done}\n`)
if (root !== cwd) {
const cdProjectName = path.relative(cwd, root)
console.log(
Expand Down
64 changes: 64 additions & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"projectName": {
"message": "Project name:",
"invalidMessage": "Invalid package.json name"
},
"shouldOverwrite": {
"dirForPrompts": {
"current": "Current directory",
"target": "Target directory"
},
"message": "is not empty. Remove existing files and continue?"
},
"packageName": {
"message": "Package name:"
},
"needsTypeScript": {
"message": "Add TypeScript?"
},
"needsJsx": {
"message": "Add JSX Support?"
},
"needsRouter": {
"message": "Add Vue Router for Single Page Application development?"
},
"needsPinia": {
"message": "Add Pinia for state management?"
},
"needsVitest": {
"message": "Add Vitest for Unit Testing?"
},
"needsE2eTesting": {
"message": "Add an End-to-End Testing Solution?",
"hint": "- Use arrow-keys. Return to submit.",
"selectOptions": {
"negative": { "title": "No" },
"cypress": {
"title": "Cypress",
"desc": "also supports unit testing with Cypress Component Testing"
},
"nightwatch": {
"title": "Nightwatch",
"desc": "also supports unit testing with Nightwatch Component Testing"
},
"playwright": { "title": "Playwright" }
}
},
"needsEslint": {
"message": "Add ESLint for code quality?"
},
"needsPrettier": {
"message": "Add Prettier for code formatting?"
},
"errors": {
"operationCancelled": "Operation cancelled"
},
"defaultToggleOptions": {
"active": "Yes",
"inactive": "No"
},
"infos": {
"scaffolding": "Scaffolding project in",
"done": "Done. Now run:"
}
}
64 changes: 64 additions & 0 deletions locales/fr-FR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"projectName": {
"message": "Nom du projet\u00a0:",
"invalidMessage": "Le nom du package.json est invalide"
},
"shouldOverwrite": {
"dirForPrompts": {
"current": "Répertoire courant",
"target": "Répertoire cible"
},
"message": "n'est pas vide. Supprimer les fichiers existants et continuer\u00a0?"
},
"packageName": {
"message": "Nom du package\u00a0:"
},
"needsTypeScript": {
"message": "Ajouter TypeScript\u00a0?"
},
"needsJsx": {
"message": "Ajouter le support de JSX\u00a0?"
},
"needsRouter": {
"message": "Ajouter Vue Router pour le développement d'applications _single page_\u00a0?"
},
"needsPinia": {
"message": "Ajouter Pinia pour la gestion de l'état\u00a0?"
},
"needsVitest": {
"message": "Ajouter Vitest pour les tests unitaires\u00a0?"
},
"needsE2eTesting": {
"message": "Ajouter une solution de test de bout en bout (e2e)\u00a0?",
"hint": "- Utilisez les flèches et appuyez sur la touche Entrée pour valider",
"selectOptions": {
"negative": { "title": "Non" },
"cypress": {
"title": "Cypress",
"desc": "prend également en charge les tests unitaires avec Cypress Component Testing"
},
"nightwatch": {
"title": "Nightwatch",
"desc": "prend également en charge les tests unitaires avec Nightwatch Component Testing"
},
"playwright": { "title": "Playwright" }
}
},
"needsEslint": {
"message": "Ajouter ESLint pour la qualité du code\u00a0?"
},
"needsPrettier": {
"message": "Ajouter Prettier pour le formatage du code\u00a0?"
},
"errors": {
"operationCancelled": "Operation annulée"
},
"defaultToggleOptions": {
"active": "Oui",
"inactive": "Non"
},
"infos": {
"scaffolding": "Génération du projet dans",
"done": "Terminé. Exécutez maintenant\u00a0:"
}
}
Loading