Skip to content

Commit

Permalink
feat: gnrm use can selete package(fix #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
alqmc authored and alqmc committed Oct 26, 2022
1 parent 4fa778e commit 9d2d342
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
3 changes: 0 additions & 3 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ 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:
label: Step to reproduce
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:
Expand Down
4 changes: 0 additions & 4 deletions .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ 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:
label: What does the proposed API look like
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
37 changes: 26 additions & 11 deletions dist/gnrm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, [
Expand Down
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"kolorist": "^1.5.1",
"prompts": "^2.4.2"
}
}
}
43 changes: 30 additions & 13 deletions package/commands/gnrm/useUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, [
Expand Down

0 comments on commit 9d2d342

Please sign in to comment.