1
0

upgrade-template.mjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env zx
  2. import 'zx/globals';
  3. import { getCargo } from './utils.mjs';
  4. // Arguments to pass to the `create-solana-program` command.
  5. const rustClientCargo = getCargo(path.join('clients', 'rust'));
  6. const jsClientPkg = require(
  7. path.join(__dirname, '..', 'clients', 'js', 'package.json')
  8. );
  9. const templateArgs = [
  10. 'token',
  11. '--address',
  12. 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
  13. '--org',
  14. 'solana-program',
  15. '--rust-client-crate-name',
  16. rustClientCargo.package.name,
  17. '--js-client-package-name',
  18. jsClientPkg.name,
  19. '--default',
  20. '--force',
  21. ];
  22. // File and folder patterns that should not be overwritten by the template upgrade.
  23. const unchangedGlobs = [
  24. 'clients/**/src/**',
  25. 'clients/**/src/*',
  26. 'clients/js/test/*',
  27. 'clients/rust/tests/*',
  28. 'program/**/*',
  29. 'program/*',
  30. 'scripts/generate-clients.mjs',
  31. 'scripts/generate-idls.mjs',
  32. 'scripts/upgrade-template.mjs',
  33. 'scripts/program/*',
  34. 'Cargo.lock',
  35. '**/pnpm-lock.yaml',
  36. 'pnpm-lock.yaml',
  37. ];
  38. // Prevent CLI arguments from being escaped.
  39. $.quote = (command) => command;
  40. // Re-generate the repo from the parent directory.
  41. cd('..');
  42. await $`pnpm create solana-program@latest ${templateArgs}`;
  43. // Go back inside the updated repo.
  44. cd('token');
  45. // Restore files and folders that should not be overwritten.
  46. await $`git add --all`;
  47. for (const glob of unchangedGlobs) {
  48. await $`git restore --worktree --staged "${glob}"`;
  49. }
  50. // Re-install dependencies.
  51. await $`pnpm install`;