Skip to content

Commit

Permalink
chore: refact
Browse files Browse the repository at this point in the history
  • Loading branch information
npmstudy committed Feb 29, 2024
1 parent 50f2634 commit 5b6fa2a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
22 changes: 22 additions & 0 deletions packages/minecat/src/__tests__/cmd/init.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it, vi } from "vitest";
import { getGitInfo } from "../../cmd/init";

describe("cmd/init", () => {
it("should getGitInfo()", () => {
const { userName, repoName } = getGitInfo(
"https://github.com/npmstudy/your-node-v20-monoreopo-project"
);

expect(userName).toBe("npmstudy");
expect(repoName).toBe("your-node-v20-monoreopo-project");
});

it("should getGitInfo()", () => {
const { userName, repoName } = getGitInfo(
"https://github.com/npmstudy/your-node-v20-monoreopo-project"
);

expect(userName).toBe("npmstudy");
expect(repoName).toBe("your-node-v20-monoreopo-project");
});
});
6 changes: 0 additions & 6 deletions packages/minecat/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import * as Index from "../index";
import * as libargs from "libargs";

describe("index", () => {
// it("prompts for the project name if none supplied", () => {
// const { stdout } = run([]);
// console.dir(stdout);
// // expect(stdout).toContain("please check this is a minecat project");
// });

it("should call libargs.cli()", () => {
const spy = vi.spyOn(libargs, "cli");

Expand Down
16 changes: 8 additions & 8 deletions packages/minecat/src/cmd/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function init(cmd) {

const originPkgDir = getOriginPkgDir(url);

//----------
// 以下根据获得的promptInput,来进行clone、目录、git等操作
if (!shell.test("-d", originPkgDir)) {
// 不存在originPkgDir,才可以执行下面的clone逻辑
cloneAndCp(promptInput, url);
Expand Down Expand Up @@ -55,23 +55,23 @@ export async function init(cmd) {
/**
* @param promptInput
*/
function mkdirPkgHome(promptInput) {
export function mkdirPkgHome(promptInput) {
const pkgHome = homedir + `/.minecat/` + promptInput.apptype + "/";
shell.mkdir("-p", pkgHome);
}

/**
* @param url
*/
function getOriginPkgDir(url) {
export function getOriginPkgDir(url) {
const { repoName } = getGitInfo(url);
return process.cwd() + "/" + repoName + "/packages";
}

/**
* @param projectName
*/
async function getParams(projectName) {
export async function getParams(projectName) {
const cfgJson = getConfig();

log(cfgJson);
Expand Down Expand Up @@ -115,7 +115,7 @@ async function getParams(projectName) {
* @param promptInput
* @param url repo url
*/
async function cloneAndCp(response, url) {
export async function cloneAndCp(response, url) {
const pkgHome = homedir + `/.minecat/` + response.apptype + "/";
const { userName, repoName } = getGitInfo(url);
const projectDir = process.cwd() + "/" + repoName;
Expand All @@ -135,7 +135,7 @@ async function cloneAndCp(response, url) {
}

//url = cfgJson[response.apptype]
function getGitInfo(url) {
export function getGitInfo(url) {
const { owner, name } = extractGitHubRepoInfo(url);

let userName = owner;
Expand All @@ -152,7 +152,7 @@ function getGitInfo(url) {
/**
* @param promptInput
*/
function movePkgToCache(promptInput) {
export function movePkgToCache(promptInput) {
const pkgHome = homedir + `/.minecat/` + promptInput.apptype + "/";
const cloneToLocalDir = process.cwd() + "/" + promptInput.newname;

Expand All @@ -169,7 +169,7 @@ function movePkgToCache(promptInput) {
/**
* @param promptInput = response.newname
*/
function resetGitInfo(promptInput) {
export function resetGitInfo(promptInput) {
const cloneToLocalDir = process.cwd() + "/" + promptInput.newname;

// remove .git && git init & git config
Expand Down

0 comments on commit 5b6fa2a

Please sign in to comment.