From 9d2d3428bc685f302cb304704f188346488297fe Mon Sep 17 00:00:00 2001 From: alqmc Date: Wed, 26 Oct 2022 17:54:18 +0800 Subject: [PATCH] feat: gnrm use can selete package(fix #16) --- .github/ISSUE_TEMPLATE/bug-report.yml | 3 -- .github/ISSUE_TEMPLATE/feature-request.yml | 4 -- dist/gnrm.js | 37 +++++++++++++------ dist/package.json | 2 +- package/commands/gnrm/useUse.ts | 43 +++++++++++++++------- 5 files changed, 57 insertions(+), 32 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index d452983..bbd8213 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -15,8 +15,6 @@ body: ### **Check if the issue is reproducible with the latest stable version.** You can use the command `pnpm view gacm versions` to view it placeholder: latest - validations: - required: true - type: textarea id: reproduce attributes: @@ -24,7 +22,6 @@ body: description: | **After the replay is turned on, what actions do we need to perform to make the bug appear? Simple and clear steps can help us locate the problem more quickly. Please clearly describe the steps of reproducing the issue. Issues without clear reproducing steps will not be repaired. If the issue marked with 'need reproduction' does not provide relevant steps within 7 days, it will be closed directly.** placeholder: Please Input - validations: - type: textarea id: expected attributes: diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml index a2fab4d..ed9d196 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yml +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -10,8 +10,6 @@ body: description: | Explain your use case, context, and rationale behind this feature request. More importantly, what is the end user experience you are trying to build that led to the need for this feature? placeholder: Please Input - validations: - required: true - type: textarea id: feature-api attributes: @@ -19,5 +17,3 @@ body: description: | Describe how you propose to solve the problem and provide code samples of how the API would work once implemented. Note that you can use Markdown to format your code blocks. placeholder: Please Input - validations: - required: true diff --git a/dist/gnrm.js b/dist/gnrm.js index d0caad7..8655b6f 100755 --- a/dist/gnrm.js +++ b/dist/gnrm.js @@ -317,26 +317,42 @@ const useLs = async (cmd) => { printMessages(messages); }; +const defaultPackageManager = ["npm", "yarn", "npm", "pnpm"]; const useUse = async ([name], cmd) => { const userConfig = await getFileUser(registriesPath); let registrylist = defaultNpmMirror; + let packageManager = "npm"; if (userConfig && userConfig.registry) registrylist = userConfig.registry; let useRegistry = void 0; if (name) { useRegistry = registrylist.find((x) => x.alias === name); } else { - const { registry } = await prompts__default["default"]({ - type: "select", - name: "registry", - message: "Pick a registry", - choices: registrylist.map((x) => { - return { - title: `${x.alias}${x.alias === x.name ? "" : `(${x.name})`} ${x.registry}`, + const { registry, pkg } = await prompts__default["default"]([ + { + type: "select", + name: "registry", + message: "Pick a registry", + choices: registrylist.map((x) => { + return { + title: `${x.alias}${x.alias === x.name ? "" : `(${x.name})`} ${x.registry}`, + value: x + }; + }) + }, + { + type: "select", + name: "pkg", + message: "Pick a packageManager,and you will set registry for it", + initial: 0, + choices: defaultPackageManager.map((x) => ({ + title: x, value: x - }; - }) - }); + })) + } + ]); + if (pkg) + packageManager = pkg; if (!registry) { log.error(`user cancel operation`); return; @@ -345,7 +361,6 @@ const useUse = async ([name], cmd) => { } if (!useRegistry) return log.error(`${name} not found`); - let packageManager = "npm"; if (cmd.packageManager) packageManager = cmd.packageManager; await execCommand(packageManager, [ diff --git a/dist/package.json b/dist/package.json index 334a2d2..ea71692 100644 --- a/dist/package.json +++ b/dist/package.json @@ -23,4 +23,4 @@ "kolorist": "^1.5.1", "prompts": "^2.4.2" } -} \ No newline at end of file +} diff --git a/package/commands/gnrm/useUse.ts b/package/commands/gnrm/useUse.ts index ce16a2a..5ffe495 100644 --- a/package/commands/gnrm/useUse.ts +++ b/package/commands/gnrm/useUse.ts @@ -6,28 +6,46 @@ import { log } from '../../utils/log'; import { execCommand } from '../../utils/shell'; import type { NrmCmd, RegistryInfo } from '../../type/shell.type'; +const defaultPackageManager = ['npm', 'yarn', 'npm', 'pnpm']; + export const useUse = async ([name]: string[], cmd: NrmCmd) => { const userConfig = await getFileUser(registriesPath); let registrylist = defaultNpmMirror; + let packageManager = 'npm'; if (userConfig && userConfig.registry) registrylist = userConfig.registry; let useRegistry: RegistryInfo | undefined = undefined; if (name) { useRegistry = registrylist.find((x) => x.alias === name); } else { - const { registry } = await prompts({ - type: 'select', - name: 'registry', - message: 'Pick a registry', - choices: registrylist.map((x) => { - return { - title: `${x.alias}${x.alias === x.name ? '' : `(${x.name})`} ${ - x.registry - }`, + const { registry, pkg } = await prompts([ + { + type: 'select', + name: 'registry', + message: 'Pick a registry', + choices: registrylist.map((x) => { + return { + title: `${x.alias}${x.alias === x.name ? '' : `(${x.name})`} ${ + x.registry + }`, + value: x, + }; + }), + }, + { + type: 'select', + name: 'pkg', + message: 'Pick a packageManager,and you will set registry for it', + initial: 0, + choices: defaultPackageManager.map((x) => ({ + title: x, value: x, - }; - }), - }); + })), + }, + ]); + + if (pkg) packageManager = pkg; + if (!registry) { log.error(`user cancel operation`); return; @@ -36,7 +54,6 @@ export const useUse = async ([name]: string[], cmd: NrmCmd) => { } if (!useRegistry) return log.error(`${name} not found`); - let packageManager = 'npm'; if (cmd.packageManager) packageManager = cmd.packageManager; await execCommand(packageManager, [