|
1 | 1 | #!/usr/bin/env zx |
2 | | -import "zx/globals"; |
| 2 | +import 'zx/globals'; |
| 3 | +import { getCargo } from './utils.mjs'; |
3 | 4 |
|
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. |
5 | 25 | 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', |
16 | 39 | ]; |
17 | 40 |
|
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. |
21 | 52 | await $`git add --all`; |
22 | 53 | for (const glob of unchangedGlobs) { |
23 | 54 | await $`git restore --worktree --staged "${glob}"`; |
24 | 55 | } |
| 56 | + |
| 57 | +// Re-install dependencies. |
25 | 58 | await $`pnpm install`; |
0 commit comments