stay-gold 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,15 +1,38 @@
1
1
  {
2
2
  "name": "stay-gold",
3
- "version": "1.0.0",
4
- "description": "Checks and balances",
5
- "main": "index.js",
3
+ "version": "1.0.1",
4
+ "description": "Checks and balances for code quality. Run as a dev dependency in any project.",
5
+ "main": "dist/index.js",
6
6
  "author": "Riley Bathurst <riley@rileybathurst.com> (https://rileybathurst.com)",
7
+ "files": [
8
+ "dist",
9
+ "named-colors.ts",
10
+ "README.md"
11
+ ],
12
+ "bin": {
13
+ "stay-gold-find": "dist/bang.js",
14
+ "stay-gold-todos": "dist/todos.js",
15
+ "stay-gold-css-vars": "dist/css-vars.js",
16
+ "stay-gold-css-named-colors": "dist/css-named-colors.js"
17
+ },
7
18
  "scripts": {
8
- "find": "node check-for-bang.ts",
9
- "todos": "node check-todo.ts",
10
- "variables": "node check-css-vars.ts",
11
- "gold": "npm run find && npm run todos && npm run variables && echo 'All checks passed!' || echo 'Some checks failed!'"
19
+ "build": "tsc",
20
+ "find": "node dist/bang.js",
21
+ "todos": "node dist/todos.js",
22
+ "variables": "node dist/css-vars.js",
23
+ "named-colors": "node dist/css-named-colors.js",
24
+ "gold": "npm run find && npm run todos && npm run variables && npm run named-colors && echo 'All checks passed!' || echo 'Some checks failed!'"
12
25
  },
26
+ "keywords": [
27
+ "code-quality",
28
+ "lint",
29
+ "css",
30
+ "typescript",
31
+ "javascript",
32
+ "todos",
33
+ "variables",
34
+ "named-colors"
35
+ ],
13
36
  "license": "ISC",
14
37
  "devDependencies": {
15
38
  "@types/node": "^24.3.1",
package/bang.ts DELETED
@@ -1,51 +0,0 @@
1
- // check-for-bang.js
2
- // Script to check for the string "// !" in project files and exit with error if found
3
-
4
- import fs from "node:fs";
5
- import path from "node:path";
6
-
7
- const exts = [".js", ".ts", ".astro", ".css", ".tsx"];
8
- // Use CommonJS __dirname directly
9
- const rootDir = path.resolve(__dirname, "src");
10
- const publicDir = path.resolve(__dirname, "public");
11
-
12
- function walk(dir: string): string[] {
13
- let results: string[] = [];
14
- const list: string[] = fs.readdirSync(dir);
15
- list.forEach((file: string) => {
16
- const filePath: string = path.join(dir, file);
17
- const stat: fs.Stats = fs.statSync(filePath);
18
- if (stat?.isDirectory()) {
19
- results = results.concat(walk(filePath));
20
- } else if (exts.includes(path.extname(file))) {
21
- results.push(filePath);
22
- }
23
- });
24
- return results;
25
- }
26
-
27
- function checkFiles(files: string[]): boolean {
28
- let found: boolean = false;
29
- files.forEach((file: string) => {
30
- const content: string = fs.readFileSync(file, "utf8");
31
- if (
32
- content.includes("// !") ||
33
- content.includes("<!-- !") ||
34
- content.includes("{/* !")
35
- ) {
36
- console.error(`Forbidden string found in: ${file}`);
37
- found = true;
38
- }
39
- });
40
- return found;
41
- }
42
-
43
- const srcFiles = walk(rootDir);
44
- const publicFiles = walk(publicDir);
45
- const allFiles = srcFiles.concat(publicFiles);
46
-
47
- if (checkFiles(allFiles)) {
48
- process.exit(1);
49
- } else {
50
- console.log("No forbidden string found.");
51
- }
@@ -1,45 +0,0 @@
1
- // check-css-named-colors.ts
2
- // Script to check for usage of named CSS colors in styles folder
3
-
4
- import fs from "node:fs";
5
- import path from "node:path";
6
- import { namedColors } from "./named-colors.js";
7
-
8
- const __dirname = path.resolve();
9
- const stylesDir = path.resolve(__dirname, "src/styles");
10
- const exts = [".css"];
11
-
12
- // List of named CSS colors (partial, can be expanded)
13
-
14
-
15
- function walkCssFiles(dir: string): string[] {
16
- return fs.readdirSync(dir)
17
- .filter((f: string) => exts.includes(path.extname(f)))
18
- .map((f: string) => path.join(dir, f));
19
- }
20
-
21
- function checkNamedColors(files: string[]): number {
22
- let totalCount = 0;
23
- files.forEach((file: string) => {
24
- const content: string = fs.readFileSync(file, "utf8");
25
- namedColors.forEach((color: string) => {
26
- const regex = new RegExp(`\\b${color}\\b`, "gi");
27
- const matches = content.match(regex);
28
- if (matches && matches.length > 0) {
29
- console.log(`Found ${matches.length} named color(s) '${color}' in: ${file}`);
30
- totalCount += matches.length;
31
- }
32
- });
33
- });
34
- return totalCount;
35
- }
36
-
37
- const cssFiles = walkCssFiles(stylesDir);
38
- const namedColorCount = checkNamedColors(cssFiles);
39
-
40
- if (namedColorCount > 0) {
41
- console.error(`Total named CSS colors found: ${namedColorCount}`);
42
- process.exit(1);
43
- } else {
44
- console.log("No named CSS colors found.");
45
- }
package/css-vars.ts DELETED
@@ -1,66 +0,0 @@
1
- // check-css-vars.ts
2
- // Script to check for usage of undefined CSS variables in styles folder
3
-
4
- import fs from "node:fs";
5
- import path from "node:path";
6
-
7
- // Use CommonJS __dirname directly
8
- if (!require.main || !require.main.filename) {
9
- throw new Error("Cannot determine __dirname: require.main or require.main.filename is undefined.");
10
- }
11
- const __dirname = path.dirname(require.main.filename);
12
- const stylesDir = path.resolve(__dirname, "src/styles");
13
- const variablesFile = path.join(stylesDir, "variables.css");
14
-
15
- function getDefinedVars(file: string): Set<string> {
16
- const content: string = fs.readFileSync(file, "utf8");
17
- const varRegex: RegExp = /--([\w-]+):/g;
18
- const vars: Set<string> = new Set();
19
- let match: RegExpExecArray | null = varRegex.exec(content);
20
- while (match !== null) {
21
- vars.add(match[1]);
22
- match = varRegex.exec(content);
23
- }
24
- return vars;
25
- }
26
-
27
- function getUsedVars(file: string): Set<string> {
28
- const content: string = fs.readFileSync(file, "utf8");
29
- const useRegex: RegExp = /var\(--([\w-]+)\)/g;
30
- const used: Set<string> = new Set();
31
- let match: RegExpExecArray | null = useRegex.exec(content);
32
- while (match !== null) {
33
- used.add(match[1]);
34
- match = useRegex.exec(content);
35
- }
36
- return used;
37
- }
38
-
39
- function walkCssFiles(dir: string): string[] {
40
- return fs
41
- .readdirSync(dir)
42
- .filter((f: string) => f.endsWith(".css") && f !== "variables.css")
43
- .map((f: string) => path.join(dir, f));
44
- }
45
-
46
- const definedVars = getDefinedVars(variablesFile);
47
- const cssFiles = walkCssFiles(stylesDir);
48
- let hasError = false;
49
-
50
- cssFiles.forEach((file) => {
51
- const usedVars = getUsedVars(file);
52
- usedVars.forEach((v) => {
53
- if (!definedVars.has(v)) {
54
- console.error(
55
- `Undefined CSS variable --${v} used in ${path.basename(file)}`,
56
- );
57
- hasError = true;
58
- }
59
- });
60
- });
61
-
62
- if (hasError) {
63
- process.exit(1);
64
- } else {
65
- console.log("All CSS variables used are defined.");
66
- }
package/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from "./bang.js";
2
- export * from "./css-named-colors.js";
3
- export * from "./css-vars.js";
4
- export * from "./todos.js";
package/todos.ts DELETED
@@ -1,52 +0,0 @@
1
- // check-todo.ts
2
- // Script to check for the string "TODO:" in project files and count occurrences
3
-
4
- import fs from "node:fs";
5
- import path from "node:path";
6
-
7
- const exts = [".js", ".ts", ".astro", ".css", ".tsx"];
8
- const mainFilename = require.main?.filename ?? __filename;
9
- const __dirname = path.dirname(mainFilename);
10
- const rootDir = path.resolve(__dirname, "src");
11
- const publicDir = path.resolve(__dirname, "public");
12
-
13
- function walk(dir: string): string[] {
14
- let results: string[] = [];
15
- const list: string[] = fs.readdirSync(dir);
16
- list.forEach((file: string) => {
17
- const filePath: string = path.join(dir, file);
18
- const stat: fs.Stats = fs.statSync(filePath);
19
- if (stat?.isDirectory()) {
20
- results = results.concat(walk(filePath));
21
- } else if (exts.includes(path.extname(file))) {
22
- results.push(filePath);
23
- }
24
- });
25
- return results;
26
- }
27
-
28
- function checkTodos(files: string[]): number {
29
- let totalCount = 0;
30
- files.forEach((file: string) => {
31
- const content: string = fs.readFileSync(file, "utf8");
32
- const matches = content.match(/TODO:/g);
33
- if (matches && matches.length > 0) {
34
- console.log(`Found ${matches.length} TODO(s) in: ${file}`);
35
- totalCount += matches.length;
36
- }
37
- });
38
- return totalCount;
39
- }
40
-
41
- const srcFiles = walk(rootDir);
42
- const publicFiles = walk(publicDir);
43
- const allFiles = srcFiles.concat(publicFiles);
44
-
45
- const todoCount = checkTodos(allFiles);
46
-
47
- if (todoCount > 0) {
48
- console.warn(`Total TODOs found: ${todoCount}`);
49
- process.exit(1);
50
- } else {
51
- console.log("No TODOs found.");
52
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2019",
4
- "module": "NodeNext",
5
- "declaration": true,
6
- "outDir": "dist",
7
- "moduleResolution": "nodenext",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "types": ["node"]
12
- },
13
- "include": ["*.ts"]
14
- }