Skip to content

Commit 1902a06

Browse files
authored
Improve upgrade script with lib name overrides (#12)
1 parent 3b25beb commit 1902a06

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"clients:rust:format": "zx ./scripts/client/format-rust.mjs",
1616
"clients:rust:lint": "zx ./scripts/client/lint-rust.mjs",
1717
"clients:rust:publish": "zx ./scripts/client/publish-rust.mjs",
18-
"clients:rust:test": "zx ./scripts/client/test-rust.mjs"
18+
"clients:rust:test": "zx ./scripts/client/test-rust.mjs",
19+
"template:upgrade": "zx ./scripts/upgrade-template.mjs"
1920
},
2021
"devDependencies": {
2122
"@iarna/toml": "^2.2.5",

scripts/upgrade-template.mjs

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
11
#!/usr/bin/env zx
2-
import "zx/globals";
2+
import 'zx/globals';
3+
import { getCargo } from './utils.mjs';
34

4-
$.quote = (command) => command;
5+
// Arguments to pass to the `create-solana-program` command.
6+
const rustClientCargo = getCargo(path.join('clients', 'rust'));
7+
const jsClientPkg = require(
8+
path.join(__dirname, '..', 'clients', 'js', 'package.json')
9+
);
10+
const templateArgs = [
11+
'system',
12+
'--address',
13+
'11111111111111111111111111111111',
14+
'--org',
15+
'solana-program',
16+
'--rust-client-crate-name',
17+
rustClientCargo.package.name,
18+
'--js-client-package-name',
19+
jsClientPkg.name,
20+
'--default',
21+
'--force',
22+
];
23+
24+
// File and folder patterns that should not be overwritten by the template upgrade.
525
const unchangedGlobs = [
6-
"clients/**/src/**",
7-
"clients/**/src/*",
8-
"clients/js/test/*",
9-
"clients/rust/tests/*",
10-
"program/**/*",
11-
"program/*",
12-
"scripts/generate-clients.mjs",
13-
"scripts/generate-idls.mjs",
14-
"scripts/upgrade-template.mjs",
15-
"scripts/program/*",
26+
'clients/**/src/**',
27+
'clients/**/src/*',
28+
'clients/js/test/*',
29+
'clients/rust/tests/*',
30+
'program/**/*',
31+
'program/*',
32+
'scripts/generate-clients.mjs',
33+
'scripts/generate-idls.mjs',
34+
'scripts/upgrade-template.mjs',
35+
'scripts/program/*',
36+
'Cargo.lock',
37+
'**/pnpm-lock.yaml',
38+
'pnpm-lock.yaml',
1639
];
1740

18-
cd("..");
19-
await $`pnpm create solana-program system --address 11111111111111111111111111111111 --default --force`;
20-
cd("system");
41+
// Prevent CLI arguments from being escaped.
42+
$.quote = (command) => command;
43+
44+
// Re-generate the repo from the parent directory.
45+
cd('..');
46+
await $`pnpm create solana-program@latest ${templateArgs}`;
47+
48+
// Go back inside the updated repo.
49+
cd('system');
50+
51+
// Restore files and folders that should not be overwritten.
2152
await $`git add --all`;
2253
for (const glob of unchangedGlobs) {
2354
await $`git restore --worktree --staged "${glob}"`;
2455
}
56+
57+
// Re-install dependencies.
2558
await $`pnpm install`;

0 commit comments

Comments
 (0)