bwsr 0.1.0 → 0.1.1

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/bwsr.js CHANGED
@@ -2,26 +2,14 @@
2
2
  const { execFileSync } = require("child_process");
3
3
  const { join } = require("path");
4
4
 
5
- const platforms = {
6
- "darwin-x64": "@bwsr/darwin-x64",
7
- "darwin-arm64": "@bwsr/darwin-arm64",
8
- "linux-x64": "@bwsr/linux-x64",
9
- "linux-arm64": "@bwsr/linux-arm64",
10
- };
11
-
12
- const key = `${process.platform}-${process.arch}`;
13
- const pkg = platforms[key];
14
-
15
- if (!pkg) {
16
- console.error(`Unsupported platform: ${key}`);
17
- process.exit(1);
18
- }
5
+ const binPath = join(__dirname, "bwsr-binary");
19
6
 
20
7
  try {
21
- const binPath = require.resolve(pkg);
22
- const bwsr = join(binPath, "..", "bwsr");
23
- execFileSync(bwsr, process.argv.slice(2), { stdio: "inherit" });
8
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
24
9
  } catch (e) {
10
+ if (e.status !== undefined) {
11
+ process.exit(e.status);
12
+ }
25
13
  console.error(`Failed to run bwsr: ${e.message}`);
26
14
  process.exit(1);
27
15
  }
package/package.json CHANGED
@@ -1,15 +1,12 @@
1
1
  {
2
2
  "name": "bwsr",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Fast CLI for managing browser daemons via Playwright CDP",
5
5
  "bin": {
6
6
  "bwsr": "./bin/bwsr.js"
7
7
  },
8
- "optionalDependencies": {
9
- "@bwsr/linux-x64": "0.1.0",
10
- "@bwsr/linux-arm64": "0.1.0",
11
- "@bwsr/darwin-x64": "0.1.0",
12
- "@bwsr/darwin-arm64": "0.1.0"
8
+ "scripts": {
9
+ "postinstall": "node ./scripts/postinstall.js"
13
10
  },
14
11
  "repository": {
15
12
  "type": "git",
@@ -0,0 +1,63 @@
1
+ const { execSync } = require("child_process");
2
+ const { createWriteStream, chmodSync, existsSync, mkdirSync } = require("fs");
3
+ const { join } = require("path");
4
+ const https = require("https");
5
+
6
+ const VERSION = require("../package.json").version;
7
+ const REPO = "lagz0ne/pw-run";
8
+
9
+ const PLATFORMS = {
10
+ "darwin-x64": "bwsr-darwin-x64",
11
+ "darwin-arm64": "bwsr-darwin-arm64",
12
+ "linux-x64": "bwsr-linux-x64",
13
+ "linux-arm64": "bwsr-linux-arm64",
14
+ };
15
+
16
+ const key = `${process.platform}-${process.arch}`;
17
+ const artifact = PLATFORMS[key];
18
+
19
+ if (!artifact) {
20
+ console.error(`Unsupported platform: ${key}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ const binDir = join(__dirname, "..", "bin");
25
+ const binPath = join(binDir, "bwsr-binary");
26
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${artifact}`;
27
+
28
+ if (existsSync(binPath)) {
29
+ process.exit(0);
30
+ }
31
+
32
+ if (!existsSync(binDir)) {
33
+ mkdirSync(binDir, { recursive: true });
34
+ }
35
+
36
+ console.log(`Downloading bwsr v${VERSION} for ${key}...`);
37
+
38
+ function download(url, dest) {
39
+ return new Promise((resolve, reject) => {
40
+ https.get(url, (res) => {
41
+ if (res.statusCode === 302 || res.statusCode === 301) {
42
+ return download(res.headers.location, dest).then(resolve).catch(reject);
43
+ }
44
+ if (res.statusCode !== 200) {
45
+ return reject(new Error(`Failed to download: ${res.statusCode}`));
46
+ }
47
+ const file = createWriteStream(dest);
48
+ res.pipe(file);
49
+ file.on("finish", () => {
50
+ file.close();
51
+ chmodSync(dest, 0o755);
52
+ resolve();
53
+ });
54
+ }).on("error", reject);
55
+ });
56
+ }
57
+
58
+ download(url, binPath)
59
+ .then(() => console.log("Done!"))
60
+ .catch((err) => {
61
+ console.error(`Failed to download: ${err.message}`);
62
+ process.exit(1);
63
+ });