Skip to content

Commit eb6f048

Browse files
committed
fix: skip postinstall git clean when not in a git repository
1 parent 623e1e2 commit eb6f048

3 files changed

Lines changed: 26 additions & 55 deletions

File tree

package-lock.json

Lines changed: 0 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"css",
4242
"defaultmodules",
4343
"js",
44+
"scripts",
4445
"serveronly",
4546
"translations",
4647
"favicon.svg",
@@ -49,7 +50,7 @@
4950
"sideEffects": true,
5051
"scripts": {
5152
"config:check": "node js/check_config.js",
52-
"postinstall": "git clean -df fonts vendor modules/default",
53+
"postinstall": "node scripts/postinstall.js",
5354
"install-mm": "npm install --no-audit --no-fund --no-update-notifier --only=prod --omit=dev",
5455
"install-mm:dev": "npm install --no-audit --no-fund --no-update-notifier && npx playwright install chromium",
5556
"lint:css": "stylelint 'css/**/*.css' 'defaultmodules/**/*.css' --fix",

scripts/postinstall.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
/**
3+
* postinstall.js
4+
*
5+
* Runs `git clean -df fonts vendor modules/default` only when executed
6+
* inside a git repository. When magicmirror is installed as an npm
7+
* dependency in another project, the working directory is not a git
8+
* repo and the clean step is silently skipped.
9+
*
10+
* Cross-platform (Linux, macOS, Windows).
11+
*/
12+
13+
"use strict";
14+
15+
const { execSync } = require("child_process");
16+
17+
try {
18+
execSync("git rev-parse --git-dir", { stdio: "ignore" });
19+
} catch {
20+
// Not a git repository — skip git clean.
21+
process.exit(0);
22+
}
23+
24+
execSync("git clean -df fonts vendor modules/default", { stdio: "inherit" });

0 commit comments

Comments
 (0)