Skip to content

Commit

Permalink
refactor: Remove ShellJS, colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed May 1, 2021
1 parent 5ffe73d commit e1b4834
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 90 deletions.
67 changes: 14 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -20,14 +20,12 @@
"node": ">= 10.8.0"
},
"dependencies": {
"colors": "^1.4.0",
"handlebars": "^4.7.7",
"lodash": "^4.17.21",
"lunr": "^2.3.9",
"marked": "^2.0.3",
"minimatch": "^3.0.0",
"progress": "^2.0.3",
"shelljs": "^0.8.4",
"shiki": "^0.9.3",
"typedoc-default-themes": "^0.12.10"
},
Expand All @@ -42,7 +40,6 @@
"@types/mocha": "^8.2.2",
"@types/mockery": "^1.4.29",
"@types/node": "^15.0.1",
"@types/shelljs": "^0.8.8",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
Expand Down
50 changes: 16 additions & 34 deletions src/lib/converter/plugins/GitHubPlugin.ts
@@ -1,13 +1,17 @@
import * as ShellJS from "shelljs";
import * as Path from "path";
import { spawnSync } from "child_process";

import { SourceReference } from "../../models/sources/file";
import type { SourceReference } from "../../models/sources/file";
import { Component, ConverterComponent } from "../components";
import { BasePath } from "../utils/base-path";
import { Converter } from "../converter";
import { Context } from "../context";
import type { Context } from "../context";
import { BindOption } from "../../utils";

function git(...args: string[]) {
return spawnSync("git", args, { encoding: "utf-8", windowsHide: true });
}

/**
* Stores data of a repository.
*/
Expand Down Expand Up @@ -55,7 +59,6 @@ export class Repository {
constructor(path: string, gitRevision: string, repoLinks: string[]) {
this.path = path;
this.branch = gitRevision || "master";
ShellJS.pushd(path);

for (let i = 0, c = repoLinks.length; i < c; i++) {
const url = /(github(?:\.[a-z]+)*\.[a-z]{2,})[:/]([^/]+)\/(.*)/.exec(
Expand All @@ -76,10 +79,8 @@ export class Repository {
}
}

let out = <ShellJS.ExecOutputReturnValue>(
ShellJS.exec("git ls-files", { silent: true })
);
if (out.code === 0) {
let out = git("-C", path, "ls-files");
if (out.status === 0) {
out.stdout.split("\n").forEach((file) => {
if (file !== "") {
this.files.push(BasePath.normalize(path + "/" + file));
Expand All @@ -88,15 +89,11 @@ export class Repository {
}

if (!gitRevision) {
out = <ShellJS.ExecOutputReturnValue>(
ShellJS.exec("git rev-parse --short HEAD", { silent: true })
);
if (out.code === 0) {
out = git("-C", path, "rev-parse", "--short", "HEAD");
if (out.status === 0) {
this.branch = out.stdout.replace("\n", "");
}
}

ShellJS.popd();
}

/**
Expand Down Expand Up @@ -148,31 +145,17 @@ export class Repository {
gitRevision: string,
gitRemote: string
): Repository | undefined {
ShellJS.pushd(path);
const out = <ShellJS.ExecOutputReturnValue>(
ShellJS.exec("git rev-parse --show-toplevel", { silent: true })
);
const remotesOutput = <ShellJS.ExecOutputReturnValue>(
ShellJS.exec(`git remote get-url ${gitRemote}`, { silent: true })
);
ShellJS.popd();
const out = git("-C", path, "rev-parse", "--show-toplevel");
const remotesOutput = git("-C", path, "remote", "get-url", gitRemote);

if (
!out ||
out.code !== 0 ||
!remotesOutput ||
remotesOutput.code !== 0
) {
if (out.status !== 0 || remotesOutput.status !== 0) {
return;
}

const remotes: string[] =
remotesOutput.code === 0 ? remotesOutput.stdout.split("\n") : [];

return new Repository(
BasePath.normalize(out.stdout.replace("\n", "")),
gitRevision,
remotes
remotesOutput.stdout.split("\n")
);
}
}
Expand Down Expand Up @@ -205,8 +188,7 @@ export class GitHubPlugin extends ConverterComponent {
* @param converter The converter this plugin should be attached to.
*/
initialize() {
ShellJS.config.silent = true;
if (ShellJS.which("git")) {
if (git("--version").status === 0) {
this.listenTo(
this.owner,
Converter.EVENT_RESOLVE_END,
Expand Down

0 comments on commit e1b4834

Please sign in to comment.