All files utils.ts

90.47% Statements 19/21
78.57% Branches 11/14
100% Functions 1/1
90.47% Lines 19/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89          3x                             3x 1x 1x   2x 2x 1x 1x   1x 1x 1x 1x 1x           1x 1x 1x 1x                                       1x                 1x                                  
import minimist from 'minimist';
import { create } from 'create-kkt';
import path from 'path';
import fs from 'fs-extra';
export async function run(): Promise<void> {
  const argvs = minimist(process.argv.slice(2), {
    alias: {
      output: 'o',
      version: 'v',
      force: 'f',
      path: 'p',
      example: 'e',
    },
    default: {
      path: 'https://antdpro.github.io/antdp/zip/',
      output: '.',
      force: false,
      example: 'basic',
    },
  });
  if (argvs.h || argvs.help) {
    console.log(helpCli);
    return;
  }
  const { version } = require('../package.json');
  if (argvs.v || argvs.version) {
    console.log(`\n create-antdp v${version}\n`);
    return;
  }
  argvs.appName = argvs._[0];
  argvs.example = argvs.e = String(argvs.example).toLocaleLowerCase();
  try {
    await create(argvs, helpExample);
    const pkgPath = path.join(
      process.cwd(),
      argvs.output,
      argvs.appName,
      'package.json',
    );
    Eif (fs.existsSync(pkgPath)) {
      const pkg = require(pkgPath);
      Eif (pkg.version) {
        await fs.writeJSON(
          pkgPath,
          {
            ...pkg,
            name: argvs.appName || pkg.name,
            version: '1.0.0',
            scripts: { ...pkg.scripts },
          },
          { spaces: '  ' },
        );
      }
    }
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
 
  // umiinstall
}
 
export const helpExample: string = `Example:
 
    \x1b[35myarn\x1b[0m create antdp \x1b[33mappName\x1b[0m
    \x1b[35mnpx\x1b[0m create-antdp \x1b[33mmy-app\x1b[0m
    \x1b[35mnpm\x1b[0m create antdp \x1b[33mmy-app\x1b[0m
    \x1b[35mnpm\x1b[0m create antdp \x1b[33mmy-app\x1b[0m -f
    \x1b[35mnpm\x1b[0m create antdp \x1b[33mmy-app\x1b[0m -p \x1b[34mhttps://antdpro.github.io/antdp/zip/\x1b[0m
`;
 
export const helpCli: string = `
  Usage: create-antdp <app-name> [options] [--help|h]
 
  Options:
 
    --version, -v   Show version number
    --help, -h      Displays help information.
    --output, -o    Output directory.
    --example, -e   Example from: \x1b[34mhttp://antdpro.github.io/antdp/\x1b[0m, default: "antdp-base"
    --path, -p      Specify the download target git address.
                      default: "\x1b[34mhttp://antdpro.github.io/antdp/\x1b[0m"
  
  ${helpExample}
  
  Copyright 2021
 
`;