diff --git a/MODULE_README.txt b/MODULE_README.txt new file mode 100644 index 0000000..350271a --- /dev/null +++ b/MODULE_README.txt @@ -0,0 +1 @@ +No user data is contained within this folder. The contents of this folder can safely be deleted when upgrading/downgrading the module. \ No newline at end of file diff --git a/README.md b/README.md index 7f99a55..bc7ca22 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,10 @@ Add your gif to the end of the gifs array in [`gifs.json`](https://github.com/se } ``` +### Opening a PR + +Run `yarn gh:pr` to automatically open a PR with your added GIFs rendered in the PR body, otherwise follow the instructions below. + ### Validating and submitting your entry 1. Run `yarn test` to make sure everything passes diff --git a/cache.js b/cache.js index a02c04a..263ecd8 100644 --- a/cache.js +++ b/cache.js @@ -4,10 +4,12 @@ const fs = require('fs'); const names = gifs.map(({ name }) => name); const cache = () => ( - (_cache = { - _names: names, - }), - fs.writeFileSync('./.cache.json', JSON.stringify(_cache)), + fs.writeFileSync( + './.cache.json', + JSON.stringify({ + _names: names, + }) + ), console.log('\033[38;5;229m', 'Cache updated') ); cache(); diff --git a/gifs.json b/gifs.json index 93854f3..9758654 100644 --- a/gifs.json +++ b/gifs.json @@ -776,6 +776,13 @@ "url": "https://media.giphy.com/media/S99cgkURVO62qemEKM/giphy.gif", "description": "Astro Happy Dance", "active": 1 + }, + { + "_id": 111, + "name": "keanu-ty", + "url": "https://c.tenor.com/6bUnLYb54jgAAAAd/thank-you-thanks.gif", + "description": "thank-you", + "active": 1 } ] } diff --git a/package.json b/package.json index 953ff1c..2e11439 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "build:cache": "node cache.js", "test": "./node_modules/.bin/jest", "add:gif": "node add-gif.js", + "gh:pr": "yarn test && node scripts/pull-request.js", "test:watch": "yarn test --watch", "prepare": "husky install", "prettier:write": "./node_modules/.bin/prettier --write '*.{js,json,md}'" diff --git a/scripts/pull-request.js b/scripts/pull-request.js new file mode 100644 index 0000000..27a9dc1 --- /dev/null +++ b/scripts/pull-request.js @@ -0,0 +1,21 @@ +const util = require('util'); +const exec = util.promisify(require('child_process').exec); + +async function run() { + const r = new RegExp(/(\+ "url": "|",\n)/gm); + const { stdout: rawGIFLines } = await exec(`git diff master... gifs.json | grep '+ "url": '`); + const newGIFLinks = rawGIFLines.replace(r, '').split('+ url: '); + console.log('Writing PR body with new GIFs: ', newGIFLinks); + const formattedGIFMarkDown = newGIFLinks.map((gifURL) => `![New GIF](${gifURL})\n`); + const { stdout: branch } = await exec('git branch --show-current'); + console.log('Pushing changes to remote\n'); + await exec(`git push origin -u ${branch}`); + console.log('Remote received changes\n'); + console.log('Opening new PR\n'); + const { stdout: message } = await exec( + `gh pr create --title 'Adding More Gifs' --body '## Added GIFs \n\n ${formattedGIFMarkDown}'` + ); + console.log(`New PR opened @ ${message.replace('\n', '')}`); +} + +run();