X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/honkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"resolve": "^1.17.0",
"semver": "^5.1.0",
"send": "^0.17.1",
"spawn-cmd": "0.0.2",
"tiny-lr": "^1.1.1",
"tmp": "0.0.28",
"try-resolve": "^1.0.1",
Expand Down
44 changes: 3 additions & 41 deletions packages/honkit/src/utils/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import is from "is";
import childProcess from "child_process";

import { spawn } from "spawn-cmd";
import Promise from "./promise";

/**
Expand All @@ -11,15 +9,15 @@ import Promise from "./promise";
@param {Object} options
@return {Promise}
*/
function exec(command, options) {
function exec(command: string, options: { encoding?: "buffer" } & childProcess.ExecOptions) {
const d = Promise.defer();

const child = childProcess.exec(command, options, (err, stdout, stderr) => {
if (!err) {
return d.resolve();
}

err.message = stdout.toString("utf8") + stderr.toString("utf8");
err.message = stdout.toString() + stderr.toString();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString does not require argument

d.reject(err);
});

Expand All @@ -34,48 +32,13 @@ function exec(command, options) {
return d.promise;
}

/**
Spawn an executable

@param {string} command
@param {Array} args
@param {Object} options
@return {Promise}
*/
function spawnCmd(command, args, options) {
const d = Promise.defer();
const child = spawn(command, args, options);

child.on("error", (error) => {
return d.reject(error);
});

child.stdout.on("data", (data) => {
d.notify(data);
});

child.stderr.on("data", (data) => {
d.notify(data);
});

child.on("close", (code) => {
if (code === 0) {
d.resolve();
} else {
d.reject(new Error(`Error with command "${command}"`));
}
});

return d.promise;
}

/**
Transform an option object to a command line string

@param {String|number} value
@param {string}
*/
function escapeShellArg(value) {
function escapeShellArg(value: string) {
if (is.number(value)) {
return value;
}
Expand Down Expand Up @@ -114,6 +77,5 @@ function optionsToShellArgs(options) {

export default {
exec: exec,
spawn: spawnCmd,
optionsToShellArgs: optionsToShellArgs,
};
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9520,11 +9520,6 @@ source-map@^0.7.3:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==

spawn-cmd@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/spawn-cmd/-/spawn-cmd-0.0.2.tgz#6d5e251fad0eab00b0f193d245669a7a228ec0de"
integrity sha1-bV4lH60OqwCw8ZPSRWaaeiKOwN4=

spdx-correct@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.1.tgz#dece81ac9c1e6713e5f7d1b6f17d468fa53d89a9"
Expand Down
X Tutup