From 6d26f177692ebab95cc0aa2a3268e9ffeb65ab68 Mon Sep 17 00:00:00 2001 From: Yury Shapkarin Date: Mon, 6 Jul 2020 06:22:33 +0300 Subject: [PATCH] update/get-browser-globals/combine.js WIP #166 --- .gitignore | 1 + update/get-browser-globals/combine.js | 17 ++++++++++++++++- update/get-browser-globals/jshint.js | 2 +- update/get-browser-globals/readme.md | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0687a95..460b56a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules yarn.lock browser_vars.json +result_browser_vars.json diff --git a/update/get-browser-globals/combine.js b/update/get-browser-globals/combine.js index 33090b5..1285880 100644 --- a/update/get-browser-globals/combine.js +++ b/update/get-browser-globals/combine.js @@ -2,4 +2,19 @@ const fs = require('fs'); -const file = fs.readFileSync('./browser_vars.json'); +const json = require('../../browser_vars.json'); + +const diff_array = function(oneObj, otherObj){ + const defaultKeys = Object.keys(oneObj); + const yours = Object.keys(otherObj); + + return defaultKeys.filter(key => !yours.includes(key)); +}; + +const browser = json['jshint']; +const my = json['my']; + +const difference = diff_array(browser, my).reduce(name => `\n${name}: true,\n`, ''); + +fs.writeFileSync('./result_browser_vars.json', `{ "result": \n\t${JSON.stringify(difference, null, '\t\t')}`); + diff --git a/update/get-browser-globals/jshint.js b/update/get-browser-globals/jshint.js index b29babe..4eec46d 100644 --- a/update/get-browser-globals/jshint.js +++ b/update/get-browser-globals/jshint.js @@ -70,4 +70,4 @@ for (const key of globals) { ret[key] = key.startsWith('on'); } -fs.writeFileSync('./browser_vars.json', `{ "jshint": \n\t${JSON.stringify(ret, null, '\t\t')},\n"my":\n\t{}\n}`); +fs.writeFileSync('./browser_vars.json', `{ "jshint": \n\t${JSON.stringify(ret, null, '\t\t')},\n"my":\n\n}`); diff --git a/update/get-browser-globals/readme.md b/update/get-browser-globals/readme.md index 73074ef..a9bffe0 100644 --- a/update/get-browser-globals/readme.md +++ b/update/get-browser-globals/readme.md @@ -5,4 +5,4 @@ - Open file `browser_vars.json` - Paste yours current clipboard to the field `my` at the root of the project. - run `npm run combine-browser` -- Copy and paste the result from the `browser_vars.json` to the field `browser` at the `globals.json` +- Copy and paste the result from the `result_browser_vars.json` to the field `browser` at the `globals.json`