2022-01-20 02:10:16 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-08-25 09:02:22 -04:00
|
|
|
|
|
|
|
import { runCommand } from "./helpers.ts";
|
|
|
|
|
|
|
|
export interface CargoMetadata {
|
|
|
|
packages: CargoPackageMetadata[];
|
|
|
|
/** Identifiers in the `packages` array of the workspace members. */
|
|
|
|
"workspace_members": string[];
|
|
|
|
/** The absolute workspace root directory path. */
|
|
|
|
"workspace_root": string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CargoPackageMetadata {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
version: string;
|
|
|
|
dependencies: CargoDependencyMetadata[];
|
|
|
|
/** Path to Cargo.toml */
|
|
|
|
"manifest_path": string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CargoDependencyMetadata {
|
|
|
|
name: string;
|
|
|
|
/** Version requrement (ex. ^0.1.0) */
|
|
|
|
req: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getMetadata(directory: string) {
|
|
|
|
const result = await runCommand({
|
|
|
|
cwd: directory,
|
|
|
|
cmd: ["cargo", "metadata", "--format-version", "1"],
|
|
|
|
});
|
|
|
|
return JSON.parse(result!) as CargoMetadata;
|
|
|
|
}
|
|
|
|
|
2021-08-30 13:35:48 -04:00
|
|
|
export function publishCrate(directory: string) {
|
|
|
|
return runCargoSubCommand({
|
|
|
|
directory,
|
|
|
|
args: ["publish"],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function build(directory: string) {
|
|
|
|
return runCargoSubCommand({
|
|
|
|
directory,
|
|
|
|
args: ["build", "-vv"],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function check(directory: string) {
|
|
|
|
return runCargoSubCommand({
|
|
|
|
directory,
|
|
|
|
args: ["check"],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function runCargoSubCommand(params: {
|
|
|
|
args: string[];
|
|
|
|
directory: string;
|
|
|
|
}) {
|
2021-08-25 09:02:22 -04:00
|
|
|
const p = Deno.run({
|
2021-08-30 13:35:48 -04:00
|
|
|
cwd: params.directory,
|
|
|
|
cmd: ["cargo", ...params.args],
|
2021-08-25 09:02:22 -04:00
|
|
|
stderr: "inherit",
|
|
|
|
stdout: "inherit",
|
|
|
|
});
|
|
|
|
|
|
|
|
const status = await p.status();
|
|
|
|
if (!status.success) {
|
|
|
|
throw new Error("Failed");
|
|
|
|
}
|
|
|
|
}
|