UNPKG

piral-cli

Version:

The standard CLI for creating and building a Piral instance or a Pilet.

83 lines 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.installDependencies = installDependencies; exports.uninstallPackage = uninstallPackage; exports.installPackage = installPackage; exports.detectClient = detectClient; exports.initProject = initProject; exports.isProject = isProject; exports.listProjects = listProjects; const path_1 = require("path"); const log_1 = require("../common/log"); const io_1 = require("../common/io"); const scripts_1 = require("../common/scripts"); const MemoryStream_1 = require("../common/MemoryStream"); // Helpers: function runBunProcess(args, target, output) { (0, log_1.log)('generalDebug_0003', 'Starting the Bun process ...'); const cwd = (0, path_1.resolve)(process.cwd(), target); return (0, scripts_1.runCommand)('bun', args, cwd, output); } function convert(flags) { return flags.map((flag) => { switch (flag) { case '--save-exact': return '--exact'; case '--save-dev': return '--dev'; case '--no-save': // unfortunately no (https://github.com/yarnpkg/yarn/issues/1743) return ''; default: return flag; } }); } // Client interface functions: async function installDependencies(target = '.', ...flags) { const ms = new MemoryStream_1.MemoryStream(); await runBunProcess(['install', ...convert(flags)], target, ms); (0, log_1.log)('generalDebug_0003', `Bun install dependencies result: ${ms.value}`); return ms.value; } async function uninstallPackage(packageRef, target = '.', ...flags) { const ms = new MemoryStream_1.MemoryStream(); await runBunProcess(['remove', packageRef, ...convert(flags)], target, ms); (0, log_1.log)('generalDebug_0003', `Bun remove package result: ${ms.value}`); return ms.value; } async function installPackage(packageRef, target = '.', ...flags) { const ms = new MemoryStream_1.MemoryStream(); await runBunProcess(['add', packageRef, ...convert(flags)], target, ms); (0, log_1.log)('generalDebug_0003', `Bun add package result: ${ms.value}`); return ms.value; } async function detectClient(root, stopDir = (0, path_1.resolve)(root, '/')) { return !!(await (0, io_1.findFile)(root, 'bun.lockb', stopDir)); } async function initProject(projectName, target) { } async function isProject(root, packageRef) { const details = await listProjects(root); if (typeof details === 'object') { // TODO this won't work right now return typeof details?.[packageRef]?.location === 'string'; } return false; } // Functions to exclusively use from Bun client: async function listProjects(target) { const ms = new MemoryStream_1.MemoryStream(); try { await runBunProcess(['pm', 'ls', '--all'], target, ms); } catch (e) { (0, log_1.log)('generalDebug_0003', `Bun workspaces error: ${e}`); return {}; } (0, log_1.log)('generalDebug_0003', `Bun workspaces result: ${ms.value}`); return ms.value .split('\n') .filter((m) => m.startsWith('├──')) .map((m) => m.replace('├── ', '')); } //# sourceMappingURL=bun.js.map