Design system.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { cp } from 'fs/promises';
  2. import { resolve } from 'path';
  3. import { Argv } from 'yargs';
  4. const copyFiles = async () => {
  5. const srcPath = resolve(__dirname, '..', '..', '..', 'src', 'next');
  6. const destPath = resolve(__dirname, '..', '..', '..', '.amanuensis', 'next');
  7. await cp(srcPath, destPath, { recursive: true });
  8. };
  9. interface PackageManager {
  10. name: string;
  11. testCmd: [string, string[]];
  12. installCmd: [string, string[]];
  13. }
  14. const packageManagers: PackageManager[] = [
  15. {
  16. name: 'pnpm',
  17. testCmd: ['pnpm', ['--version']],
  18. installCmd: ['pnpm', ['install', '--ignore-workspace']],
  19. },
  20. {
  21. name: 'yarn',
  22. testCmd: ['yarn', ['--version']],
  23. installCmd: ['yarn', ['install']],
  24. },
  25. {
  26. name: 'npm',
  27. testCmd: ['npm', ['--version']],
  28. installCmd: ['npm', ['install']],
  29. },
  30. ];
  31. const installDependencies = async () => {
  32. const { execa } = await import('execa');
  33. const selectedPackageManagerIndex = await packageManagers.reduce(
  34. async (prevPmPromise, pkgm, i) => {
  35. const prevPm = await prevPmPromise;
  36. const { testCmd } = pkgm;
  37. const testPm = await execa(...testCmd);
  38. if (testPm.exitCode === 0 && prevPm === -1) {
  39. return i;
  40. }
  41. return prevPm;
  42. },
  43. Promise.resolve(-1),
  44. );
  45. if (selectedPackageManagerIndex < 0) {
  46. process.stderr.write('No package manager found\n');
  47. process.exit(-1);
  48. }
  49. const { [selectedPackageManagerIndex]: selectedPackageManager } = packageManagers;
  50. const cwd = resolve(__dirname, '..', '..', '..', '.amanuensis', 'next');
  51. process.stdout.write(`In path: ${cwd}\n`);
  52. process.stdout.write(`Installing dependencies with ${selectedPackageManager.name}\n`);
  53. await execa(
  54. selectedPackageManager.installCmd[0],
  55. selectedPackageManager.installCmd[1],
  56. { cwd },
  57. );
  58. };
  59. export const description = 'Initialize a new Amanuensis project' as const;
  60. export const builder = (yargsBuilder: Argv) => yargsBuilder;
  61. const init = async () => {
  62. await copyFiles();
  63. await installDependencies();
  64. return 0;
  65. };
  66. export default init;