Catch invalid copyright info and fix broken files

This commit is contained in:
Richie Bendall 2019-05-31 23:19:18 +12:00
parent 46eb2eb45b
commit 549dbb9627
No known key found for this signature in database
GPG key ID: 1C6A99DFA9D306FC
2 changed files with 17 additions and 11 deletions

26
test.js
View file

@ -6,18 +6,22 @@ const CSS = require('css')
let errored = false
const users = fs.readdirSync('users')
users.forEach(async user => {
if (user.endsWith("json")) {
fs.readFile(path.join('users', user), "utf8", async (err, content) => {
users.forEach(async (user) => {
if (user.endsWith('json')) {
fs.readFile(path.join('users', user), 'utf8', async (err, content) => {
if (err) {
errored = true
console.error(`Unable to read ${user}`)
} else {
try {
JSON.parse(content)
const u = JSON.parse(content)
if (!u.locked && !u.copyright) {
errored = true
console.error(`Copyright not specified in ${user} (${e})`)
}
} catch (e) {
errored = true
console.error(`Invalid JSON in file: ${user} (${e})`)
console.error(`Invalid JSON in ${user} (${e})`)
}
}
})
@ -28,9 +32,9 @@ users.forEach(async user => {
})
const themes = fs.readdirSync('themes')
themes.forEach(async theme => {
if (theme.endsWith("css")) {
fs.readFile(path.join('themes', theme), "utf8", async (err, content) => {
themes.forEach(async (theme) => {
if (theme.endsWith('css')) {
fs.readFile(path.join('themes', theme), 'utf8', async (err, content) => {
if (err) {
errored = true
console.error(`Unable to read ${theme}`)
@ -39,11 +43,13 @@ themes.forEach(async theme => {
CSS.parse(content)
} catch (e) {
errored = true
console.error(`Invalid CSS in file: ${theme} (${e})`)
console.error(`Invalid CSS in ${theme} (${e})`)
}
}
})
}
})
if (errored) process.exit(1)
setTimeout(() => {
if (errored) process.exit(1)
}, 500)

View file

@ -1,5 +1,5 @@
{
"copyright": "",
"copyright": "Jesús Urrutia",
"url": "http://jesusurrutia.com",
"email": "jesus.urrutia@gmail.com",
"version": "html",