parent
6e1aed86ff
commit
16795ce4bc
@ -0,0 +1,118 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const { apps: technologies, categories } = JSON.parse(
|
||||
fs.readFileSync(path.resolve(`${__dirname}/../src/apps.json`))
|
||||
)
|
||||
|
||||
try {
|
||||
Object.keys(technologies).forEach((name) => {
|
||||
const technology = technologies[name]
|
||||
|
||||
;['url', 'html', 'meta', 'headers', 'cookies', 'script', 'js'].forEach(
|
||||
(type) => {
|
||||
if (technology[type]) {
|
||||
const keyed =
|
||||
typeof technology[type] === 'string' ||
|
||||
Array.isArray(technology[type])
|
||||
? { _: technology[type] }
|
||||
: technology[type]
|
||||
|
||||
Object.keys(keyed).forEach((key) => {
|
||||
const patterns = Array.isArray(keyed[key])
|
||||
? keyed[key]
|
||||
: [keyed[key]]
|
||||
|
||||
patterns.forEach((pattern, index) => {
|
||||
const id = `${name}: ${type}[${key === '_' ? `${index}` : key}]`
|
||||
|
||||
const [regex, ...flags] = pattern.split('\\;')
|
||||
|
||||
let maxGroups = 0
|
||||
|
||||
flags.forEach((flag) => {
|
||||
const [key, value] = flag.split(':')
|
||||
|
||||
if (key === 'version') {
|
||||
const refs = value.match(/\\(\d+)/g)
|
||||
|
||||
if (refs) {
|
||||
maxGroups = refs.reduce((max, ref) =>
|
||||
Math.max(max, parseInt(refs[1] || 0))
|
||||
)
|
||||
}
|
||||
} else if (key === 'confidence') {
|
||||
if (
|
||||
!/^\d+$/.test(value) ||
|
||||
parseInt(value, 10) < 0 ||
|
||||
parseInt(value, 10) > 99
|
||||
) {
|
||||
throw new Error(
|
||||
`Confidence value must a number between 0 and 99: ${value} (${id})`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Invalid flag: ${key} (${id})`)
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
new RegExp(regex)
|
||||
} catch (error) {
|
||||
throw new Error(`${error.message} (${id})`)
|
||||
}
|
||||
|
||||
const groups = new RegExp(`${regex}|`).exec('').length - 1
|
||||
|
||||
if (groups > maxGroups) {
|
||||
throw new Error(
|
||||
`Too many non-capturing groups, expected ${maxGroups}: ${regex} (${id})`
|
||||
)
|
||||
}
|
||||
|
||||
if (type === 'html' && !/[<>]/.test(regex)) {
|
||||
throw new Error(
|
||||
`HTML pattern must include < or >: ${regex} (${id})`
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
technology.cats.forEach((id) => {
|
||||
if (!categories[id]) {
|
||||
throw new Error(`No such category: ${id} (${name})`)
|
||||
}
|
||||
})
|
||||
|
||||
if (
|
||||
technology.icon &&
|
||||
!fs.existsSync(
|
||||
path.resolve(
|
||||
`${__dirname}/../src/drivers/webextension/images/icons/${technology.icon}`
|
||||
)
|
||||
)
|
||||
) {
|
||||
throw new Error(`No such icon: ${technology.icon} (${name})`)
|
||||
}
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
const { protocol } = new URL(technology.website)
|
||||
|
||||
if (protocol !== 'http:' && protocol !== 'https:') {
|
||||
throw new Error('Invalid protocol')
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Invalid website URL: ${technology.website} (${name})`)
|
||||
}
|
||||
|
||||
// TODO check implies, excludes
|
||||
})
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(error.message)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,22 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"file-type": "7.4.*",
|
||||
"is-svg": "2.1.*",
|
||||
"read-chunk": "2.1.*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nuxtjs/eslint-config": "^1.0.1",
|
||||
"@nuxtjs/eslint-module": "^1.2.0",
|
||||
"@prantlf/jsonlint": "^10.2.0",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"chai": "^4.2.0",
|
||||
"convert-svg-to-png": "^0.5.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"eslint": "^6.1.0",
|
||||
"eslint-config-prettier": "^4.1.0",
|
||||
"eslint-plugin-nuxt": "^0.5.2",
|
||||
"eslint-plugin-prettier": "^3.1.3",
|
||||
"mocha": "^5.2.0",
|
||||
"prettier": "^1.16.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R spec src",
|
||||
"lint": "eslint src",
|
||||
"lint:fix": "eslint src --fix"
|
||||
"validate:json": "jsonlint -qV ./schema.json ./src/apps.json && node ./bin/validate.js",
|
||||
"validate": "yarn validate:json",
|
||||
"convert": "cd ./src/drivers/webextension/images/icons ; cp *.svg converted ; cd converted ; convert-svg-to-png *.svg --width 32 --height 32 ; rm *.svg",
|
||||
"jsonprettify": "jsonlint -si --trim-trailing-commas --enforce-double-quotes ./src/apps.json",
|
||||
"build": "yarn validate && yarn jsonprettify"
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in new issue