forked from AlexRogalskiy/github-action-screenshots
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added information on documentation
- Loading branch information
ADMSK\AVROGAL1
committed
Feb 16, 2021
1 parent
8e5ffc1
commit 28334a0
Showing
6 changed files
with
53 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
'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, | ||
toString: toFormatString, | ||
isNonEmptyString, | ||
isBlankString, | ||
notBlankOrElse, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters