Skip to content

Commit

Permalink
rename helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 19, 2024
1 parent 11947d3 commit 06b17bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
21 changes: 2 additions & 19 deletions scripts/helpers/utils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function partitionArguments(
: [args, []];
}

export function partitionArgumentsV2(
export function partitionArgumentsWithDefaultArgs(
args: string[],
delimiter: string,
defaultArgs?: string[],
Expand All @@ -144,24 +144,7 @@ export async function getInstalledSolanaVersion(): Promise<string | undefined> {
}
}

export function parseCliArguments(): { manifestPath: string; args: string[] } {
// Command-line arguments.
const args = cliArguments();
// Extract the relative crate directory from the command-line arguments. This
// is the only required argument.
const relativePath = args.shift();

if (!relativePath) {
throw new Error('Missing relative manifest path');
}

return {
manifestPath: path.join(workingDirectory, relativePath, 'Cargo.toml'),
args,
};
}

export function parseCliArgumentsV2(): { command: string, libraryPath: string; args: string[] } {
export function parseCliArguments(): { command: string, libraryPath: string; args: string[] } {
const command = process.argv[2];
const args = process.argv.slice(3);

Expand Down
8 changes: 4 additions & 4 deletions scripts/js.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import 'zx/globals';
import {
parseCliArgumentsV2,
partitionArgumentsV2,
parseCliArguments,
partitionArgumentsWithDefaultArgs,
} from './helpers/utils.mts';

enum Command {
Expand All @@ -15,13 +15,13 @@ enum Command {
Publish = 'publish',
}

const { command, libraryPath, args } = parseCliArgumentsV2();
const { command, libraryPath, args } = parseCliArguments();

async function pnpm(
command: string,
build = false,
) {
const [pnpmArgs, commandArgs] = partitionArgumentsV2(args, '--');
const [pnpmArgs, commandArgs] = partitionArgumentsWithDefaultArgs(args, '--');
cd(libraryPath);
await $`pnpm install`;
if (build) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/rust.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'zx/globals';
import {
getCargo,
getToolchainArgument,
parseCliArgumentsV2,
partitionArgumentsV2,
parseCliArguments,
partitionArgumentsWithDefaultArgs,
popArgument,
workingDirectory,
} from './helpers/utils.mts';
Expand All @@ -23,7 +23,7 @@ enum Command {
Publish = 'publish',
}

const { command, libraryPath, args } = parseCliArgumentsV2();
const { command, libraryPath, args } = parseCliArguments();
const manifestPath = path.join(libraryPath, 'Cargo.toml');

async function cargo(
Expand All @@ -32,7 +32,7 @@ async function cargo(
defaultArgs?: string[],
variables?: [string, string][],
) {
const [cargoArgs, commandArgs] = partitionArgumentsV2(args, '--', defaultArgs);
const [cargoArgs, commandArgs] = partitionArgumentsWithDefaultArgs(args, '--', defaultArgs);
variables?.forEach(([k, v]) => $.env[k] = v);
await $`cargo ${toolchain} ${command} --manifest-path ${manifestPath} ${cargoArgs} -- ${commandArgs}`;
}
Expand Down

0 comments on commit 06b17bc

Please sign in to comment.