Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
"validator:start": "tsx ./scripts/helpers/start-validator.mts",
"validator:restart": "pnpm validator:start --restart",
"validator:stop": "tsx ./scripts/helpers/stop-validator.mts",
"js:format": "tsx ./scripts/js/format.mts",
"js:lint": "tsx ./scripts/js/lint.mts",
"js:publish": "tsx ./scripts/js/publish.mts",
"js:test": "tsx ./scripts/js/test.mts",
"rust:format": "tsx ./scripts/rust/format.mts clients/rust",
"rust:lint": "tsx ./scripts/rust/lint.mts clients/rust",
"rust:lint:clippy": "tsx ./scripts/rust/lint-clippy.mts clients/rust",
"rust:lint:docs": "tsx ./scripts/rust/lint-docs.mts clients/rust",
"rust:lint:features": "tsx ./scripts/rust/lint-features.mts clients/rust",
"rust:publish": "tsx ./scripts/rust/publish.mts clients/rust",
"rust:test": "tsx ./scripts/rust/test.mts clients/rust",
"interface:format": "tsx ./scripts/rust/format.mts interface",
"interface:lint": "tsx ./scripts/rust/lint.mts interface",
"interface:lint:clippy": "tsx ./scripts/rust/lint-clippy.mts interface",
"interface:lint:docs": "tsx ./scripts/rust/lint-docs.mts interface",
"interface:lint:features": "tsx ./scripts/rust/lint-features.mts interface",
"interface:publish": "tsx ./scripts/rust/publish.mts interface",
"interface:test": "tsx ./scripts/rust/test.mts interface",
"interface:wasm": "tsx ./scripts/rust/wasm.mts interface",
"js:format": "tsx ./scripts/js.mts format clients/js",
"js:lint": "tsx ./scripts/js.mts lint clients/js",
"js:publish": "tsx ./scripts/js.mts publish clients/js",
"js:test": "tsx ./scripts/js.mts test clients/js",
"rust:format": "tsx ./scripts/rust.mts format clients/rust",
"rust:lint": "tsx ./scripts/rust.mts lint clients/rust",
"rust:lint:clippy": "tsx ./scripts/rust.mts lint-clippy clients/rust",
"rust:lint:docs": "tsx ./scripts/rust.mts lint-docs clients/rust",
"rust:lint:features": "tsx ./scripts/rust.mts lint-features clients/rust",
"rust:publish": "tsx ./scripts/rust.mts publish clients/rust",
"rust:test": "tsx ./scripts/rust.mts test clients/rust",
"interface:format": "tsx ./scripts/rust.mts format interface",
"interface:lint": "tsx ./scripts/rust.mts lint interface",
"interface:lint:clippy": "tsx ./scripts/rust.mts lint-clippy interface",
"interface:lint:docs": "tsx ./scripts/rust.mts lint-docs interface",
"interface:lint:features": "tsx ./scripts/rust.mts lint-features interface",
"interface:publish": "tsx ./scripts/rust.mts publish interface",
"interface:test": "tsx ./scripts/rust.mts test interface",
"interface:wasm": "tsx ./scripts/rust.mts wasm interface",
"template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts"
},
"devDependencies": {
Expand Down
26 changes: 22 additions & 4 deletions scripts/helpers/utils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ export function partitionArguments(
: [args, []];
}

export function partitionArgumentsWithDefaultArgs(
args: string[],
delimiter: string,
defaultArgs?: string[],
): [string[], string[]] {
const [providedCargoArgs, providedCommandArgs] = partitionArguments(args, delimiter);
if (defaultArgs) {
const [defaultCargoArgs, defaultCommandArgs] = partitionArguments(defaultArgs, delimiter);
return [
[...defaultCargoArgs, ...providedCargoArgs],
[...defaultCommandArgs, ...providedCommandArgs],
];
}
return [providedCargoArgs, providedCommandArgs];
}

export async function getInstalledSolanaVersion(): Promise<string | undefined> {
try {
const { stdout } = await $`solana --version`.quiet();
Expand All @@ -128,9 +144,10 @@ export async function getInstalledSolanaVersion(): Promise<string | undefined> {
}
}

export function parseCliArguments(): { manifestPath: string; args: string[] } {
// Command-line arguments.
const args = cliArguments();
export function parseCliArguments(): { command: string, libraryPath: string; args: string[] } {
const command = process.argv[2];
const args = process.argv.slice(3);

// Extract the relative crate directory from the command-line arguments. This
// is the only required argument.
const relativePath = args.shift();
Expand All @@ -140,7 +157,8 @@ export function parseCliArguments(): { manifestPath: string; args: string[] } {
}

return {
manifestPath: path.join(workingDirectory, relativePath, 'Cargo.toml'),
command,
libraryPath: path.join(workingDirectory, relativePath),
args,
};
}
99 changes: 99 additions & 0 deletions scripts/js.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env zx

// Script for working with JavaScript projects.

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

enum Command {
Format = 'format',
Lint = 'lint',
Test = 'test',
Publish = 'publish',
}

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

async function pnpm(
command: string,
build = false,
) {
const [pnpmArgs, commandArgs] = partitionArgumentsWithDefaultArgs(args, '--');
cd(libraryPath);
await $`pnpm install`;
if (build) {
await $`pnpm build`;
}
await $`pnpm ${command} ${pnpmArgs} -- ${commandArgs}`;
}

async function format() {
return pnpm('format');
}

async function lint() {
return pnpm('lint');
}

async function test() {
// Start the local validator, or restart it if it is already running.
await $`pnpm validator:restart`;

// Build the client and run the tests.
return pnpm('test', true);
}

async function publish() {
const [level, tag = 'latest'] = args;
if (!level) {
throw new Error('A version level — e.g. "path" — must be provided.');
}

// Go to the directory and install the dependencies.
cd(libraryPath);
await $`pnpm install`;

// Update the version.
const versionArgs = [
'--no-git-tag-version',
...(level.startsWith('pre') ? [`--preid ${tag}`] : []),
];
let { stdout } = await $`pnpm version ${level} ${versionArgs}`;
const newVersion = stdout.slice(1).trim();

// Expose the new version to CI if needed.
if (process.env.CI) {
await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`;
}

// Publish the package.
// This will also build the package before publishing (see prepublishOnly script).
await $`pnpm publish --no-git-checks --tag ${tag}`;

// Commit the new version.
await $`git commit -am "Publish JS client v${newVersion}"`;

// Tag the new version.
await $`git tag -a js@v${newVersion} -m "JS client v${newVersion}"`;
}


switch (command) {
case Command.Format:
await format();
break;
case Command.Lint:
await lint();
break;
case Command.Test:
await test();
break;
case Command.Publish:
await publish();
break;
default:
throw new Error(`Unknown command: ${command}`);
}
8 changes: 0 additions & 8 deletions scripts/js/format.mts

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/js/lint.mts

This file was deleted.

35 changes: 0 additions & 35 deletions scripts/js/publish.mts

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/js/test.mts

This file was deleted.

Loading
Loading