-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor: fix hasOwnProperty and format code #3749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
08dc0f4
chore(refactor): upbringing code quality
maze-runnar 11b5ec0
Update replace-config.js
maze-runnar dda2257
Do not access Object.prototype method 'hasOwnProperty' from target ob…
maze-runnar 3131ae3
Do not access Object.prototype method 'hasOwnProperty' from target ob…
maze-runnar 1bf2389
Do not access Object.prototype method 'hasOwnProperty' from target ob…
maze-runnar 12f556d
Update loader.js
maze-runnar 06a320d
Update environment.js
maze-runnar 9cfeda8
Do not access Object.prototype method 'hasOwnProperty' from target ob…
maze-runnar 24dd9bc
Do not access Object.prototype method 'hasOwnProperty' from target ob…
maze-runnar 030be8f
Update device.js
maze-runnar 8c9a4a9
reverting comments in replace-config
maze-runnar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,30 +1,30 @@ | ||
| require('dotenv').config() | ||
| require('dotenv').config(); | ||
|
|
||
| const fs = require('fs'); | ||
| const promisify = require('util').promisify | ||
| const { merge } = require('lodash') | ||
| const safeEval = require('safe-eval') | ||
| const promisify = require('util').promisify; | ||
| const { merge } = require('lodash'); | ||
| const safeEval = require('safe-eval'); | ||
|
|
||
| const env = require('../config/environment') | ||
| const appName = 'open-event-frontend' | ||
| const env = require('../config/environment'); | ||
| const appName = 'open-event-frontend'; | ||
|
|
||
| const environment = env('production') | ||
| const environment = env('production'); | ||
|
|
||
| async function replaceFastbootConfig() { | ||
| const packagePath = './dist/package.json' | ||
| const packageInfo = require('.' + packagePath) | ||
| const packagePath = './dist/package.json'; | ||
| const packageInfo = require('.' + packagePath); | ||
|
|
||
| const old = packageInfo.fastboot.config[appName] | ||
| const old = packageInfo.fastboot.config[appName]; | ||
| packageInfo.fastboot.config[appName] = merge(old, environment); | ||
| await promisify(fs.writeFile)(packagePath, JSON.stringify(packageInfo)) | ||
| await promisify(fs.writeFile)(packagePath, JSON.stringify(packageInfo)); | ||
|
|
||
| console.log('Transformed package.json with new environment') | ||
| //console.log('Transformed package.json with new environment') | ||
| } | ||
|
|
||
| function findObject(js, objectStart) { | ||
| let braceCount = 1; | ||
|
|
||
| const start = js.indexOf("{", objectStart); | ||
| const start = js.indexOf('{', objectStart); | ||
|
|
||
| if (start < 0) { | ||
| return null; | ||
|
|
@@ -38,15 +38,15 @@ function findObject(js, objectStart) { | |
| const c = js[index]; | ||
|
|
||
| if (!parseBlocker && !parseBlockerBuffer) { | ||
| if (c == "{") { | ||
| if (c === '{') { | ||
| braceCount += 1; | ||
| } else if (c == "}") { | ||
| braceCount -= 1; | ||
| } else if (c === '"' || c === "'" || c === "`") { | ||
| parseBlocker = c; | ||
| } else if (js[index - 1] == "/") { | ||
| if (c == "/") parseBlocker = "\n"; | ||
| else if (c == "*") parseBlockerBuffer = "*/"; | ||
| } else if (js[index - 1] === '/') { | ||
| if (c === '/') { parseBlocker = "\n"; } | ||
| else if (c === "*") { parseBlockerBuffer = "*/"; } | ||
| } | ||
|
|
||
| if (braceCount === 0) { | ||
|
|
@@ -55,7 +55,7 @@ function findObject(js, objectStart) { | |
| } else { | ||
| if (c === parseBlocker) { | ||
| parseBlocker = null; | ||
| } else if (c == '/' && js[index - 1] == '*') { | ||
| } else if (c === '/' && js[index - 1] == '*') { | ||
| parseBlockerBuffer = null; | ||
| } | ||
| } | ||
|
|
@@ -72,43 +72,43 @@ function findObject(js, objectStart) { | |
| } | ||
|
|
||
| function replace(str, start, end, replacement) { | ||
| return str.substring(0, start) + replacement + str.substring(end + 1, str.length) | ||
| return str.substring(0, start) + replacement + str.substring(end + 1, str.length); | ||
| } | ||
|
|
||
| async function replaceWebConfig() { | ||
| const pattern = new RegExp(`^${appName}.*\.js$`) | ||
| const basePath = './dist/assets/' | ||
| const appJs = (await promisify(fs.readdir)(basePath)).filter(name => name.match(pattern)) | ||
| const pattern = new RegExp(`^${appName}.*\.js$`); | ||
| const basePath = './dist/assets/'; | ||
| const appJs = (await promisify(fs.readdir)(basePath)).filter(name => name.match(pattern)); | ||
|
|
||
| const envDefinition = 'define("open-event-frontend/config/environment"' | ||
| const envDefinition = 'define("open-event-frontend/config/environment"'; | ||
|
|
||
| for (const js of appJs) { | ||
| const jsPath = basePath + js; | ||
| const code = (await promisify(fs.readFile)(jsPath)).toString() | ||
| let defineIndex = code.indexOf(envDefinition) | ||
| let defineIndex = code.indexOf(envDefinition); | ||
|
|
||
| if (defineIndex < 0) { | ||
| defineIndex = code.indexOf(envDefinition.replace(/"/g, "'")) | ||
| defineIndex = code.indexOf(envDefinition.replace(/"/g, "'")); | ||
| if (defineIndex < 0) | ||
| continue; | ||
| } | ||
|
|
||
| const defaultIndex = code.indexOf('default', defineIndex + 1) | ||
| const defaultIndex = code.indexOf('default', defineIndex + 1); | ||
|
|
||
| if (defaultIndex < 0) | ||
| if (defaultIndex < 0) { | ||
| continue; | ||
|
|
||
| } | ||
| // File with environment definition found | ||
|
|
||
| console.log('Transforming ' + js) | ||
| const object = findObject(code, defaultIndex) | ||
| //console.log('Transforming ' + js) | ||
|
||
|
|
||
| const object = findObject(code, defaultIndex); | ||
|
|
||
| console.log('Environment Object Found', object) | ||
| //console.log('Environment Object Found', object) | ||
|
||
|
|
||
| const webEnvJson = code.substring(object.start, object.end + 1) | ||
| const old = safeEval('(' + webEnvJson + ')') | ||
|
|
||
| const newEnv = JSON.stringify(merge(old, environment)) | ||
| const newCode = replace(code, object.start, object.end, newEnv) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert