rwsdk 0.1.7 โ 0.1.8
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/bin/rwsync +2 -0
- package/dist/scripts/debug-sync.mjs +76 -13
- package/package.json +5 -3
package/bin/rwsync
ADDED
|
@@ -1,16 +1,71 @@
|
|
|
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 $({
|
|
@@ -30,6 +85,7 @@ export const debugSync = async (opts) => {
|
|
|
30
85
|
$({
|
|
31
86
|
stdio: "inherit",
|
|
32
87
|
shell: true,
|
|
88
|
+
cwd: sdkDir,
|
|
33
89
|
}) `npx chokidar-cli './src/**' './package.json' -c "${syncCommand}"`;
|
|
34
90
|
}
|
|
35
91
|
else if (build) {
|
|
@@ -43,15 +99,22 @@ export const debugSync = async (opts) => {
|
|
|
43
99
|
};
|
|
44
100
|
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
45
101
|
const args = process.argv.slice(2);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
targetDir
|
|
50
|
-
sdkDir
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
102
|
+
const flags = new Set(args.filter((arg) => arg.startsWith("--")));
|
|
103
|
+
const positionalArgs = args.filter((arg) => !arg.startsWith("--"));
|
|
104
|
+
if (flags.has("--_sync")) {
|
|
105
|
+
const [sdkDir, targetDir] = positionalArgs;
|
|
106
|
+
await performSync(sdkDir, targetDir);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const targetDir = positionalArgs[0] ?? process.cwd();
|
|
110
|
+
debugSync({
|
|
111
|
+
targetDir,
|
|
112
|
+
sdkDir: process.env.RWSDK_REPO
|
|
113
|
+
? path.resolve(__dirname, process.env.RWSDK_REPO, "sdk")
|
|
114
|
+
: path.resolve(__dirname, "..", ".."),
|
|
115
|
+
dev: flags.has("--dev"),
|
|
116
|
+
watch: flags.has("--watch"),
|
|
117
|
+
build: flags.has("--build"),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
57
120
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rwsdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"rw-scripts": "./bin/rw-scripts.mjs"
|
|
7
|
+
"rw-scripts": "./bin/rw-scripts.mjs",
|
|
8
|
+
"rwsync": "./bin/rwsync"
|
|
8
9
|
},
|
|
9
10
|
"files": [
|
|
10
11
|
"./README.md",
|
|
11
|
-
"./dist"
|
|
12
|
+
"./dist",
|
|
13
|
+
"./bin"
|
|
12
14
|
],
|
|
13
15
|
"exports": {
|
|
14
16
|
"./vite": {
|