|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 4 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 5 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 6 | + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } |
| 7 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 8 | + }); |
| 9 | +}; |
| 10 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 11 | + if (mod && mod.__esModule) return mod; |
| 12 | + var result = {}; |
| 13 | + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
| 14 | + result["default"] = mod; |
| 15 | + return result; |
| 16 | +}; |
| 17 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 18 | +const child = __importStar(require("child_process")); |
| 19 | +const path = __importStar(require("path")); |
| 20 | +const tc = __importStar(require("@actions/tool-cache")); |
| 21 | +const core = __importStar(require("@actions/core")); |
| 22 | +/** |
| 23 | + * Install Cordova Cli |
| 24 | + * |
| 25 | + * https://www.npmjs.com/package/cordova |
| 26 | + * |
| 27 | + * @param version |
| 28 | + */ |
| 29 | +function installCordova(version) { |
| 30 | + return __awaiter(this, void 0, void 0, function* () { |
| 31 | + yield installNpmPkg('cordova', version); |
| 32 | + // install cordova-res |
| 33 | + // https://github.com/ionic-team/cordova-res |
| 34 | + // await installNpmPkg('cordova-res'); |
| 35 | + }); |
| 36 | +} |
| 37 | +exports.installCordova = installCordova; |
| 38 | +/** |
| 39 | + * Install Ionic Cli |
| 40 | + * |
| 41 | + * https://www.npmjs.com/package/ionic |
| 42 | + */ |
| 43 | +function installIonic(version) { |
| 44 | + return __awaiter(this, void 0, void 0, function* () { |
| 45 | + yield installNpmPkg('ionic', version); |
| 46 | + }); |
| 47 | +} |
| 48 | +exports.installIonic = installIonic; |
| 49 | +/** |
| 50 | + * Install Java |
| 51 | + * |
| 52 | + */ |
| 53 | +function installJava() { |
| 54 | + return __awaiter(this, void 0, void 0, function* () { |
| 55 | + if (process.platform === 'linux') { |
| 56 | + yield exec2(path.join(__dirname, 'install-openjdk-8')); |
| 57 | + } |
| 58 | + }); |
| 59 | +} |
| 60 | +exports.installJava = installJava; |
| 61 | +/** |
| 62 | + * Install CocoaPods |
| 63 | + * |
| 64 | + */ |
| 65 | +function installPods() { |
| 66 | + return __awaiter(this, void 0, void 0, function* () { |
| 67 | + if (process.platform === 'darwin') { |
| 68 | + yield exec2(`sudo gem install cocoapods`); |
| 69 | + } |
| 70 | + }); |
| 71 | +} |
| 72 | +exports.installPods = installPods; |
| 73 | +/** |
| 74 | + * Install NPM Package |
| 75 | + * |
| 76 | + * @param pkg : name of package |
| 77 | + * @param version : version |
| 78 | + */ |
| 79 | +function installNpmPkg(pkg, version) { |
| 80 | + return __awaiter(this, void 0, void 0, function* () { |
| 81 | + // attach cached package |
| 82 | + if (version) { |
| 83 | + const packageDir = tc.find(pkg, version); |
| 84 | + if (packageDir) { |
| 85 | + core.addPath(packageDir); |
| 86 | + return; |
| 87 | + } |
| 88 | + } |
| 89 | + // install npm package |
| 90 | + yield exec2(`sudo npm install -g ${pkg}${version ? '@' + version : ''}`); |
| 91 | + let installedPath = yield exec2(`echo $(npm root -g)/${pkg}`); |
| 92 | + if (!installedPath) { |
| 93 | + return; |
| 94 | + } |
| 95 | + // remove linebreak in the command |
| 96 | + installedPath = installedPath.replace(/(\r\n|\n|\r)/gm, ""); |
| 97 | + if (!version) { |
| 98 | + // installed version |
| 99 | + version = (yield exec2(`node -p "require('${installedPath}/package.json').version"`)); |
| 100 | + // cache installed package |
| 101 | + const cachedPath = yield tc.cacheDir(installedPath, pkg, version); |
| 102 | + core.addPath(cachedPath); |
| 103 | + } |
| 104 | + }); |
| 105 | +} |
| 106 | +exports.installNpmPkg = installNpmPkg; |
| 107 | +function exec2(command) { |
| 108 | + return __awaiter(this, void 0, void 0, function* () { |
| 109 | + return new Promise((resolve, reject) => { |
| 110 | + child.exec(command, (err, stdout, stderr) => { |
| 111 | + if (stderr) { |
| 112 | + resolve(); |
| 113 | + } |
| 114 | + if (err) { |
| 115 | + console.log(err); |
| 116 | + reject(err); |
| 117 | + } |
| 118 | + resolve(stdout); |
| 119 | + }); |
| 120 | + }); |
| 121 | + }); |
| 122 | +} |
0 commit comments