w3wallets 0.0.1 → 0.0.2

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/index.js CHANGED
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // src/withExtension.ts
38
38
  var import_path = __toESM(require("path"));
39
+ var import_fs = __toESM(require("fs"));
39
40
  var import_test = require("@playwright/test");
40
41
  var import_test2 = require("@playwright/test");
41
42
  function withExtensions(test, config) {
@@ -43,6 +44,11 @@ function withExtensions(test, config) {
43
44
  return test.extend({
44
45
  context: async ({}, use) => {
45
46
  const userDataDir = import_path.default.join(process.cwd(), ".tmp-user-data");
47
+ const backpackDownloaded = import_fs.default.existsSync(
48
+ import_path.default.join(backpack, "manifest.json")
49
+ );
50
+ if (!backpackDownloaded)
51
+ throw Error("Cannot find Backpack. download it `npx w3wallets`");
46
52
  const context = await import_test2.chromium.launchPersistentContext(userDataDir, {
47
53
  headless: false,
48
54
  args: [
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/withExtension.ts
2
2
  import path from "path";
3
+ import fs from "fs";
3
4
  import "@playwright/test";
4
5
  import { chromium } from "@playwright/test";
5
6
  function withExtensions(test, config) {
@@ -7,6 +8,11 @@ function withExtensions(test, config) {
7
8
  return test.extend({
8
9
  context: async ({}, use) => {
9
10
  const userDataDir = path.join(process.cwd(), ".tmp-user-data");
11
+ const backpackDownloaded = fs.existsSync(
12
+ path.join(backpack, "manifest.json")
13
+ );
14
+ if (!backpackDownloaded)
15
+ throw Error("Cannot find Backpack. download it `npx w3wallets`");
10
16
  const context = await chromium.launchPersistentContext(userDataDir, {
11
17
  headless: false,
12
18
  args: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "w3wallets",
3
3
  "description": "browser wallets for playwright",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "Max Andreev <maxick20@gmail.com>",
@@ -12,6 +12,9 @@
12
12
  "files": [
13
13
  "dist"
14
14
  ],
15
+ "bin": {
16
+ "w3wallets": "./src/scripts/download.js"
17
+ },
15
18
  "devDependencies": {
16
19
  "@arethetypeswrong/cli": "^0.17.2",
17
20
  "@changesets/cli": "^2.27.11",
@@ -30,8 +33,14 @@
30
33
  "clean": "rm -rf dist",
31
34
  "check-format": "prettier --check .",
32
35
  "check-exports": "attw --pack .",
36
+ "format": "prettier --write .",
33
37
  "lint": "tsc",
34
38
  "ci": "yarn lint && yarn clean && yarn build && yarn check-format && yarn check-exports",
39
+ "changeset": "npx changeset",
35
40
  "local-release": "changeset version && changeset publish"
41
+ },
42
+ "dependencies": {
43
+ "adm-zip": "^0.5.16",
44
+ "follow-redirects": "^1.15.9"
36
45
  }
37
- }
46
+ }
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { https } = require("follow-redirects");
6
+ const AdmZip = require("adm-zip");
7
+
8
+ const args = process.argv.slice(2);
9
+
10
+ // Default configurations
11
+ const DEFAULT_WALLET = "backpack";
12
+ const DEFAULT_DOWNLOAD_LINK =
13
+ "https://github.com/coral-xyz/backpack/releases/download/0.10.1-latest-4/build-beta-4.zip";
14
+
15
+ // Parse arguments
16
+ const walletArg = args.find((arg) => arg.startsWith("--wallet="));
17
+ const downloadArg = args.find((arg) => arg.startsWith("--version="));
18
+
19
+ const wallet = walletArg ? walletArg.split("=")[1] : DEFAULT_WALLET;
20
+ const downloadLink = downloadArg
21
+ ? downloadArg.split("=")[1]
22
+ : DEFAULT_DOWNLOAD_LINK;
23
+ const outputDir = path.resolve(`extensions/${wallet}`);
24
+ const zipPath = path.resolve(outputDir, `${wallet}.zip`);
25
+
26
+ console.log(`Fetching ${wallet}...`);
27
+
28
+ // Ensure the output directory exists
29
+ fs.mkdirSync(outputDir, { recursive: true });
30
+
31
+ // Download the zip file
32
+ https
33
+ .get(downloadLink, (response) => {
34
+ if (response.statusCode !== 200) {
35
+ console.error(
36
+ `Failed to download file. Status Code: ${response.statusCode}`,
37
+ );
38
+ return;
39
+ }
40
+
41
+ const fileStream = fs.createWriteStream(zipPath);
42
+ response.pipe(fileStream);
43
+
44
+ fileStream.on("finish", () => {
45
+ fileStream.close();
46
+ console.log(`Downloaded to ${zipPath}`);
47
+
48
+ // Unzip the file
49
+ console.log("Unzipping...");
50
+ const zip = new AdmZip(zipPath);
51
+ zip.extractAllTo(outputDir, true);
52
+ console.log(`Extracted to ${outputDir}`);
53
+
54
+ fs.unlinkSync(zipPath);
55
+
56
+ // Check if the result is a single directory with manifest.json inside
57
+ const files = fs.readdirSync(outputDir);
58
+ if (files.length === 1) {
59
+ const singleDirPath = path.join(outputDir, files[0]);
60
+ if (
61
+ fs.lstatSync(singleDirPath).isDirectory() &&
62
+ fs.existsSync(path.join(singleDirPath, "manifest.json"))
63
+ ) {
64
+ // Move all files from the directory to the outputDir
65
+ const nestedFiles = fs.readdirSync(singleDirPath);
66
+ nestedFiles.forEach((file) => {
67
+ const srcPath = path.join(singleDirPath, file);
68
+ const destPath = path.join(outputDir, file);
69
+ fs.renameSync(srcPath, destPath);
70
+ });
71
+ } else {
72
+ throw Error("Cannot find the manifest.json file");
73
+ }
74
+ }
75
+ });
76
+ })
77
+ .on("error", (err) => {
78
+ console.error(`Error downloading the file: ${err.message}`);
79
+ });