placementt-core 1.400.961 → 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/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # placementt-core
2
+
3
+ Shared code (types, Firebase helpers, utilities, shared UI) used by `placementt-web`, `placementt-backend`, and `placementt-app`.
4
+
5
+ ## Testing local changes before publishing
6
+
7
+ Normally, `placementt-web` and `placementt-backend` depend on published npm versions of this package (via the `dev`/`prod`/`emu` dist-tags). While you're working on a change here, you don't want to publish to npm just to test it — instead, build it locally and link it into the consuming repo with [yalc](https://github.com/wclr/yalc).
8
+
9
+ ### 1. Publish your local changes to the yalc store
10
+
11
+ From this repo, run:
12
+
13
+ ```
14
+ yarn test-local dev # or: yarn test-local d
15
+ yarn test-local prod # or: yarn test-local p
16
+ ```
17
+
18
+ This builds your current working tree (including uncommitted changes) with the chosen config flavor (dev swaps in dev Firebase config/credentials, prod leaves it as-is), then publishes it to your local yalc store under a fixed sentinel version (`0.0.0-local-dev` / `0.0.0-local-prod`). It restores all the swapped files afterward, so your working tree is left clean.
19
+
20
+ Re-run this command any time you make further changes you want to test — it always re-publishes over the same sentinel version.
21
+
22
+ ### 2. Pull it into placementt-web or placementt-backend
23
+
24
+ From `placementt-web` or `placementt-backend`, run:
25
+
26
+ ```
27
+ yarn core dev # or: yarn core d
28
+ yarn core prod # or: yarn core p
29
+ ```
30
+
31
+ This checks whether a matching local yalc build exists (published in step 1). If it does, it links your local build in via `yalc add` instead of installing from npm. If it doesn't, it falls back to installing the real published `dev`/`prod` dist-tag from npm as normal.
32
+
33
+ Match the flavor to what you published in step 1 (`dev` ↔ `dev`, `prod` ↔ `prod`).
34
+
35
+ ### 3. Restart the dev server/emulator to pick it up
36
+
37
+ Neither CRA's dev server nor the Firebase emulator watches `node_modules` for changes, so you need to restart after linking. Add `--restart` (or `-r`) to the same command to do this in one step:
38
+
39
+ ```
40
+ yarn core dev --restart # or: yarn core d -r
41
+ ```
42
+
43
+ - **placementt-web**: kills whatever's running on port 3000, clears `node_modules/.cache`, and runs `yarn start`.
44
+ - **placementt-backend**: rebuilds the functions bundle (`npm run build`) and starts the functions emulator (`firebase emulators:start --only functions`).
45
+
46
+ ### Full loop
47
+
48
+ ```
49
+ # in placementt-core, after making changes
50
+ yarn test-local dev
51
+
52
+ # in placementt-web and/or placementt-backend
53
+ yarn core dev --restart
54
+ ```
55
+
56
+ Repeat step 1 + step 3 as you iterate. Once you're happy with the change, commit it here, bump the version, and publish for real (`yarn deploy` / `yarn deploy-all`) — then re-run `yarn core dev` (or `prod`) in the consuming repos without `--restart` to drop back to the real published version instead of the local link.
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.961",
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);