index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import path from 'path';
  6. import { Command } from 'commander';
  7. import { updateFlowgramVersion } from './update-version';
  8. import { syncMaterial } from './materials';
  9. import { findUsedMaterials } from './find-materials';
  10. import { createApp } from './create-app';
  11. const program = new Command();
  12. program.name('flowgram-cli').version('1.0.0').description('Flowgram CLI');
  13. program
  14. .command('create-app')
  15. .description('Create a new flowgram project')
  16. .argument('[string]', 'Project name')
  17. .action(async (projectName) => {
  18. await createApp(projectName);
  19. });
  20. program
  21. .command('materials')
  22. .description('Sync materials to the project')
  23. .argument(
  24. '[string]',
  25. 'Material name or names\nExample 1: components/variable-selector \nExample2: components/variable-selector,effect/provideJsonSchemaOutputs'
  26. )
  27. .option('--refresh-project-imports', 'Refresh project imports to copied materials', false)
  28. .option('--target-material-root-dir <string>', 'Target directory to copy materials')
  29. .option('--select-multiple', 'Select multiple materials', false)
  30. .action(async (materialName, options) => {
  31. await syncMaterial({
  32. materialName,
  33. refreshProjectImports: options.refreshProjectImports,
  34. targetMaterialRootDir: options.targetMaterialRootDir
  35. ? path.join(process.cwd(), options.targetMaterialRootDir)
  36. : undefined,
  37. selectMultiple: options.selectMultiple,
  38. });
  39. });
  40. program
  41. .command('find-used-materials')
  42. .description('Find used materials in the project')
  43. .action(async () => {
  44. await findUsedMaterials();
  45. });
  46. program
  47. .command('update-version')
  48. .description('Update flowgram version in the project')
  49. .argument('[string]', 'Flowgram version')
  50. .action(async (version) => {
  51. await updateFlowgramVersion(version);
  52. });
  53. program.parse(process.argv);