child_process#execFileSync TypeScript Examples
The following examples show how to use
child_process#execFileSync.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: spFormat.ts From sourcepawn-vscode with MIT License | 6 votes |
spawnClangFormat(args, stdio) {
let nativeBinary;
try {
nativeBinary = this.getNativeBinary();
} catch (e) {
return undefined;
}
try {
let clangFormatProcess = execFileSync(nativeBinary, args);
return clangFormatProcess.toString();
} catch (e) {
console.error("Error", e);
return undefined;
}
}
Example #2
Source File: brew.ts From setup-cpp with Apache License 2.0 | 6 votes |
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupBrew(_version: string, _setupDir: string, _arch: string) {
if (!["darwin", "linux"].includes(process.platform)) {
return undefined
}
if (typeof binDir === "string") {
return { binDir }
}
const maybeBinDir = which.sync("brew", { nothrow: true })
if (maybeBinDir !== null) {
binDir = dirname(maybeBinDir)
return { binDir }
}
// brew is not thread-safe
execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, {
stdio: "inherit",
})
binDir = "/usr/local/bin/"
return { binDir }
}
Example #3
Source File: windowsExecutableCodeSignatureVerifier.ts From electron-differential-updater with MIT License | 6 votes |
function handleError(logger: Logger, error: Error | null, stderr: string | null): void {
if (isOldWin6()) {
logger.warn(`Cannot execute Get-AuthenticodeSignature: ${error || stderr}. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.`)
return
}
try {
execFileSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "ConvertTo-Json test"], {timeout: 10 * 1000})
}
catch (testError) {
logger.warn(`Cannot execute ConvertTo-Json: ${testError.message}. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.`)
return
}
if (error != null) {
throw error
}
if (stderr) {
logger.warn(`Cannot execute Get-AuthenticodeSignature, stderr: ${stderr}. Ignoring signature validation due to unknown stderr.`)
return
}
}
Example #4
Source File: sudo.ts From mysterium-vpn-desktop with MIT License | 6 votes |
catalinaSudoExec = (cmd: string) => {
execFileSync("sudo", ["--askpass", "sh", "-c", cmd], {
encoding: "utf8",
env: {
PATH: process.env.PATH,
SUDO_ASKPASS: staticAssetPath("sudo-askpass.osascript.js"),
},
})
}
Example #5
Source File: make-monthly-stat.ts From merged-pr-stat with MIT License | 6 votes |
async function main(): Promise<void> {
program.requiredOption("--start <yyyy/MM>").requiredOption("--end <yyyy/MM>").requiredOption("--query <query>");
program.parse(process.argv);
const startDate = parse(program.start, "yyyy/MM", new Date());
const endDate = parse(program.end, "yyyy/MM", new Date());
const query = program.query as string;
const allStats = [];
for (let start = startDate; start <= endDate; start = addMonths(start, 1)) {
const end = add(start, { months: 1, seconds: -1 });
console.error(format(start, "yyyy-MM-dd HH:mm:ss"));
console.error(format(end, "yyyy-MM-dd HH:mm:ss"));
const stdout = execFileSync(
"merged-pr-stat",
["--start", start.toISOString(), "--end", end.toISOString(), "--query", query],
{ encoding: "utf8" }
);
const result = {
startDate: format(start, "yyyy-MM-dd HH:mm:ss"),
endDate: format(end, "yyyy-MM-dd HH:mm:ss"),
...JSON.parse(stdout),
};
allStats.push(result);
}
process.stdout.write(csvStringify(allStats, { header: true }));
}
Example #6
Source File: make-rotate-stat-on-interval-days-basis.ts From merged-pr-stat with MIT License | 6 votes |
// Make stat between (<date> - <aggregationDays>) and <date>
// and move aggregation period by <intervalDays>.
async function main(): Promise<void> {
program
.requiredOption("--start <date>")
.requiredOption("--end <date>")
.requiredOption("--interval-days <days>")
.requiredOption("--aggregation-days <days>")
.requiredOption("--query <query>");
program.parse(process.argv);
const startDate = parseISO(program.start);
const endDate = parseISO(program.end);
const query = program.query as string;
const intervalDays = parseInt(program.intervalDays);
const aggregationDays = parseInt(program.aggregationDays);
const allStats = [];
for (let start = startDate; start < endDate; start = addDays(start, intervalDays)) {
const aggregateFrom = add(start, { days: -aggregationDays });
const aggregateTo = start;
console.error(format(aggregateFrom, "yyyy-MM-dd HH:mm:ss"));
console.error(format(aggregateTo, "yyyy-MM-dd HH:mm:ss"));
const stdout = execFileSync(
"merged-pr-stat",
["--start", aggregateFrom.toISOString(), "--end", aggregateTo.toISOString(), "--query", query],
{ encoding: "utf8" }
);
const result = {
startDate: format(aggregateFrom, "yyyy-MM-dd HH:mm:ss"),
endDate: format(aggregateTo, "yyyy-MM-dd HH:mm:ss"),
...JSON.parse(stdout),
};
allStats.push(result);
}
process.stdout.write(csvStringify(allStats, { header: true }));
}
Example #7
Source File: make-stat-on-interval-days-basis.ts From merged-pr-stat with MIT License | 6 votes |
async function main(): Promise<void> {
program
.requiredOption("--start <date>")
.requiredOption("--end <date>")
.requiredOption("--interval-days <days>")
.requiredOption("--query <query>");
program.parse(process.argv);
const startDate = parseISO(program.start);
const endDate = parseISO(program.end);
const query = program.query as string;
const intervalDays = parseInt(program.intervalDays);
const allStats = [];
for (let start = startDate; start < endDate; start = addDays(start, intervalDays)) {
const end = add(start, { days: intervalDays, seconds: -1 });
console.error(format(start, "yyyy-MM-dd HH:mm:ss"));
console.error(format(end, "yyyy-MM-dd HH:mm:ss"));
const stdout = execFileSync(
"merged-pr-stat",
["--start", start.toISOString(), "--end", end.toISOString(), "--query", query],
{ encoding: "utf8" }
);
const result = {
startDate: format(start, "yyyy-MM-dd HH:mm:ss"),
endDate: format(end, "yyyy-MM-dd HH:mm:ss"),
...JSON.parse(stdout),
};
allStats.push(result);
}
process.stdout.write(csvStringify(allStats, { header: true }));
}
Example #8
Source File: website-generator.ts From editor with MIT License | 6 votes |
(async function () {
// compile public code
execFileSync("tsc", ["--project", "./tsconfig.website-generator.json"], {
cwd: path.join(__dirname, "..")
});
const index = {
html: createHTMLTemplate()
};
fs.writeFileSync(path.join(outputDir, "index.html"), index.html, "utf-8");
})().catch((error) => {
console.error(error.message);
console.error(String(error.output));
process.exit(1);
});
Example #9
Source File: command.ts From flatpak-vscode with MIT License | 5 votes |
execSync(): Buffer {
return execFileSync(this.program, this.args, {
cwd: this.cwd
})
}
Example #10
Source File: AppImageUpdater.ts From electron-differential-updater with MIT License | 5 votes |
protected doInstall(options: InstallOptions): boolean {
const appImageFile = process.env.APPIMAGE!!
if (appImageFile == null) {
throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND")
}
// https://stackoverflow.com/a/1712051/1910191
unlinkSync(appImageFile)
let destination: string
const existingBaseName = path.basename(appImageFile)
// https://github.com/electron-userland/electron-builder/issues/2964
// if no version in existing file name, it means that user wants to preserve current custom name
if (path.basename(options.installerPath) === existingBaseName || !/\d+\.\d+\.\d+/.test(existingBaseName)) {
// no version in the file name, overwrite existing
destination = appImageFile
}
else {
destination = path.join(path.dirname(appImageFile), path.basename(options.installerPath))
}
execFileSync("mv", ["-f", options.installerPath, destination])
const env: any = {
...process.env,
APPIMAGE_SILENT_INSTALL: "true",
}
if (options.isForceRunAfter) {
spawn(destination, [], {
detached: true,
stdio: "ignore",
env,
})
.unref()
}
else {
env.APPIMAGE_EXIT_AFTER_INSTALL = "true"
execFileSync(destination, [], {env})
}
return true
}
Example #11
Source File: make-long-term-log.ts From merged-pr-stat with MIT License | 5 votes |
async function main(): Promise<void> {
program.requiredOption("--start <date>").requiredOption("--end <date>").requiredOption("--query <query>");
program.parse(process.argv);
const startDate = parseISO(program.start);
const endDate = parseISO(program.end);
const query = program.query as string;
const intervalDays = 7;
const allLogs = [];
process.stdout.write(
"title,author,url,createdAt,mergedAt,additions,deletions,authoredDate,leadTimeSeconds,timeToMergeSeconds\n"
);
for (let start = startDate; start < endDate; start = addDays(start, intervalDays)) {
const end = min([add(start, { days: intervalDays, seconds: -1 }), endDate]);
console.error(format(start, "yyyy-MM-dd HH:mm:ss"));
console.error(format(end, "yyyy-MM-dd HH:mm:ss"));
const stdout = execFileSync(
"merged-pr-stat",
["log", "--start", start.toISOString(), "--end", end.toISOString(), "--query", query],
{ encoding: "utf8" }
);
const logs: any[] = JSON.parse(stdout);
process.stdout.write(
csvStringify(
logs.map((l) => [
l.title,
l.author,
l.url,
l.createdAt,
l.mergedAt,
l.additions,
l.deletions,
l.authoredDate,
l.leadTimeSeconds,
l.timeToMergeSeconds,
])
)
);
}
}
Example #12
Source File: run-on-blame.ts From action-php-codesniffer with MIT License | 5 votes |
export async function runOnBlame(files: string[]): Promise<void> {
try {
const options: Record<string, string> = {};
const standard = core.getInput('standard');
if (standard) options.standard = standard;
const lintResults = await lint(
files,
core.getInput('phpcs_path', { required: true })
);
const dontFailOnWarning =
core.getInput('fail_on_warnings') == 'false' ||
core.getInput('fail_on_warnings') === 'off';
if (!lintResults.totals.errors) {
if (dontFailOnWarning) return;
if (!lintResults.totals.warnings) return;
}
// blame files and output relevant errors
const payload = github.context
.payload as Webhooks.WebhookPayloadPullRequest;
// get email of author of first commit in PR
const authorEmail = execFileSync(
'git',
['--no-pager', 'log', '--format=%ae', `${github.context.sha}^!`],
{ encoding: 'utf8', windowsHide: true, timeout: 5000 }
).trim();
console.log('PR author email: %s', authorEmail);
for (const [file, results] of Object.entries(lintResults.files)) {
const blameMap = await blame(file);
let headerPrinted = false;
for (const message of results.messages) {
if (blameMap.get(message.line)?.authorMail === authorEmail) {
// that's our line
// we simulate checkstyle output to be picked up by problem matched
if (!headerPrinted) {
console.log(`<file name="${path.relative(process.cwd(), file)}">`);
headerPrinted = true;
}
// output the problem
console.log(
'<error line="%d" column="%d" severity="%s" message="%s" source="%s"/>',
message.line,
message.column,
message.type.toLowerCase(),
message.message,
message.source
);
// fail
if (message.type === 'WARNING' && !dontFailOnWarning)
core.setFailed(message.message);
else if (message.type === 'ERROR') core.setFailed(message.message);
}
}
}
} catch (err) {
core.debug(err);
core.setFailed(err);
}
}