From 98e6c59255b4aad785282be5c1e443e2fdd5b405 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Tue, 10 Nov 2020 22:56:18 +0700 Subject: [PATCH] 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 --- database/db.js | 9 ++++++--- database/migration.js | 3 +-- gulpfile.js | 13 +++++++++---- scripts/bump-versions.js | 17 +++++++++++------ scripts/cf-purge.js | 11 +++++++---- scripts/clean-up.js | 6 ++++-- scripts/delete-expired.js | 12 ++++++++---- scripts/thumbs.js | 12 ++++++++---- src/versions.json | 2 +- 9 files changed, 55 insertions(+), 30 deletions(-) diff --git a/database/db.js b/database/db.js index b938efb..9b08e9f 100644 --- a/database/db.js +++ b/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') diff --git a/database/migration.js b/database/migration.js index 7056db8..3e586ea 100644 --- a/database/migration.js +++ b/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 => { diff --git a/gulpfile.js b/gulpfile.js index f5fa4e1..09f629d 100644 --- a/gulpfile.js +++ b/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')) diff --git a/scripts/bump-versions.js b/scripts/bump-versions.js index ed5b348..ed3a506 100644 --- a/scripts/bump-versions.js +++ b/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) diff --git a/scripts/cf-purge.js b/scripts/cf-purge.js index 3eb7fe2..f7204fd 100644 --- a/scripts/cf-purge.js +++ b/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 => { diff --git a/scripts/clean-up.js b/scripts/clean-up.js index e55b62a..c46948b 100644 --- a/scripts/clean-up.js +++ b/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 diff --git a/scripts/delete-expired.js b/scripts/delete-expired.js index 376956b..f848045 100644 --- a/scripts/delete-expired.js +++ b/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 => { diff --git a/scripts/thumbs.js b/scripts/thumbs.js index 90a25b5..573f2d5 100644 --- a/scripts/thumbs.js +++ b/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'}`) } } diff --git a/src/versions.json b/src/versions.json index 5e91273..aee892f 100644 --- a/src/versions.json +++ b/src/versions.json @@ -1,5 +1,5 @@ { - "1": "1604592710", + "1": "1604592711", "2": "1602515119", "3": "1602515119", "4": "1602515119",