Skip to content

Commit e1b4834

Browse files
committed
refactor: Remove ShellJS, colors
1 parent 5ffe73d commit e1b4834

File tree

3 files changed

+30
-90
lines changed

3 files changed

+30
-90
lines changed

package-lock.json

Lines changed: 14 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
"node": ">= 10.8.0"
2121
},
2222
"dependencies": {
23-
"colors": "^1.4.0",
2423
"handlebars": "^4.7.7",
2524
"lodash": "^4.17.21",
2625
"lunr": "^2.3.9",
2726
"marked": "^2.0.3",
2827
"minimatch": "^3.0.0",
2928
"progress": "^2.0.3",
30-
"shelljs": "^0.8.4",
3129
"shiki": "^0.9.3",
3230
"typedoc-default-themes": "^0.12.10"
3331
},
@@ -42,7 +40,6 @@
4240
"@types/mocha": "^8.2.2",
4341
"@types/mockery": "^1.4.29",
4442
"@types/node": "^15.0.1",
45-
"@types/shelljs": "^0.8.8",
4643
"@typescript-eslint/eslint-plugin": "^4.22.0",
4744
"@typescript-eslint/parser": "^4.22.0",
4845
"eslint": "^7.25.0",

src/lib/converter/plugins/GitHubPlugin.ts

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import * as ShellJS from "shelljs";
21
import * as Path from "path";
2+
import { spawnSync } from "child_process";
33

4-
import { SourceReference } from "../../models/sources/file";
4+
import type { SourceReference } from "../../models/sources/file";
55
import { Component, ConverterComponent } from "../components";
66
import { BasePath } from "../utils/base-path";
77
import { Converter } from "../converter";
8-
import { Context } from "../context";
8+
import type { Context } from "../context";
99
import { BindOption } from "../../utils";
1010

11+
function git(...args: string[]) {
12+
return spawnSync("git", args, { encoding: "utf-8", windowsHide: true });
13+
}
14+
1115
/**
1216
* Stores data of a repository.
1317
*/
@@ -55,7 +59,6 @@ export class Repository {
5559
constructor(path: string, gitRevision: string, repoLinks: string[]) {
5660
this.path = path;
5761
this.branch = gitRevision || "master";
58-
ShellJS.pushd(path);
5962

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

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

9091
if (!gitRevision) {
91-
out = <ShellJS.ExecOutputReturnValue>(
92-
ShellJS.exec("git rev-parse --short HEAD", { silent: true })
93-
);
94-
if (out.code === 0) {
92+
out = git("-C", path, "rev-parse", "--short", "HEAD");
93+
if (out.status === 0) {
9594
this.branch = out.stdout.replace("\n", "");
9695
}
9796
}
98-
99-
ShellJS.popd();
10097
}
10198

10299
/**
@@ -148,31 +145,17 @@ export class Repository {
148145
gitRevision: string,
149146
gitRemote: string
150147
): Repository | undefined {
151-
ShellJS.pushd(path);
152-
const out = <ShellJS.ExecOutputReturnValue>(
153-
ShellJS.exec("git rev-parse --show-toplevel", { silent: true })
154-
);
155-
const remotesOutput = <ShellJS.ExecOutputReturnValue>(
156-
ShellJS.exec(`git remote get-url ${gitRemote}`, { silent: true })
157-
);
158-
ShellJS.popd();
148+
const out = git("-C", path, "rev-parse", "--show-toplevel");
149+
const remotesOutput = git("-C", path, "remote", "get-url", gitRemote);
159150

160-
if (
161-
!out ||
162-
out.code !== 0 ||
163-
!remotesOutput ||
164-
remotesOutput.code !== 0
165-
) {
151+
if (out.status !== 0 || remotesOutput.status !== 0) {
166152
return;
167153
}
168154

169-
const remotes: string[] =
170-
remotesOutput.code === 0 ? remotesOutput.stdout.split("\n") : [];
171-
172155
return new Repository(
173156
BasePath.normalize(out.stdout.replace("\n", "")),
174157
gitRevision,
175-
remotes
158+
remotesOutput.stdout.split("\n")
176159
);
177160
}
178161
}
@@ -205,8 +188,7 @@ export class GitHubPlugin extends ConverterComponent {
205188
* @param converter The converter this plugin should be attached to.
206189
*/
207190
initialize() {
208-
ShellJS.config.silent = true;
209-
if (ShellJS.which("git")) {
191+
if (git("--version").status === 0) {
210192
this.listenTo(
211193
this.owner,
212194
Converter.EVENT_RESOLVE_END,

0 commit comments

Comments
 (0)