diff --git a/packages/scripts/package.json b/packages/scripts/package.json index 80f833e0..9bd5c810 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -14,15 +14,14 @@ }, "devDependencies": { "@soybeanjs/changelog": "0.3.15", - "@types/prompts": "2.4.9", "bumpp": "9.3.0", "c12": "1.9.0", "cac": "6.7.14", "consola": "3.2.3", + "enquirer": "2.4.1", "execa": "8.0.1", "kolorist": "1.8.0", "npm-check-updates": "16.14.15", - "prompts": "2.4.2", "rimraf": "5.0.5" } } diff --git a/packages/scripts/src/commands/git-commit.ts b/packages/scripts/src/commands/git-commit.ts index 2e1f6095..875ea969 100644 --- a/packages/scripts/src/commands/git-commit.ts +++ b/packages/scripts/src/commands/git-commit.ts @@ -1,10 +1,16 @@ import path from 'node:path'; import { readFileSync } from 'node:fs'; -import prompts from 'prompts'; +import { prompt } from 'enquirer'; import { bgRed, green, red, yellow } from 'kolorist'; import { execCommand } from '../shared'; import type { CliOption } from '../types'; +interface PromptObject { + types: string; + scopes: string; + description: string; +} + /** * Git commit with Conventional Commits standard * @@ -18,20 +24,20 @@ export async function gitCommit( const typesChoices = gitCommitTypes.map(([value, msg]) => { const nameWithSuffix = `${value}:`; - const title = `${nameWithSuffix.padEnd(12)}${msg}`; + const message = `${nameWithSuffix.padEnd(12)}${msg}`; return { - value, - title + name: value, + message }; }); const scopesChoices = gitCommitScopes.map(([value, msg]) => ({ - value, - title: `${value.padEnd(30)} (${msg})` + name: value, + message: `${value.padEnd(30)} (${msg})` })); - const result = await prompts([ + const result = await prompt([ { name: 'types', type: 'select', diff --git a/packages/scripts/src/commands/router.ts b/packages/scripts/src/commands/router.ts index 2b2a7b80..f4075894 100644 --- a/packages/scripts/src/commands/router.ts +++ b/packages/scripts/src/commands/router.ts @@ -2,32 +2,43 @@ import process from 'node:process'; import path from 'node:path'; import { writeFile } from 'node:fs/promises'; import { existsSync, mkdirSync } from 'node:fs'; -import prompts from 'prompts'; +import { prompt } from 'enquirer'; import { green, red } from 'kolorist'; +interface PromptObject { + routeName: string; + addRouteParams: boolean; + routeParams: string; +} + /** generate route */ export async function generateRoute() { - const result = await prompts([ + const result = await prompt([ { - type: 'text', name: 'routeName', + type: 'text', message: 'please enter route name', initial: 'demo-route_child' }, { - type: 'confirm', name: 'addRouteParams', + type: 'confirm', message: 'add route params?', initial: false - }, - { - type: pre => (pre ? 'text' : null), - name: 'routeParams', - message: 'please enter route params', - initial: 'id' } ]); + if (result.addRouteParams) { + const answers = await prompt({ + name: 'routeParams', + type: 'text', + message: 'please enter route params', + initial: 'id' + }); + + Object.assign(result, answers); + } + const PAGE_DIR_NAME_PATTERN = /^[\w-]+[0-9a-zA-Z]+$/; if (!PAGE_DIR_NAME_PATTERN.test(result.routeName)) { @@ -42,7 +53,7 @@ For example: const PARAM_REG = /^\w+$/g; - if (!PARAM_REG.test(result.routeParams)) { + if (result.routeParams && !PARAM_REG.test(result.routeParams)) { throw new Error(red('route params is invalid, it only allow letters, numbers or "_".')); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8fe01f68..9e0dd21f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -214,10 +214,7 @@ importers: devDependencies: '@soybeanjs/changelog': specifier: 0.3.15 - version: 0.3.15(@unocss/eslint-config@0.58.5)(eslint-plugin-vue@9.22.0)(eslint@8.57.0)(typescript@5.3.3)(vue-eslint-parser@9.4.2) - '@types/prompts': - specifier: 2.4.9 - version: 2.4.9 + version: 0.3.15(eslint@8.57.0)(typescript@5.3.3) bumpp: specifier: 9.3.0 version: 9.3.0 @@ -230,6 +227,9 @@ importers: consola: specifier: 3.2.3 version: 3.2.3 + enquirer: + specifier: 2.4.1 + version: 2.4.1 execa: specifier: 8.0.1 version: 8.0.1 @@ -239,9 +239,6 @@ importers: npm-check-updates: specifier: 16.14.15 version: 16.14.15 - prompts: - specifier: 2.4.2 - version: 2.4.2 rimraf: specifier: 5.0.5 version: 5.0.5 @@ -1383,11 +1380,11 @@ packages: engines: {node: '>=14.16'} dev: true - /@soybeanjs/changelog@0.3.15(@unocss/eslint-config@0.58.5)(eslint-plugin-vue@9.22.0)(eslint@8.57.0)(typescript@5.3.3)(vue-eslint-parser@9.4.2): + /@soybeanjs/changelog@0.3.15(eslint@8.57.0)(typescript@5.3.3): resolution: {integrity: sha512-DnRx5MSiOxrwcfdfoAD8WByiKOPMVmI5ABlm8KcAlRHiFw0jDK4IfU0K2PfVba9lK/ZCpzplMcjC7Fn2qqt5Vg==} engines: {node: '>=14'} dependencies: - '@soybeanjs/eslint-config': 1.2.3(@unocss/eslint-config@0.58.5)(eslint-plugin-vue@9.22.0)(eslint@8.57.0)(typescript@5.3.3)(vue-eslint-parser@9.4.2) + '@soybeanjs/eslint-config': 1.2.3(eslint@8.57.0)(typescript@5.3.3) cli-progress: 3.12.0 convert-gitmoji: 0.1.5 dayjs: 1.11.10 @@ -1495,6 +1492,82 @@ packages: - supports-color dev: true + /@soybeanjs/eslint-config@1.2.3(eslint@8.57.0)(typescript@5.3.3): + resolution: {integrity: sha512-OEBHuhpfDZU/DMcku5kQo0fu/42lOQaKstRUZMTZcMbKpQIfQ4I3KhruRrtfAflCBJ35NPeF4mN1LhxumMBKjg==} + peerDependencies: + '@toml-tools/parser': '*' + '@unocss/eslint-config': '>=0.58.0' + eslint: '>=8.40.0' + eslint-plugin-astro: '>=0.30.0' + eslint-plugin-react: '>=7.0.0' + eslint-plugin-react-hooks: '>=4.0.0' + eslint-plugin-react-native: '>=4.0.0' + eslint-plugin-react-refresh: '>=0.4.0' + eslint-plugin-solid: '>=0.10.0' + eslint-plugin-svelte: '>=2.0.0' + eslint-plugin-vue: '>=9.19.0' + prettier-plugin-astro: '>=0.12.0' + prettier-plugin-svelte: '>=3.0.0' + prettier-plugin-toml: '>=2.0.0' + typescript: '>=5.0.0' + vue-eslint-parser: '>=9.3.2' + peerDependenciesMeta: + '@toml-tools/parser': + optional: true + '@unocss/eslint-config': + optional: true + eslint-plugin-astro: + optional: true + eslint-plugin-react: + optional: true + eslint-plugin-react-hooks: + optional: true + eslint-plugin-react-native: + optional: true + eslint-plugin-react-refresh: + optional: true + eslint-plugin-solid: + optional: true + eslint-plugin-svelte: + optional: true + eslint-plugin-vue: + optional: true + prettier-plugin-astro: + optional: true + prettier-plugin-svelte: + optional: true + prettier-plugin-toml: + optional: true + vue-eslint-parser: + optional: true + dependencies: + '@antfu/eslint-define-config': 1.23.0-2 + '@antfu/install-pkg': 0.3.1 + '@eslint/eslintrc': 3.0.2 + '@eslint/js': 8.57.0 + '@typescript-eslint/eslint-plugin': 7.1.0(@typescript-eslint/parser@7.1.0)(eslint@8.57.0)(typescript@5.3.3) + '@typescript-eslint/parser': 7.1.0(eslint@8.57.0)(typescript@5.3.3) + eslint: 8.57.0 + eslint-config-prettier: 9.1.0(eslint@8.57.0) + eslint-parser-plain: 0.1.0 + eslint-plugin-i: 2.29.1(@typescript-eslint/parser@7.1.0)(eslint@8.57.0) + eslint-plugin-n: 16.6.2(eslint@8.57.0) + eslint-plugin-prettier: 5.1.3(eslint-config-prettier@9.1.0)(eslint@8.57.0)(prettier@3.2.5) + eslint-plugin-unicorn: 51.0.1(eslint@8.57.0) + globals: 14.0.0 + local-pkg: 0.5.0 + prettier: 3.2.5 + prettier-plugin-jsdoc: 1.3.0(prettier@3.2.5) + prettier-plugin-json-sort: 0.0.2(prettier@3.2.5) + prompts: 2.4.2 + typescript: 5.3.3 + transitivePeerDependencies: + - '@types/eslint' + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack + - supports-color + dev: true + /@szmarczak/http-timer@5.0.1: resolution: {integrity: sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw==} engines: {node: '>=14.16'} @@ -1587,13 +1660,6 @@ packages: resolution: {integrity: sha512-k7kRA033QNtC+gLc4VPlfnue58CM1iQLgn1IMAU8VPHGOj7oIHPp9UlhedEnD/Gl8evoCjwkZjlBORtZ3JByUA==} dev: true - /@types/prompts@2.4.9: - resolution: {integrity: sha512-qTxFi6Buiu8+50/+3DGIWLHM6QuWsEKugJnnP6iv2Mc4ncxE4A/OJkjuVOA+5X0X1S/nq5VJRa8Lu+nwcvbrKA==} - dependencies: - '@types/node': 20.11.24 - kleur: 3.0.3 - dev: true - /@types/qs@6.9.12: resolution: {integrity: sha512-bZcOkJ6uWrL0Qb2NAWKa7TBU+mJHPzhx9jjLL1KHF+XpzEcR7EXHvjbHlGtR/IsP1vyPrehuS6XqkmaePy//mg==} dev: true @@ -2240,6 +2306,11 @@ packages: string-width: 4.2.3 dev: true + /ansi-colors@4.1.3: + resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} + engines: {node: '>=6'} + dev: true + /ansi-escapes@6.2.0: resolution: {integrity: sha512-kzRaCqXnpzWs+3z5ABPQiVke+iq0KXkHo8xiWV4RPTi5Yli0l97BEQuhXV1s7+aSU/fu1kUuxgS4MsQ0fRuygw==} engines: {node: '>=14.16'} @@ -3352,6 +3423,14 @@ packages: dev: true optional: true + /enquirer@2.4.1: + resolution: {integrity: sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ==} + engines: {node: '>=8.6'} + dependencies: + ansi-colors: 4.1.3 + strip-ansi: 6.0.1 + dev: true + /entities@1.1.2: resolution: {integrity: sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==} dev: true