stay-gold 1.0.3 → 1.0.4

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/dist/bang.js CHANGED
@@ -1,29 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  // check-for-bang.js
3
3
  // Script to check for the string "// !" in project files and exit with error if found
4
- import { readdirSync, statSync, readFileSync } from "node:fs";
5
- import { resolve, join, extname, dirname } from "node:path";
6
- import { fileURLToPath } from "node:url";
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
4
+ import { readFileSync } from "node:fs";
5
+ import { resolve } from "node:path";
6
+ import { walk } from "./walk.js";
9
7
  const exts = [".js", ".ts", ".astro", ".css", ".tsx"];
10
8
  const rootDir = resolve(process.cwd(), "src");
11
9
  const publicDir = resolve(process.cwd(), "public");
12
- function walk(dir) {
13
- let results = [];
14
- const list = readdirSync(dir);
15
- list.forEach((file) => {
16
- const filePath = join(dir, file);
17
- const stat = statSync(filePath);
18
- if (stat === null || stat === void 0 ? void 0 : stat.isDirectory()) {
19
- results = results.concat(walk(filePath));
20
- }
21
- else if (exts.includes(extname(file))) {
22
- results.push(filePath);
23
- }
24
- });
25
- return results;
26
- }
27
10
  function checkFiles(files) {
28
11
  let found = false;
29
12
  files.forEach((file) => {
@@ -37,8 +20,8 @@ function checkFiles(files) {
37
20
  });
38
21
  return found;
39
22
  }
40
- const srcFiles = walk(rootDir);
41
- const publicFiles = walk(publicDir);
23
+ const srcFiles = walk(rootDir, exts);
24
+ const publicFiles = walk(publicDir, exts);
42
25
  const allFiles = srcFiles.concat(publicFiles);
43
26
  if (checkFiles(allFiles)) {
44
27
  process.exit(1);
@@ -1 +1,2 @@
1
+ #!/usr/bin/env node
1
2
  export {};
@@ -1,21 +1,20 @@
1
+ #!/usr/bin/env node
1
2
  // check-css-named-colors.ts
2
3
  // Script to check for usage of named CSS colors in styles folder
3
- import fs from "node:fs";
4
- import path from "node:path";
4
+ import { readFileSync, readdirSync } from "node:fs";
5
+ import { resolve, join, extname } from "node:path";
5
6
  import { namedColors } from "./named-colors.js";
6
- const __dirname = path.resolve();
7
- const stylesDir = path.resolve(__dirname, "src/styles");
7
+ const stylesDir = resolve(process.cwd(), "src/styles");
8
8
  const exts = [".css"];
9
- // List of named CSS colors (partial, can be expanded)
10
9
  function walkCssFiles(dir) {
11
- return fs.readdirSync(dir)
12
- .filter((f) => exts.includes(path.extname(f)))
13
- .map((f) => path.join(dir, f));
10
+ return readdirSync(dir)
11
+ .filter((f) => exts.includes(extname(f)))
12
+ .map((f) => join(dir, f));
14
13
  }
15
14
  function checkNamedColors(files) {
16
15
  let totalCount = 0;
17
16
  files.forEach((file) => {
18
- const content = fs.readFileSync(file, "utf8");
17
+ const content = readFileSync(file, "utf8");
19
18
  namedColors.forEach((color) => {
20
19
  const regex = new RegExp(`\\b${color}\\b`, "gi");
21
20
  const matches = content.match(regex);
@@ -1 +1,2 @@
1
+ #!/usr/bin/env node
1
2
  export {};
package/dist/css-vars.js CHANGED
@@ -1,16 +1,12 @@
1
+ #!/usr/bin/env node
1
2
  // check-css-vars.ts
2
3
  // Script to check for usage of undefined CSS variables in styles folder
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- // Use CommonJS __dirname directly
6
- if (!require.main || !require.main.filename) {
7
- throw new Error("Cannot determine __dirname: require.main or require.main.filename is undefined.");
8
- }
9
- const __dirname = path.dirname(require.main.filename);
10
- const stylesDir = path.resolve(__dirname, "src/styles");
11
- const variablesFile = path.join(stylesDir, "variables.css");
4
+ import { readFileSync, readdirSync } from "node:fs";
5
+ import { resolve, join, basename } from "node:path";
6
+ const stylesDir = resolve(process.cwd(), "src/styles");
7
+ const variablesFile = join(stylesDir, "variables.css");
12
8
  function getDefinedVars(file) {
13
- const content = fs.readFileSync(file, "utf8");
9
+ const content = readFileSync(file, "utf8");
14
10
  const varRegex = /--([\w-]+):/g;
15
11
  const vars = new Set();
16
12
  let match = varRegex.exec(content);
@@ -21,7 +17,7 @@ function getDefinedVars(file) {
21
17
  return vars;
22
18
  }
23
19
  function getUsedVars(file) {
24
- const content = fs.readFileSync(file, "utf8");
20
+ const content = readFileSync(file, "utf8");
25
21
  const useRegex = /var\(--([\w-]+)\)/g;
26
22
  const used = new Set();
27
23
  let match = useRegex.exec(content);
@@ -32,10 +28,9 @@ function getUsedVars(file) {
32
28
  return used;
33
29
  }
34
30
  function walkCssFiles(dir) {
35
- return fs
36
- .readdirSync(dir)
31
+ return readdirSync(dir)
37
32
  .filter((f) => f.endsWith(".css") && f !== "variables.css")
38
- .map((f) => path.join(dir, f));
33
+ .map((f) => join(dir, f));
39
34
  }
40
35
  const definedVars = getDefinedVars(variablesFile);
41
36
  const cssFiles = walkCssFiles(stylesDir);
@@ -44,7 +39,7 @@ cssFiles.forEach((file) => {
44
39
  const usedVars = getUsedVars(file);
45
40
  usedVars.forEach((v) => {
46
41
  if (!definedVars.has(v)) {
47
- console.error(`Undefined CSS variable --${v} used in ${path.basename(file)}`);
42
+ console.error(`Undefined CSS variable --${v} used in ${basename(file)}`);
48
43
  hasError = true;
49
44
  }
50
45
  });
package/dist/todos.d.ts CHANGED
@@ -1 +1,2 @@
1
+ #!/usr/bin/env node
1
2
  export {};
package/dist/todos.js CHANGED
@@ -1,32 +1,16 @@
1
+ #!/usr/bin/env node
1
2
  // check-todo.ts
2
3
  // Script to check for the string "TODO:" in project files and count occurrences
3
- var _a, _b;
4
- import fs from "node:fs";
5
- import path from "node:path";
4
+ import { readFileSync } from "node:fs";
5
+ import { resolve } from "node:path";
6
+ import { walk } from "./walk.js";
6
7
  const exts = [".js", ".ts", ".astro", ".css", ".tsx"];
7
- const mainFilename = (_b = (_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) !== null && _b !== void 0 ? _b : __filename;
8
- const __dirname = path.dirname(mainFilename);
9
- const rootDir = path.resolve(__dirname, "src");
10
- const publicDir = path.resolve(__dirname, "public");
11
- function walk(dir) {
12
- let results = [];
13
- const list = fs.readdirSync(dir);
14
- list.forEach((file) => {
15
- const filePath = path.join(dir, file);
16
- const stat = fs.statSync(filePath);
17
- if (stat === null || stat === void 0 ? void 0 : stat.isDirectory()) {
18
- results = results.concat(walk(filePath));
19
- }
20
- else if (exts.includes(path.extname(file))) {
21
- results.push(filePath);
22
- }
23
- });
24
- return results;
25
- }
8
+ const rootDir = resolve(process.cwd(), "src");
9
+ const publicDir = resolve(process.cwd(), "public");
26
10
  function checkTodos(files) {
27
11
  let totalCount = 0;
28
12
  files.forEach((file) => {
29
- const content = fs.readFileSync(file, "utf8");
13
+ const content = readFileSync(file, "utf8");
30
14
  const matches = content.match(/TODO:/g);
31
15
  if (matches && matches.length > 0) {
32
16
  console.log(`Found ${matches.length} TODO(s) in: ${file}`);
@@ -35,8 +19,8 @@ function checkTodos(files) {
35
19
  });
36
20
  return totalCount;
37
21
  }
38
- const srcFiles = walk(rootDir);
39
- const publicFiles = walk(publicDir);
22
+ const srcFiles = walk(rootDir, exts);
23
+ const publicFiles = walk(publicDir, exts);
40
24
  const allFiles = srcFiles.concat(publicFiles);
41
25
  const todoCount = checkTodos(allFiles);
42
26
  if (todoCount > 0) {
package/dist/walk.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function walk(dir: string, exts: string[]): string[];
2
+ export { walk };
package/dist/walk.js ADDED
@@ -0,0 +1,18 @@
1
+ import { readdirSync, statSync } from "node:fs";
2
+ import { extname, join } from "node:path";
3
+ function walk(dir, exts) {
4
+ let results = [];
5
+ const list = readdirSync(dir);
6
+ list.forEach((file) => {
7
+ const filePath = join(dir, file);
8
+ const stat = statSync(filePath);
9
+ if (stat === null || stat === void 0 ? void 0 : stat.isDirectory()) {
10
+ results = results.concat(walk(filePath, exts));
11
+ }
12
+ else if (exts.includes(extname(file))) {
13
+ results.push(filePath);
14
+ }
15
+ });
16
+ return results;
17
+ }
18
+ export { walk };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stay-gold",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "Checks and balances for code quality. Run as a dev dependency in any project.",
6
6
  "main": "dist/index.js",