genezio
Version:
Command line utility to interact with Genezio infrastructure.
53 lines (52 loc) • 1.97 kB
JavaScript
import { $ } from "execa";
import { detectPipCommand } from "../utils/detectPythonCommand.js";
export default class PipPackageManager {
constructor() {
this.command = "pip";
this.pythonCommand = "python"; // Default Python command
this.init();
}
async init() {
// Detects either pip or pip3 and sets it as the command
this.command = (await detectPipCommand()) ?? this.command;
}
async install(packages, cwd, args) {
await $({ cwd }) `${this.command} install ${packages.join(" ")} ${args?.join(" ") ?? ""}`;
}
async cleanInstall(cwd, args) {
await $({ cwd }) `${this.command} install ${args?.join(" ") ?? ""}`;
}
installSync(packages = [], cwd) {
$({ cwd }).sync `${this.command} install ${packages.join(" ")}`;
}
async link(packages = [], cwd) {
await $({ cwd }) `${this.command} install -e ${packages.join(" ")}`;
}
// TODO Implement publish when we support this functionality
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async publish(cwd) {
return;
}
// TODO Implement addScopedRegistry and removeScopedRegistry when we support this functionality
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async addScopedRegistry(url, authToken) {
return;
}
async removeScopedRegistry() {
return;
}
async getVersion() {
if (this.version !== undefined) {
return this.version;
}
const { stdout } = await $ `${this.command} --version`;
this.version = stdout.split(" ")[1].trim();
return this.version;
}
async pack(cwd, destination) {
// Uses the detected Python command (either `python` or `python3`)
await $({ cwd }) `${this.pythonCommand} setup.py sdist --dist-dir ${destination}`;
const { stdout } = await $({ cwd }) `ls ${destination}`;
return stdout.trim();
}
}