-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to check and generate format
- Loading branch information
1 parent
e4750aa
commit 71aeaee
Showing
3 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const jsonFilePath = path.join(__dirname, "crawler-user-agents.json"); | ||
|
||
const original = fs.readFileSync(jsonFilePath, "utf-8"); | ||
|
||
const updated = JSON.stringify(JSON.parse(original), null, 2) + '\n'; | ||
|
||
if (process.argv[2] === "--generate") { | ||
fs.writeFileSync(jsonFilePath, updated); | ||
process.exit(0); | ||
} | ||
|
||
if (process.argv[2] === "--check") { | ||
if (updated !== original) { | ||
console.error("JSON file format is wrong. Run `node validate.js --generate` to update."); | ||
process.exit(1); | ||
} | ||
} | ||
|