From 67808803a403fe4ae4e3c4d3d3a448b24991378f Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Sat, 14 Aug 2021 19:12:42 +0200 Subject: [PATCH] Use Prettier to format files --- .prettierignore | 2 ++ .prettierrc.json | 1 + gulpfile.js | 43 ++++++++++++++-------------- package.json | 7 +++-- src/main.js | 60 +++++++++++++++++++--------------------- src/scss/_variables.scss | 6 ++-- src/scss/style.scss | 8 +++--- yarn.lock | 5 ++++ 8 files changed, 68 insertions(+), 64 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.json diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..86b67dc --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +dist +*.md diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1 @@ +{} diff --git a/gulpfile.js b/gulpfile.js index 09634e2..4776daf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,42 +1,41 @@ -const gulp = require('gulp'); -const postcss = require('gulp-postcss'); -const sass = require('gulp-sass')(require('sass')); -const sourcemaps = require('gulp-sourcemaps'); -const terser = require('gulp-terser'); - +const gulp = require("gulp"); +const postcss = require("gulp-postcss"); +const sass = require("gulp-sass")(require("sass")); +const sourcemaps = require("gulp-sourcemaps"); +const terser = require("gulp-terser"); function html() { - return gulp.src('./src/index.html') - .pipe(gulp.dest('./dist/')); + return gulp.src("./src/index.html").pipe(gulp.dest("./dist/")); } function css() { - return gulp.src('./src/scss/*.scss') + return gulp + .src("./src/scss/*.scss") .pipe(sourcemaps.init()) - .pipe(sass.sync().on('error', sass.logError)) + .pipe(sass.sync().on("error", sass.logError)) .pipe(postcss([require("autoprefixer"), require("postcss-csso")])) - .pipe(sourcemaps.write('.')) - .pipe(gulp.dest('./dist/')); + .pipe(sourcemaps.write(".")) + .pipe(gulp.dest("./dist/")); } function js() { - return gulp.src('./src/main.js') + return gulp + .src("./src/main.js") .pipe(sourcemaps.init()) .pipe(terser({ ecma: 5 })) - .pipe(sourcemaps.write('.')) - .pipe(gulp.dest('./dist/')); + .pipe(sourcemaps.write(".")) + .pipe(gulp.dest("./dist/")); } function static() { - return gulp.src('./src/static/**/*') - .pipe(gulp.dest('./dist/')); + return gulp.src("./src/static/**/*").pipe(gulp.dest("./dist/")); } exports.default = gulp.parallel(html, css, js, static); exports.watch = () => { - gulp.watch('./src/index.pug', html); - gulp.watch('./src/style/*.scss', css); - gulp.watch('./src/script/index.js', js); - gulp.watch('./src/static/*', static); -} + gulp.watch("./src/index.pug", html); + gulp.watch("./src/style/*.scss", css); + gulp.watch("./src/script/index.js", js); + gulp.watch("./src/static/*", static); +}; diff --git a/package.json b/package.json index cd63997..6da603a 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "author": "Nikita Karamov ", "homepage": "https://toot.karamoff.dev/", "repository": { - "type": "git", - "url": "https://github.com/NickKaramoff/toot.git" - }, + "type": "git", + "url": "https://github.com/NickKaramoff/toot.git" + }, "private": true, "scripts": { "build": "gulp", @@ -25,6 +25,7 @@ "gulp-terser": "^2.0.1", "postcss": "^8.2.15", "postcss-csso": "^5.0.1", + "prettier": "2.3.2", "sass": "^1.37.5", "sirv-cli": "^1.0.10" }, diff --git a/src/main.js b/src/main.js index 04c8182..b527f1c 100644 --- a/src/main.js +++ b/src/main.js @@ -20,32 +20,30 @@ function normalizeUrl(url) { if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) { url = "https://" + url; } - if (url.charAt(url.length - 1) !== '/'){ + if (url.charAt(url.length - 1) !== "/") { url = url + "/"; } return url; } -const instance = document.getElementById('instance'); -const instances_list = document.getElementById('instances_list'); +const instance = document.getElementById("instance"); +const instances_list = document.getElementById("instances_list"); -var prefillInstance = window.localStorage.getItem('mastodon_instance'); +var prefillInstance = window.localStorage.getItem("mastodon_instance"); -var paramPairs = window.location.search.substr(1).split('&'); +var paramPairs = window.location.search.substr(1).split("&"); var paramPairsLength = paramPairs.length; for (var i = 0; i < paramPairsLength; i++) { - var paramPair = paramPairs[i].split('='); - if (paramPair[0] === 'text') { - document.getElementById('text').value = decodeURIComponent(paramPair[1]); - } else if (paramPair[0] === 'instance') { + var paramPair = paramPairs[i].split("="); + if (paramPair[0] === "text") { + document.getElementById("text").value = decodeURIComponent(paramPair[1]); + } else if (paramPair[0] === "instance") { prefillInstance = decodeURIComponent(paramPair[1]); } } -delete i -delete paramPair function instances_loading_error() { - console.error('Failed to fetch servers list from joinmastodon.'); + console.error("Failed to fetch servers list from joinmastodon."); } function instances_loaded() { @@ -57,14 +55,14 @@ function instances_loaded() { const servers = JSON.parse(this.responseText); const chosen_instance = instance.value; - const domains = servers.map(obj => obj.domain); + const domains = servers.map((obj) => obj.domain); if (chosen_instance && domains.indexOf(chosen_instance) === -1) { domains.push(chosen_instance); } domains.sort(); for (const domain of domains) { - const opt = document.createElement('option'); + const opt = document.createElement("option"); opt.value = normalizeUrl(domain); instances_list.appendChild(opt); } @@ -74,28 +72,26 @@ if (prefillInstance != null) { instance.value = normalizeUrl(prefillInstance); } -instance.addEventListener('focus', function (e) { +instance.addEventListener("focus", function (e) { if (instances_list.children.length === 0) { const req = new XMLHttpRequest(); - req.addEventListener('load', instances_loaded); - req.addEventListener('error', instances_loading_error); - req.open('GET', 'https://api.joinmastodon.org/servers'); + req.addEventListener("load", instances_loaded); + req.addEventListener("error", instances_loading_error); + req.open("GET", "https://api.joinmastodon.org/servers"); req.send(); } -}) +}); -document - .getElementById('form') - .addEventListener('submit', function (e) { - e.preventDefault(); - var text = e.target.elements['text'].value; - var instance = normalizeUrl(e.target.elements['instance'].value); - var remember = e.target.elements['remember'].checked; +document.getElementById("form").addEventListener("submit", function (e) { + e.preventDefault(); + var text = e.target.elements["text"].value; + var instance = normalizeUrl(e.target.elements["instance"].value); + var remember = e.target.elements["remember"].checked; - if (remember) { - window.localStorage.setItem('mastodon_instance', instance); - } + if (remember) { + window.localStorage.setItem("mastodon_instance", instance); + } - var shareUrl = instance + "share?text=" + encodeURIComponent(text); - window.location.href = shareUrl; - }) + var shareUrl = instance + "share?text=" + encodeURIComponent(text); + window.location.href = shareUrl; +}); diff --git a/src/scss/_variables.scss b/src/scss/_variables.scss index e24079f..6a6000d 100644 --- a/src/scss/_variables.scss +++ b/src/scss/_variables.scss @@ -16,11 +16,11 @@ along with this program. If not, see . */ -$text-font: 'Roboto', sans-serif; +$text-font: "Roboto", sans-serif; -$bg: #1F232B; +$bg: #1f232b; $text: #9baec8; -$title:#d9e1e8; +$title: #d9e1e8; $button-bg: #2b90d9; $button-hover-bg: #56a7e1; diff --git a/src/scss/style.scss b/src/scss/style.scss index 8ba1837..3607e94 100644 --- a/src/scss/style.scss +++ b/src/scss/style.scss @@ -101,11 +101,11 @@ main { font-size: 1rem; border-radius: 4px; - &[type=checkbox] { + &[type="checkbox"] { margin-right: 8px; } - &[type=submit] { + &[type="submit"] { display: inline-block; text-align: center; background-color: $button-bg; @@ -127,7 +127,7 @@ main { } textarea, - input[type=url] { + input[type="url"] { color: inherit; width: 100%; outline: 0; @@ -162,7 +162,7 @@ footer { flex-wrap: wrap; section { - margin: .5rem 1rem; + margin: 0.5rem 1rem; a { color: inherit; diff --git a/yarn.lock b/yarn.lock index 109882c..c6cf772 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2101,6 +2101,11 @@ postcss@^8.2.15: nanoid "^3.1.23" source-map-js "^0.6.2" +prettier@2.3.2: + version "2.3.2" + resolved "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d" + integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ== + pretty-hrtime@^1.0.0: version "1.0.3" resolved "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"