placementt-core 1.400.962 → 1.400.963
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/package.json +3 -2
- package/watch-local.js +99 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "placementt-core",
|
|
4
4
|
"author": "Placementt",
|
|
5
|
-
"version": "1.400.
|
|
5
|
+
"version": "1.400.963",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"pack": "yarn pack",
|
|
15
15
|
"deploy": "tsc && yarn publish",
|
|
16
16
|
"deploy-all": "node deploy-all.js",
|
|
17
|
-
"test-local": "node test-local.js"
|
|
17
|
+
"test-local": "node test-local.js",
|
|
18
|
+
"watch-local": "node watch-local.js"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
20
21
|
"@reduxjs/toolkit": "^2.0.0",
|
package/watch-local.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Watch mode for the local yalc dev loop: keeps `tsc --watch` running against
|
|
3
|
+
// the current working tree (including uncommitted changes), and on every
|
|
4
|
+
// successful compile runs `yalc push`, which republishes the sentinel
|
|
5
|
+
// version and pushes the update into any project that has already run
|
|
6
|
+
// `yalc add placementt-core@<sentinel>` (i.e. already run `yarn core d` /
|
|
7
|
+
// `yarn core p` once). Mirrors the config-swap logic in test-local.js, but
|
|
8
|
+
// swaps once for the whole session instead of once per build.
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
const {execSync, spawn} = require("child_process");
|
|
11
|
+
|
|
12
|
+
const flagMap = {
|
|
13
|
+
"prod": "prod",
|
|
14
|
+
"dev": "dev",
|
|
15
|
+
"p": "prod",
|
|
16
|
+
"d": "dev",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const flag = process.argv.find((arg) => Object.keys(flagMap).includes(arg));
|
|
20
|
+
|
|
21
|
+
if (!flag) {
|
|
22
|
+
console.error("Usage: yarn watch-local dev | yarn watch-local prod (or -d / -p)");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const target = flagMap[flag];
|
|
27
|
+
const localVersion = target === "dev" ? "0.0.0-local-dev" : "0.0.0-local-prod";
|
|
28
|
+
|
|
29
|
+
const packageJsonPath = "package.json";
|
|
30
|
+
const firebaseConfigPath = "src/firebase/firebaseConfig.tsx";
|
|
31
|
+
const hooksPath = "src/hooks.tsx";
|
|
32
|
+
|
|
33
|
+
const originalPackageJson = fs.readFileSync(packageJsonPath, "utf8");
|
|
34
|
+
const originalFirebaseConfig = fs.readFileSync(firebaseConfigPath, "utf8");
|
|
35
|
+
const originalHooks = fs.readFileSync(hooksPath, "utf8");
|
|
36
|
+
|
|
37
|
+
let restored = false;
|
|
38
|
+
function restore() {
|
|
39
|
+
if (restored) return;
|
|
40
|
+
restored = true;
|
|
41
|
+
fs.writeFileSync(packageJsonPath, originalPackageJson);
|
|
42
|
+
fs.writeFileSync(firebaseConfigPath, originalFirebaseConfig);
|
|
43
|
+
fs.writeFileSync(hooksPath, originalHooks);
|
|
44
|
+
try {
|
|
45
|
+
execSync("git checkout -- lib", {stdio: "inherit"});
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.warn("⚠️ Could not reset lib/ via git checkout — check `git status`.");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const packageJson = JSON.parse(originalPackageJson);
|
|
52
|
+
packageJson.version = localVersion;
|
|
53
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
|
|
54
|
+
|
|
55
|
+
if (target === "dev") {
|
|
56
|
+
console.log("🛠 Switching to DEV config for this watch session...");
|
|
57
|
+
fs.writeFileSync(
|
|
58
|
+
firebaseConfigPath,
|
|
59
|
+
originalFirebaseConfig.replace(/\(credentialsProd\)/g, "(credentialsDev)"),
|
|
60
|
+
);
|
|
61
|
+
fs.writeFileSync(
|
|
62
|
+
hooksPath,
|
|
63
|
+
originalHooks.replace(/XMPXCMUUOJ/g, "A0ZB50I7VS"),
|
|
64
|
+
);
|
|
65
|
+
} else {
|
|
66
|
+
console.log("🛠 Using PROD config (unmodified) for this watch session...");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log(`👀 Watching src/ — every successful compile is pushed to yalc as ${localVersion}.`);
|
|
70
|
+
console.log(` First time only: run \`yarn core ${flag}\` in placementt-web / placementt-backend to link it.`);
|
|
71
|
+
|
|
72
|
+
const tsc = spawn("node_modules/.bin/tsc", ["--watch", "--preserveWatchOutput"], {
|
|
73
|
+
stdio: ["ignore", "pipe", "inherit"],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
tsc.stdout.on("data", (chunk) => {
|
|
77
|
+
const text = chunk.toString();
|
|
78
|
+
process.stdout.write(text);
|
|
79
|
+
if (/Found 0 errors\./.test(text)) {
|
|
80
|
+
try {
|
|
81
|
+
execSync("yalc push", {stdio: "inherit"});
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error("⚠️ yalc push failed:", e.message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
tsc.on("exit", (code) => {
|
|
89
|
+
restore();
|
|
90
|
+
process.exit(code ?? 0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
process.on("SIGINT", () => {
|
|
94
|
+
tsc.kill("SIGINT");
|
|
95
|
+
});
|
|
96
|
+
process.on("SIGTERM", () => {
|
|
97
|
+
tsc.kill("SIGTERM");
|
|
98
|
+
});
|
|
99
|
+
process.on("exit", restore);
|