diff --git a/package.json b/package.json index de95985..73e174d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "clients:rust:format": "zx ./scripts/client/format-rust.mjs", "clients:rust:lint": "zx ./scripts/client/lint-rust.mjs", "clients:rust:publish": "zx ./scripts/client/publish-rust.mjs", - "clients:rust:test": "zx ./scripts/client/test-rust.mjs" + "clients:rust:test": "zx ./scripts/client/test-rust.mjs", + "template:upgrade": "zx ./scripts/upgrade-template.mjs" }, "devDependencies": { "@iarna/toml": "^2.2.5", diff --git a/scripts/upgrade-template.mjs b/scripts/upgrade-template.mjs index e5907a6..946d3a9 100644 --- a/scripts/upgrade-template.mjs +++ b/scripts/upgrade-template.mjs @@ -1,25 +1,58 @@ #!/usr/bin/env zx -import "zx/globals"; +import 'zx/globals'; +import { getCargo } from './utils.mjs'; -$.quote = (command) => command; +// Arguments to pass to the `create-solana-program` command. +const rustClientCargo = getCargo(path.join('clients', 'rust')); +const jsClientPkg = require( + path.join(__dirname, '..', 'clients', 'js', 'package.json') +); +const templateArgs = [ + 'system', + '--address', + '11111111111111111111111111111111', + '--org', + 'solana-program', + '--rust-client-crate-name', + rustClientCargo.package.name, + '--js-client-package-name', + jsClientPkg.name, + '--default', + '--force', +]; + +// File and folder patterns that should not be overwritten by the template upgrade. const unchangedGlobs = [ - "clients/**/src/**", - "clients/**/src/*", - "clients/js/test/*", - "clients/rust/tests/*", - "program/**/*", - "program/*", - "scripts/generate-clients.mjs", - "scripts/generate-idls.mjs", - "scripts/upgrade-template.mjs", - "scripts/program/*", + 'clients/**/src/**', + 'clients/**/src/*', + 'clients/js/test/*', + 'clients/rust/tests/*', + 'program/**/*', + 'program/*', + 'scripts/generate-clients.mjs', + 'scripts/generate-idls.mjs', + 'scripts/upgrade-template.mjs', + 'scripts/program/*', + 'Cargo.lock', + '**/pnpm-lock.yaml', + 'pnpm-lock.yaml', ]; -cd(".."); -await $`pnpm create solana-program system --address 11111111111111111111111111111111 --default --force`; -cd("system"); +// Prevent CLI arguments from being escaped. +$.quote = (command) => command; + +// Re-generate the repo from the parent directory. +cd('..'); +await $`pnpm create solana-program@latest ${templateArgs}`; + +// Go back inside the updated repo. +cd('system'); + +// Restore files and folders that should not be overwritten. await $`git add --all`; for (const glob of unchangedGlobs) { await $`git restore --worktree --staged "${glob}"`; } + +// Re-install dependencies. await $`pnpm install`;