Skip to content

Commit 26ee42b

Browse files
authored
Fix #1: Ignore entries which are within comments
1 parent 14809be commit 26ee42b

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

collection/SAMPLE_ONE.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ exchangeCode = async (req, res, next) => {
2424
url: "https://accounts.google.com/o/oauth2/token",
2525
json: true,
2626
form: {
27+
// replaced process.env.GOOGLE_ID for sematic purposes
2728
client_id: process.env.GOOGLE_CLIENT_ID,
2829
client_secret: process.env.GOOGLE_CLIENT_SECRET,
2930
grant_type: "authorization_code",

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
"devDependencies": {
2626
"@types/node": "^14.11.2",
2727
"@types/recursive-readdir": "^2.2.0",
28+
"@types/strip-comments": "^2.0.0",
2829
"typescript": "^4.0.2"
2930
},
3031
"dependencies": {
31-
"recursive-readdir": "^2.2.2"
32+
"recursive-readdir": "^2.2.2",
33+
"strip-comments": "^2.0.1"
3234
}
3335
}

src/app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import fs from 'fs'
44
import recursive from 'recursive-readdir'
55

66
/** include auxillary functions */
7-
import { Filter, extractWordsFrom, extractKeysFrom, writeDataToEnv } from './aux'
7+
import { Filter, extractWordsFrom, extractKeysFrom, writeDataToEnv, stripComments } from './aux'
88

99
/** main function runner */
1010
const worker = async () => {
1111
const files = await recursive('./', Filter)
1212
let words: Array<string> = []
1313
for (let i = 0; i < files.length; i += 1) {
1414
const data = await fs.readFileSync(files[i], 'utf8')
15-
extractWordsFrom(data).forEach((word) => words.push(word))
15+
const strippedData = stripComments(data)
16+
extractWordsFrom(strippedData).forEach((word) => words.push(word))
1617
}
1718
const keys: Array<string> = extractKeysFrom(words)
1819
writeDataToEnv(keys)

src/aux.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import fs from 'fs'
2+
import strip from 'strip-comments'
23

34
export const Filter: string[] = ['!*.{ts,js,jsx}', 'node_modules/*']
45

6+
export const stripComments = (data: string): string => {
7+
const strippedData = strip(data)
8+
return strippedData
9+
}
10+
511
export const extractWordsFrom = (data: string): Array<string> => {
612
const regexMatches: RegExpMatchArray = data.match(/process.env.\s*([^\W]*)/gi) || []
713
return regexMatches

0 commit comments

Comments
 (0)