fork
Configure Feed
Select the types of activity you want to include in your feed.
this repo has no description
fork
Configure Feed
Select the types of activity you want to include in your feed.
1// Janky script to get around pnpm link issues
2// Probably don't use this. Probably
3/* eslint-disable no-console */
4const fs = require("fs");
5const path = require("path");
6const child_process = require("child_process");
7
8const cwd = process.cwd();
9const onDisk = {
10 "@moonlight-mod/lunast": "../lunast",
11 "@moonlight-mod/moonmap": "../moonmap",
12 "@moonlight-mod/mappings": "../mappings"
13};
14
15function exec(cmd, dir) {
16 child_process.execSync(cmd, { cwd: dir, stdio: "inherit" });
17}
18
19function getDeps(packageJSON) {
20 const ret = {};
21 Object.assign(ret, packageJSON.dependencies || {});
22 Object.assign(ret, packageJSON.devDependencies || {});
23 Object.assign(ret, packageJSON.peerDependencies || {});
24 return ret;
25}
26
27function link(dir) {
28 const packageJSONPath = path.join(dir, "package.json");
29 if (!fs.existsSync(packageJSONPath)) return;
30 const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf8"));
31 const deps = getDeps(packageJSON);
32
33 for (const [dep, relativePath] of Object.entries(onDisk)) {
34 const fullPath = path.join(cwd, relativePath);
35 if (deps[dep]) {
36 exec(`pnpm link ${fullPath}`, dir);
37 }
38 }
39}
40
41function undo(dir) {
42 exec("pnpm unlink", dir);
43 try {
44 if (fs.existsSync(path.join(dir, "pnpm-lock.yaml"))) {
45 exec("git restore pnpm-lock.yaml", dir);
46 }
47 } catch {
48 // ignored
49 }
50}
51
52const shouldUndo = process.argv.includes("--undo");
53const packages = fs.readdirSync("./packages");
54
55for (const path of Object.values(onDisk)) {
56 console.log(path);
57 if (shouldUndo) {
58 undo(path);
59 } else {
60 link(path);
61 }
62}
63
64if (shouldUndo) {
65 console.log(cwd);
66 undo(cwd);
67 for (const pkg of packages) {
68 const dir = path.join(cwd, "packages", pkg);
69 console.log(dir);
70 undo(dir);
71 }
72} else {
73 for (const pkg of packages) {
74 const dir = path.join(cwd, "packages", pkg);
75 console.log(dir);
76 link(dir);
77 }
78}