1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const path_1 = require("path");
|
7 | const node_fetch_1 = __importDefault(require("node-fetch"));
|
8 | const execa_1 = __importDefault(require("execa"));
|
9 | const fs_1 = require("fs");
|
10 | const build_utils_1 = require("@now/build-utils");
|
11 |
|
12 |
|
13 | const url = 'https://portableruby.s3.amazonaws.com/ruby-2.5.3.zip';
|
14 |
|
15 | async function downloadPortableRuby(path) {
|
16 | console.log('downloading "ruby-2.5.3.zip"...');
|
17 | const res = await node_fetch_1.default(url);
|
18 | if (!res.ok || res.status !== 200) {
|
19 | throw new Error(`Could not download "ruby-2.5.3.zip" from "${url}"`);
|
20 | }
|
21 | const dir = await build_utils_1.getWriteableDirectory();
|
22 | const filePath = path_1.join(dir, 'ruby-2.5.3.zip');
|
23 | const writeStream = fs_1.createWriteStream(filePath);
|
24 | await new Promise((resolve, reject) => {
|
25 | res.body
|
26 | .on('error', reject)
|
27 | .pipe(writeStream)
|
28 | .on('finish', resolve);
|
29 | });
|
30 | try {
|
31 | await execa_1.default('unzip', ['-q', '-d', path, filePath], { stdio: 'inherit' });
|
32 | }
|
33 | catch (err) {
|
34 | console.log('could not unzip ruby-2.5.3.zip');
|
35 | throw err;
|
36 | }
|
37 | return {
|
38 | rubyPath: path_1.join(path, 'bin', 'ruby'),
|
39 | gemPath: path_1.join(path, 'bin', 'gem'),
|
40 | };
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 | async function downloadAndInstallBundler() {
|
46 | const { GEM_HOME } = process.env;
|
47 | if (!GEM_HOME) {
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | throw new Error('Could not install "bundler": "GEM_HOME" env var is not set');
|
53 | }
|
54 | console.log('installing ruby...');
|
55 | const { rubyPath, gemPath } = await downloadPortableRuby(GEM_HOME);
|
56 | console.log('installing bundler...');
|
57 | await execa_1.default(gemPath, ['install', 'bundler', '--no-document'], { stdio: 'inherit' });
|
58 | return {
|
59 | rubyPath,
|
60 | gemPath,
|
61 | bundlerPath: path_1.join(GEM_HOME, 'bin', 'bundler'),
|
62 | };
|
63 | }
|
64 | exports.downloadAndInstallBundler = downloadAndInstallBundler;
|