.github
1 year ago
.gitignore
1 year ago
.travis.yml
2 years ago
LICENSE
3 years ago
MANIFEST.in
2 years ago
README.md
1 year ago
__init__.py
1 year ago
composer.json
3 years ago
crawler-user-agents.json
1 year ago
format.js
1 year ago
go.mod
2 years ago
go.sum
2 years ago
index.d.ts
3 years ago
main.php
3 years ago
package-lock.json
2 years ago
package.json
2 years ago
pyproject.toml
1 year ago
test_harness.py
1 year ago
test_validation.py
3 years ago
validate.go
1 year ago
validate.php
3 years ago
validate.py
2 years ago
validate_test.go
1 year ago
format.js
35 lines
| 1 | /** |
| 2 | * This file is used for checking and updating the format of the JSON file. |
| 3 | * |
| 4 | * You can check the format via `node format.js --check` and regenerate the |
| 5 | * file with the correct formatting using `node format.js --generate`. |
| 6 | * |
| 7 | * The formatting logic uses `JSON.stringify` with 2 spaces, which will keep |
| 8 | * separating commas on the same line as any closing character. This technique |
| 9 | * was chosen for simplicty and to align with common default JSON formatters, |
| 10 | * such as VSCode. |
| 11 | */ |
| 12 | |
| 13 | const fs = require("fs"); |
| 14 | const path = require("path"); |
| 15 | |
| 16 | const jsonFilePath = path.join(__dirname, "crawler-user-agents.json"); |
| 17 | |
| 18 | const original = fs.readFileSync(jsonFilePath, "utf-8"); |
| 19 | |
| 20 | const updated = JSON.stringify(JSON.parse(original), null, 2) + '\n'; |
| 21 | |
| 22 | if (process.argv[2] === "--generate") { |
| 23 | fs.writeFileSync(jsonFilePath, updated); |
| 24 | process.exit(0); |
| 25 | } |
| 26 | |
| 27 | if (process.argv[2] === "--check") { |
| 28 | if (updated !== original) { |
| 29 | console.error("JSON file format is wrong. Run `node format.js --generate` to update."); |
| 30 | console.error("Format must be 2 spaces, with newlines for objects and arrays, and separating commas on the line with the previous closing character."); |
| 31 | process.exit(1); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 |