format: run npm format task

This commit is contained in:
peaceiris 2019-09-21 10:00:59 +09:00
parent 7e7e0130d0
commit 4e3dcc4c49
7 changed files with 52 additions and 52 deletions

View file

@ -1,18 +1,18 @@
import getOS from "../src/get-os";
import getOS from '../src/get-os';
describe("getOS", () => {
test("test", () => {
expect(getOS("linux")).toBe("Linux");
expect(getOS("darwin")).toBe("macOS");
expect(getOS("win32")).toBe("Windows");
describe('getOS', () => {
test('test', () => {
expect(getOS('linux')).toBe('Linux');
expect(getOS('darwin')).toBe('macOS');
expect(getOS('win32')).toBe('Windows');
});
test("test exception", () => {
test('test exception', () => {
// expect(() => {
// getOS("win32");
// }).toThrowError("Windows is not supported");
expect(() => {
getOS("centos");
}).toThrowError("centos is not supported");
getOS('centos');
}).toThrowError('centos is not supported');
});
});

View file

@ -1,17 +1,17 @@
import getURL from "../src/get-url";
import getURL from '../src/get-url';
describe("getURL()", () => {
test("test", () => {
describe('getURL()', () => {
test('test', () => {
const baseURL =
"https://github.com/gohugoio/hugo/releases/download/v0.58.2";
'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
const urlLinux = `${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`;
const urlLinuxExtended = `${baseURL}/hugo_extended_0.58.2_Linux-64bit.tar.gz`;
const urlMacOS = `${baseURL}/hugo_0.58.2_macOS-64bit.tar.gz`;
const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`;
expect(getURL("Linux", "false", "0.58.2")).toBe(urlLinux);
expect(getURL("Linux", "true", "0.58.2")).toBe(urlLinuxExtended);
expect(getURL("macOS", "false", "0.58.2")).toBe(urlMacOS);
expect(getURL("Windows", "false", "0.58.2")).toBe(urlWindows);
expect(getURL('Linux', 'false', '0.58.2')).toBe(urlLinux);
expect(getURL('Linux', 'true', '0.58.2')).toBe(urlLinuxExtended);
expect(getURL('macOS', 'false', '0.58.2')).toBe(urlMacOS);
expect(getURL('Windows', 'false', '0.58.2')).toBe(urlWindows);
});
// test("test exception", () => {

View file

@ -1,10 +1,10 @@
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
export default function getLatestVersion(): Promise<string> {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const url: string = "https://formulae.brew.sh/api/formula/hugo.json";
xhr.open("GET", url);
const url: string = 'https://formulae.brew.sh/api/formula/hugo.json';
xhr.open('GET', url);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {

View file

@ -1,10 +1,10 @@
export default function getOS(platform: string) {
if (platform === "linux") {
return "Linux";
} else if (platform === "darwin") {
return "macOS";
} else if (platform === "win32") {
return "Windows";
if (platform === 'linux') {
return 'Linux';
} else if (platform === 'darwin') {
return 'macOS';
} else if (platform === 'win32') {
return 'Windows';
// throw new Error("Windows is not supported");
} else {
throw new Error(`${platform} is not supported`);

View file

@ -4,27 +4,27 @@ export default function getURL(
version: string
): string {
const extendedStr = (extended: string) => {
if (extended === "true") {
return "extended_";
if (extended === 'true') {
return 'extended_';
} else {
return "";
return '';
// } else {
// throw new Error(`Invalid input (extended): ${extended}`);
}
};
const ext = (os: string) => {
if (os === "Windows") {
return "zip";
if (os === 'Windows') {
return 'zip';
} else {
return "tar.gz";
return 'tar.gz';
}
};
const hugoName: string = `hugo_${extendedStr(
extended
)}${version}_${os}-64bit`;
const baseURL: string = "https://github.com/gohugoio/hugo/releases/download";
const baseURL: string = 'https://github.com/gohugoio/hugo/releases/download';
const url: string = `${baseURL}/v${version}/${hugoName}.${ext(os)}`;
return url;

View file

@ -1,22 +1,22 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import getLatestVersion from "./get-latest-version";
import installer from "./installer";
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import getLatestVersion from './get-latest-version';
import installer from './installer';
// most @actions toolkit packages have async methods
async function run() {
const dump = async () => {
// Show version
await exec.exec("hugo version");
await exec.exec("go version");
await exec.exec("git --version");
await exec.exec('hugo version');
await exec.exec('go version');
await exec.exec('git --version');
};
try {
const hugoVersion: string = core.getInput("hugo-version");
const hugoVersion: string = core.getInput('hugo-version');
console.log(`Hugo version: ${hugoVersion}`);
if (hugoVersion === "" || hugoVersion === "latest") {
if (hugoVersion === '' || hugoVersion === 'latest') {
getLatestVersion().then(
async function(latestVersion): Promise<void> {
await installer(latestVersion);

View file

@ -1,12 +1,12 @@
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import * as io from "@actions/io";
import getOS from "./get-os";
import getURL from "./get-url";
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as io from '@actions/io';
import getOS from './get-os';
import getURL from './get-url';
export default async function installer(version: string) {
try {
const extended: string = core.getInput("extended");
const extended: string = core.getInput('extended');
console.log(`Hugo extended: ${extended}`);
const osName: string = getOS(process.platform);
@ -21,17 +21,17 @@ export default async function installer(version: string) {
// Download and extract Hugo binary
const hugoAssets: string = await tc.downloadTool(hugoURL);
let hugoBin: string = "";
if (osName === "Windows") {
let hugoBin: string = '';
if (osName === 'Windows') {
const hugoExtractedFolder: string = await tc.extractZip(
hugoAssets,
"/tmp"
'/tmp'
);
hugoBin = `${hugoExtractedFolder}/hugo.exe`;
} else {
const hugoExtractedFolder: string = await tc.extractTar(
hugoAssets,
"/tmp"
'/tmp'
);
hugoBin = `${hugoExtractedFolder}/hugo`;
}