diff --git a/.prettierrc.yaml b/.prettierrc.yaml index 9462811c..7e6eca36 100644 --- a/.prettierrc.yaml +++ b/.prettierrc.yaml @@ -2,7 +2,7 @@ printWidth: 110 tabWidth: 2 useTabs: false endOfLine: lf -semi: false +semi: true singleQuote: true quoteProps: 'consistent' jsxSingleQuote: false diff --git a/index.js b/index.js index e797c2ef..f173de45 100644 --- a/index.js +++ b/index.js @@ -1,53 +1,55 @@ -'use strict' +'use strict'; -const core = require('@actions/core') -const path = require('path') -const http = require('https') -const fs = require('fs') +const core = require('@actions/core'); +const path = require('path'); +const http = require('https'); +const fs = require('fs'); -const config = require('./src/config') -const { notBlankOrElse } = require('./src/utils') +const config = require('./src/config'); +const { notBlankOrElse } = require('./src/utils'); async function createSnapshot(url, filePath, fileName, fileExtension) { try { - const imagePath = path.join(filePath, `${fileName}.${fileExtension}`) - console.log(`Generating screenshot with parameters: url=${url}, file=${imagePath}\n`) + const imagePath = path.join(filePath, `${fileName}.${fileExtension}`); + console.log(` + Generating screenshot with parameters: url=${url}, file=${imagePath} + `); if (!fs.existsSync(filePath)) { - fs.mkdirSync(filePath) + fs.mkdirSync(filePath); } - const image = fs.createWriteStream(imagePath) + const image = fs.createWriteStream(imagePath); await http.get(url, resp => { - resp.pipe(image) - }) + resp.pipe(image); + }); - return imagePath + return imagePath; } catch (e) { - console.error(e) + console.error(e); } } async function run() { - const url = 'https://www.brainyquote.com/quote_of_the_day' //score.getInput('url'); - const width = 400 //notBlankOrElse(core.getInput('width'), config.width); - const height = 400 //notBlankOrElse(core.getInput('height'), config.height); - const fullPage = notBlankOrElse(core.getInput('fullPage'), config.fullPage) - const encoding = notBlankOrElse(core.getInput('encoding'), config.encoding) + const url = core.getInput('url'); + const width = notBlankOrElse(core.getInput('width'), config.width); + const height = notBlankOrElse(core.getInput('height'), config.height); + const fullPage = notBlankOrElse(core.getInput('fullPage'), config.fullPage); + const encoding = notBlankOrElse(core.getInput('encoding'), config.encoding); - const fileName = notBlankOrElse(core.getInput('name'), config.name) - const filePath = notBlankOrElse(core.getInput('path'), config.path) - const fileExtension = notBlankOrElse(core.getInput('type'), config.type) + const fileName = notBlankOrElse(core.getInput('name'), config.name); + const filePath = notBlankOrElse(core.getInput('path'), config.path); + const fileExtension = notBlankOrElse(core.getInput('type'), config.type); - const target = `${config.url}?url=${url}&width=${width}&height=${height}&fullPage=${fullPage}&encoding=${encoding}&type=${fileExtension}` + const target = `${config.url}?url=${url}&width=${width}&height=${height}&fullPage=${fullPage}&encoding=${encoding}&type=${fileExtension}`; - const imagePath = await createSnapshot(target, filePath, fileName, fileExtension) + const imagePath = await createSnapshot(target, filePath, fileName, fileExtension); - core.setOutput('image', imagePath) + core.setOutput('image', imagePath); } -module.exports = run +module.exports = run; if (require.main === module) { - run() + run(); } diff --git a/jest.config.js b/jest.config.js index 0f9a824a..e98e222f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -30,4 +30,4 @@ module.exports = { }, coverageDirectory: './coverage', coverageReporters: ['json', 'lcov', 'text', 'clover', 'html'], -} +}; diff --git a/src/config.js b/src/config.js index c4e0eb24..d895e108 100644 --- a/src/config.js +++ b/src/config.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; const CONFIG = { url: 'https://styled-screenshots.vercel.app/api', @@ -9,6 +9,6 @@ const CONFIG = { fullPage: false, width: 1024, height: 768, -} +}; -module.exports = CONFIG +module.exports = CONFIG; diff --git a/src/utils.js b/src/utils.js index ef7d74e2..76a51d2d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,37 +1,37 @@ -'use strict' +'use strict'; const createOptions = (width, height) => { return { shotSize: { width, height }, windowSize: { width, height }, - } -} + }; +}; const isNonEmptyString = str => { - return str && str.length > 0 -} + return str && str.length > 0; +}; const isBlankString = str => { - return !str || /^\s*$/.test(str) -} + return !str || /^\s*$/.test(str); +}; const notBlankOrElse = (str, defaultValue) => { - return isBlankString(str) ? defaultValue : str -} + return isBlankString(str) ? defaultValue : str; +}; const toFormatString = obj => { - return `(${objToString(obj)})` -} + return `(${objToString(obj)})`; +}; const objToString = obj => { - let str = '' + let str = ''; for (const p in obj) { if (Object.prototype.hasOwnProperty.call(obj, p)) { - str += `${p} => ${typeof obj[p] === 'object' ? `[${objToString(obj[p])}]` : `${+obj[p]},`}` + str += `${p} => ${typeof obj[p] === 'object' ? `[${objToString(obj[p])}]` : `${+obj[p]},`}`; } } - return str -} + return str; +}; module.exports = { createOptions, @@ -39,4 +39,4 @@ module.exports = { isNonEmptyString, isBlankString, notBlankOrElse, -} +}; diff --git a/wallaby.js b/wallaby.js index 1dc1ebae..f0f7fa26 100644 --- a/wallaby.js +++ b/wallaby.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; module.exports = wallaby => ({ files: [ @@ -20,4 +20,4 @@ module.exports = wallaby => ({ }, testFramework: 'jest', -}) +});