Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Add Additional Scripts to 'npm run fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Aug 23, 2022
1 parent b58dcd6 commit 608092c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@
"pre-commit": "lint"
}
}
}
}
27 changes: 27 additions & 0 deletions scripts/doctor/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import glob from 'glob';

export async function fileChecker() {
const fileList = await new Promise((resolve) => {
glob('./{src,src-webviews,resources}/**/*', (err, files) => {
if (err) {
return resolve(files);
}

return resolve(files);
});
});

console.log(`Verifying ${fileList.length} Files`);
let validated = 0;
for (let filePath of fileList) {
let isValid = /^[a-zA-Z 0-9\-._\/\\]+$/g.test(filePath)

if (isValid) {
validated += 1;
} else {
console.warn(`Invalid File Name: ${filePath}`);
}
}

console.log(`${validated}/${fileList.length} Validated`)
}
7 changes: 6 additions & 1 deletion scripts/doctor/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import glob from 'glob';
import path from 'path';
import { fileChecker } from './files.js';

function sanitizePath(p) {
return p.replace(/\\/g, '/');
Expand Down Expand Up @@ -54,7 +55,7 @@ async function cleanup() {

let badFiles = [];
badFiles = await new Promise((resolve) => {
glob('./src/core/**/*.js', (err, files) => {
glob('./{src,src-webviews}/core/**/*.js', (err, files) => {
if (err) {
return resolve(files);
}
Expand All @@ -65,9 +66,13 @@ async function cleanup() {

for (const file of badFiles) {
if (fs.existsSync(file)) {
console.log(`Removed File: ${file}`);
fs.rmSync(file, { recursive: true, force: true });
}
}

// Checks for invalid file names...
await fileChecker();
}

init();

0 comments on commit 608092c

Please sign in to comment.