download-binary.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["tauri"] = factory();
  8. else
  9. root["tauri"] = factory();
  10. })(this, function() {
  11. return /******/ (() => { // webpackBootstrap
  12. /******/ var __webpack_modules__ = ({
  13. /***/ "../cli.rs/Cargo.toml":
  14. /*!****************************!*\
  15. !*** ../cli.rs/Cargo.toml ***!
  16. \****************************/
  17. /***/ ((module) => {
  18. module.exports = {
  19. "workspace": {},
  20. "package": {
  21. "name": "tauri-cli",
  22. "version": "1.0.0-beta.5",
  23. "authors": [
  24. "Tauri Programme within The Commons Conservancy"
  25. ],
  26. "edition": "2018",
  27. "categories": [
  28. "gui",
  29. "web-programming"
  30. ],
  31. "license": "Apache-2.0 OR MIT",
  32. "homepage": "https://tauri.studio",
  33. "repository": "https://github.com/tauri-apps/tauri",
  34. "description": "Command line interface for building Tauri apps",
  35. "include": [
  36. "src/",
  37. "/templates",
  38. "MergeModules/",
  39. "*.json",
  40. "*.rs"
  41. ]
  42. },
  43. "bin": [
  44. {
  45. "name": "cargo-tauri",
  46. "path": "src/main.rs"
  47. }
  48. ],
  49. "dependencies": {
  50. "clap": {
  51. "version": "3.0.0-beta.2",
  52. "features": [
  53. "yaml"
  54. ]
  55. },
  56. "anyhow": "1.0",
  57. "tauri-bundler": {
  58. "version": "1.0.0-beta.3",
  59. "path": "../bundler"
  60. },
  61. "colored": "2.0",
  62. "once_cell": "1.8",
  63. "serde": {
  64. "version": "1.0",
  65. "features": [
  66. "derive"
  67. ]
  68. },
  69. "serde_json": "1.0",
  70. "serde_with": "1.9",
  71. "notify": "4.0",
  72. "shared_child": "0.3",
  73. "toml_edit": "0.2",
  74. "json-patch": "0.2",
  75. "schemars": "0.8",
  76. "toml": "0.5",
  77. "valico": "3.6",
  78. "handlebars": "4.1",
  79. "include_dir": "0.6",
  80. "minisign": "0.6",
  81. "base64": "0.13.0",
  82. "ureq": "2.1",
  83. "os_info": "3.0",
  84. "semver": "1.0",
  85. "regex": "1.5",
  86. "lazy_static": "1",
  87. "libc": "0.2",
  88. "terminal_size": "0.1",
  89. "unicode-width": "0.1",
  90. "tempfile": "3",
  91. "zeroize": "1.3"
  92. },
  93. "target": {
  94. "cfg(windows)": {
  95. "dependencies": {
  96. "winapi": {
  97. "version": "0.3",
  98. "features": [
  99. "winbase",
  100. "winuser",
  101. "consoleapi",
  102. "processenv",
  103. "wincon"
  104. ]
  105. },
  106. "encode_unicode": "0.3"
  107. }
  108. },
  109. "cfg(target_os = \"linux\")": {
  110. "dependencies": {
  111. "heck": "0.3"
  112. }
  113. }
  114. },
  115. "build-dependencies": {
  116. "schemars": "0.8",
  117. "serde": {
  118. "version": "1.0",
  119. "features": [
  120. "derive"
  121. ]
  122. },
  123. "serde_json": "1.0",
  124. "serde_with": "1.9"
  125. }
  126. }
  127. /***/ }),
  128. /***/ "./src/helpers/download-binary.ts":
  129. /*!****************************************!*\
  130. !*** ./src/helpers/download-binary.ts ***!
  131. \****************************************/
  132. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  133. "use strict";
  134. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  135. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  136. return new (P || (P = Promise))(function (resolve, reject) {
  137. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  138. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  139. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  140. step((generator = generator.apply(thisArg, _arguments || [])).next());
  141. });
  142. };
  143. var __generator = (this && this.__generator) || function (thisArg, body) {
  144. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  145. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  146. function verb(n) { return function (v) { return step([n, v]); }; }
  147. function step(op) {
  148. if (f) throw new TypeError("Generator is already executing.");
  149. while (_) try {
  150. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  151. if (y = 0, t) op = [op[0] & 2, t.value];
  152. switch (op[0]) {
  153. case 0: case 1: t = op; break;
  154. case 4: _.label++; return { value: op[1], done: false };
  155. case 5: _.label++; y = op[1]; op = [0]; continue;
  156. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  157. default:
  158. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  159. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  160. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  161. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  162. if (t[2]) _.ops.pop();
  163. _.trys.pop(); continue;
  164. }
  165. op = body.call(thisArg, _);
  166. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  167. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  168. }
  169. };
  170. var __importDefault = (this && this.__importDefault) || function (mod) {
  171. return (mod && mod.__esModule) ? mod : { "default": mod };
  172. };
  173. Object.defineProperty(exports, "__esModule", ({ value: true }));
  174. exports.downloadRustup = exports.downloadCli = void 0;
  175. var stream_1 = __importDefault(__webpack_require__(/*! stream */ "stream"));
  176. var util_1 = __webpack_require__(/*! util */ "util");
  177. var fs_1 = __importDefault(__webpack_require__(/*! fs */ "fs"));
  178. var got_1 = __importDefault(__webpack_require__(/*! got */ "got"));
  179. var path_1 = __importDefault(__webpack_require__(/*! path */ "path"));
  180. var pipeline = util_1.promisify(stream_1.default.pipeline);
  181. // Webpack reads the file at build-time, so this becomes a static var
  182. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
  183. var tauriCliManifest = __webpack_require__(/*! ../../../cli.rs/Cargo.toml */ "../cli.rs/Cargo.toml");
  184. var downloads = {};
  185. function downloadBinaryRelease(tag, asset, outPath) {
  186. return __awaiter(this, void 0, void 0, function () {
  187. var url, removeDownloadedCliIfNeeded;
  188. return __generator(this, function (_a) {
  189. switch (_a.label) {
  190. case 0:
  191. url = "https://github.com/tauri-apps/binary-releases/releases/download/" + tag + "/" + asset;
  192. removeDownloadedCliIfNeeded = function () {
  193. try {
  194. if (!(url in downloads)) {
  195. // eslint-disable-next-line security/detect-non-literal-fs-filename
  196. fs_1.default.unlinkSync(outPath);
  197. }
  198. }
  199. finally {
  200. process.exit();
  201. }
  202. };
  203. // on exit, we remove the `tauri-cli` file if the download didn't complete
  204. process.on('exit', removeDownloadedCliIfNeeded);
  205. process.on('SIGINT', removeDownloadedCliIfNeeded);
  206. process.on('SIGTERM', removeDownloadedCliIfNeeded);
  207. process.on('SIGHUP', removeDownloadedCliIfNeeded);
  208. process.on('SIGBREAK', removeDownloadedCliIfNeeded);
  209. // TODO: Check hash of download
  210. // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, security/detect-non-literal-fs-filename
  211. return [4 /*yield*/, pipeline(got_1.default.stream(url), fs_1.default.createWriteStream(outPath)).catch(function (e) {
  212. try {
  213. // eslint-disable-next-line security/detect-non-literal-fs-filename
  214. fs_1.default.unlinkSync(outPath);
  215. }
  216. catch (_a) { }
  217. throw e;
  218. })
  219. // eslint-disable-next-line security/detect-object-injection
  220. ];
  221. case 1:
  222. // TODO: Check hash of download
  223. // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, security/detect-non-literal-fs-filename
  224. _a.sent();
  225. // eslint-disable-next-line security/detect-object-injection
  226. downloads[url] = true;
  227. // eslint-disable-next-line security/detect-non-literal-fs-filename
  228. fs_1.default.chmodSync(outPath, 448);
  229. console.log('Download Complete');
  230. return [2 /*return*/];
  231. }
  232. });
  233. });
  234. }
  235. function downloadCli() {
  236. return __awaiter(this, void 0, void 0, function () {
  237. var version, platform, extension, outPath;
  238. return __generator(this, function (_a) {
  239. switch (_a.label) {
  240. case 0:
  241. version = tauriCliManifest.package.version;
  242. platform = process.platform;
  243. if (platform === 'win32') {
  244. platform = 'windows';
  245. }
  246. else if (platform === 'linux') {
  247. platform = 'linux';
  248. }
  249. else if (platform === 'darwin') {
  250. platform = 'macos';
  251. }
  252. else {
  253. throw Error('Unsupported platform');
  254. }
  255. extension = platform === 'windows' ? '.exe' : '';
  256. outPath = path_1.default.join(__dirname, "../../bin/tauri-cli" + extension);
  257. console.log('Downloading Rust CLI...');
  258. return [4 /*yield*/, downloadBinaryRelease("tauri-cli-v" + version, "tauri-cli_" + platform + extension, outPath)];
  259. case 1:
  260. _a.sent();
  261. return [2 /*return*/];
  262. }
  263. });
  264. });
  265. }
  266. exports.downloadCli = downloadCli;
  267. function downloadRustup() {
  268. return __awaiter(this, void 0, void 0, function () {
  269. var assetName;
  270. return __generator(this, function (_a) {
  271. switch (_a.label) {
  272. case 0:
  273. assetName = process.platform === 'win32' ? 'rustup-init.exe' : 'rustup-init.sh';
  274. console.log('Downloading Rustup...');
  275. return [4 /*yield*/, downloadBinaryRelease('rustup', assetName, path_1.default.join(__dirname, "../../bin/" + assetName))];
  276. case 1: return [2 /*return*/, _a.sent()];
  277. }
  278. });
  279. });
  280. }
  281. exports.downloadRustup = downloadRustup;
  282. /***/ }),
  283. /***/ "fs":
  284. /*!*********************!*\
  285. !*** external "fs" ***!
  286. \*********************/
  287. /***/ ((module) => {
  288. "use strict";
  289. module.exports = require("fs");;
  290. /***/ }),
  291. /***/ "got":
  292. /*!**********************!*\
  293. !*** external "got" ***!
  294. \**********************/
  295. /***/ ((module) => {
  296. "use strict";
  297. module.exports = require("got");;
  298. /***/ }),
  299. /***/ "path":
  300. /*!***********************!*\
  301. !*** external "path" ***!
  302. \***********************/
  303. /***/ ((module) => {
  304. "use strict";
  305. module.exports = require("path");;
  306. /***/ }),
  307. /***/ "stream":
  308. /*!*************************!*\
  309. !*** external "stream" ***!
  310. \*************************/
  311. /***/ ((module) => {
  312. "use strict";
  313. module.exports = require("stream");;
  314. /***/ }),
  315. /***/ "util":
  316. /*!***********************!*\
  317. !*** external "util" ***!
  318. \***********************/
  319. /***/ ((module) => {
  320. "use strict";
  321. module.exports = require("util");;
  322. /***/ })
  323. /******/ });
  324. /************************************************************************/
  325. /******/ // The module cache
  326. /******/ var __webpack_module_cache__ = {};
  327. /******/
  328. /******/ // The require function
  329. /******/ function __webpack_require__(moduleId) {
  330. /******/ // Check if module is in cache
  331. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  332. /******/ if (cachedModule !== undefined) {
  333. /******/ return cachedModule.exports;
  334. /******/ }
  335. /******/ // Create a new module (and put it into the cache)
  336. /******/ var module = __webpack_module_cache__[moduleId] = {
  337. /******/ // no module.id needed
  338. /******/ // no module.loaded needed
  339. /******/ exports: {}
  340. /******/ };
  341. /******/
  342. /******/ // Execute the module function
  343. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  344. /******/
  345. /******/ // Return the exports of the module
  346. /******/ return module.exports;
  347. /******/ }
  348. /******/
  349. /************************************************************************/
  350. /******/
  351. /******/ // startup
  352. /******/ // Load entry module and return exports
  353. /******/ // This entry module is referenced by other modules so it can't be inlined
  354. /******/ var __webpack_exports__ = __webpack_require__("./src/helpers/download-binary.ts");
  355. /******/
  356. /******/ return __webpack_exports__;
  357. /******/ })()
  358. ;
  359. });
  360. //# sourceMappingURL=download-binary.js.map