expanded gulp linter to lint server-side JS files

changed reporter formatter for gulp stylelint from verbose to string
this should now only print out issues to console

linted other server-side JS files that i missed out on previous commits

bumped versions.js to trigger github actions
This commit is contained in:
Bobby Wibowo 2020-11-10 22:56:18 +07:00
parent 395a318de0
commit 98e6c59255
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
9 changed files with 55 additions and 30 deletions

View File

@ -1,7 +1,7 @@
const init = async db => { const init = async db => {
// Create the tables we need to store galleries and files // Create the tables we need to store galleries and files
await db.schema.hasTable('albums').then(exists => { await db.schema.hasTable('albums').then(exists => {
if (!exists) if (!exists) {
return db.schema.createTable('albums', function (table) { return db.schema.createTable('albums', function (table) {
table.increments() table.increments()
table.integer('userid') table.integer('userid')
@ -15,10 +15,11 @@ const init = async db => {
table.integer('public') table.integer('public')
table.string('description') table.string('description')
}) })
}
}) })
await db.schema.hasTable('files').then(exists => { await db.schema.hasTable('files').then(exists => {
if (!exists) if (!exists) {
return db.schema.createTable('files', function (table) { return db.schema.createTable('files', function (table) {
table.increments() table.increments()
table.integer('userid') table.integer('userid')
@ -32,10 +33,11 @@ const init = async db => {
table.integer('timestamp') table.integer('timestamp')
table.integer('expirydate') table.integer('expirydate')
}) })
}
}) })
await db.schema.hasTable('users').then(exists => { await db.schema.hasTable('users').then(exists => {
if (!exists) if (!exists) {
return db.schema.createTable('users', function (table) { return db.schema.createTable('users', function (table) {
table.increments() table.increments()
table.string('username') table.string('username')
@ -46,6 +48,7 @@ const init = async db => {
table.integer('permission') table.integer('permission')
table.integer('registration') table.integer('registration')
}) })
}
}) })
const root = await db.table('users') const root = await db.table('users')

View File

@ -25,8 +25,7 @@ const map = {
for (const tableName of tableNames) { for (const tableName of tableNames) {
const columnNames = Object.keys(map[tableName]) const columnNames = Object.keys(map[tableName])
for (const columnName of columnNames) { for (const columnName of columnNames) {
if (await db.schema.hasColumn(tableName, columnName)) if (await db.schema.hasColumn(tableName, columnName)) continue
continue
const columnType = map[tableName][columnName] const columnType = map[tableName][columnName]
await db.schema.table(tableName, table => { await db.schema.table(tableName, table => {

View File

@ -39,7 +39,7 @@ gulp.task('lint:sass', () => {
return gulp.src('./src/**/*.scss') return gulp.src('./src/**/*.scss')
.pipe(stylelint({ .pipe(stylelint({
failAfterError: true, failAfterError: true,
reporters: [{ formatter: 'verbose', console: true }] reporters: [{ formatter: 'string', console: true }]
})) }))
}) })
@ -49,13 +49,18 @@ gulp.task('lint:css', () => {
}) })
.pipe(stylelint({ .pipe(stylelint({
failAfterError: true, failAfterError: true,
reporters: [{ formatter: 'verbose', console: true }] reporters: [{ formatter: 'string', console: true }]
})) }))
}) })
gulp.task('lint:js', () => { gulp.task('lint:js', () => {
return gulp.src('./src/**/*.js', { return gulp.src([
ignore: './src/libs/**/*' './*.js',
'./{controllers,database,routes,scripts,src}/**/*.js'
], {
ignore: [
'./src/libs/**/*'
]
}) })
.pipe(eslint()) .pipe(eslint())
.pipe(eslint.format('stylish')) .pipe(eslint.format('stylish'))

View File

@ -34,17 +34,19 @@ const self = {
const lower = arg.toLowerCase() const lower = arg.toLowerCase()
if (lower === 'a') { if (lower === 'a') {
self.types = {} self.types = {}
for (let i = min; i <= max; i++) for (let i = min; i <= max; i++) {
self.types[i] = '' self.types[i] = ''
}
break break
} }
const parsed = parseInt(lower) const parsed = parseInt(lower)
// Only accept 1 to 4 // Only accept 1 to 4
if (!isNaN(parsed) && parsed >= min && parsed <= max) if (!isNaN(parsed) && parsed >= min && parsed <= max) {
self.types[parsed] = '' self.types[parsed] = ''
}
} }
if (args.includes('--help') || args.includes('-h') || !Object.keys(self.types).length) if (args.includes('--help') || args.includes('-h') || !Object.keys(self.types).length) {
return console.log(self.stripIndents(` return console.log(self.stripIndents(`
Bump version strings for client-side assets. Bump version strings for client-side assets.
@ -60,6 +62,7 @@ const self = {
5: Fontello font files. 5: Fontello font files.
a: Shortcut to update all types. a: Shortcut to update all types.
`)) `))
}
const file = path.resolve('./src/versions.json') const file = path.resolve('./src/versions.json')
@ -67,11 +70,12 @@ const self = {
try { try {
await self.access(file) await self.access(file)
} catch (error) { } catch (error) {
if (error.code === 'ENOENT') if (error.code === 'ENOENT') {
await self.writeFile(file, '{}') await self.writeFile(file, '{}')
else } else {
// Re-throw error // Re-throw error
throw error throw error
}
} }
// Read & parse existing versions // Read & parse existing versions
@ -81,8 +85,9 @@ const self = {
// We use current timestamp cause it will always increase // We use current timestamp cause it will always increase
const types = Object.keys(self.types) const types = Object.keys(self.types)
const bumped = String(Math.floor(Date.now() / 1000)) // 1s precision const bumped = String(Math.floor(Date.now() / 1000)) // 1s precision
for (const type of types) for (const type of types) {
self.types[type] = bumped self.types[type] = bumped
}
// Overwrite existing versions with new versions // Overwrite existing versions with new versions
const data = Object.assign(old, self.types) const data = Object.assign(old, self.types)

View File

@ -4,7 +4,7 @@ const utils = require('./../controllers/utilsController')
const location = process.argv[1].replace(process.cwd() + '/', '') const location = process.argv[1].replace(process.cwd() + '/', '')
const args = process.argv.slice(2) const args = process.argv.slice(2)
if (!args.length || args.includes('--help') || args.includes('-h')) if (!args.length || args.includes('--help') || args.includes('-h')) {
return console.log(utils.stripIndents(` return console.log(utils.stripIndents(`
Purge Cloudflare's cache. Purge Cloudflare's cache.
@ -14,14 +14,17 @@ const utils = require('./../controllers/utilsController')
filename: filename:
Upload names separated by space (will automatically include their thumbs if available). Upload names separated by space (will automatically include their thumbs if available).
`)) `))
}
const results = await utils.purgeCloudflareCache(args, true, true) const results = await utils.purgeCloudflareCache(args, true, true)
for (const result of results) for (const result of results) {
if (result.errors.length) if (result.errors.length) {
result.errors.forEach(error => console.error(`CF: ${error}`)) result.errors.forEach(error => console.error(`CF: ${error}`))
else } else {
console.log(`URLs:\n${result.files.join('\n')}\n\nSuccess: ${result.success}`) console.log(`URLs:\n${result.files.join('\n')}\n\nSuccess: ${result.success}`)
}
}
})() })()
.then(() => process.exit(0)) .then(() => process.exit(0))
.catch(error => { .catch(error => {

View File

@ -13,8 +13,9 @@ self.getFiles = async directory => {
const files = [] const files = []
for (const name of names) { for (const name of names) {
const lstat = await paths.lstat(path.join(directory, name)) const lstat = await paths.lstat(path.join(directory, name))
if (lstat.isFile() && !name.startsWith('.')) if (lstat.isFile() && !name.startsWith('.')) {
files.push(name) files.push(name)
}
} }
return files return files
} }
@ -23,7 +24,7 @@ self.getFiles = async directory => {
const location = process.argv[1].replace(process.cwd() + '/', '') const location = process.argv[1].replace(process.cwd() + '/', '')
const args = process.argv.slice(2) const args = process.argv.slice(2)
if (args.includes('--help') || args.includes('-h')) if (args.includes('--help') || args.includes('-h')) {
return console.log(utils.stripIndents(` return console.log(utils.stripIndents(`
Clean up files that are not in the database. Clean up files that are not in the database.
@ -34,6 +35,7 @@ self.getFiles = async directory => {
0 = Only list names of files that are not in the database. 0 = Only list names of files that are not in the database.
1 = Clean up the files. 1 = Clean up the files.
`)) `))
}
self.mode = parseInt(args[0]) || 0 self.mode = parseInt(args[0]) || 0
const dryrun = self.mode === 0 const dryrun = self.mode === 0

View File

@ -8,7 +8,7 @@ const self = {
const location = process.argv[1].replace(process.cwd() + '/', '') const location = process.argv[1].replace(process.cwd() + '/', '')
const args = process.argv.slice(2) const args = process.argv.slice(2)
if (args.includes('--help') || args.includes('-h')) if (args.includes('--help') || args.includes('-h')) {
return console.log(utils.stripIndents(` return console.log(utils.stripIndents(`
Bulk delete expired files. Bulk delete expired files.
@ -20,6 +20,7 @@ const self = {
1 = Delete expired files (output file names). 1 = Delete expired files (output file names).
2 = Delete expired files (no output). 2 = Delete expired files (no output).
`)) `))
}
self.mode = parseInt(args[0]) || 0 self.mode = parseInt(args[0]) || 0
const dryrun = self.mode === 0 const dryrun = self.mode === 0
@ -29,13 +30,16 @@ const self = {
if (quiet) return if (quiet) return
if (result.expired.length) if (result.expired.length) {
for (const expired of result.expired) for (const expired of result.expired) {
console.log(expired) console.log(expired)
}
}
console.log(`Expired files: ${result.expired.length}`) console.log(`Expired files: ${result.expired.length}`)
if (result.failed) if (result.failed) {
console.log(`Failed to delete: ${result.failed.length}`) console.log(`Failed to delete: ${result.failed.length}`)
}
})() })()
.then(() => process.exit(0)) .then(() => process.exit(0))
.catch(error => { .catch(error => {

View File

@ -19,8 +19,9 @@ self.getFiles = async directory => {
const files = [] const files = []
for (const name of names) { for (const name of names) {
const lstat = await paths.lstat(path.join(directory, name)) const lstat = await paths.lstat(path.join(directory, name))
if (lstat.isFile() && !name.startsWith('.')) if (lstat.isFile() && !name.startsWith('.')) {
files.push(name) files.push(name)
}
} }
return files return files
} }
@ -38,7 +39,7 @@ self.getFiles = async directory => {
![0, 1].includes(self.force) || ![0, 1].includes(self.force) ||
![0, 1].includes(self.verbose) || ![0, 1].includes(self.verbose) ||
args.includes('--help') || args.includes('--help') ||
args.includes('-h')) args.includes('-h')) {
return console.log(utils.stripIndents(` return console.log(utils.stripIndents(`
Generate thumbnails. Generate thumbnails.
@ -50,6 +51,7 @@ self.getFiles = async directory => {
verbose: 0 = only print missing thumbs (default), 1 = print all verbose: 0 = only print missing thumbs (default), 1 = print all
cfcache: 0 = do not clear cloudflare cache (default), 1 = clear cloudflare cache cfcache: 0 = do not clear cloudflare cache (default), 1 = clear cloudflare cache
`)) `))
}
console.log('Looking through existing thumbnails\u2026') console.log('Looking through existing thumbnails\u2026')
const uploads = await self.getFiles(paths.uploads) const uploads = await self.getFiles(paths.uploads)
@ -60,8 +62,9 @@ self.getFiles = async directory => {
}) })
console.log(`Found ${thumbs.length} existing thumbnails (may include placeholder symlinks).`) console.log(`Found ${thumbs.length} existing thumbnails (may include placeholder symlinks).`)
if (!self.verbose) if (!self.verbose) {
console.log('Verbose logging disabled! Please be patient, this script may appear to be frozen but is actually working in the background.') console.log('Verbose logging disabled! Please be patient, this script may appear to be frozen but is actually working in the background.')
}
const succeeded = [] const succeeded = []
let error = 0 let error = 0
@ -92,8 +95,9 @@ self.getFiles = async directory => {
return `thumbs/${name.slice(0, -extname.length)}.png` return `thumbs/${name.slice(0, -extname.length)}.png`
}), true, false) }), true, false)
for (let i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {
if (results[i].errors.length) if (results[i].errors.length) {
results[i].errors.forEach(error => console.error(`CF: ${error}`)) results[i].errors.forEach(error => console.error(`CF: ${error}`))
}
console.log(`Status [${i}]: ${results[i].success ? 'OK' : 'ERROR'}`) console.log(`Status [${i}]: ${results[i].success ? 'OK' : 'ERROR'}`)
} }
} }

View File

@ -1,5 +1,5 @@
{ {
"1": "1604592710", "1": "1604592711",
"2": "1602515119", "2": "1602515119",
"3": "1602515119", "3": "1602515119",
"4": "1602515119", "4": "1602515119",