mavi-dashboard 0.0.8 → 0.0.9
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 +4 -0
- package/package.json +5 -2
- package/scripts/postinstall.cjs +85 -0
package/README.md
CHANGED
|
@@ -33,3 +33,7 @@ Styles are generated when Tailwind scans this package’s sources. Your app **mu
|
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
Without `@tailwindcss/vite`, or without scanning `mavi-dashboard` sources (fixed in `@heinricov/mavi-ui` ≥ 0.0.2), the layout will look unstyled.
|
|
36
|
+
|
|
37
|
+
## Install hook
|
|
38
|
+
|
|
39
|
+
On `npm install`, if the project looks like **Vite + React** or **Create React App**, this package overwrites `src/App.tsx` (or `src/App.jsx` if that file already exists) with the default route shell from the Mavi demo (requires `react-router-dom`). Set `MAVI_DASHBOARD_SKIP_INSTALL_HOOK=1` to skip.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mavi-dashboard",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "React dashboard layout with sidebar, header, and theme shell",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,9 +25,11 @@
|
|
|
25
25
|
"types": "./src/dashboard/index.ts",
|
|
26
26
|
"files": [
|
|
27
27
|
"src",
|
|
28
|
+
"scripts",
|
|
28
29
|
"README.md"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
32
|
+
"postinstall": "node ./scripts/postinstall.cjs",
|
|
31
33
|
"typecheck": "tsc --noEmit"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
@@ -36,7 +38,8 @@
|
|
|
36
38
|
"peerDependencies": {
|
|
37
39
|
"lucide-react": "^1.8.0",
|
|
38
40
|
"react": "^18.0.0 || ^19.0.0",
|
|
39
|
-
"react-dom": "^18.0.0 || ^19.0.0"
|
|
41
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
42
|
+
"react-router-dom": "^6.0.0 || ^7.0.0"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"@types/react": "^19.2.10",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require("fs")
|
|
3
|
+
const path = require("path")
|
|
4
|
+
|
|
5
|
+
if (
|
|
6
|
+
process.env.MAVI_DASHBOARD_SKIP_INSTALL_HOOK === "1" ||
|
|
7
|
+
process.env.MAVI_DASHBOARD_SKIP_POSTINSTALL === "1"
|
|
8
|
+
) {
|
|
9
|
+
process.exit(0)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const projectRoot = process.env.INIT_CWD || process.cwd()
|
|
13
|
+
const thisPackageRoot = path.resolve(__dirname, "..")
|
|
14
|
+
|
|
15
|
+
if (path.resolve(projectRoot) === path.resolve(thisPackageRoot)) {
|
|
16
|
+
process.exit(0)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let pkg
|
|
20
|
+
try {
|
|
21
|
+
pkg = JSON.parse(
|
|
22
|
+
fs.readFileSync(path.join(projectRoot, "package.json"), "utf8"),
|
|
23
|
+
)
|
|
24
|
+
} catch {
|
|
25
|
+
process.exit(0)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies }
|
|
29
|
+
const hasReact = Boolean(deps.react || deps["react-dom"])
|
|
30
|
+
if (!hasReact) process.exit(0)
|
|
31
|
+
|
|
32
|
+
if (deps.next || deps["@remix-run/react"]) process.exit(0)
|
|
33
|
+
|
|
34
|
+
const hasVite =
|
|
35
|
+
Boolean(deps.vite || deps["@vitejs/plugin-react"]) ||
|
|
36
|
+
[
|
|
37
|
+
"vite.config.ts",
|
|
38
|
+
"vite.config.js",
|
|
39
|
+
"vite.config.mjs",
|
|
40
|
+
"vite.config.cjs",
|
|
41
|
+
"vite.config.mts",
|
|
42
|
+
].some((name) => fs.existsSync(path.join(projectRoot, name)))
|
|
43
|
+
|
|
44
|
+
const isCra = Boolean(deps["react-scripts"])
|
|
45
|
+
if (!((hasVite && hasReact) || isCra)) process.exit(0)
|
|
46
|
+
|
|
47
|
+
const appSource = `import { Routes, Route } from "react-router-dom"
|
|
48
|
+
|
|
49
|
+
export function App() {
|
|
50
|
+
return (
|
|
51
|
+
<Routes>
|
|
52
|
+
<Route path="/" element={<div>Dashboard</div>} />
|
|
53
|
+
<Route path="/laporan" element={<div>Laporan</div>} />
|
|
54
|
+
<Route path="/project/1" element={<div>Project 1</div>} />
|
|
55
|
+
<Route path="/project/2" element={<div>Project 2</div>} />
|
|
56
|
+
<Route path="/project/3" element={<div>Project 3</div>} />
|
|
57
|
+
<Route path="/project/4" element={<div>Project 4</div>} />
|
|
58
|
+
<Route path="/data-produk" element={<div>Data Produk</div>} />
|
|
59
|
+
<Route path="/data-user" element={<div>Data User</div>} />
|
|
60
|
+
<Route path="/about" element={<div>About</div>} />
|
|
61
|
+
<Route path="/settings" element={<div>Settings</div>} />
|
|
62
|
+
</Routes>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
|
|
67
|
+
const srcDir = path.join(projectRoot, "src")
|
|
68
|
+
const tsxPath = path.join(srcDir, "App.tsx")
|
|
69
|
+
const jsxPath = path.join(srcDir, "App.jsx")
|
|
70
|
+
|
|
71
|
+
let targetPath
|
|
72
|
+
if (fs.existsSync(tsxPath)) targetPath = tsxPath
|
|
73
|
+
else if (fs.existsSync(jsxPath)) targetPath = jsxPath
|
|
74
|
+
else targetPath = tsxPath
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
if (!fs.existsSync(srcDir)) fs.mkdirSync(srcDir, { recursive: true })
|
|
78
|
+
if (fs.existsSync(targetPath)) {
|
|
79
|
+
const current = fs.readFileSync(targetPath, "utf8")
|
|
80
|
+
if (current === appSource) process.exit(0)
|
|
81
|
+
}
|
|
82
|
+
fs.writeFileSync(targetPath, appSource, "utf8")
|
|
83
|
+
} catch {
|
|
84
|
+
process.exit(0)
|
|
85
|
+
}
|