rwsdk 0.1.6-test.20250702140551 โ 0.1.7-test.20250702144028
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/dist/scripts/debug-sync.mjs +76 -14
- package/package.json +1 -1
|
@@ -1,23 +1,78 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { $ } from "../lib/$.mjs";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
4
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const getPackageManagerInfo = (targetDir) => {
|
|
8
|
+
if (existsSync(path.join(targetDir, "yarn.lock"))) {
|
|
9
|
+
return { name: "yarn", lockFile: "yarn.lock", command: "add" };
|
|
10
|
+
}
|
|
11
|
+
if (existsSync(path.join(targetDir, "pnpm-lock.yaml"))) {
|
|
12
|
+
return { name: "pnpm", lockFile: "pnpm-lock.yaml", command: "add" };
|
|
13
|
+
}
|
|
14
|
+
return { name: "npm", lockFile: "package-lock.json", command: "install" };
|
|
15
|
+
};
|
|
16
|
+
const performSync = async (sdkDir, targetDir) => {
|
|
17
|
+
console.log("๐๏ธ rebuilding sdk...");
|
|
18
|
+
await $({ cwd: sdkDir, stdio: "inherit", shell: true }) `pnpm build`;
|
|
19
|
+
console.log("๐ฆ packing sdk...");
|
|
20
|
+
const packResult = await $({ cwd: sdkDir, shell: true }) `npm pack`;
|
|
21
|
+
const tarballName = packResult.stdout?.trim() ?? "";
|
|
22
|
+
const tarballPath = path.resolve(sdkDir, tarballName);
|
|
23
|
+
console.log(` installing ${tarballName} in ${targetDir}...`);
|
|
24
|
+
const pm = getPackageManagerInfo(targetDir);
|
|
25
|
+
const packageJsonPath = path.join(targetDir, "package.json");
|
|
26
|
+
const lockfilePath = path.join(targetDir, pm.lockFile);
|
|
27
|
+
const originalPackageJson = await fs
|
|
28
|
+
.readFile(packageJsonPath, "utf-8")
|
|
29
|
+
.catch(() => null);
|
|
30
|
+
const originalLockfile = await fs
|
|
31
|
+
.readFile(lockfilePath, "utf-8")
|
|
32
|
+
.catch(() => null);
|
|
33
|
+
try {
|
|
34
|
+
let installCommand = `${pm.name} ${pm.command} ${tarballPath}`;
|
|
35
|
+
if (pm.name === "yarn") {
|
|
36
|
+
installCommand = `yarn add file:${tarballPath}`;
|
|
37
|
+
}
|
|
38
|
+
await $({
|
|
39
|
+
cwd: targetDir,
|
|
40
|
+
stdio: "inherit",
|
|
41
|
+
shell: true,
|
|
42
|
+
}) `${installCommand}`;
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
if (originalPackageJson) {
|
|
46
|
+
console.log("Restoring package.json...");
|
|
47
|
+
await fs.writeFile(packageJsonPath, originalPackageJson);
|
|
48
|
+
}
|
|
49
|
+
if (originalLockfile) {
|
|
50
|
+
console.log(`Restoring ${pm.lockFile}...`);
|
|
51
|
+
await fs.writeFile(lockfilePath, originalLockfile);
|
|
52
|
+
}
|
|
53
|
+
await fs.unlink(tarballPath).catch(() => {
|
|
54
|
+
// ignore if deletion fails
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
console.log("โ
done syncing");
|
|
58
|
+
};
|
|
5
59
|
export const debugSync = async (opts) => {
|
|
6
60
|
const { targetDir, sdkDir = process.cwd(), dev, watch, build } = opts;
|
|
7
61
|
if (!targetDir) {
|
|
8
62
|
console.error("โ Please provide a target directory as an argument.");
|
|
9
63
|
process.exit(1);
|
|
10
64
|
}
|
|
11
|
-
const
|
|
65
|
+
const thisScriptPath = fileURLToPath(import.meta.url);
|
|
66
|
+
const syncCommand = `tsx ${thisScriptPath} --_sync ${sdkDir} ${targetDir}`;
|
|
12
67
|
// Run initial sync
|
|
13
|
-
await
|
|
68
|
+
await performSync(sdkDir, targetDir);
|
|
14
69
|
if (!process.env.NO_CLEAN_VITE) {
|
|
15
70
|
console.log("๐งน Cleaning Vite cache...");
|
|
16
71
|
await $({
|
|
17
72
|
stdio: "inherit",
|
|
18
73
|
shell: true,
|
|
19
74
|
cwd: targetDir,
|
|
20
|
-
}) `rm -rf node_modules/.vite
|
|
75
|
+
}) `rm -rf ${targetDir}/node_modules/.vite*`;
|
|
21
76
|
}
|
|
22
77
|
// If dev flag is present, clean vite cache and start dev server
|
|
23
78
|
if (dev) {
|
|
@@ -43,15 +98,22 @@ export const debugSync = async (opts) => {
|
|
|
43
98
|
};
|
|
44
99
|
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
45
100
|
const args = process.argv.slice(2);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
targetDir
|
|
50
|
-
sdkDir
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
101
|
+
const flags = new Set(args.filter((arg) => arg.startsWith("--")));
|
|
102
|
+
const positionalArgs = args.filter((arg) => !arg.startsWith("--"));
|
|
103
|
+
if (flags.has("--_sync")) {
|
|
104
|
+
const [sdkDir, targetDir] = positionalArgs;
|
|
105
|
+
await performSync(sdkDir, targetDir);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const targetDir = positionalArgs[0] ?? process.cwd();
|
|
109
|
+
debugSync({
|
|
110
|
+
targetDir,
|
|
111
|
+
sdkDir: process.env.SDK_REPO
|
|
112
|
+
? path.resolve(__dirname, process.env.SDK_REPO, "sdk")
|
|
113
|
+
: path.resolve(__dirname, "..", ".."),
|
|
114
|
+
dev: flags.has("--dev"),
|
|
115
|
+
watch: flags.has("--watch"),
|
|
116
|
+
build: flags.has("--build"),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
57
119
|
}
|