Browse Source

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
master
Bobby Wibowo 7 months ago
parent
commit
98e6c59255
No known key found for this signature in database GPG Key ID: 51C3A1E1E22D26CF
  1. 9
      database/db.js
  2. 3
      database/migration.js
  3. 13
      gulpfile.js
  4. 17
      scripts/bump-versions.js
  5. 11
      scripts/cf-purge.js
  6. 6
      scripts/clean-up.js
  7. 12
      scripts/delete-expired.js
  8. 12
      scripts/thumbs.js
  9. 2
      src/versions.json

9
database/db.js

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

3
database/migration.js

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

13
gulpfile.js

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

17
scripts/bump-versions.js

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

11
scripts/cf-purge.js

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

6
scripts/clean-up.js

@ -13,8 +13,9 @@ self.getFiles = async directory => {
const files = []
for (const name of names) {
const lstat = await paths.lstat(path.join(directory, name))
if (lstat.isFile() && !name.startsWith('.'))
if (lstat.isFile() && !name.startsWith('.')) {
files.push(name)
}
}
return files
}
@ -23,7 +24,7 @@ self.getFiles = async directory => {
const location = process.argv[1].replace(process.cwd() + '/', '')
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(`
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.
1 = Clean up the files.
`))
}
self.mode = parseInt(args[0]) || 0
const dryrun = self.mode === 0

12
scripts/delete-expired.js

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

12
scripts/thumbs.js

@ -19,8 +19,9 @@ self.getFiles = async directory => {
const files = []
for (const name of names) {
const lstat = await paths.lstat(path.join(directory, name))
if (lstat.isFile() && !name.startsWith('.'))
if (lstat.isFile() && !name.startsWith('.')) {
files.push(name)
}
}
return files
}
@ -38,7 +39,7 @@ self.getFiles = async directory => {
![0, 1].includes(self.force) ||
![0, 1].includes(self.verbose) ||
args.includes('--help') ||
args.includes('-h'))
args.includes('-h')) {
return console.log(utils.stripIndents(`
Generate thumbnails.
@ -50,6 +51,7 @@ self.getFiles = async directory => {
verbose: 0 = only print missing thumbs (default), 1 = print all
cfcache: 0 = do not clear cloudflare cache (default), 1 = clear cloudflare cache
`))
}
console.log('Looking through existing thumbnails\u2026')
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).`)
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.')
}
const succeeded = []
let error = 0
@ -92,8 +95,9 @@ self.getFiles = async directory => {
return `thumbs/${name.slice(0, -extname.length)}.png`
}), true, false)
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}`))
}
console.log(`Status [${i}]: ${results[i].success ? 'OK' : 'ERROR'}`)
}
}

2
src/versions.json

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

Loading…
Cancel
Save