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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 48 additions & 15 deletions scripts/upgrade-template.mjs
Original file line number Diff line number Diff line change
@@ -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`;