Skip to content

Commit

Permalink
docs: updates on workflows
Browse files Browse the repository at this point in the history
Added information on documentation
  • Loading branch information
ADMSK\AVROGAL1 committed Feb 16, 2021
1 parent 8e5ffc1 commit 28334a0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ printWidth: 110
tabWidth: 2
useTabs: false
endOfLine: lf
semi: false
semi: true
singleQuote: true
quoteProps: 'consistent'
jsxSingleQuote: false
Expand Down
58 changes: 30 additions & 28 deletions index.js
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();
}
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ module.exports = {
},
coverageDirectory: './coverage',
coverageReporters: ['json', 'lcov', 'text', 'clover', 'html'],
}
};
6 changes: 3 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'
'use strict';

const CONFIG = {
url: 'https://styled-screenshots.vercel.app/api',
Expand All @@ -9,6 +9,6 @@ const CONFIG = {
fullPage: false,
width: 1024,
height: 768,
}
};

module.exports = CONFIG
module.exports = CONFIG;
32 changes: 16 additions & 16 deletions src/utils.js
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,
}
};
4 changes: 2 additions & 2 deletions wallaby.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'
'use strict';

module.exports = wallaby => ({
files: [
Expand All @@ -20,4 +20,4 @@ module.exports = wallaby => ({
},

testFramework: 'jest',
})
});

0 comments on commit 28334a0

Please sign in to comment.