Переглянути джерело

refactor(musare.sh): Use package.json lint scripts and autoremove markdown lint container

Owen Diffey 2 роки тому
батько
коміт
a554a57d30

+ 3 - 2
backend/.eslintignore

@@ -1,2 +1,3 @@
-node_modules
-build
+.git/
+build/
+node_modules/

+ 2 - 0
backend/.prettierignore

@@ -1 +1,3 @@
+.git/
+build/
 node_modules/

+ 8 - 8
backend/.prettierrc

@@ -1,9 +1,9 @@
 {
-    "singleQuote": false,
-    "tabWidth": 4,
-    "useTabs": true,
-    "trailingComma": "none",
-    "arrowParens": "avoid",
-    "endOfLine":"auto",
-    "printWidth": 120
-}
+	"singleQuote": false,
+	"tabWidth": 4,
+	"useTabs": true,
+	"trailingComma": "none",
+	"arrowParens": "avoid",
+	"endOfLine": "lf",
+	"printWidth": 120
+}

+ 15 - 7
backend/core.js

@@ -267,18 +267,26 @@ class Job {
 		this.module.log(...args);
 	}
 
+	/**
+	 * Set whether to job is a long job.
+	 */
 	keepLongJob() {
 		this.longJob = true;
 	}
 
+	/**
+	 * Forget long job.
+	 */
 	forgetLongJob() {
 		this.longJob = false;
 		this.module.moduleManager.jobManager.removeJob(this);
 	}
 
 	/**
-	 * 
+	 * Update and emit progress of job
+	 *
 	 * @param {data} data - Data to publish upon progress
+	 * @param {boolean} notALongJob - Whether job is not a long job
 	 */
 	publishProgress(data, notALongJob) {
 		if (this.longJob || notALongJob) {
@@ -289,7 +297,7 @@ class Job {
 					this.lastProgressData = data;
 
 					if (data.status === "update") {
-						if ((Date.now() - this.lastProgressTime) > 1000) {
+						if (Date.now() - this.lastProgressTime > 1000) {
 							this.lastProgressTime = Date.now();
 						} else {
 							if (this.lastProgressTimeout) clearTimeout(this.lastProgressTimeout);
@@ -303,11 +311,11 @@ class Job {
 					} else if (data.status === "success" || data.status === "error")
 						if (this.lastProgressTimeout) clearTimeout(this.lastProgressTimeout);
 
-					if (data.title)	this.longJobTitle = data.title;
+					if (data.title) this.longJobTitle = data.title;
 
 					this.onProgress.emit("progress", data);
 				}
-			} else this.log("Progress published, but no onProgress specified.")
+			} else this.log("Progress published, but no onProgress specified.");
 		} else {
 			this.parentJob.publishProgress(data);
 		}
@@ -615,7 +623,8 @@ export default class CoreClass {
 					this[job.name]
 						.apply(job, [job.payload])
 						.then(response => {
-							if (!options.isQuiet) this.log("INFO", `Ran job ${job.name} (${job.toString()}) successfully`);
+							if (!options.isQuiet)
+								this.log("INFO", `Ran job ${job.name} (${job.toString()}) successfully`);
 							job.setStatus("FINISHED");
 							job.setResponse(response);
 							this.jobStatistics[job.name].successful += 1;
@@ -689,8 +698,7 @@ export default class CoreClass {
 							}
 							resolve();
 						});
-				else
-					this.log("ERROR", `Job not found! ${job.name}`)
+				else this.log("ERROR", `Job not found! ${job.name}`);
 			} else {
 				this.log(
 					"INFO",

+ 12 - 19
backend/index.js

@@ -5,7 +5,7 @@ import config from "config";
 import fs from "fs";
 
 import * as readline from "node:readline";
-import package_json from "./package.json" assert { type: "json" };
+import packageJson from "./package.json" assert { type: "json" };
 
 const REQUIRED_CONFIG_VERSION = 12;
 
@@ -33,7 +33,7 @@ console.log = (...args) => {
 	if (!blacklisted) oldConsole.log.apply(null, args);
 };
 
-const MUSARE_VERSION = package_json.version;
+const MUSARE_VERSION = packageJson.version;
 
 const printVersion = () => {
 	console.log(`Musare version: ${MUSARE_VERSION}.`);
@@ -44,20 +44,16 @@ const printVersion = () => {
 		else if (fs.existsSync(".git/HEAD")) gitFolder = ".git";
 
 		if (gitFolder) {
-			const head_contents = fs.readFileSync(`${gitFolder}/HEAD`).toString().replaceAll("\n", "");
-			const branch = new RegExp("ref: refs/heads/([A-Za-z0-9_.-]+)").exec(head_contents)[1];
-			const config_contents = fs.readFileSync(`${gitFolder}/config`).toString().replaceAll("\t", "").split("\n");
-			const remote = new RegExp("remote = (.+)").exec(
-				config_contents[config_contents.indexOf(`[branch "${branch}"]`) + 1]
-			)[1];
-			const remote_url = new RegExp("url = (.+)").exec(
-				config_contents[config_contents.indexOf(`[remote "${remote}"]`) + 1]
-			)[1];
-			const latest_commit = fs.readFileSync(`${gitFolder}/refs/heads/${branch}`).toString().replaceAll("\n", "");
-			const latest_commit_short = latest_commit.substr(0, 7);
+			const headContents = fs.readFileSync(`${gitFolder}/HEAD`).toString().replaceAll("\n", "");
+			const [, branch] = /ref: refs\/heads\/([A-Za-z0-9_.-]+)/.exec(headContents);
+			const configContents = fs.readFileSync(`${gitFolder}/config`).toString().replaceAll("\t", "").split("\n");
+			const [, remote] = /remote = (.+)/.exec(configContents[configContents.indexOf(`[branch "${branch}"]`) + 1]);
+			const [, remoteUrl] = /url = (.+)/.exec(configContents[configContents.indexOf(`[remote "${remote}"]`) + 1]);
+			const latestCommit = fs.readFileSync(`${gitFolder}/refs/heads/${branch}`).toString().replaceAll("\n", "");
+			const latestCommitShort = latestCommit.substr(0, 7);
 
 			console.log(
-				`Git branch: ${remote}/${branch}. Remote url: ${remote_url}. Latest commit: ${latest_commit} (${latest_commit_short}).`
+				`Git branch: ${remote}/${branch}. Remote url: ${remoteUrl}. Latest commit: ${latestCommit} (${latestCommitShort}).`
 			);
 		} else console.log("Could not find .git folder.");
 	} catch (e) {
@@ -76,6 +72,7 @@ if (config.get("configVersion") !== REQUIRED_CONFIG_VERSION && !config.get("skip
 
 if (config.debug && config.debug.traceUnhandledPromises === true) {
 	console.log("Enabled trace-unhandled/register");
+	// eslint-disable-next-line import/no-extraneous-dependencies
 	import("trace-unhandled/register");
 }
 
@@ -343,7 +340,6 @@ const rl = readline.createInterface({
 					.map(module => `${parts[0]} ${module}${parts[0] === "runjob" ? " " : ""}`);
 				return [hits.length ? hits : modules, command];
 			}
-			return [];
 		}
 		if (parts.length === 3) {
 			if (parts[0] === "runjob") {
@@ -355,12 +351,9 @@ const rl = readline.createInterface({
 						.map(job => `${parts[0]} ${parts[1]} ${job} `);
 					return [hits.length ? hits : jobs, command];
 				}
-			} else {
-				return [];
 			}
-		} else {
-			return [];
 		}
+		return [];
 	}
 });
 

+ 2 - 2
backend/package.json

@@ -12,7 +12,7 @@
     "dev": "nodemon --es-module-specifier-resolution=node",
     "docker:dev": "nodemon --es-module-specifier-resolution=node --legacy-watch --no-stdin /opt/app",
     "docker:prod": "node --es-module-specifier-resolution=node /opt/app",
-    "lint": "eslint --cache logic",
+    "lint": "eslint . --ext .js",
     "typescript": "tsc --noEmit --skipLibCheck"
   },
   "dependencies": {
@@ -52,4 +52,4 @@
     "ts-node": "^10.9.1",
     "typescript": "^4.9.5"
   }
-}
+}

+ 0 - 14
backend/test.js

@@ -1,14 +0,0 @@
-import sckey from "soundcloud-key-fetch";
-
-// sckey.fetchKey().then(key => {
-// 	console.log(key);
-// });
-
-// sckey.testKey(KEY).then(result => {
-// 	// returns a boolean; true/false
-// 	if (result) {
-// 		console.log("The key works!");
-// 	} else {
-// 		console.log("The key didn't work.");
-// 	}
-// });

+ 5 - 2
frontend/.eslintignore

@@ -1,2 +1,5 @@
-node_modules
-dist
+.git/
+build/
+dist/fonts/
+dist/assets/
+node_modules/

+ 5 - 2
frontend/.prettierignore

@@ -1,2 +1,5 @@
-node_modules/
-build/
+.git/
+build/
+dist/fonts/
+dist/assets/
+node_modules/

+ 8 - 8
frontend/.prettierrc

@@ -1,8 +1,8 @@
-{
-    "singleQuote": false,
-    "tabWidth": 4,
-    "useTabs": true,
-    "trailingComma": "none",
-    "arrowParens": "avoid",
-    "endOfLine":"auto"
-}
+{
+	"singleQuote": false,
+	"tabWidth": 4,
+	"useTabs": true,
+	"trailingComma": "none",
+	"arrowParens": "avoid",
+	"endOfLine": "lf"
+}

+ 1 - 1
frontend/package.json

@@ -12,7 +12,7 @@
   "license": "GPL-3.0",
   "repository": "https://github.com/Musare/Musare",
   "scripts": {
-    "lint": "eslint --cache src --ext .js,.ts,.vue",
+    "lint": "eslint . --ext .js,.ts,.vue",
     "dev": "vite",
     "prod": "vite build --emptyOutDir",
     "typescript": "vue-tsc --noEmit --skipLibCheck",

+ 4 - 4
frontend/vite.config.js

@@ -54,17 +54,17 @@ const fetchVersionAndGitInfo = () => {
 			let latestCommitShort;
 
 			if (configContents.indexOf(`[branch "${branch}"]`) >= 0) {
-				remote = /remote = (.+)/.exec(
+				[, remote] = /remote = (.+)/.exec(
 					configContents[
 						configContents.indexOf(`[branch "${branch}"]`) + 1
 					]
-				)[1];
+				);
 
-				remoteUrl = /url = (.+)/.exec(
+				[, remoteUrl] = /url = (.+)/.exec(
 					configContents[
 						configContents.indexOf(`[remote "${remote}"]`) + 1
 					]
-				)[1];
+				);
 
 				latestCommit = fs
 					.readFileSync(`${gitFolder}/refs/heads/${branch}`)

+ 3 - 3
musare.sh

@@ -301,17 +301,17 @@ case $1 in
         if [[ ${servicesString:0:1} == 1 ]]; then
             if [[ ${servicesString:2:4} == "all" || "${servicesString:2}" == *frontend* ]]; then
                 echo -e "${CYAN}Running frontend lint...${NC}"
-                ${dockerCompose} exec -T frontend npx eslint $cache src --ext .js,.ts,.vue $fix
+                ${dockerCompose} exec -T frontend npm run lint -- $cache $fix
                 frontendExitValue=$?
             fi
             if [[ ${servicesString:2:4} == "all" || "${servicesString:2}" == *backend* ]]; then
                 echo -e "${CYAN}Running backend lint...${NC}"
-                ${dockerCompose} exec -T backend npx eslint $cache logic $fix
+                ${dockerCompose} exec -T backend npm run lint -- $cache $fix
                 backendExitValue=$?
             fi
             if [[ ${servicesString:2:4} == "all" || "${servicesString:2}" == *docs* ]]; then
                 echo -e "${CYAN}Running docs lint...${NC}"
-                ${docker} run -v "${scriptLocation}":/workdir ghcr.io/igorshubovych/markdownlint-cli:latest ".wiki" "*.md" $fix
+                ${docker} run --rm -v "${scriptLocation}":/workdir ghcr.io/igorshubovych/markdownlint-cli:latest ".wiki" "*.md" $fix
                 docsExitValue=$?
             fi
             if [[ ${frontendExitValue} -gt 0 || ${backendExitValue} -gt 0 || ${docsExitValue} -gt 0 ]]; then