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", () => { describe('getOS', () => {
test("test", () => { test('test', () => {
expect(getOS("linux")).toBe("Linux"); expect(getOS('linux')).toBe('Linux');
expect(getOS("darwin")).toBe("macOS"); expect(getOS('darwin')).toBe('macOS');
expect(getOS("win32")).toBe("Windows"); expect(getOS('win32')).toBe('Windows');
}); });
test("test exception", () => { test('test exception', () => {
// expect(() => { // expect(() => {
// getOS("win32"); // getOS("win32");
// }).toThrowError("Windows is not supported"); // }).toThrowError("Windows is not supported");
expect(() => { expect(() => {
getOS("centos"); getOS('centos');
}).toThrowError("centos is not supported"); }).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()", () => { describe('getURL()', () => {
test("test", () => { test('test', () => {
const baseURL = 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 urlLinux = `${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`;
const urlLinuxExtended = `${baseURL}/hugo_extended_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 urlMacOS = `${baseURL}/hugo_0.58.2_macOS-64bit.tar.gz`;
const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`; const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`;
expect(getURL("Linux", "false", "0.58.2")).toBe(urlLinux); expect(getURL('Linux', 'false', '0.58.2')).toBe(urlLinux);
expect(getURL("Linux", "true", "0.58.2")).toBe(urlLinuxExtended); expect(getURL('Linux', 'true', '0.58.2')).toBe(urlLinuxExtended);
expect(getURL("macOS", "false", "0.58.2")).toBe(urlMacOS); expect(getURL('macOS', 'false', '0.58.2')).toBe(urlMacOS);
expect(getURL("Windows", "false", "0.58.2")).toBe(urlWindows); expect(getURL('Windows', 'false', '0.58.2')).toBe(urlWindows);
}); });
// test("test exception", () => { // 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> { export default function getLatestVersion(): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
const url: string = "https://formulae.brew.sh/api/formula/hugo.json"; const url: string = 'https://formulae.brew.sh/api/formula/hugo.json';
xhr.open("GET", url); xhr.open('GET', url);
xhr.send(); xhr.send();
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) { if (xhr.readyState === 4 && xhr.status === 200) {

View file

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

View file

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

View file

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

View file

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