guard-my-design-system 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -83,7 +83,7 @@ Judge your uncommitted work before anyone else sees it:
83
83
  npx guard-my-design-system@latest
84
84
  ```
85
85
 
86
- | Command | What you get |
86
+ | Command                                                   | What you get |
87
87
  |---|---|
88
88
  | <code>npx&nbsp;guard-my-design-system@latest</code> | Your working tree's added lines judged against main, in the terminal |
89
89
  | <code>npx&nbsp;guard-my-design-system@latest&nbsp;&lt;path&gt;</code> | Judge a different repo than the current directory |
package/index.mjs CHANGED
@@ -13,6 +13,8 @@
13
13
  * --strict, 2 could not run.
14
14
  */
15
15
  import { resolve } from 'node:path';
16
+ import { readFileSync } from 'node:fs';
17
+ import { execFileSync } from 'node:child_process';
16
18
  import { learnSystem } from 'roast-my-design-system/engine';
17
19
  import { defaultBase, addedLines } from './src/diff.mjs';
18
20
  import { judge } from './src/judge.mjs';
@@ -25,7 +27,22 @@ const opt = (name) => {
25
27
  return i > -1 && argv[i + 1] ? argv[i + 1] : null;
26
28
  };
27
29
 
30
+ if (flag('version') || argv.includes('-v')) {
31
+ const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
32
+ console.log(`guard-my-design-system ${pkg.version}`);
33
+ process.exit(0);
34
+ }
35
+
28
36
  const cwd = resolve(argv[0] && !argv[0].startsWith('--') ? argv[0] : '.');
37
+
38
+ // The guard judges diffs, so a git repository is its whole world. Say so
39
+ // calmly instead of letting git's own fatals leak through.
40
+ try {
41
+ execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd, stdio: 'ignore' });
42
+ } catch {
43
+ console.error('guard: this is not a git repository, and the guard judges diffs. Run it inside a repo.');
44
+ process.exit(2);
45
+ }
29
46
  const base = opt('base') ?? defaultBase(cwd);
30
47
  if (!base) {
31
48
  console.error('guard: cannot find a base to diff against (no origin/main, origin/master, main or master). Pass one with --base <ref>.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guard-my-design-system",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Your design system dies one pull request at a time. This makes sure it doesn't. A guard that judges only the lines a change adds, against the system the repo already has, and names the on-system value the author probably meant.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/diff.mjs CHANGED
@@ -11,7 +11,7 @@ import { join } from 'node:path';
11
11
  export function defaultBase(cwd) {
12
12
  for (const ref of ['origin/main', 'origin/master', 'main', 'master']) {
13
13
  try {
14
- return execFileSync('git', ['merge-base', 'HEAD', ref], { cwd, encoding: 'utf8' }).trim();
14
+ return execFileSync('git', ['merge-base', 'HEAD', ref], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
15
15
  } catch { /* try the next spelling */ }
16
16
  }
17
17
  return null;