cli.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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/api/cli.ts":
  129. /*!************************!*\
  130. !*** ./src/api/cli.ts ***!
  131. \************************/
  132. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  133. "use strict";
  134. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  135. // SPDX-License-Identifier: Apache-2.0
  136. // SPDX-License-Identifier: MIT
  137. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  138. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  139. return new (P || (P = Promise))(function (resolve, reject) {
  140. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  141. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  142. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  143. step((generator = generator.apply(thisArg, _arguments || [])).next());
  144. });
  145. };
  146. var __generator = (this && this.__generator) || function (thisArg, body) {
  147. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  148. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  149. function verb(n) { return function (v) { return step([n, v]); }; }
  150. function step(op) {
  151. if (f) throw new TypeError("Generator is already executing.");
  152. while (_) try {
  153. 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;
  154. if (y = 0, t) op = [op[0] & 2, t.value];
  155. switch (op[0]) {
  156. case 0: case 1: t = op; break;
  157. case 4: _.label++; return { value: op[1], done: false };
  158. case 5: _.label++; y = op[1]; op = [0]; continue;
  159. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  160. default:
  161. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  162. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  163. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  164. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  165. if (t[2]) _.ops.pop();
  166. _.trys.pop(); continue;
  167. }
  168. op = body.call(thisArg, _);
  169. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  170. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  171. }
  172. };
  173. Object.defineProperty(exports, "__esModule", ({ value: true }));
  174. exports.build = exports.dev = exports.init = void 0;
  175. var rust_cli_1 = __webpack_require__(/*! ../helpers/rust-cli */ "./src/helpers/rust-cli.ts");
  176. function toKebabCase(value) {
  177. return value
  178. .replace(/([a-z])([A-Z])/g, '$1-$2')
  179. .replace(/\s+/g, '-')
  180. .toLowerCase();
  181. }
  182. function runCliCommand(command, args) {
  183. return __awaiter(this, void 0, void 0, function () {
  184. var argsArray, _i, _a, _b, argName, argValue;
  185. return __generator(this, function (_c) {
  186. switch (_c.label) {
  187. case 0:
  188. argsArray = [];
  189. for (_i = 0, _a = Object.entries(args !== null && args !== void 0 ? args : {}); _i < _a.length; _i++) {
  190. _b = _a[_i], argName = _b[0], argValue = _b[1];
  191. if (argValue === false) {
  192. continue;
  193. }
  194. argsArray.push("--" + toKebabCase(argName));
  195. if (argValue === true) {
  196. continue;
  197. }
  198. argsArray.push(typeof argValue === 'string' ? argValue : JSON.stringify(argValue));
  199. }
  200. return [4 /*yield*/, rust_cli_1.runOnRustCli(command, argsArray)];
  201. case 1: return [2 /*return*/, _c.sent()];
  202. }
  203. });
  204. });
  205. }
  206. var init = function (args) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
  207. switch (_a.label) {
  208. case 0: return [4 /*yield*/, runCliCommand('init', args)];
  209. case 1: return [2 /*return*/, _a.sent()];
  210. }
  211. }); }); };
  212. exports.init = init;
  213. var dev = function (args) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
  214. switch (_a.label) {
  215. case 0: return [4 /*yield*/, runCliCommand('dev', args)];
  216. case 1: return [2 /*return*/, _a.sent()];
  217. }
  218. }); }); };
  219. exports.dev = dev;
  220. var build = function (args) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
  221. switch (_a.label) {
  222. case 0: return [4 /*yield*/, runCliCommand('build', args)];
  223. case 1: return [2 /*return*/, _a.sent()];
  224. }
  225. }); }); };
  226. exports.build = build;
  227. /***/ }),
  228. /***/ "./src/helpers/download-binary.ts":
  229. /*!****************************************!*\
  230. !*** ./src/helpers/download-binary.ts ***!
  231. \****************************************/
  232. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  233. "use strict";
  234. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  235. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  236. return new (P || (P = Promise))(function (resolve, reject) {
  237. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  238. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  239. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  240. step((generator = generator.apply(thisArg, _arguments || [])).next());
  241. });
  242. };
  243. var __generator = (this && this.__generator) || function (thisArg, body) {
  244. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  245. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  246. function verb(n) { return function (v) { return step([n, v]); }; }
  247. function step(op) {
  248. if (f) throw new TypeError("Generator is already executing.");
  249. while (_) try {
  250. 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;
  251. if (y = 0, t) op = [op[0] & 2, t.value];
  252. switch (op[0]) {
  253. case 0: case 1: t = op; break;
  254. case 4: _.label++; return { value: op[1], done: false };
  255. case 5: _.label++; y = op[1]; op = [0]; continue;
  256. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  257. default:
  258. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  259. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  260. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  261. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  262. if (t[2]) _.ops.pop();
  263. _.trys.pop(); continue;
  264. }
  265. op = body.call(thisArg, _);
  266. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  267. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  268. }
  269. };
  270. var __importDefault = (this && this.__importDefault) || function (mod) {
  271. return (mod && mod.__esModule) ? mod : { "default": mod };
  272. };
  273. Object.defineProperty(exports, "__esModule", ({ value: true }));
  274. exports.downloadRustup = exports.downloadCli = void 0;
  275. var stream_1 = __importDefault(__webpack_require__(/*! stream */ "stream"));
  276. var util_1 = __webpack_require__(/*! util */ "util");
  277. var fs_1 = __importDefault(__webpack_require__(/*! fs */ "fs"));
  278. var got_1 = __importDefault(__webpack_require__(/*! got */ "got"));
  279. var path_1 = __importDefault(__webpack_require__(/*! path */ "path"));
  280. var pipeline = util_1.promisify(stream_1.default.pipeline);
  281. // Webpack reads the file at build-time, so this becomes a static var
  282. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
  283. var tauriCliManifest = __webpack_require__(/*! ../../../cli.rs/Cargo.toml */ "../cli.rs/Cargo.toml");
  284. var downloads = {};
  285. function downloadBinaryRelease(tag, asset, outPath) {
  286. return __awaiter(this, void 0, void 0, function () {
  287. var url, removeDownloadedCliIfNeeded;
  288. return __generator(this, function (_a) {
  289. switch (_a.label) {
  290. case 0:
  291. url = "https://github.com/tauri-apps/binary-releases/releases/download/" + tag + "/" + asset;
  292. removeDownloadedCliIfNeeded = function () {
  293. try {
  294. if (!(url in downloads)) {
  295. // eslint-disable-next-line security/detect-non-literal-fs-filename
  296. fs_1.default.unlinkSync(outPath);
  297. }
  298. }
  299. finally {
  300. process.exit();
  301. }
  302. };
  303. // on exit, we remove the `tauri-cli` file if the download didn't complete
  304. process.on('exit', removeDownloadedCliIfNeeded);
  305. process.on('SIGINT', removeDownloadedCliIfNeeded);
  306. process.on('SIGTERM', removeDownloadedCliIfNeeded);
  307. process.on('SIGHUP', removeDownloadedCliIfNeeded);
  308. process.on('SIGBREAK', removeDownloadedCliIfNeeded);
  309. // TODO: Check hash of download
  310. // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, security/detect-non-literal-fs-filename
  311. return [4 /*yield*/, pipeline(got_1.default.stream(url), fs_1.default.createWriteStream(outPath)).catch(function (e) {
  312. try {
  313. // eslint-disable-next-line security/detect-non-literal-fs-filename
  314. fs_1.default.unlinkSync(outPath);
  315. }
  316. catch (_a) { }
  317. throw e;
  318. })
  319. // eslint-disable-next-line security/detect-object-injection
  320. ];
  321. case 1:
  322. // TODO: Check hash of download
  323. // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, security/detect-non-literal-fs-filename
  324. _a.sent();
  325. // eslint-disable-next-line security/detect-object-injection
  326. downloads[url] = true;
  327. // eslint-disable-next-line security/detect-non-literal-fs-filename
  328. fs_1.default.chmodSync(outPath, 448);
  329. console.log('Download Complete');
  330. return [2 /*return*/];
  331. }
  332. });
  333. });
  334. }
  335. function downloadCli() {
  336. return __awaiter(this, void 0, void 0, function () {
  337. var version, platform, extension, outPath;
  338. return __generator(this, function (_a) {
  339. switch (_a.label) {
  340. case 0:
  341. version = tauriCliManifest.package.version;
  342. platform = process.platform;
  343. if (platform === 'win32') {
  344. platform = 'windows';
  345. }
  346. else if (platform === 'linux') {
  347. platform = 'linux';
  348. }
  349. else if (platform === 'darwin') {
  350. platform = 'macos';
  351. }
  352. else {
  353. throw Error('Unsupported platform');
  354. }
  355. extension = platform === 'windows' ? '.exe' : '';
  356. outPath = path_1.default.join(__dirname, "../../bin/tauri-cli" + extension);
  357. console.log('Downloading Rust CLI...');
  358. return [4 /*yield*/, downloadBinaryRelease("tauri-cli-v" + version, "tauri-cli_" + platform + extension, outPath)];
  359. case 1:
  360. _a.sent();
  361. return [2 /*return*/];
  362. }
  363. });
  364. });
  365. }
  366. exports.downloadCli = downloadCli;
  367. function downloadRustup() {
  368. return __awaiter(this, void 0, void 0, function () {
  369. var assetName;
  370. return __generator(this, function (_a) {
  371. switch (_a.label) {
  372. case 0:
  373. assetName = process.platform === 'win32' ? 'rustup-init.exe' : 'rustup-init.sh';
  374. console.log('Downloading Rustup...');
  375. return [4 /*yield*/, downloadBinaryRelease('rustup', assetName, path_1.default.join(__dirname, "../../bin/" + assetName))];
  376. case 1: return [2 /*return*/, _a.sent()];
  377. }
  378. });
  379. });
  380. }
  381. exports.downloadRustup = downloadRustup;
  382. /***/ }),
  383. /***/ "./src/helpers/logger.ts":
  384. /*!*******************************!*\
  385. !*** ./src/helpers/logger.ts ***!
  386. \*******************************/
  387. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  388. "use strict";
  389. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  390. // SPDX-License-Identifier: Apache-2.0
  391. // SPDX-License-Identifier: MIT
  392. var __importDefault = (this && this.__importDefault) || function (mod) {
  393. return (mod && mod.__esModule) ? mod : { "default": mod };
  394. };
  395. Object.defineProperty(exports, "__esModule", ({ value: true }));
  396. var chalk_1 = __importDefault(__webpack_require__(/*! chalk */ "chalk"));
  397. var ms_1 = __importDefault(__webpack_require__(/*! ms */ "ms"));
  398. var prevTime;
  399. exports.default = (function (banner, color) {
  400. if (color === void 0) { color = chalk_1.default.green; }
  401. return function (msg) {
  402. var curr = +new Date();
  403. var diff = curr - (prevTime || curr);
  404. prevTime = curr;
  405. if (msg) {
  406. console.log(
  407. // TODO: proper typings for color and banner
  408. // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call
  409. " " + color(String(banner)) + " " + msg + " " + chalk_1.default.green("+" + ms_1.default(diff)));
  410. }
  411. else {
  412. console.log();
  413. }
  414. };
  415. });
  416. /***/ }),
  417. /***/ "./src/helpers/rust-cli.ts":
  418. /*!*********************************!*\
  419. !*** ./src/helpers/rust-cli.ts ***!
  420. \*********************************/
  421. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  422. "use strict";
  423. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  424. // SPDX-License-Identifier: Apache-2.0
  425. // SPDX-License-Identifier: MIT
  426. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  427. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  428. return new (P || (P = Promise))(function (resolve, reject) {
  429. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  430. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  431. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  432. step((generator = generator.apply(thisArg, _arguments || [])).next());
  433. });
  434. };
  435. var __generator = (this && this.__generator) || function (thisArg, body) {
  436. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  437. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  438. function verb(n) { return function (v) { return step([n, v]); }; }
  439. function step(op) {
  440. if (f) throw new TypeError("Generator is already executing.");
  441. while (_) try {
  442. 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;
  443. if (y = 0, t) op = [op[0] & 2, t.value];
  444. switch (op[0]) {
  445. case 0: case 1: t = op; break;
  446. case 4: _.label++; return { value: op[1], done: false };
  447. case 5: _.label++; y = op[1]; op = [0]; continue;
  448. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  449. default:
  450. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  451. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  452. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  453. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  454. if (t[2]) _.ops.pop();
  455. _.trys.pop(); continue;
  456. }
  457. op = body.call(thisArg, _);
  458. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  459. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  460. }
  461. };
  462. var __spreadArray = (this && this.__spreadArray) || function (to, from) {
  463. for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
  464. to[j] = from[i];
  465. return to;
  466. };
  467. Object.defineProperty(exports, "__esModule", ({ value: true }));
  468. exports.runOnRustCli = void 0;
  469. var fs_1 = __webpack_require__(/*! fs */ "fs");
  470. var path_1 = __webpack_require__(/*! path */ "path");
  471. var spawn_1 = __webpack_require__(/*! ./spawn */ "./src/helpers/spawn.ts");
  472. var download_binary_1 = __webpack_require__(/*! ./download-binary */ "./src/helpers/download-binary.ts");
  473. var currentTauriCliVersion = function () {
  474. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
  475. var tauriCliManifest =
  476. // eslint-disable-next-line @typescript-eslint/no-var-requires
  477. __webpack_require__(/*! ../../../cli.rs/Cargo.toml */ "../cli.rs/Cargo.toml");
  478. return tauriCliManifest.package.version;
  479. };
  480. function runOnRustCli(command, args) {
  481. return __awaiter(this, void 0, void 0, function () {
  482. var targetPath, targetCliPath, resolveCb, rejectCb, pid, promise, onClose, cliPath, localCliPath;
  483. return __generator(this, function (_a) {
  484. switch (_a.label) {
  485. case 0:
  486. targetPath = path_1.resolve(__dirname, '../..');
  487. targetCliPath = path_1.join(targetPath, 'bin/tauri-cli' + (process.platform === 'win32' ? '.exe' : ''));
  488. promise = new Promise(function (resolve, reject) {
  489. resolveCb = resolve;
  490. rejectCb = function () { return reject(new Error()); };
  491. });
  492. onClose = function (code, pid) {
  493. if (code === 0) {
  494. resolveCb();
  495. }
  496. else {
  497. rejectCb();
  498. }
  499. };
  500. if (!fs_1.existsSync(targetCliPath)) return [3 /*break*/, 1];
  501. pid = spawn_1.spawn(targetCliPath, __spreadArray(['tauri', command], args), process.cwd(), onClose);
  502. return [3 /*break*/, 4];
  503. case 1:
  504. if (true) return [3 /*break*/, 3];
  505. return [4 /*yield*/, download_binary_1.downloadCli()];
  506. case 2:
  507. _a.sent();
  508. pid = spawn_1.spawn(targetCliPath, __spreadArray(['tauri', command], args), process.cwd(), onClose);
  509. return [3 /*break*/, 4];
  510. case 3:
  511. if (fs_1.existsSync(path_1.resolve(targetPath, '../bundler'))) {
  512. cliPath = path_1.resolve(targetPath, '../cli.rs');
  513. spawn_1.spawnSync('cargo', ['build', '--release'], cliPath);
  514. localCliPath = path_1.resolve(targetPath, '../cli.rs/target/release/cargo-tauri');
  515. pid = spawn_1.spawn(localCliPath, __spreadArray(['tauri', command], args), process.cwd(), onClose);
  516. }
  517. else {
  518. spawn_1.spawnSync('cargo', [
  519. 'install',
  520. '--root',
  521. targetPath,
  522. 'tauri-cli',
  523. '--version',
  524. currentTauriCliVersion()
  525. ], process.cwd());
  526. pid = spawn_1.spawn(targetCliPath, __spreadArray(['tauri', command], args), process.cwd(), onClose);
  527. }
  528. _a.label = 4;
  529. case 4: return [2 /*return*/, { pid: pid, promise: promise }];
  530. }
  531. });
  532. });
  533. }
  534. exports.runOnRustCli = runOnRustCli;
  535. /***/ }),
  536. /***/ "./src/helpers/spawn.ts":
  537. /*!******************************!*\
  538. !*** ./src/helpers/spawn.ts ***!
  539. \******************************/
  540. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  541. "use strict";
  542. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  543. // SPDX-License-Identifier: Apache-2.0
  544. // SPDX-License-Identifier: MIT
  545. var __importDefault = (this && this.__importDefault) || function (mod) {
  546. return (mod && mod.__esModule) ? mod : { "default": mod };
  547. };
  548. Object.defineProperty(exports, "__esModule", ({ value: true }));
  549. exports.spawnSync = exports.spawn = void 0;
  550. var cross_spawn_1 = __importDefault(__webpack_require__(/*! cross-spawn */ "cross-spawn"));
  551. var logger_1 = __importDefault(__webpack_require__(/*! ./logger */ "./src/helpers/logger.ts"));
  552. var chalk_1 = __importDefault(__webpack_require__(/*! chalk */ "chalk"));
  553. var log = logger_1.default('app:spawn');
  554. var warn = logger_1.default('app:spawn', chalk_1.default.red);
  555. /*
  556. Returns pid, takes onClose
  557. */
  558. var spawn = function (cmd, params, cwd, onClose) {
  559. var _a;
  560. log("Running \"" + cmd + " " + params.join(' ') + "\"");
  561. log();
  562. // TODO: move to execa?
  563. var runner = cross_spawn_1.default(cmd, params, {
  564. stdio: 'inherit',
  565. cwd: cwd,
  566. env: process.env
  567. });
  568. runner.on('close', function (code) {
  569. var _a;
  570. log();
  571. if (code) {
  572. // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
  573. log("Command \"" + cmd + "\" failed with exit code: " + code);
  574. }
  575. // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
  576. onClose && onClose(code !== null && code !== void 0 ? code : 0, (_a = runner.pid) !== null && _a !== void 0 ? _a : 0);
  577. });
  578. return (_a = runner.pid) !== null && _a !== void 0 ? _a : 0;
  579. };
  580. exports.spawn = spawn;
  581. /*
  582. Returns nothing, takes onFail
  583. */
  584. var spawnSync = function (cmd, params, cwd, onFail) {
  585. log("[sync] Running \"" + cmd + " " + params.join(' ') + "\"");
  586. log();
  587. var runner = cross_spawn_1.default.sync(cmd, params, {
  588. stdio: 'inherit',
  589. cwd: cwd
  590. });
  591. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
  592. if (runner.status || runner.error) {
  593. warn();
  594. // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
  595. warn("\u26A0\uFE0F Command \"" + cmd + "\" failed with exit code: " + runner.status);
  596. if (runner.status === null) {
  597. warn("\u26A0\uFE0F Please globally install \"" + cmd + "\"");
  598. }
  599. // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
  600. onFail && onFail();
  601. process.exit(1);
  602. }
  603. };
  604. exports.spawnSync = spawnSync;
  605. /***/ }),
  606. /***/ "chalk":
  607. /*!************************!*\
  608. !*** external "chalk" ***!
  609. \************************/
  610. /***/ ((module) => {
  611. "use strict";
  612. module.exports = require("chalk");;
  613. /***/ }),
  614. /***/ "cross-spawn":
  615. /*!******************************!*\
  616. !*** external "cross-spawn" ***!
  617. \******************************/
  618. /***/ ((module) => {
  619. "use strict";
  620. module.exports = require("cross-spawn");;
  621. /***/ }),
  622. /***/ "fs":
  623. /*!*********************!*\
  624. !*** external "fs" ***!
  625. \*********************/
  626. /***/ ((module) => {
  627. "use strict";
  628. module.exports = require("fs");;
  629. /***/ }),
  630. /***/ "got":
  631. /*!**********************!*\
  632. !*** external "got" ***!
  633. \**********************/
  634. /***/ ((module) => {
  635. "use strict";
  636. module.exports = require("got");;
  637. /***/ }),
  638. /***/ "ms":
  639. /*!*********************!*\
  640. !*** external "ms" ***!
  641. \*********************/
  642. /***/ ((module) => {
  643. "use strict";
  644. module.exports = require("ms");;
  645. /***/ }),
  646. /***/ "path":
  647. /*!***********************!*\
  648. !*** external "path" ***!
  649. \***********************/
  650. /***/ ((module) => {
  651. "use strict";
  652. module.exports = require("path");;
  653. /***/ }),
  654. /***/ "stream":
  655. /*!*************************!*\
  656. !*** external "stream" ***!
  657. \*************************/
  658. /***/ ((module) => {
  659. "use strict";
  660. module.exports = require("stream");;
  661. /***/ }),
  662. /***/ "util":
  663. /*!***********************!*\
  664. !*** external "util" ***!
  665. \***********************/
  666. /***/ ((module) => {
  667. "use strict";
  668. module.exports = require("util");;
  669. /***/ })
  670. /******/ });
  671. /************************************************************************/
  672. /******/ // The module cache
  673. /******/ var __webpack_module_cache__ = {};
  674. /******/
  675. /******/ // The require function
  676. /******/ function __webpack_require__(moduleId) {
  677. /******/ // Check if module is in cache
  678. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  679. /******/ if (cachedModule !== undefined) {
  680. /******/ return cachedModule.exports;
  681. /******/ }
  682. /******/ // Create a new module (and put it into the cache)
  683. /******/ var module = __webpack_module_cache__[moduleId] = {
  684. /******/ // no module.id needed
  685. /******/ // no module.loaded needed
  686. /******/ exports: {}
  687. /******/ };
  688. /******/
  689. /******/ // Execute the module function
  690. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  691. /******/
  692. /******/ // Return the exports of the module
  693. /******/ return module.exports;
  694. /******/ }
  695. /******/
  696. /************************************************************************/
  697. /******/
  698. /******/ // startup
  699. /******/ // Load entry module and return exports
  700. /******/ // This entry module is referenced by other modules so it can't be inlined
  701. /******/ var __webpack_exports__ = __webpack_require__("./src/api/cli.ts");
  702. /******/
  703. /******/ return __webpack_exports__;
  704. /******/ })()
  705. ;
  706. });
  707. //# sourceMappingURL=cli.js.map