piral-cli
Version:
The standard CLI for creating and building a Piral instance or a Pilet.
49 lines • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addPiralInstancePiletDefaults = void 0;
exports.addPiralInstancePilet = addPiralInstancePilet;
const path_1 = require("path");
const types_1 = require("../types");
const common_1 = require("../common");
exports.addPiralInstancePiletDefaults = {
logLevel: types_1.LogLevels.info,
app: undefined,
source: '.',
selected: false,
npmClient: undefined,
cert: undefined,
allowSelfSigned: common_1.config.allowSelfSigned,
};
async function addPiralInstancePilet(baseDir = process.cwd(), options = {}) {
const { npmClient: defaultNpmClient = exports.addPiralInstancePiletDefaults.npmClient, logLevel = exports.addPiralInstancePiletDefaults.logLevel, source = exports.addPiralInstancePiletDefaults.source, selected = exports.addPiralInstancePiletDefaults.selected, app = exports.addPiralInstancePiletDefaults.app, cert = exports.addPiralInstancePiletDefaults.cert, allowSelfSigned = exports.addPiralInstancePiletDefaults.allowSelfSigned, } = options;
(0, common_1.ensure)('baseDir', baseDir, 'string');
(0, common_1.ensure)('source', source, 'string');
const fullBase = (0, path_1.resolve)(process.cwd(), baseDir);
(0, common_1.setLogLevel)(logLevel);
(0, common_1.progress)('Reading configuration ...');
const npmClient = await (0, common_1.determineNpmClient)(fullBase, defaultNpmClient);
const allEntries = await (0, common_1.matchAnyPilet)(fullBase, [source]);
const ca = await (0, common_1.getCertificate)(cert);
const agent = (0, common_1.getAgent)({ ca, allowSelfSigned });
const tasks = allEntries.map(async (entryModule) => {
const targetDir = (0, path_1.dirname)(entryModule);
const piletJsonPath = await (0, common_1.findFile)(targetDir, common_1.piletJson);
if (piletJsonPath) {
const piletJsonDir = (0, path_1.dirname)(piletJsonPath);
const root = await (0, common_1.findPiletRoot)(piletJsonDir);
const packageName = await (0, common_1.installPiralInstance)(app, fullBase, root, npmClient, agent, selected);
const piralInfo = await (0, common_1.readPiralPackage)(root, packageName);
const isEmulator = (0, common_1.checkAppShellPackage)(piralInfo);
if (isEmulator) {
// in the emulator case we get the files (and files_once) from the contained tarballs
await (0, common_1.copyPiralFiles)(root, packageName, piralInfo, common_1.ForceOverwrite.yes, {});
}
}
else {
(0, common_1.log)('piletJsonNotAvailable_0180', targetDir);
}
});
await Promise.all(tasks);
(0, common_1.logDone)(`Added the Piral instance!`);
}
//# sourceMappingURL=add-piral-instance-pilet.js.map