Skip to content

Commit

Permalink
fix: Fix the display errors of help info.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jan 19, 2021
1 parent 064f748 commit 309a863
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
14 changes: 2 additions & 12 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
#!/usr/bin/env node

import minimist, { ParsedArgs } from 'minimist';
import minimist from 'minimist';
import { create } from './create';

export type Argvs = {
appName?: string;
f?: boolean;
force?: boolean;
e?: string;
example?: string;
p?: string;
path?: string;
} & ParsedArgs;

async function run(): Promise<void> {
try {
const argvs = minimist(process.argv.slice(2));
Expand Down Expand Up @@ -44,7 +34,7 @@ async function run(): Promise<void> {
argvs.path = argvs.p = argvs.path || argvs.p || 'https://kktjs.github.io/zip/';
argvs.force = argvs.f = argvs.force || argvs.f || false;
argvs.example = argvs.e = argvs.example || argvs.e || 'basic';
create(argvs);
create(argvs, exampleHelp);
} catch (error) {
console.log(`\x1b[31m${error.message}\x1b[0m`);
console.log(error);
Expand Down
18 changes: 13 additions & 5 deletions src/create.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import fs from 'fs-extra';
import { ParsedArgs } from 'minimist';
import path from 'path';
import download from 'download';
import ora from 'ora';
import { Argvs, exampleHelp } from './cli';

export type CreateOptions = {} & Argvs;
export type CreateOptions = {
appName?: string;
f?: boolean;
force?: boolean;
e?: string;
example?: string;
p?: string;
path?: string;
} & ParsedArgs;

export async function create(argv: CreateOptions) {
export async function create(argv: CreateOptions, exampleHelp: () => void) {
const spinner = ora('Downloading Example.');
try {
if (!argv.appName || !/^[A-Za-z0-9_\-\.]{1,}$/.test(argv.appName)) {
Expand All @@ -16,13 +24,13 @@ export async function create(argv: CreateOptions) {
` \x1b[31mThe name directory name\x1b[0m \x1b[33m${argv.appName}\x1b[0m \x1b[31mcontains special characters.\x1b[0m`,
);
}
exampleHelp();
exampleHelp && exampleHelp();
console.log(`\n`);
return;
}
if (!argv.path || typeof argv.path !== 'string') {
console.log(`\n Uh oh! \x1b[31mPlease specify download address\x1b[0m.`);
exampleHelp();
exampleHelp && exampleHelp();
console.log(`\n`);
return;
}
Expand Down

0 comments on commit 309a863

Please sign in to comment.