@lamantin/fastpush
Version:
Typed fastlane frontend for pushing builds to store
70 lines • 3.37 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fastlane = void 0;
const child_process_1 = __importDefault(require("child_process"));
const jetpack = require("fs-jetpack");
const FastlaneError_1 = require("./FastlaneError");
const util_1 = require("util");
function fastlane(platformDirectory, task, debug = false) {
return __awaiter(this, void 0, void 0, function* () {
const fastfilePath = platformDirectory + '/fastlane/Fastfile';
const contextFilePath = jetpack
.cwd(__dirname)
.cwd('../../assets')
.path('Context.rb');
const fastfileOriginal = jetpack
.read(fastfilePath)
.split('\n')
.filter(it => !it.includes('Context.rb'))
.join('\n');
const importLine = `import '${contextFilePath}'`;
const fastfileModifyed = `${importLine}\n${fastfileOriginal}`;
jetpack.write(fastfilePath, fastfileModifyed);
function revertChanges() {
try {
jetpack.write(fastfilePath, fastfileOriginal);
}
catch (e) {
console.warn('Unable revert changes', e);
}
}
// shell.exec(`bundle install`)
// TODO: validate user input for security policy
// shelljs not supported interactive input/output so we should use child_process
// child_process.execSync('cd ' + jetpack.cwd())
try {
const command = `bundle exec fastlane ${task}`.trim();
if (debug) {
console.log('Execute fastlane in directory:', platformDirectory, `with command:\n${command}\n`);
}
const exec = util_1.promisify(child_process_1.default.exec);
const promise = exec(`cd ${platformDirectory} && ${command}`.trim(), { maxBuffer: Number.POSITIVE_INFINITY });
promise.child.stdout.pipe(process.stdout);
promise.child.stderr.pipe(process.stderr);
promise.child.stdin.pipe(process.stdin);
promise.child.on('exit', revertChanges);
promise.child.on('disconnect', revertChanges);
promise.child.on('uncaughtException', revertChanges);
promise.child.on('unhandledRejection', revertChanges);
yield promise;
}
catch (e) {
revertChanges();
throw new FastlaneError_1.FastlaneError(e.message, e.status || e.code);
}
});
}
exports.fastlane = fastlane;
//# sourceMappingURL=fastlane.js.map