brick-break 1.0.0 → 1.1.0

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
@@ -27,14 +27,29 @@ or just run it directly:
27
27
  npx brick-break next build
28
28
  ```
29
29
 
30
+ ## global install (recommended for non-js projects)
31
+
32
+ ```bash
33
+ npm i -g brick-break
34
+ ```
35
+
36
+ now you can use `bb` anywhere:
37
+
38
+ ```bash
39
+ bb cargo build
40
+ bb go build
41
+ bb pytest
42
+ bb make
43
+ ```
44
+
30
45
  ## works with everything
31
46
 
32
47
  ```bash
33
- brick-break next build
34
- brick-break npm run build
35
- brick-break tsc
36
- brick-break cargo build
37
- brick-break go build
48
+ bb next build
49
+ bb npm run build
50
+ bb tsc
51
+ bb cargo build
52
+ bb go build
38
53
  ```
39
54
 
40
55
  if it can fail, brick-break can make it funnier.
package/dist/cli.js CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const index_1 = require("./index");
5
5
  const args = process.argv.slice(2);
6
6
  if (!args.length) {
7
- console.log('usage: brick-break <command>');
8
- console.log('example: brick-break npm run build');
7
+ console.log('usage: bb <command>');
8
+ console.log('example: bb npm run build');
9
9
  process.exit(1);
10
10
  }
11
11
  (0, index_1.runCommand)(args);
package/dist/index.js CHANGED
@@ -8,7 +8,13 @@ exports.runCommand = runCommand;
8
8
  const child_process_1 = require("child_process");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const sound = path_1.default.join(__dirname, '..', 'sound.mp3');
11
+ let lastPlayed = 0;
12
+ const cooldown = 3000; // don't spam the sound
11
13
  function playSound() {
14
+ const now = Date.now();
15
+ if (now - lastPlayed < cooldown)
16
+ return;
17
+ lastPlayed = now;
12
18
  const p = process.platform;
13
19
  if (p === 'darwin') {
14
20
  (0, child_process_1.spawn)('afplay', [sound]);
@@ -17,15 +23,44 @@ function playSound() {
17
23
  (0, child_process_1.spawn)('powershell', ['-c', `(New-Object Media.SoundPlayer '${sound}').PlaySync()`]);
18
24
  }
19
25
  else {
20
- // linux - try pulseaudio first, fallback to alsa
21
26
  const player = (0, child_process_1.spawn)('paplay', [sound]);
22
27
  player.on('error', () => (0, child_process_1.spawn)('aplay', [sound]));
23
28
  }
24
29
  }
30
+ // patterns that indicate an error
31
+ const errorPatterns = [
32
+ /\u{2A2F}/u, // ⨯ (nextjs error)
33
+ /error(\[|:|\s)/i, // error: or error[ or error
34
+ /failed/i,
35
+ /exception/i,
36
+ /panic/i, // rust/go
37
+ /cannot find/i,
38
+ /not found/i,
39
+ /undefined/i,
40
+ /compilation failed/i,
41
+ ];
42
+ function hasError(text) {
43
+ return errorPatterns.some(p => p.test(text));
44
+ }
25
45
  function runCommand(args) {
26
46
  const cmd = args[0];
27
47
  const rest = args.slice(1);
28
- const proc = (0, child_process_1.spawn)(cmd, rest, { stdio: 'inherit', shell: true });
48
+ const proc = (0, child_process_1.spawn)(cmd, rest, {
49
+ stdio: ['inherit', 'pipe', 'pipe'],
50
+ shell: true
51
+ });
52
+ proc.stdout?.on('data', (data) => {
53
+ const text = data.toString();
54
+ process.stdout.write(text);
55
+ if (hasError(text))
56
+ playSound();
57
+ });
58
+ proc.stderr?.on('data', (data) => {
59
+ const text = data.toString();
60
+ process.stderr.write(text);
61
+ if (hasError(text))
62
+ playSound();
63
+ });
29
64
  proc.on('close', code => {
30
65
  if (code !== 0)
31
66
  playSound();
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "brick-break",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Play a Lego break sound when your build fails",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {
8
- "brick-break": "dist/cli.js"
8
+ "brick-break": "dist/cli.js",
9
+ "bb": "dist/cli.js"
9
10
  },
10
11
  "files": [
11
12
  "dist",