added prettier tool

This commit is contained in:
Artur Stolear
2020-03-10 11:42:51 +02:00
parent 5c4fb6ec6b
commit 2690f37786
32 changed files with 930 additions and 902 deletions

View File

@@ -1,62 +1,66 @@
import * as fs from "fs";
import * as path from "path";
import * as fs from 'fs'
import * as path from 'path'
import uuidv4 from "uuid";
import uuidv4 from 'uuid'
import * as core from "@actions/core";
import * as exe from "@actions/exec";
import * as io from "@actions/io";
import * as toolCache from "@actions/tool-cache";
import * as core from '@actions/core'
import * as exe from '@actions/exec'
import * as io from '@actions/io'
import * as toolCache from '@actions/tool-cache'
import { injectable } from "inversify";
import {injectable} from 'inversify'
import { IBuildAgent, IExecResult } from "../../core/models";
import {IBuildAgent, IExecResult} from '../../core/models'
@injectable()
class BuildAgent implements IBuildAgent {
public get agentName(): string {
return "GitHub Actions";
return 'GitHub Actions'
}
public find(toolName: string, versionSpec: string, arch?: string): string {
return toolCache.find(toolName, versionSpec, arch);
return toolCache.find(toolName, versionSpec, arch)
}
public cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string> {
return toolCache.cacheDir(sourceDir, tool, version, arch);
public cacheDir(
sourceDir: string,
tool: string,
version: string,
arch?: string
): Promise<string> {
return toolCache.cacheDir(sourceDir, tool, version, arch)
}
public async createTempDir(): Promise<string> {
const IS_WINDOWS = process.platform === "win32";
const IS_WINDOWS = process.platform === 'win32'
let tempDirectory: string = process.env.RUNNER_TEMP || "";
let tempDirectory: string = process.env.RUNNER_TEMP || ''
if (!tempDirectory) {
let baseLocation: string;
let baseLocation: string
if (IS_WINDOWS) {
// On Windows use the USERPROFILE env variable
baseLocation = process.env.USERPROFILE || "C:\\";
baseLocation = process.env.USERPROFILE || 'C:\\'
} else {
if (process.platform === "darwin") {
baseLocation = "/Users";
if (process.platform === 'darwin') {
baseLocation = '/Users'
} else {
baseLocation = "/home";
baseLocation = '/home'
}
}
tempDirectory = path.join(baseLocation, "actions", "temp");
tempDirectory = path.join(baseLocation, 'actions', 'temp')
}
const dest = path.join(tempDirectory, uuidv4());
await io.mkdirP(dest);
return dest;
const dest = path.join(tempDirectory, uuidv4())
await io.mkdirP(dest)
return dest
}
public debug(message: string): void {
core.debug(message);
core.debug(message)
}
public setFailed(message: string, done?: boolean): void {
core.setFailed(message);
core.setFailed(message)
}
public setSucceeded(message: string, done?: boolean): void {
@@ -64,108 +68,103 @@ class BuildAgent implements IBuildAgent {
}
public exportVariable(name: string, val: string): void {
core.exportVariable(name, val);
core.exportVariable(name, val)
}
public getVariable(name: string): string {
return process.env[name];
return process.env[name]
}
public addPath(inputPath: string): void {
core.addPath(inputPath);
core.addPath(inputPath)
}
public which(tool: string, check?: boolean): Promise<string> {
return io.which(tool, check);
return io.which(tool, check)
}
public async exec(exec: string, args: string[]): Promise<IExecResult> {
const dotnetPath = await io.which(exec, true);
let resultCode = 0;
let stdout = "";
let stderr = "";
resultCode = await exe.exec(
`"${dotnetPath}"`,
args,
{
listeners: {
stderr: (data: Buffer) => {
stderr += data.toString();
},
stdout: (data: Buffer) => {
stdout += data.toString();
},
const dotnetPath = await io.which(exec, true)
let resultCode = 0
let stdout = ''
let stderr = ''
resultCode = await exe.exec(`"${dotnetPath}"`, args, {
listeners: {
stderr: (data: Buffer) => {
stderr += data.toString()
},
});
stdout: (data: Buffer) => {
stdout += data.toString()
}
}
})
return {
code: resultCode,
error: null,
stderr,
stdout,
};
stdout
}
}
public getSourceDir(): string {
return this.getVariable("GITHUB_WORKSPACE");
return this.getVariable('GITHUB_WORKSPACE')
}
public setOutput(name: string, value: string): void {
core.setOutput(name, value);
core.setOutput(name, value)
}
public getInput(input: string, required?: boolean): string {
return core.getInput(input, { required } as core.InputOptions);
return core.getInput(input, {required} as core.InputOptions)
}
public getListInput(input: string, required?: boolean): string[] {
return core
.getInput(input, { required } as core.InputOptions)
.split("\n")
.filter(x => x !== "");
.getInput(input, {required} as core.InputOptions)
.split('\n')
.filter(x => x !== '')
}
public getBooleanInput(input: string, required?: boolean): boolean {
const inputValue = this.getInput(input, required);
return (inputValue || "false").toLowerCase() === "true";
const inputValue = this.getInput(input, required)
return (inputValue || 'false').toLowerCase() === 'true'
}
public isValidInputFile(input: string, file: string): boolean {
return this.filePathSupplied(input) && this.fileExists(file);
return this.filePathSupplied(input) && this.fileExists(file)
}
public filePathSupplied(file: string): boolean {
const pathValue = path.resolve(this.getInput(file) || "");
const repoRoot = this.getSourceDir();
return pathValue !== repoRoot;
const pathValue = path.resolve(this.getInput(file) || '')
const repoRoot = this.getSourceDir()
return pathValue !== repoRoot
}
public fileExists(file: string): boolean {
return this._exist(file) && this._stats(file).isFile();
return this._exist(file) && this._stats(file).isFile()
}
public directoryExists(file: string): boolean {
return this._exist(file) && this._stats(file).isDirectory();
return this._exist(file) && this._stats(file).isDirectory()
}
private _exist(file: string): boolean {
let exist = false;
let exist = false
try {
exist = !!(file && fs.statSync(file) != null);
exist = !!(file && fs.statSync(file) != null)
} catch (err) {
if (err && err.code === "ENOENT") {
exist = false;
if (err && err.code === 'ENOENT') {
exist = false
} else {
throw err;
throw err
}
}
return exist;
return exist
}
private _stats(file: string): fs.Stats {
return fs.statSync(file);
return fs.statSync(file)
}
}
}
export {
BuildAgent,
};
export {BuildAgent}