Skip to content

Commit

Permalink
fix: gnrm test options -r
Browse files Browse the repository at this point in the history
  • Loading branch information
kinfuy committed Mar 22, 2023
1 parent 4e4c132 commit 4ddd7df
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
dist
4 changes: 2 additions & 2 deletions dist/gacm.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ var dependencies = {
cac: "^6.7.14",
execa: "5.1.1",
kolorist: "^1.5.1",
prompts: "^2.4.2",
"node-fetch": "2.6.6"
"node-fetch": "2.6.6",
prompts: "^2.4.2"
};
var pkg = {
name: name,
Expand Down
15 changes: 7 additions & 8 deletions dist/gnrm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var dependencies$1 = {
cac: "^6.7.14",
execa: "5.1.1",
kolorist: "^1.5.1",
prompts: "^2.4.2",
"node-fetch": "2.6.6"
"node-fetch": "2.6.6",
prompts: "^2.4.2"
};
var pkg$1 = {
name: name$1,
Expand Down Expand Up @@ -487,7 +487,6 @@ const testRegistry = async (registry) => {
});
status = response.ok;
} catch (error) {
console.log(error);
isTimeout = error.type === "request-timeout";
}
return {
Expand Down Expand Up @@ -518,8 +517,8 @@ const useTest = async (cmd) => {
await iterator;
return;
}
if (cmd.packageManager) {
const registry2 = registryList.find((x) => x.alias === cmd.packageManager);
if (cmd.registry) {
const registry2 = registryList.find((x) => x.alias === cmd.registry || x.name === cmd.registry);
if (registry2)
await test(registry2);
return;
Expand All @@ -537,14 +536,14 @@ const useTest = async (cmd) => {
})
}
]);
await test(registry.registry);
await test(registry);
};

const program = cac__default["default"]("gnrm");
program.version(useVersion());
program.command("ls", "\u5F53\u524D\u7528\u6237\u5217\u8868").option("-p, --packageManager <packageManager>", "\u67E5\u770B\u5BF9\u5E94\u5305\u7BA1\u7406\u5668\uFF1A\u9ED8\u8BA4npm").action(useLs);
program.command("use [name]", "\u5207\u6362\u955C\u50CF\u6E90").option("-p, --packageManager <packageManager>", "\u8BBE\u7F6E\u5BF9\u5E94\u5305\u7BA1\u7406\u5668\uFF1A\u9ED8\u8BA4npm").action(useUse);
program.command("test", "\u5207\u6362\u955C\u50CF\u6E90").option("-p, --packageManager <packageManager>", "\u6D4B\u8BD5\u5BF9\u5E94\u5305\u7BA1\u7406\u5668\uFF1A\u9ED8\u8BA4npm").option("-a, --all", "\u6D4B\u8BD5\u5B58\u5728\u7684\u955C\u50CF\u6E90").action(useTest);
program.command("use [name]", "\u5207\u6362\u955C\u50CF\u6E90").option("-p, --registry <packageManager>", "\u8BBE\u7F6E\u5BF9\u5E94\u5305\u7BA1\u7406\u5668\uFF1A\u9ED8\u8BA4npm").action(useUse);
program.command("test", "\u5207\u6362\u955C\u50CF\u6E90").option("-r, --registry <registry>", "\u6D4B\u8BD5\u6E90\u540D\u79F0\u6216\u8005\u522B\u540D").option("-a, --all", "\u6D4B\u8BD5\u5B58\u5728\u7684\u955C\u50CF\u6E90").action(useTest);
program.command("add", "\u6DFB\u52A0\u955C\u50CF").option("-n, --name <name>", "\u955C\u50CF\u540D\u79F0").option("-r, --registry <registry>", "\u955C\u50CF\u5730\u5740").option("-a, --alias <alias>", "\u955C\u50CF\u522B\u540D").action(useAdd);
program.command("alias <origin> <target>", "\u955C\u50CF\u6DFB\u52A0\u522B\u540D").action(useAlias);
program.command("delete <name>", "\u5220\u9664\u955C\u50CF").action(useDelete);
Expand Down
6 changes: 3 additions & 3 deletions dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"cac": "^6.7.14",
"execa": "5.1.1",
"kolorist": "^1.5.1",
"prompts": "^2.4.2",
"node-fetch": "2.6.6"
"node-fetch": "2.6.6",
"prompts": "^2.4.2"
}
}
}
8 changes: 3 additions & 5 deletions package/commands/gnrm/useTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const testRegistry = async (registry: string) => {
status = response.ok;
}
catch (error: any) {
// eslint-disable-next-line no-console
console.log(error);
isTimeout = error.type === 'request-timeout';
}
return {
Expand Down Expand Up @@ -55,8 +53,8 @@ export const useTest = async (cmd: TestCmd) => {
return;
}

if (cmd.packageManager) {
const registry = registryList.find(x => x.alias === cmd.packageManager);
if (cmd.registry) {
const registry = registryList.find(x => x.alias === cmd.registry || x.name === cmd.registry);
if (registry)
await test(registry);

Expand All @@ -79,5 +77,5 @@ export const useTest = async (cmd: TestCmd) => {
}
]);

await test(registry.registry);
await test(registry);
};
4 changes: 2 additions & 2 deletions package/gnrm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ program

program
.command('use [name]', '切换镜像源')
.option('-p, --packageManager <packageManager>', '设置对应包管理器:默认npm')
.option('-p, --registry <packageManager>', '设置对应包管理器:默认npm')
.action(useUse);

program
.command('test', '切换镜像源')
.option('-p, --packageManager <packageManager>', '测试对应包管理器:默认npm')
.option('-r, --registry <registry>', '测试源名称或者别名')
.option('-a, --all', '测试存在的镜像源')
.action(useTest);

Expand Down
2 changes: 1 addition & 1 deletion package/type/shell.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface UserOldInfoJson extends Record<string, any> {

export type PackageManagertype = 'pnpm' | 'npm' | 'cnpm' | 'yarn';
export interface NrmCmd {
packageManager: PackageManagertype
registry: string
}

export interface TestCmd extends NrmCmd {
Expand Down

0 comments on commit 4ddd7df

Please sign in to comment.