permaweb-deploy 2.0.2 → 2.2.0

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/.eslintrc.js CHANGED
@@ -22,7 +22,7 @@ module.exports = {
22
22
  {
23
23
  groups: [
24
24
  ['^react', '^@?\\w'],
25
- ['^arweave', '@irys/sdk', '@permaweb/aoconnect', '^@?\\w'],
25
+ ['^arweave', '@ar.io/sdk', '@ardrive/turbo-sdk', '@permaweb/aoconnect', '^@?\\w'],
26
26
  ['^\\u0000'],
27
27
  ['^\\.\\.(?!/?$)', '^\\.\\./?$'],
28
28
  ['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
package/README.md CHANGED
@@ -1,28 +1,61 @@
1
- # Permaweb deployment package
1
+ # Permaweb Deployment Package
2
2
 
3
- Inspired by the [cookbook github action deployment guide](https://cookbook.arweave.dev/guides/deployment/github-action.html), `permaweb-deploy` is a Node.js command-line tool designed to streamline the deployment of JavaScript bundles to the permaweb using Arweave. It simplifies the process by bundling JS code, deploying it as a transaction to Arweave, and updating ArNS (Arweave Name Service) with the transaction ID.
3
+ Inspired by the [cookbook github action deployment guide](https://cookbook.arweave.dev/guides/deployment/github-action.html), `permaweb-deploy` is a Node.js command-line tool designed to streamline the deployment of web applications to the permaweb using Arweave. It simplifies the process by uploading your build folder, creating Arweave manifests, and updating ArNS (Arweave Name Service) records via ANT (Arweave Name Token) with the transaction ID.
4
4
 
5
5
  ### Features
6
- - **Bundle Deployment:** Automatically bundles your JS code and deploys it to Arweave.
7
- - **ArNS Update:** Updates ArNS with the new transaction ID each time new content is deployed.
8
- - **Automated Workflow:** Integrates with GitHub Actions for continuous deployment directly from your repository.
6
+ - **Turbo SDK Integration:** Uses Turbo SDK for fast, reliable file uploads to Arweave
7
+ - **Arweave Manifest v0.2.0:** Creates manifests with fallback support for SPAs
8
+ - **ArNS Updates:** Updates ArNS records via ANT with new transaction IDs and metadata
9
+ - **Automated Workflow:** Integrates with GitHub Actions for continuous deployment
10
+ - **Git Hash Tagging:** Automatically tags deployments with Git commit hashes
11
+ - **404 Fallback Detection:** Automatically detects and sets 404.html as fallback
12
+ - **Network Support:** Supports mainnet, testnet, and custom ARIO process IDs
9
13
 
10
14
  ### Installation
15
+
11
16
  Install the package using npm:
17
+
12
18
  ```bash
13
19
  npm install permaweb-deploy
14
20
  ```
15
21
 
22
+ For development use:
23
+ ```bash
24
+ npm install permaweb-deploy --save-dev
25
+ ```
26
+
27
+ For Yarn users:
28
+ ```bash
29
+ yarn add permaweb-deploy --dev --ignore-engines
30
+ ```
31
+
16
32
  ### Prerequisites
17
- Before using `permaweb-deploy`, you must:
18
- 1. Encode your Arweave wallet key in base64 format and set it as a GitHub secret:
19
33
 
34
+ Before using `permaweb-deploy`, you must:
35
+ 1. **Arweave Wallet:** Have an Arweave wallet with Turbo Credits for uploading
36
+ 2. **ArNS Name:** Own or control an ArNS name (which has an associated ANT process)
37
+ 3. **Wallet Encoding:** Encode your Arweave wallet key in base64 format:
20
38
  ```bash
21
39
  base64 -i wallet.json | pbcopy
22
40
  ```
23
- 3. Ensure that the secret name for the encoded wallet is `DEPLOY_KEY`.
41
+ 4. **GitHub Secret:** Set the encoded wallet as a GitHub secret named `DEPLOY_KEY`
42
+
43
+ ⚠️ **Important:** Use a dedicated wallet for deployments to minimize security risks. Ensure your wallet has sufficient Turbo Credits for uploads.
44
+
45
+ ### CLI Options
46
+ ```bash
47
+ permaweb-deploy [options]
48
+ ```
49
+
50
+ | Option | Alias | Description | Default | Required |
51
+ |--------|-------|-------------|---------|----------|
52
+ | `--arns-name` | `-n` | ArNS name for deployment | - | ✅ |
53
+ | `--ario-process` | `-p` | ARIO process ID or "mainnet"/"testnet" | `mainnet` | ❌ |
54
+ | `--deploy-folder` | `-d` | Folder to deploy | `./dist` | ❌ |
55
+ | `--undername` | `-u` | ANT undername to update | `@` | ❌ |
24
56
 
25
57
  ### Usage
58
+
26
59
  To deploy your application, ensure you have a build script and a deployment script in your `package.json`:
27
60
 
28
61
  ```json
@@ -32,10 +65,55 @@ To deploy your application, ensure you have a build script and a deployment scri
32
65
  }
33
66
  ```
34
67
 
35
- Replace `<ARNS_NAME>` with your ArNS name.
68
+ **Example with custom options:**
69
+ ```bash
70
+ permaweb-deploy --arns-name "your-arns-name" --deploy-folder "./build" --undername "app"
71
+ ```
72
+
73
+ Replace `<ARNS_NAME>` with your ArNS name. You can also specify testnet, mainnet, and custom process IDs for the ARIO process to use.
74
+
75
+ **Mainnet (default) config:**
76
+ ```json
77
+ "scripts": {
78
+ "build": "your-build-command",
79
+ "deploy-main": "npm run build && permaweb-deploy --arns-name <ARNS_NAME> --ario-process mainnet"
80
+ }
81
+ ```
82
+
83
+ **Testnet config:**
84
+ ```json
85
+ "scripts": {
86
+ "build": "your-build-command",
87
+ "deploy-main": "npm run build && permaweb-deploy --arns-name <ARNS_NAME> --ario-process testnet"
88
+ }
89
+ ```
90
+
91
+ **Custom process ID config:**
92
+ ```json
93
+ "scripts": {
94
+ "build": "your-build-command",
95
+ "deploy-main": "npm run build && permaweb-deploy --arns-name <ARNS_NAME> --ario-process GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc"
96
+ }
97
+ ```
98
+
99
+ ### Manual CLI Deployment
100
+ ```bash
101
+ DEPLOY_KEY=$(base64 -i wallet.json) npx permaweb-deploy --arns-name <ARNS_NAME>
102
+ ```
103
+
104
+ ### Technical Details
105
+ - **Upload Service:** Uses Turbo SDK for fast, reliable file uploads to Arweave
106
+ - **Manifest Format:** Creates Arweave manifests using version 0.2.0 specification
107
+ - **Fallback Support:** Automatically detects `404.html` and sets it as fallback, otherwise uses `index.html`
108
+ - **Upload Timeout:** 10-second timeout per file upload for reliability
109
+ - **ArNS Record TTL:** Sets 3600 seconds (1 hour) TTL for ArNS records via ANT
110
+ - **Deployment Tags:** Automatically adds `App-Name: Permaweb-Deploy` and Git hash tags
111
+ - **Network Support:** Supports mainnet, testnet, and custom ARIO process IDs
36
112
 
37
113
  ### GitHub Actions Workflow
114
+
38
115
  To automate the deployment, set up a GitHub Actions workflow as follows:
116
+
39
117
  ```yaml
40
118
  name: publish
41
119
 
@@ -48,8 +126,8 @@ jobs:
48
126
  publish:
49
127
  runs-on: ubuntu-latest
50
128
  steps:
51
- - uses: actions/checkout@v2
52
- - uses: actions/setup-node@v1
129
+ - uses: actions/checkout@v4
130
+ - uses: actions/setup-node@v4
53
131
  with:
54
132
  node-version: 20.x
55
133
  - run: npm install
@@ -58,13 +136,26 @@ jobs:
58
136
  DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
59
137
  ```
60
138
 
61
- ### To deploy to permaweb manually via cli
139
+ ### Security & Best Practices
140
+ - **Dedicated Wallet:** Always use a dedicated wallet for deployments to minimize security risks
141
+ - **Wallet Encoding:** The wallet must be base64 encoded to be used in the deployment script
142
+ - **ArNS Name:** The ArNS Name must be passed so that the ANT Process can be resolved to update the target undername or root record
143
+ - **Turbo Credits:** Ensure your wallet has sufficient Turbo Credits before deployment
144
+ - **Secret Management:** Keep your `DEPLOY_KEY` secret secure and never commit it to your repository
145
+ - **Build Security:** Always check your build for exposed environmental secrets before deployment, as data on Arweave is permanent
62
146
 
63
- ```sh
64
- DEPLOY_KEY=$(base64 -i wallet.json) npx permaweb-deploy --arns-name <ARNS_NAME>
65
- ```
147
+ ### Troubleshooting
148
+ - **Error: "ARNS_NAME not configured":** Ensure you're passing the `--arns-name` flag with a valid ArNS name
149
+ - **Error: "DEPLOY_KEY not configured":** Verify your base64 encoded wallet is set as the `DEPLOY_KEY` environment variable
150
+ - **Error: "deploy-folder does not exist":** Check that your build folder exists and the path is correct
151
+ - **Error: "deploy-file does not exist":** Check that your build file exists and the path is correct
152
+ - **Error: "ARNS name does not exist":** Verify the ArNS name is correct and exists in the specified network
153
+ - **Upload timeouts:** Files have a 10-second upload timeout. Large files may fail and require optimization
154
+ - **Insufficient Turbo Credits:** Ensure your wallet has enough Turbo Credits for the deployment
66
155
 
67
- ### Important Notes
68
- - **Security:** Always use a dedicated wallet for deployments to minimize risk.
69
- - **Wallet Key:** The wallet must be base64 encoded to be used in the deployment script.
70
- - **ARNS Name:** The ArNS Name must be passed in so that the ANT Process can be resolved to update the target undername or root record.
156
+ ### Dependencies
157
+ - **@ar.io/sdk:** - For ANT operations and ArNS management
158
+ - **@ardrive/turbo-sdk:** - For fast file uploads to Arweave
159
+ - **@permaweb/aoconnect:** - For AO network connectivity
160
+ - **mime-types:** - For automatic content type detection
161
+ - **yargs:** - For CLI argument parsing
package/dist/index.js CHANGED
@@ -1,18 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.getTagValue = getTagValue;
9
- var _sdk = require("@ar.io/sdk");
10
4
  var _fs = _interopRequireDefault(require("fs"));
11
5
  var _yargs = _interopRequireDefault(require("yargs"));
12
6
  var _helpers = require("yargs/helpers");
13
- var _turbo = _interopRequireDefault(require("./turbo"));
7
+ var _sdk = require("@ar.io/sdk");
8
+ var _turboSdk = require("@ardrive/turbo-sdk");
9
+ var _aoconnect = require("@permaweb/aoconnect");
10
+ var _turbo = require("./turbo");
14
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
12
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
13
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
16
14
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
17
15
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
16
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -21,7 +19,14 @@ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(
21
19
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
22
20
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
23
21
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
24
- var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).option('arns-name', {
22
+ var arweaveTxIdRegex = /^[a-zA-Z0-9-_]{43}$/;
23
+ var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).option('ario-process', {
24
+ alias: 'p',
25
+ type: 'string',
26
+ description: 'The ARIO process to use',
27
+ demandOption: true,
28
+ "default": _sdk.ARIO_MAINNET_PROCESS_ID
29
+ }).option('arns-name', {
25
30
  alias: 'n',
26
31
  type: 'string',
27
32
  description: 'The ARNS name',
@@ -31,6 +36,10 @@ var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).option('a
31
36
  type: 'string',
32
37
  description: 'Folder to deploy.',
33
38
  "default": './dist'
39
+ }).option('deploy-file', {
40
+ alias: 'f',
41
+ type: 'string',
42
+ description: 'File to deploy.'
34
43
  }).option('undername', {
35
44
  alias: 'u',
36
45
  type: 'string',
@@ -39,21 +48,21 @@ var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).option('a
39
48
  }).argv;
40
49
  var DEPLOY_KEY = process.env.DEPLOY_KEY;
41
50
  var ARNS_NAME = argv.arnsName;
42
- function getTagValue(list, name) {
43
- for (var i = 0; i < list.length; i++) {
44
- if (list[i]) {
45
- if (list[i].name === name) {
46
- return list[i].value;
47
- }
48
- }
49
- }
50
- return STORAGE.none;
51
+ var ARIO_PROCESS = argv.arioProcess;
52
+ if (ARIO_PROCESS === 'mainnet') {
53
+ ARIO_PROCESS = _sdk.ARIO_MAINNET_PROCESS_ID;
54
+ } else if (ARIO_PROCESS === 'testnet') {
55
+ ARIO_PROCESS = _sdk.ARIO_TESTNET_PROCESS_ID;
51
56
  }
52
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
53
- var jwk, ario, arnsNameRecord, manifestId, signer, ant;
54
- return _regeneratorRuntime().wrap(function _callee$(_context) {
55
- while (1) switch (_context.prev = _context.next) {
57
+ _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
58
+ var jwk, ario, arnsNameRecord, txId, turbo, signer, ant, _t;
59
+ return _regenerator().w(function (_context) {
60
+ while (1) switch (_context.n) {
56
61
  case 0:
62
+ if (!ARIO_PROCESS || !arweaveTxIdRegex.test(ARIO_PROCESS)) {
63
+ console.error('ARIO_PROCESS must be a valid Arweave transaction ID, or "mainnet" or "testnet"');
64
+ process.exit(1);
65
+ }
57
66
  if (!DEPLOY_KEY) {
58
67
  console.error('DEPLOY_KEY not configured');
59
68
  process.exit(1);
@@ -62,43 +71,67 @@ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
62
71
  console.error('ARNS_NAME not configured');
63
72
  process.exit(1);
64
73
  }
65
- if (argv.deployFolder.length == 0) {
66
- console.error('deploy folder must not be empty');
74
+ if (argv.deployFile && !_fs["default"].existsSync(argv.deployFile)) {
75
+ console.error("deploy-file [".concat(argv.deployFolder, "] does not exist"));
67
76
  process.exit(1);
77
+ } else {
78
+ if (!_fs["default"].existsSync(argv.deployFolder)) {
79
+ console.error("deploy-folder [".concat(argv.deployFolder, "] does not exist"));
80
+ process.exit(1);
81
+ }
68
82
  }
69
- if (argv.undername.length == 0) {
70
- console.error('undername must not be empty');
71
- process.exit(1);
72
- }
73
- if (!_fs["default"].existsSync(argv.deployFolder)) {
74
- console.error("deploy folder [".concat(argv.deployFolder, "] does not exist"));
83
+ if (argv.undername.length === 0) {
84
+ console.error('undername must be set');
75
85
  process.exit(1);
76
86
  }
77
87
  jwk = JSON.parse(Buffer.from(DEPLOY_KEY, 'base64').toString('utf-8'));
78
- ario = _sdk.ARIO.init();
79
- _context.next = 9;
88
+ ario = _sdk.ARIO.init({
89
+ process: new _sdk.AOProcess({
90
+ processId: ARIO_PROCESS,
91
+ ao: (0, _aoconnect.connect)({
92
+ MODE: 'legacy',
93
+ CU_URL: 'https://cu.ardrive.io'
94
+ })
95
+ })
96
+ });
97
+ _context.n = 1;
80
98
  return ario.getArNSRecord({
81
99
  name: ARNS_NAME
82
100
  })["catch"](function (e) {
83
101
  console.error("ARNS name [".concat(ARNS_NAME, "] does not exist"));
84
102
  process.exit(1);
85
103
  });
86
- case 9:
87
- arnsNameRecord = _context.sent;
88
- _context.prev = 10;
89
- _context.next = 13;
90
- return (0, _turbo["default"])(argv, jwk);
91
- case 13:
92
- manifestId = _context.sent;
104
+ case 1:
105
+ arnsNameRecord = _context.v;
106
+ _context.p = 2;
107
+ if (!argv.deployFile) {
108
+ _context.n = 4;
109
+ break;
110
+ }
111
+ turbo = _turboSdk.TurboFactory.authenticated({
112
+ privateKey: jwk
113
+ });
114
+ _context.n = 3;
115
+ return (0, _turbo.uploadFile)(argv.deployFile, turbo);
116
+ case 3:
117
+ txId = _context.v.id;
118
+ _context.n = 6;
119
+ break;
120
+ case 4:
121
+ _context.n = 5;
122
+ return (0, _turbo.uploadDirectory)(argv, jwk);
123
+ case 5:
124
+ txId = _context.v;
125
+ case 6:
93
126
  signer = new _sdk.ArweaveSigner(jwk);
94
127
  ant = _sdk.ANT.init({
95
128
  processId: arnsNameRecord.processId,
96
129
  signer: signer
97
130
  }); // Update the ANT record (assumes the JWK is a controller or owner)
98
- _context.next = 18;
131
+ _context.n = 7;
99
132
  return ant.setRecord({
100
133
  undername: argv.undername,
101
- transactionId: manifestId,
134
+ transactionId: txId,
102
135
  ttlSeconds: 3600
103
136
  }, {
104
137
  tags: [{
@@ -109,18 +142,17 @@ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
109
142
  value: process.env.GITHUB_SHA
110
143
  }] : []))
111
144
  });
112
- case 18:
113
- console.log("Deployed TxId [".concat(manifestId, "] to name [").concat(ARNS_NAME, "] for ANT [").concat(arnsNameRecord.processId, "] using undername [").concat(argv.undername, "]"));
114
- _context.next = 25;
145
+ case 7:
146
+ console.log("Deployed TxId [".concat(txId, "] to name [").concat(ARNS_NAME, "] for ANT [").concat(arnsNameRecord.processId, "] using undername [").concat(argv.undername, "]"));
147
+ _context.n = 9;
115
148
  break;
116
- case 21:
117
- _context.prev = 21;
118
- _context.t0 = _context["catch"](10);
119
- console.error('Deployment failed:', _context.t0);
149
+ case 8:
150
+ _context.p = 8;
151
+ _t = _context.v;
152
+ console.error('Deployment failed:', _t);
120
153
  process.exit(1); // Exit with error code
121
- case 25:
122
- case "end":
123
- return _context.stop();
154
+ case 9:
155
+ return _context.a(2);
124
156
  }
125
- }, _callee, null, [[10, 21]]);
157
+ }, _callee, null, [[2, 8]]);
126
158
  }))();
@@ -1,20 +1,21 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports["default"] = TurboDeploy;
8
- var _turboSdk = require("@ardrive/turbo-sdk");
6
+ exports.uploadDirectory = uploadDirectory;
7
+ exports.uploadFile = uploadFile;
9
8
  var _fs = _interopRequireDefault(require("fs"));
10
9
  var _mimeTypes = _interopRequireDefault(require("mime-types"));
11
10
  var _path = _interopRequireDefault(require("path"));
12
11
  var _stream = require("stream");
12
+ var _turboSdk = require("@ardrive/turbo-sdk");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
15
14
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
16
15
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
17
16
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
17
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
18
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
18
19
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
19
20
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
20
21
  // Gets MIME types for each file to tag the upload
@@ -22,24 +23,72 @@ function getContentType(filePath) {
22
23
  var res = _mimeTypes["default"].lookup(filePath);
23
24
  return res || 'application/octet-stream';
24
25
  }
25
- function TurboDeploy(_x, _x2) {
26
- return _TurboDeploy.apply(this, arguments);
26
+ function uploadFile(_x, _x2) {
27
+ return _uploadFile.apply(this, arguments);
28
+ }
29
+ function _uploadFile() {
30
+ _uploadFile = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(path, turbo) {
31
+ var fileSize, contentType, uploadResult, _t;
32
+ return _regenerator().w(function (_context) {
33
+ while (1) switch (_context.n) {
34
+ case 0:
35
+ console.log("Uploading file: ".concat(path, "..."));
36
+ _context.p = 1;
37
+ fileSize = _fs["default"].statSync(path).size;
38
+ contentType = getContentType(path);
39
+ _context.n = 2;
40
+ return turbo.uploadFile({
41
+ fileStreamFactory: function fileStreamFactory() {
42
+ return _fs["default"].createReadStream(path);
43
+ },
44
+ fileSizeFactory: function fileSizeFactory() {
45
+ return fileSize;
46
+ },
47
+ signal: AbortSignal.timeout(10000),
48
+ // Cancel the upload after 10 seconds
49
+ dataItemOpts: {
50
+ tags: [{
51
+ name: 'Content-Type',
52
+ value: contentType
53
+ }, {
54
+ name: 'App-Name',
55
+ value: 'Permaweb-Deploy'
56
+ }]
57
+ }
58
+ });
59
+ case 2:
60
+ uploadResult = _context.v;
61
+ console.log("Uploaded ".concat(path, " with id:"), uploadResult.id);
62
+ return _context.a(2, uploadResult);
63
+ case 3:
64
+ _context.p = 3;
65
+ _t = _context.v;
66
+ console.error("Error uploading file ".concat(path, ":"), _t);
67
+ case 4:
68
+ return _context.a(2);
69
+ }
70
+ }, _callee, null, [[1, 3]]);
71
+ }));
72
+ return _uploadFile.apply(this, arguments);
73
+ }
74
+ function uploadDirectory(_x3, _x4) {
75
+ return _uploadDirectory.apply(this, arguments);
27
76
  }
28
- function _TurboDeploy() {
29
- _TurboDeploy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(argv, jwk) {
77
+ function _uploadDirectory() {
78
+ _uploadDirectory = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(argv, jwk) {
30
79
  var turbo, deployFolder, newManifest, processFiles, _processFiles, uploadManifest, _uploadManifest, manifestId;
31
- return _regeneratorRuntime().wrap(function _callee3$(_context4) {
32
- while (1) switch (_context4.prev = _context4.next) {
80
+ return _regenerator().w(function (_context4) {
81
+ while (1) switch (_context4.n) {
33
82
  case 0:
34
83
  _uploadManifest = function _uploadManifest3() {
35
- _uploadManifest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(manifest) {
36
- var manifestString, uploadResult;
37
- return _regeneratorRuntime().wrap(function _callee2$(_context3) {
38
- while (1) switch (_context3.prev = _context3.next) {
84
+ _uploadManifest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(manifest) {
85
+ var manifestString, uploadResult, _t4;
86
+ return _regenerator().w(function (_context3) {
87
+ while (1) switch (_context3.n) {
39
88
  case 0:
40
- _context3.prev = 0;
89
+ _context3.p = 0;
41
90
  manifestString = JSON.stringify(manifest);
42
- _context3.next = 4;
91
+ _context3.n = 1;
43
92
  return turbo.uploadFile({
44
93
  fileStreamFactory: function fileStreamFactory() {
45
94
  return _stream.Readable.from(Buffer.from(manifestString));
@@ -58,143 +107,98 @@ function _TurboDeploy() {
58
107
  }]
59
108
  }
60
109
  });
61
- case 4:
62
- uploadResult = _context3.sent;
63
- return _context3.abrupt("return", uploadResult.id);
64
- case 8:
65
- _context3.prev = 8;
66
- _context3.t0 = _context3["catch"](0);
67
- console.error('Error uploading manifest:', _context3.t0);
68
- return _context3.abrupt("return", null);
69
- case 12:
70
- case "end":
71
- return _context3.stop();
110
+ case 1:
111
+ uploadResult = _context3.v;
112
+ return _context3.a(2, uploadResult.id);
113
+ case 2:
114
+ _context3.p = 2;
115
+ _t4 = _context3.v;
116
+ console.error('Error uploading manifest:', _t4);
117
+ return _context3.a(2, null);
72
118
  }
73
- }, _callee2, null, [[0, 8]]);
119
+ }, _callee3, null, [[0, 2]]);
74
120
  }));
75
121
  return _uploadManifest.apply(this, arguments);
76
122
  };
77
- uploadManifest = function _uploadManifest2(_x4) {
123
+ uploadManifest = function _uploadManifest2(_x6) {
78
124
  return _uploadManifest.apply(this, arguments);
79
125
  };
80
126
  _processFiles = function _processFiles3() {
81
- _processFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(dir) {
82
- var files, _iterator, _step, _loop;
83
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
84
- while (1) switch (_context2.prev = _context2.next) {
127
+ _processFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(dir) {
128
+ var files, _iterator, _step, file, filePath, relativePath, uploadResult, _t2, _t3;
129
+ return _regenerator().w(function (_context2) {
130
+ while (1) switch (_context2.n) {
85
131
  case 0:
86
132
  files = _fs["default"].readdirSync(dir);
87
133
  _iterator = _createForOfIteratorHelper(files);
88
- _context2.prev = 2;
89
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
90
- var file, filePath, relativePath, fileSize, contentType, uploadResult;
91
- return _regeneratorRuntime().wrap(function _loop$(_context) {
92
- while (1) switch (_context.prev = _context.next) {
93
- case 0:
94
- file = _step.value;
95
- _context.prev = 1;
96
- filePath = _path["default"].join(dir, file);
97
- relativePath = _path["default"].relative(deployFolder, filePath);
98
- if (!_fs["default"].statSync(filePath).isDirectory()) {
99
- _context.next = 9;
100
- break;
101
- }
102
- _context.next = 7;
103
- return processFiles(filePath);
104
- case 7:
105
- _context.next = 24;
106
- break;
107
- case 9:
108
- console.log("Uploading file: ".concat(relativePath));
109
- _context.prev = 10;
110
- fileSize = _fs["default"].statSync(filePath).size;
111
- contentType = getContentType(filePath);
112
- _context.next = 15;
113
- return turbo.uploadFile({
114
- fileStreamFactory: function fileStreamFactory() {
115
- return _fs["default"].createReadStream(filePath);
116
- },
117
- fileSizeFactory: function fileSizeFactory() {
118
- return fileSize;
119
- },
120
- signal: AbortSignal.timeout(10000),
121
- // cancel the upload after 10 seconds
122
- dataItemOpts: {
123
- tags: [{
124
- name: 'Content-Type',
125
- value: contentType
126
- }, {
127
- name: 'App-Name',
128
- value: 'Permaweb-Deploy'
129
- }]
130
- }
131
- });
132
- case 15:
133
- uploadResult = _context.sent;
134
- console.log("Uploaded ".concat(relativePath, " with id:"), uploadResult.id);
135
- // adds uploaded file txId to the new manifest json
136
- newManifest.paths[relativePath] = {
137
- id: uploadResult.id
138
- };
139
- if (file === '404.html') {
140
- // sets manifest fallback to 404.html if found
141
- newManifest.fallback.id = uploadResult.id;
142
- }
143
- _context.next = 24;
144
- break;
145
- case 21:
146
- _context.prev = 21;
147
- _context.t0 = _context["catch"](10);
148
- console.error("Error uploading file ".concat(relativePath, ":"), _context.t0);
149
- case 24:
150
- _context.next = 29;
151
- break;
152
- case 26:
153
- _context.prev = 26;
154
- _context.t1 = _context["catch"](1);
155
- console.error('ERROR:', _context.t1);
156
- case 29:
157
- case "end":
158
- return _context.stop();
159
- }
160
- }, _loop, null, [[1, 26], [10, 21]]);
161
- });
134
+ _context2.p = 1;
162
135
  _iterator.s();
163
- case 5:
136
+ case 2:
164
137
  if ((_step = _iterator.n()).done) {
165
- _context2.next = 9;
138
+ _context2.n = 10;
166
139
  break;
167
140
  }
168
- return _context2.delegateYield(_loop(), "t0", 7);
141
+ file = _step.value;
142
+ _context2.p = 3;
143
+ filePath = _path["default"].join(dir, file);
144
+ relativePath = _path["default"].relative(deployFolder, filePath);
145
+ if (!_fs["default"].statSync(filePath).isDirectory()) {
146
+ _context2.n = 5;
147
+ break;
148
+ }
149
+ _context2.n = 4;
150
+ return processFiles(filePath);
151
+ case 4:
152
+ _context2.n = 7;
153
+ break;
154
+ case 5:
155
+ _context2.n = 6;
156
+ return uploadFile(filePath, turbo);
157
+ case 6:
158
+ uploadResult = _context2.v;
159
+ // Adds uploaded file txId to the new manifest json
160
+ newManifest.paths[relativePath] = {
161
+ id: uploadResult.id
162
+ };
163
+ if (file === '404.html') {
164
+ // Sets manifest fallback to 404.html if found
165
+ newManifest.fallback.id = uploadResult.id;
166
+ }
169
167
  case 7:
170
- _context2.next = 5;
168
+ _context2.n = 9;
171
169
  break;
170
+ case 8:
171
+ _context2.p = 8;
172
+ _t2 = _context2.v;
173
+ console.error('ERROR:', _t2);
172
174
  case 9:
173
- _context2.next = 14;
175
+ _context2.n = 2;
176
+ break;
177
+ case 10:
178
+ _context2.n = 12;
174
179
  break;
175
180
  case 11:
176
- _context2.prev = 11;
177
- _context2.t1 = _context2["catch"](2);
178
- _iterator.e(_context2.t1);
179
- case 14:
180
- _context2.prev = 14;
181
+ _context2.p = 11;
182
+ _t3 = _context2.v;
183
+ _iterator.e(_t3);
184
+ case 12:
185
+ _context2.p = 12;
181
186
  _iterator.f();
182
- return _context2.finish(14);
183
- case 17:
184
- case "end":
185
- return _context2.stop();
187
+ return _context2.f(12);
188
+ case 13:
189
+ return _context2.a(2);
186
190
  }
187
- }, _callee, null, [[2, 11, 14, 17]]);
191
+ }, _callee2, null, [[3, 8], [1, 11, 12, 13]]);
188
192
  }));
189
193
  return _processFiles.apply(this, arguments);
190
194
  };
191
- processFiles = function _processFiles2(_x3) {
195
+ processFiles = function _processFiles2(_x5) {
192
196
  return _processFiles.apply(this, arguments);
193
197
  };
194
198
  turbo = _turboSdk.TurboFactory.authenticated({
195
199
  privateKey: jwk
196
200
  });
197
- deployFolder = argv.deployFolder; //Uses Arweave manifest version 0.2.0, which supports fallbacks
201
+ deployFolder = argv.deployFolder; // Uses Arweave manifest version 0.2.0, which supports fallbacks
198
202
  newManifest = {
199
203
  manifest: 'arweave/paths',
200
204
  version: '0.2.0',
@@ -203,29 +207,28 @@ function _TurboDeploy() {
203
207
  },
204
208
  fallback: {},
205
209
  paths: {}
206
- }; // starts processing files in the selected directory
207
- _context4.next = 9;
210
+ }; // Starts processing files in the selected directory
211
+ _context4.n = 1;
208
212
  return processFiles(deployFolder);
209
- case 9:
213
+ case 1:
210
214
  if (!newManifest.fallback.id) {
211
- // if no 404.html file is found, manifest fallback is set to the txId of index.html
215
+ // If no 404.html file is found, manifest fallback is set to the txId of index.html
212
216
  newManifest.fallback.id = newManifest.paths['index.html'].id;
213
217
  }
214
- _context4.next = 12;
218
+ _context4.n = 2;
215
219
  return uploadManifest(newManifest);
216
- case 12:
217
- manifestId = _context4.sent;
220
+ case 2:
221
+ manifestId = _context4.v;
218
222
  if (!manifestId) {
219
- _context4.next = 16;
223
+ _context4.n = 3;
220
224
  break;
221
225
  }
222
226
  console.log("Manifest uploaded with Id: ".concat(manifestId));
223
- return _context4.abrupt("return", manifestId);
224
- case 16:
225
- case "end":
226
- return _context4.stop();
227
+ return _context4.a(2, manifestId);
228
+ case 3:
229
+ return _context4.a(2);
227
230
  }
228
- }, _callee3);
231
+ }, _callee4);
229
232
  }));
230
- return _TurboDeploy.apply(this, arguments);
233
+ return _uploadDirectory.apply(this, arguments);
231
234
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "permaweb-deploy",
3
- "version": "2.0.2",
4
- "description": "Permaweb app deployment package",
3
+ "version": "2.2.0",
4
+ "description": "Permaweb App Deployment Package",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "build": "babel src --out-dir dist"
@@ -12,6 +12,7 @@
12
12
  "dependencies": {
13
13
  "@ar.io/sdk": "^3.10.1",
14
14
  "@ardrive/turbo-sdk": "^1.17.0",
15
+ "@permaweb/aoconnect": "^0.0.85",
15
16
  "mime-types": "^2.1.35",
16
17
  "yargs": "17.7.2"
17
18
  },
package/src/index.js CHANGED
@@ -1,13 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { ANT, ARIO, ArweaveSigner } from '@ar.io/sdk';
4
3
  import fs from 'fs';
5
4
  import yargs from 'yargs';
6
5
  import { hideBin } from 'yargs/helpers';
7
6
 
8
- import TurboDeploy from './turbo';
7
+ import { ANT, AOProcess, ARIO, ARIO_MAINNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID, ArweaveSigner } from '@ar.io/sdk';
8
+ import { TurboFactory } from '@ardrive/turbo-sdk';
9
+ import { connect } from '@permaweb/aoconnect';
10
+
11
+ import { uploadDirectory, uploadFile } from './turbo';
12
+
13
+ const arweaveTxIdRegex = /^[a-zA-Z0-9-_]{43}$/;
9
14
 
10
15
  const argv = yargs(hideBin(process.argv))
16
+ .option('ario-process', {
17
+ alias: 'p',
18
+ type: 'string',
19
+ description: 'The ARIO process to use',
20
+ demandOption: true,
21
+ default: ARIO_MAINNET_PROCESS_ID
22
+ })
11
23
  .option('arns-name', {
12
24
  alias: 'n',
13
25
  type: 'string',
@@ -20,6 +32,11 @@ const argv = yargs(hideBin(process.argv))
20
32
  description: 'Folder to deploy.',
21
33
  default: './dist',
22
34
  })
35
+ .option('deploy-file', {
36
+ alias: 'f',
37
+ type: 'string',
38
+ description: 'File to deploy.'
39
+ })
23
40
  .option('undername', {
24
41
  alias: 'u',
25
42
  type: 'string',
@@ -29,19 +46,19 @@ const argv = yargs(hideBin(process.argv))
29
46
 
30
47
  const DEPLOY_KEY = process.env.DEPLOY_KEY;
31
48
  const ARNS_NAME = argv.arnsName;
32
-
33
- export function getTagValue(list, name) {
34
- for (let i = 0; i < list.length; i++) {
35
- if (list[i]) {
36
- if (list[i].name === name) {
37
- return list[i].value;
38
- }
39
- }
40
- }
41
- return STORAGE.none;
49
+ let ARIO_PROCESS = argv.arioProcess;
50
+ if (ARIO_PROCESS === 'mainnet') {
51
+ ARIO_PROCESS = ARIO_MAINNET_PROCESS_ID;
52
+ } else if (ARIO_PROCESS === 'testnet') {
53
+ ARIO_PROCESS = ARIO_TESTNET_PROCESS_ID;
42
54
  }
43
55
 
44
56
  (async () => {
57
+ if (!ARIO_PROCESS || !arweaveTxIdRegex.test(ARIO_PROCESS)) {
58
+ console.error('ARIO_PROCESS must be a valid Arweave transaction ID, or "mainnet" or "testnet"');
59
+ process.exit(1);
60
+ }
61
+
45
62
  if (!DEPLOY_KEY) {
46
63
  console.error('DEPLOY_KEY not configured');
47
64
  process.exit(1);
@@ -52,32 +69,48 @@ export function getTagValue(list, name) {
52
69
  process.exit(1);
53
70
  }
54
71
 
55
-
56
- if (argv.deployFolder.length == 0) {
57
- console.error('deploy folder must not be empty');
72
+ if (argv.deployFile && !fs.existsSync(argv.deployFile)) {
73
+ console.error(`deploy-file [${argv.deployFolder}] does not exist`);
58
74
  process.exit(1);
59
75
  }
60
-
61
- if (argv.undername.length == 0) {
62
- console.error('undername must not be empty');
63
- process.exit(1);
76
+ else {
77
+ if (!fs.existsSync(argv.deployFolder)) {
78
+ console.error(`deploy-folder [${argv.deployFolder}] does not exist`);
79
+ process.exit(1);
80
+ }
64
81
  }
65
82
 
66
- if (!fs.existsSync(argv.deployFolder)) {
67
- console.error(`deploy folder [${argv.deployFolder}] does not exist`);
83
+ if (argv.undername.length === 0) {
84
+ console.error('undername must be set');
68
85
  process.exit(1);
69
86
  }
70
87
 
71
88
  const jwk = JSON.parse(Buffer.from(DEPLOY_KEY, 'base64').toString('utf-8'));
72
- const ario = ARIO.init()
73
- const arnsNameRecord = await ario.getArNSRecord({name: ARNS_NAME}).catch((e) => {
89
+ const ario = ARIO.init({
90
+ process: new AOProcess({
91
+ processId: ARIO_PROCESS,
92
+ ao: connect({
93
+ MODE: 'legacy',
94
+ CU_URL: 'https://cu.ardrive.io'
95
+ })
96
+ })
97
+ });
98
+
99
+ const arnsNameRecord = await ario.getArNSRecord({ name: ARNS_NAME }).catch((e) => {
74
100
  console.error(`ARNS name [${ARNS_NAME}] does not exist`);
75
101
  process.exit(1);
76
102
  });
77
103
 
78
-
79
104
  try {
80
- const manifestId = await TurboDeploy(argv, jwk);
105
+ let txId;
106
+ if (argv.deployFile) {
107
+ const turbo = TurboFactory.authenticated({ privateKey: jwk });
108
+ txId = (await uploadFile(argv.deployFile, turbo)).id;
109
+ }
110
+ else {
111
+ txId = await uploadDirectory(argv, jwk);
112
+ }
113
+
81
114
  const signer = new ArweaveSigner(jwk);
82
115
  const ant = ANT.init({ processId: arnsNameRecord.processId, signer });
83
116
 
@@ -85,9 +118,10 @@ export function getTagValue(list, name) {
85
118
  await ant.setRecord(
86
119
  {
87
120
  undername: argv.undername,
88
- transactionId: manifestId,
121
+ transactionId: txId,
89
122
  ttlSeconds: 3600,
90
- },{
123
+ },
124
+ {
91
125
  tags: [
92
126
  {
93
127
  name: 'App-Name',
@@ -101,7 +135,7 @@ export function getTagValue(list, name) {
101
135
  }
102
136
  );
103
137
 
104
- console.log(`Deployed TxId [${manifestId}] to name [${ARNS_NAME}] for ANT [${arnsNameRecord.processId}] using undername [${argv.undername}]`);
138
+ console.log(`Deployed TxId [${txId}] to name [${ARNS_NAME}] for ANT [${arnsNameRecord.processId}] using undername [${argv.undername}]`);
105
139
  } catch (e) {
106
140
  console.error('Deployment failed:', e);
107
141
  process.exit(1); // Exit with error code
@@ -1,20 +1,47 @@
1
- import { TurboFactory } from '@ardrive/turbo-sdk';
2
1
  import fs from 'fs';
3
2
  import mime from 'mime-types';
4
3
  import path from 'path';
5
4
  import { Readable } from 'stream';
6
5
 
6
+ import { TurboFactory } from '@ardrive/turbo-sdk';
7
+
7
8
  // Gets MIME types for each file to tag the upload
8
9
  function getContentType(filePath) {
9
10
  const res = mime.lookup(filePath);
10
11
  return res || 'application/octet-stream';
11
12
  }
12
13
 
13
- export default async function TurboDeploy(argv, jwk) {
14
+ export async function uploadFile(path, turbo) {
15
+ console.log(`Uploading file: ${path}...`);
16
+ try {
17
+ const fileSize = fs.statSync(path).size;
18
+ const contentType = getContentType(path);
19
+ const uploadResult = await turbo.uploadFile({
20
+ fileStreamFactory: () => fs.createReadStream(path),
21
+ fileSizeFactory: () => fileSize,
22
+ signal: AbortSignal.timeout(10_000), // Cancel the upload after 10 seconds
23
+ dataItemOpts: {
24
+ tags: [
25
+ { name: 'Content-Type', value: contentType },
26
+ { name: 'App-Name', value: 'Permaweb-Deploy' },
27
+ ],
28
+ },
29
+ });
30
+
31
+ console.log(`Uploaded ${path} with id:`, uploadResult.id);
32
+
33
+ return uploadResult;
34
+ } catch (err) {
35
+ console.error(`Error uploading file ${path}:`, err);
36
+ }
37
+ }
38
+
39
+ export async function uploadDirectory(argv, jwk) {
14
40
  const turbo = TurboFactory.authenticated({ privateKey: jwk });
15
41
 
16
42
  const deployFolder = argv.deployFolder;
17
- //Uses Arweave manifest version 0.2.0, which supports fallbacks
43
+
44
+ // Uses Arweave manifest version 0.2.0, which supports fallbacks
18
45
  let newManifest = {
19
46
  manifest: 'arweave/paths',
20
47
  version: '0.2.0',
@@ -32,35 +59,17 @@ export default async function TurboDeploy(argv, jwk) {
32
59
  const relativePath = path.relative(deployFolder, filePath);
33
60
 
34
61
  if (fs.statSync(filePath).isDirectory()) {
35
- // recursively process all files in a directory
62
+ // Recursively process all files in a directory
36
63
  await processFiles(filePath);
37
64
  } else {
38
- console.log(`Uploading file: ${relativePath}`);
39
- try {
40
- const fileSize = fs.statSync(filePath).size;
41
- const contentType = getContentType(filePath);
42
- const uploadResult = await turbo.uploadFile({
43
- fileStreamFactory: () => fs.createReadStream(filePath),
44
- fileSizeFactory: () => fileSize,
45
- signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
46
- dataItemOpts: {
47
- tags: [
48
- { name: 'Content-Type', value: contentType },
49
- { name: 'App-Name', value: 'Permaweb-Deploy' },
50
- ],
51
- },
52
- });
53
-
54
- console.log(`Uploaded ${relativePath} with id:`, uploadResult.id);
55
- // adds uploaded file txId to the new manifest json
56
- newManifest.paths[relativePath] = { id: uploadResult.id };
57
-
58
- if (file === '404.html') {
59
- // sets manifest fallback to 404.html if found
60
- newManifest.fallback.id = uploadResult.id;
61
- }
62
- } catch (err) {
63
- console.error(`Error uploading file ${relativePath}:`, err);
65
+ const uploadResult = await uploadFile(filePath, turbo);
66
+
67
+ // Adds uploaded file txId to the new manifest json
68
+ newManifest.paths[relativePath] = { id: uploadResult.id };
69
+
70
+ if (file === '404.html') {
71
+ // Sets manifest fallback to 404.html if found
72
+ newManifest.fallback.id = uploadResult.id;
64
73
  }
65
74
  }
66
75
  } catch (err) {
@@ -96,11 +105,11 @@ export default async function TurboDeploy(argv, jwk) {
96
105
  }
97
106
  }
98
107
 
99
- // starts processing files in the selected directory
108
+ // Starts processing files in the selected directory
100
109
  await processFiles(deployFolder);
101
110
 
102
111
  if (!newManifest.fallback.id) {
103
- // if no 404.html file is found, manifest fallback is set to the txId of index.html
112
+ // If no 404.html file is found, manifest fallback is set to the txId of index.html
104
113
  newManifest.fallback.id = newManifest.paths['index.html'].id;
105
114
  }
106
115