permaweb-deploy 1.1.5 → 1.1.7
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 +53 -34
- package/dist/turbo/index.js +247 -0
- package/package.json +4 -3
- package/src/index.js +45 -26
- package/src/turbo/index.js +111 -0
package/dist/index.js
CHANGED
|
@@ -7,9 +7,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.getTagValue = getTagValue;
|
|
9
9
|
var _sdk = require("@ar.io/sdk");
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
11
|
var _yargs = _interopRequireDefault(require("yargs"));
|
|
11
12
|
var _helpers = require("yargs/helpers");
|
|
12
|
-
var
|
|
13
|
+
var _turbo = _interopRequireDefault(require("./turbo"));
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
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; }
|
|
15
16
|
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,8 +20,17 @@ var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).option('a
|
|
|
19
20
|
type: 'string',
|
|
20
21
|
description: 'The ANT process',
|
|
21
22
|
demandOption: true
|
|
23
|
+
}).option('deploy-folder', {
|
|
24
|
+
alias: 'd',
|
|
25
|
+
type: 'string',
|
|
26
|
+
description: 'Folder to deploy.',
|
|
27
|
+
"default": './dist'
|
|
28
|
+
}).option('undername', {
|
|
29
|
+
alias: 'u',
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: 'ANT undername to update.',
|
|
32
|
+
"default": '@'
|
|
22
33
|
}).argv;
|
|
23
|
-
var DEPLOY_FOLDER = './dist';
|
|
24
34
|
var DEPLOY_KEY = process.env.DEPLOY_KEY;
|
|
25
35
|
var ANT_PROCESS = argv.antProcess;
|
|
26
36
|
function getTagValue(list, name) {
|
|
@@ -34,7 +44,7 @@ function getTagValue(list, name) {
|
|
|
34
44
|
return STORAGE.none;
|
|
35
45
|
}
|
|
36
46
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
37
|
-
var jwk,
|
|
47
|
+
var jwk, manifestId, signer, ant;
|
|
38
48
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
39
49
|
while (1) switch (_context.prev = _context.next) {
|
|
40
50
|
case 0:
|
|
@@ -52,52 +62,61 @@ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
|
52
62
|
console.error('ANT_PROCESS not configured');
|
|
53
63
|
return _context.abrupt("return");
|
|
54
64
|
case 6:
|
|
55
|
-
|
|
65
|
+
if (!(argv.deployFolder.length == 0)) {
|
|
66
|
+
_context.next = 9;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
console.error('deploy folder must not be empty');
|
|
70
|
+
return _context.abrupt("return");
|
|
71
|
+
case 9:
|
|
72
|
+
if (!(argv.undername.length == 0)) {
|
|
73
|
+
_context.next = 12;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
console.error('undername must not be empty');
|
|
77
|
+
return _context.abrupt("return");
|
|
78
|
+
case 12:
|
|
79
|
+
if (_fs["default"].existsSync(argv.deployFolder)) {
|
|
80
|
+
_context.next = 15;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
console.error("deploy folder [".concat(argv.deployFolder, "] does not exist"));
|
|
84
|
+
return _context.abrupt("return");
|
|
85
|
+
case 15:
|
|
56
86
|
jwk = JSON.parse(Buffer.from(DEPLOY_KEY, 'base64').toString('utf-8'));
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
irys.uploader.useChunking = false;
|
|
63
|
-
_context.prev = 9;
|
|
64
|
-
console.log("Deploying ".concat(DEPLOY_FOLDER, " folder"));
|
|
65
|
-
_context.next = 13;
|
|
66
|
-
return irys.uploadFolder(DEPLOY_FOLDER, {
|
|
67
|
-
indexFile: 'index.html',
|
|
68
|
-
interactivePreflight: false,
|
|
69
|
-
logFunction: function logFunction(log) {
|
|
70
|
-
return console.log(log);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
case 13:
|
|
74
|
-
txResult = _context.sent;
|
|
75
|
-
console.log("Bundle TxId [".concat(txResult.id, "]"));
|
|
87
|
+
_context.prev = 16;
|
|
88
|
+
_context.next = 19;
|
|
89
|
+
return (0, _turbo["default"])(argv, jwk);
|
|
90
|
+
case 19:
|
|
91
|
+
manifestId = _context.sent;
|
|
76
92
|
signer = new _sdk.ArweaveSigner(jwk);
|
|
77
93
|
ant = _sdk.ANT.init({
|
|
78
94
|
processId: ANT_PROCESS,
|
|
79
95
|
signer: signer
|
|
80
96
|
}); // Update the ANT record (assumes the JWK is a controller or owner)
|
|
81
|
-
_context.next =
|
|
97
|
+
_context.next = 24;
|
|
82
98
|
return ant.setRecord({
|
|
83
|
-
undername:
|
|
84
|
-
transactionId:
|
|
99
|
+
undername: argv.undername,
|
|
100
|
+
transactionId: manifestId,
|
|
85
101
|
ttlSeconds: 3600
|
|
86
102
|
}, {
|
|
87
103
|
name: 'GIT-HASH',
|
|
88
104
|
value: process.env.GITHUB_SHA
|
|
105
|
+
}, {
|
|
106
|
+
name: 'App-Name',
|
|
107
|
+
value: 'Permaweb-Deploy'
|
|
89
108
|
});
|
|
90
|
-
case
|
|
91
|
-
console.log("Deployed TxId [".concat(
|
|
92
|
-
_context.next =
|
|
109
|
+
case 24:
|
|
110
|
+
console.log("Deployed TxId [".concat(manifestId, "] to ANT [").concat(ANT_PROCESS, "] using undername [").concat(argv.undername, "]"));
|
|
111
|
+
_context.next = 30;
|
|
93
112
|
break;
|
|
94
|
-
case
|
|
95
|
-
_context.prev =
|
|
96
|
-
_context.t0 = _context["catch"](
|
|
113
|
+
case 27:
|
|
114
|
+
_context.prev = 27;
|
|
115
|
+
_context.t0 = _context["catch"](16);
|
|
97
116
|
console.error(_context.t0);
|
|
98
|
-
case
|
|
117
|
+
case 30:
|
|
99
118
|
case "end":
|
|
100
119
|
return _context.stop();
|
|
101
120
|
}
|
|
102
|
-
}, _callee, null, [[
|
|
121
|
+
}, _callee, null, [[16, 27]]);
|
|
103
122
|
}))();
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = TurboDeploy;
|
|
7
|
+
var _turboSdk = require("@ardrive/turbo-sdk");
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _stream = require("stream");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
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); }
|
|
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; } } }; }
|
|
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; } }
|
|
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 _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; }
|
|
18
|
+
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
|
+
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
|
+
// Gets MIME types for each file to tag the upload
|
|
21
|
+
function getContentType(_x) {
|
|
22
|
+
return _getContentType.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
function _getContentType() {
|
|
25
|
+
_getContentType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(filePath) {
|
|
26
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
27
|
+
while (1) switch (_context.prev = _context.next) {
|
|
28
|
+
case 0:
|
|
29
|
+
return _context.abrupt("return", _mimeTypes["default"].lookup(filePath));
|
|
30
|
+
case 1:
|
|
31
|
+
case "end":
|
|
32
|
+
return _context.stop();
|
|
33
|
+
}
|
|
34
|
+
}, _callee);
|
|
35
|
+
}));
|
|
36
|
+
return _getContentType.apply(this, arguments);
|
|
37
|
+
}
|
|
38
|
+
function TurboDeploy(_x2, _x3) {
|
|
39
|
+
return _TurboDeploy.apply(this, arguments);
|
|
40
|
+
}
|
|
41
|
+
function _TurboDeploy() {
|
|
42
|
+
_TurboDeploy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(argv, jwk) {
|
|
43
|
+
var turbo, deployFolder, newManifest, processFiles, _processFiles, uploadManifest, _uploadManifest, manifestId;
|
|
44
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
45
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
46
|
+
case 0:
|
|
47
|
+
_uploadManifest = function _uploadManifest3() {
|
|
48
|
+
_uploadManifest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(manifest) {
|
|
49
|
+
var manifestString, uploadResult;
|
|
50
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
51
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
_context4.prev = 0;
|
|
54
|
+
manifestString = JSON.stringify(manifest);
|
|
55
|
+
_context4.next = 4;
|
|
56
|
+
return turbo.uploadFile({
|
|
57
|
+
fileStreamFactory: function fileStreamFactory() {
|
|
58
|
+
return _stream.Readable.from(Buffer.from(manifestString));
|
|
59
|
+
},
|
|
60
|
+
fileSizeFactory: function fileSizeFactory() {
|
|
61
|
+
return Buffer.byteLength(manifestString);
|
|
62
|
+
},
|
|
63
|
+
signal: AbortSignal.timeout(10000),
|
|
64
|
+
dataItemOpts: {
|
|
65
|
+
tags: [{
|
|
66
|
+
name: 'Content-Type',
|
|
67
|
+
value: 'application/x.arweave-manifest+json'
|
|
68
|
+
}, {
|
|
69
|
+
name: 'App-Name',
|
|
70
|
+
value: 'Permaweb-Deploy'
|
|
71
|
+
}]
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
case 4:
|
|
75
|
+
uploadResult = _context4.sent;
|
|
76
|
+
return _context4.abrupt("return", uploadResult.id);
|
|
77
|
+
case 8:
|
|
78
|
+
_context4.prev = 8;
|
|
79
|
+
_context4.t0 = _context4["catch"](0);
|
|
80
|
+
console.error('Error uploading manifest:', _context4.t0);
|
|
81
|
+
return _context4.abrupt("return", null);
|
|
82
|
+
case 12:
|
|
83
|
+
case "end":
|
|
84
|
+
return _context4.stop();
|
|
85
|
+
}
|
|
86
|
+
}, _callee3, null, [[0, 8]]);
|
|
87
|
+
}));
|
|
88
|
+
return _uploadManifest.apply(this, arguments);
|
|
89
|
+
};
|
|
90
|
+
uploadManifest = function _uploadManifest2(_x5) {
|
|
91
|
+
return _uploadManifest.apply(this, arguments);
|
|
92
|
+
};
|
|
93
|
+
_processFiles = function _processFiles3() {
|
|
94
|
+
_processFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(dir) {
|
|
95
|
+
var files, _iterator, _step, _loop;
|
|
96
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
97
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
files = _fs["default"].readdirSync(dir);
|
|
100
|
+
_iterator = _createForOfIteratorHelper(files);
|
|
101
|
+
_context3.prev = 2;
|
|
102
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
103
|
+
var file, filePath, relativePath, fileSize, contentType, uploadResult;
|
|
104
|
+
return _regeneratorRuntime().wrap(function _loop$(_context2) {
|
|
105
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
106
|
+
case 0:
|
|
107
|
+
file = _step.value;
|
|
108
|
+
_context2.prev = 1;
|
|
109
|
+
filePath = _path["default"].join(dir, file);
|
|
110
|
+
relativePath = _path["default"].relative(deployFolder, filePath);
|
|
111
|
+
if (!_fs["default"].statSync(filePath).isDirectory()) {
|
|
112
|
+
_context2.next = 9;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
_context2.next = 7;
|
|
116
|
+
return processFiles(filePath);
|
|
117
|
+
case 7:
|
|
118
|
+
_context2.next = 26;
|
|
119
|
+
break;
|
|
120
|
+
case 9:
|
|
121
|
+
console.log("Uploading file: ".concat(relativePath));
|
|
122
|
+
_context2.prev = 10;
|
|
123
|
+
fileSize = _fs["default"].statSync(filePath).size;
|
|
124
|
+
_context2.next = 14;
|
|
125
|
+
return getContentType(filePath);
|
|
126
|
+
case 14:
|
|
127
|
+
contentType = _context2.sent;
|
|
128
|
+
_context2.next = 17;
|
|
129
|
+
return turbo.uploadFile({
|
|
130
|
+
fileStreamFactory: function fileStreamFactory() {
|
|
131
|
+
return _fs["default"].createReadStream(filePath);
|
|
132
|
+
},
|
|
133
|
+
fileSizeFactory: function fileSizeFactory() {
|
|
134
|
+
return fileSize;
|
|
135
|
+
},
|
|
136
|
+
signal: AbortSignal.timeout(10000),
|
|
137
|
+
// cancel the upload after 10 seconds
|
|
138
|
+
dataItemOpts: {
|
|
139
|
+
tags: [{
|
|
140
|
+
name: 'Content-Type',
|
|
141
|
+
value: contentType
|
|
142
|
+
}, {
|
|
143
|
+
name: 'App-Name',
|
|
144
|
+
value: 'Permaweb-Deploy'
|
|
145
|
+
}]
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
case 17:
|
|
149
|
+
uploadResult = _context2.sent;
|
|
150
|
+
console.log("Uploaded ".concat(relativePath, " with id:"), uploadResult.id);
|
|
151
|
+
// adds uploaded file txId to the new manifest json
|
|
152
|
+
newManifest.paths[relativePath] = {
|
|
153
|
+
id: uploadResult.id
|
|
154
|
+
};
|
|
155
|
+
if (file === '404.html') {
|
|
156
|
+
// sets manifest fallback to 404.html if found
|
|
157
|
+
newManifest.fallback.id = uploadResult.id;
|
|
158
|
+
}
|
|
159
|
+
_context2.next = 26;
|
|
160
|
+
break;
|
|
161
|
+
case 23:
|
|
162
|
+
_context2.prev = 23;
|
|
163
|
+
_context2.t0 = _context2["catch"](10);
|
|
164
|
+
console.error("Error uploading file ".concat(relativePath, ":"), _context2.t0);
|
|
165
|
+
case 26:
|
|
166
|
+
_context2.next = 31;
|
|
167
|
+
break;
|
|
168
|
+
case 28:
|
|
169
|
+
_context2.prev = 28;
|
|
170
|
+
_context2.t1 = _context2["catch"](1);
|
|
171
|
+
console.error('ERROR:', _context2.t1);
|
|
172
|
+
case 31:
|
|
173
|
+
case "end":
|
|
174
|
+
return _context2.stop();
|
|
175
|
+
}
|
|
176
|
+
}, _loop, null, [[1, 28], [10, 23]]);
|
|
177
|
+
});
|
|
178
|
+
_iterator.s();
|
|
179
|
+
case 5:
|
|
180
|
+
if ((_step = _iterator.n()).done) {
|
|
181
|
+
_context3.next = 9;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
return _context3.delegateYield(_loop(), "t0", 7);
|
|
185
|
+
case 7:
|
|
186
|
+
_context3.next = 5;
|
|
187
|
+
break;
|
|
188
|
+
case 9:
|
|
189
|
+
_context3.next = 14;
|
|
190
|
+
break;
|
|
191
|
+
case 11:
|
|
192
|
+
_context3.prev = 11;
|
|
193
|
+
_context3.t1 = _context3["catch"](2);
|
|
194
|
+
_iterator.e(_context3.t1);
|
|
195
|
+
case 14:
|
|
196
|
+
_context3.prev = 14;
|
|
197
|
+
_iterator.f();
|
|
198
|
+
return _context3.finish(14);
|
|
199
|
+
case 17:
|
|
200
|
+
case "end":
|
|
201
|
+
return _context3.stop();
|
|
202
|
+
}
|
|
203
|
+
}, _callee2, null, [[2, 11, 14, 17]]);
|
|
204
|
+
}));
|
|
205
|
+
return _processFiles.apply(this, arguments);
|
|
206
|
+
};
|
|
207
|
+
processFiles = function _processFiles2(_x4) {
|
|
208
|
+
return _processFiles.apply(this, arguments);
|
|
209
|
+
};
|
|
210
|
+
turbo = _turboSdk.TurboFactory.authenticated({
|
|
211
|
+
privateKey: jwk
|
|
212
|
+
});
|
|
213
|
+
deployFolder = argv.deployFolder; //Uses Arweave manifest version 0.2.0, which supports fallbacks
|
|
214
|
+
newManifest = {
|
|
215
|
+
manifest: 'arweave/paths',
|
|
216
|
+
version: '0.2.0',
|
|
217
|
+
index: {
|
|
218
|
+
path: 'index.html'
|
|
219
|
+
},
|
|
220
|
+
fallback: {},
|
|
221
|
+
paths: {}
|
|
222
|
+
}; // starts processing files in the selected directory
|
|
223
|
+
_context5.next = 9;
|
|
224
|
+
return processFiles(deployFolder);
|
|
225
|
+
case 9:
|
|
226
|
+
if (!newManifest.fallback.id) {
|
|
227
|
+
// if no 404.html file is found, manifest fallback is set to the txId of index.html
|
|
228
|
+
newManifest.fallback.id = newManifest.paths['index.html'].id;
|
|
229
|
+
}
|
|
230
|
+
_context5.next = 12;
|
|
231
|
+
return uploadManifest(newManifest);
|
|
232
|
+
case 12:
|
|
233
|
+
manifestId = _context5.sent;
|
|
234
|
+
if (!manifestId) {
|
|
235
|
+
_context5.next = 16;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
console.log("Manifest uploaded with Id: ".concat(manifestId));
|
|
239
|
+
return _context5.abrupt("return", manifestId);
|
|
240
|
+
case 16:
|
|
241
|
+
case "end":
|
|
242
|
+
return _context5.stop();
|
|
243
|
+
}
|
|
244
|
+
}, _callee4);
|
|
245
|
+
}));
|
|
246
|
+
return _TurboDeploy.apply(this, arguments);
|
|
247
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "permaweb-deploy",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Permaweb app deployment package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"permaweb-deploy": "./dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@ar.io/sdk": "1.2.
|
|
14
|
-
"@
|
|
13
|
+
"@ar.io/sdk": "^1.2.2",
|
|
14
|
+
"@ardrive/turbo-sdk": "^1.9.0",
|
|
15
|
+
"mime-types": "^2.1.35",
|
|
15
16
|
"yargs": "17.7.2"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { ANT, ArweaveSigner } from '@ar.io/sdk';
|
|
4
|
+
import fs from 'fs';
|
|
4
5
|
import yargs from 'yargs';
|
|
5
6
|
import { hideBin } from 'yargs/helpers';
|
|
6
7
|
|
|
7
|
-
import
|
|
8
|
+
import TurboDeploy from './turbo';
|
|
8
9
|
|
|
9
10
|
const argv = yargs(hideBin(process.argv))
|
|
10
11
|
.option('ant-process', {
|
|
@@ -13,9 +14,19 @@ const argv = yargs(hideBin(process.argv))
|
|
|
13
14
|
description: 'The ANT process',
|
|
14
15
|
demandOption: true,
|
|
15
16
|
})
|
|
16
|
-
.
|
|
17
|
+
.option('deploy-folder', {
|
|
18
|
+
alias: 'd',
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'Folder to deploy.',
|
|
21
|
+
default: './dist',
|
|
22
|
+
})
|
|
23
|
+
.option('undername', {
|
|
24
|
+
alias: 'u',
|
|
25
|
+
type: 'string',
|
|
26
|
+
description: 'ANT undername to update.',
|
|
27
|
+
default: '@',
|
|
28
|
+
}).argv;
|
|
17
29
|
|
|
18
|
-
const DEPLOY_FOLDER = './dist';
|
|
19
30
|
const DEPLOY_KEY = process.env.DEPLOY_KEY;
|
|
20
31
|
const ANT_PROCESS = argv.antProcess;
|
|
21
32
|
|
|
@@ -41,37 +52,45 @@ export function getTagValue(list, name) {
|
|
|
41
52
|
return;
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const irys = new Irys({ url: 'https://turbo.ardrive.io', token: 'arweave', key: jwk });
|
|
49
|
-
irys.uploader.useChunking = false;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
console.log(`Deploying ${DEPLOY_FOLDER} folder`);
|
|
55
|
+
if (argv.deployFolder.length == 0) {
|
|
56
|
+
console.error('deploy folder must not be empty');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
60
|
+
if (argv.undername.length == 0) {
|
|
61
|
+
console.error('undername must not be empty');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
59
64
|
|
|
60
|
-
|
|
65
|
+
if (!fs.existsSync(argv.deployFolder)) {
|
|
66
|
+
console.error(`deploy folder [${argv.deployFolder}] does not exist`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
61
69
|
|
|
70
|
+
let jwk = JSON.parse(Buffer.from(DEPLOY_KEY, 'base64').toString('utf-8'));
|
|
71
|
+
try {
|
|
72
|
+
const manifestId = await TurboDeploy(argv, jwk);
|
|
62
73
|
const signer = new ArweaveSigner(jwk);
|
|
63
74
|
const ant = ANT.init({ processId: ANT_PROCESS, signer });
|
|
64
75
|
|
|
65
76
|
// Update the ANT record (assumes the JWK is a controller or owner)
|
|
66
|
-
await ant.setRecord(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
await ant.setRecord(
|
|
78
|
+
{
|
|
79
|
+
undername: argv.undername,
|
|
80
|
+
transactionId: manifestId,
|
|
81
|
+
ttlSeconds: 3600,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'GIT-HASH',
|
|
85
|
+
value: process.env.GITHUB_SHA,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'App-Name',
|
|
89
|
+
value: 'Permaweb-Deploy',
|
|
90
|
+
}
|
|
91
|
+
);
|
|
73
92
|
|
|
74
|
-
console.log(`Deployed TxId [${
|
|
93
|
+
console.log(`Deployed TxId [${manifestId}] to ANT [${ANT_PROCESS}] using undername [${argv.undername}]`);
|
|
75
94
|
} catch (e) {
|
|
76
95
|
console.error(e);
|
|
77
96
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { TurboFactory } from '@ardrive/turbo-sdk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import mime from 'mime-types';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { Readable } from 'stream';
|
|
6
|
+
|
|
7
|
+
// Gets MIME types for each file to tag the upload
|
|
8
|
+
async function getContentType(filePath) {
|
|
9
|
+
return mime.lookup(filePath);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default async function TurboDeploy(argv, jwk) {
|
|
13
|
+
const turbo = TurboFactory.authenticated({ privateKey: jwk });
|
|
14
|
+
|
|
15
|
+
const deployFolder = argv.deployFolder;
|
|
16
|
+
//Uses Arweave manifest version 0.2.0, which supports fallbacks
|
|
17
|
+
let newManifest = {
|
|
18
|
+
manifest: 'arweave/paths',
|
|
19
|
+
version: '0.2.0',
|
|
20
|
+
index: { path: 'index.html' },
|
|
21
|
+
fallback: {},
|
|
22
|
+
paths: {},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
async function processFiles(dir) {
|
|
26
|
+
const files = fs.readdirSync(dir);
|
|
27
|
+
|
|
28
|
+
for (const file of files) {
|
|
29
|
+
try {
|
|
30
|
+
const filePath = path.join(dir, file);
|
|
31
|
+
const relativePath = path.relative(deployFolder, filePath);
|
|
32
|
+
|
|
33
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
34
|
+
// recursively process all files in a directory
|
|
35
|
+
await processFiles(filePath);
|
|
36
|
+
} else {
|
|
37
|
+
console.log(`Uploading file: ${relativePath}`);
|
|
38
|
+
try {
|
|
39
|
+
const fileSize = fs.statSync(filePath).size;
|
|
40
|
+
const contentType = await getContentType(filePath);
|
|
41
|
+
const uploadResult = await turbo.uploadFile({
|
|
42
|
+
fileStreamFactory: () => fs.createReadStream(filePath),
|
|
43
|
+
fileSizeFactory: () => fileSize,
|
|
44
|
+
signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
|
|
45
|
+
dataItemOpts: {
|
|
46
|
+
tags: [
|
|
47
|
+
{ name: 'Content-Type', value: contentType },
|
|
48
|
+
{ name: 'App-Name', value: 'Permaweb-Deploy' },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
console.log(`Uploaded ${relativePath} with id:`, uploadResult.id);
|
|
54
|
+
// adds uploaded file txId to the new manifest json
|
|
55
|
+
newManifest.paths[relativePath] = { id: uploadResult.id };
|
|
56
|
+
|
|
57
|
+
if (file === '404.html') {
|
|
58
|
+
// sets manifest fallback to 404.html if found
|
|
59
|
+
newManifest.fallback.id = uploadResult.id;
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.error(`Error uploading file ${relativePath}:`, err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error('ERROR:', err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function uploadManifest(manifest) {
|
|
72
|
+
try {
|
|
73
|
+
const manifestString = JSON.stringify(manifest);
|
|
74
|
+
const uploadResult = await turbo.uploadFile({
|
|
75
|
+
fileStreamFactory: () => Readable.from(Buffer.from(manifestString)),
|
|
76
|
+
fileSizeFactory: () => Buffer.byteLength(manifestString),
|
|
77
|
+
signal: AbortSignal.timeout(10_000),
|
|
78
|
+
dataItemOpts: {
|
|
79
|
+
tags: [
|
|
80
|
+
{
|
|
81
|
+
name: 'Content-Type',
|
|
82
|
+
value: 'application/x.arweave-manifest+json',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'App-Name',
|
|
86
|
+
value: 'Permaweb-Deploy',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
return uploadResult.id;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('Error uploading manifest:', error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// starts processing files in the selected directory
|
|
99
|
+
await processFiles(deployFolder);
|
|
100
|
+
|
|
101
|
+
if (!newManifest.fallback.id) {
|
|
102
|
+
// if no 404.html file is found, manifest fallback is set to the txId of index.html
|
|
103
|
+
newManifest.fallback.id = newManifest.paths['index.html'].id;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const manifestId = await uploadManifest(newManifest);
|
|
107
|
+
if (manifestId) {
|
|
108
|
+
console.log(`Manifest uploaded with Id: ${manifestId}`);
|
|
109
|
+
return manifestId;
|
|
110
|
+
}
|
|
111
|
+
}
|