brick-break 1.2.1 → 1.3.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 +9 -1
- package/dist/cli.js +41 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,15 @@ if it can fail, brick-break can make it funnier.
|
|
|
56
56
|
|
|
57
57
|
## next.js hmr support
|
|
58
58
|
|
|
59
|
-
for errors that happen while the dev server is running (hot reload)
|
|
59
|
+
for errors that happen while the dev server is running (hot reload):
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bb init
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
this automatically adds `<BrickBreak />` to your layout.tsx.
|
|
66
|
+
|
|
67
|
+
or add it manually:
|
|
60
68
|
|
|
61
69
|
```tsx
|
|
62
70
|
// app/layout.tsx
|
package/dist/cli.js
CHANGED
|
@@ -2,21 +2,57 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
5
7
|
const args = process.argv.slice(2);
|
|
6
8
|
if (!args.length) {
|
|
7
9
|
console.log('usage: bb <command>');
|
|
10
|
+
console.log(' bb init - setup next.js hmr support');
|
|
8
11
|
console.log('example: bb npm run build');
|
|
9
12
|
process.exit(1);
|
|
10
13
|
}
|
|
14
|
+
// handle init command
|
|
15
|
+
if (args[0] === 'init') {
|
|
16
|
+
const layoutPaths = [
|
|
17
|
+
(0, path_1.join)(process.cwd(), 'app/layout.tsx'),
|
|
18
|
+
(0, path_1.join)(process.cwd(), 'src/app/layout.tsx'),
|
|
19
|
+
(0, path_1.join)(process.cwd(), 'app/layout.jsx'),
|
|
20
|
+
(0, path_1.join)(process.cwd(), 'src/app/layout.jsx'),
|
|
21
|
+
];
|
|
22
|
+
const layoutPath = layoutPaths.find(p => (0, fs_1.existsSync)(p));
|
|
23
|
+
if (!layoutPath) {
|
|
24
|
+
console.log('\x1b[31merror: no layout.tsx found\x1b[0m');
|
|
25
|
+
console.log('make sure you are in a next.js project root');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
let content = (0, fs_1.readFileSync)(layoutPath, 'utf-8');
|
|
29
|
+
if (content.includes('brick-break')) {
|
|
30
|
+
console.log('\x1b[33mbrick-break already installed in layout\x1b[0m');
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
// add import at the top (after other imports or 'use client')
|
|
34
|
+
const importLine = "import { BrickBreak } from 'brick-break/next'\n";
|
|
35
|
+
if (content.includes("'use client'") || content.includes('"use client"')) {
|
|
36
|
+
content = content.replace(/(["']use client["'][\s\n]*)/, `$1${importLine}`);
|
|
37
|
+
}
|
|
38
|
+
else if (content.includes('import ')) {
|
|
39
|
+
content = content.replace(/(import .+\n)/, `${importLine}$1`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
content = importLine + content;
|
|
43
|
+
}
|
|
44
|
+
// add <BrickBreak /> after <body> or <body ...>
|
|
45
|
+
content = content.replace(/(<body[^>]*>)(\s*)/, '$1$2<BrickBreak />\n ');
|
|
46
|
+
(0, fs_1.writeFileSync)(layoutPath, content);
|
|
47
|
+
console.log('\x1b[32m✓ added BrickBreak to ' + layoutPath + '\x1b[0m');
|
|
48
|
+
console.log('hmr errors will now play the sound');
|
|
49
|
+
process.exit(0);
|
|
50
|
+
}
|
|
11
51
|
// detect next.js dev mode
|
|
12
52
|
const isNextDev = args.some(a => a.includes('next')) && args.some(a => a === 'dev');
|
|
13
53
|
if (isNextDev) {
|
|
14
54
|
console.log('\x1b[36m');
|
|
15
|
-
console.log('brick-break: for hmr error sounds,
|
|
16
|
-
console.log('');
|
|
17
|
-
console.log(" import { BrickBreak } from 'brick-break/next'");
|
|
18
|
-
console.log('');
|
|
19
|
-
console.log(' // then add <BrickBreak /> inside <body>');
|
|
55
|
+
console.log('brick-break: for hmr error sounds, run: bb init');
|
|
20
56
|
console.log('\x1b[0m');
|
|
21
57
|
}
|
|
22
58
|
(0, index_1.runCommand)(args);
|