CoE CLI kūrimas pridedant naują komandą (Nebenaudojama)

Pastaba.

CoE CLI yra pasenęs ir nepridedama jokių naujų funkcijų. Problemos nebeperžiūrimos ir nebesprendžiamos.

Jei nustatėte galimą saugos problemą, praneškite apie tai „Microsoft“ reagavimo į saugos grėsmes centras.

Be Power Platform administravimo centro, apsvarstykite galimybę naudoti Microsoft Power Platform CLI, Power Platform API, Power Platform atsargų API ir Power Platform for Admins V2 jungtį.

Norėdami įtraukti naują komandos pavyzdį, naudokite šią komandą, kad suformuotumėte pradinę komandos "TypeScript" ir "Jest JavaScript" testavimo sistemos vieneto testo sąranką.

cd coe-cli
coe cli add -n sample

Prijunkite komandą prie komandinės eilutės

Baigę naujos komandos vieneto bandymą, atlikite šias užduotis.

  1. Peržiūrėkite https://www.npmjs.com/package/commander komandas ir parinktis.

  2. Atnaujinkite commands.ts, kad būtų įtraukta nauja arba antrinė komanda.

    • Importuokite failus failo viršuje.

      import { SampleArguments, SampleCommand} from './sample';
      
    • Įtraukite funkciją, skirtą injekciniam liejimui.

      createSampleCommand: () => SampleCommand
      
    • Sukurkite komandą naudodami konstružsakytoriaus funkciją.

      this.createSampleCommand = () => new SampleCommand
      
    • Įtraukite funkciją.

       AddSampleCommand(program: commander.Command) {
           var run = program.command('sample')
               .description('A new sample command')
               .option('-c, --comment <comment>', 'The comment for the command')
               .action(async (options: any) : Promise<void> => {
                   let args = new SampleArguments();
                   args.comment = options.comment;
                   let command = this.createSampleCommand();
                   await command.execute(args)
               });
       }
      
    • Užregistruokite naują komandą, kad inicijuotumėte funkciją.

      this.AddSampleCommand(program);
      
  3. Atnaujinkite commands.spec.ts, kad būtų įtraukti vienetų bandymai.

    • Įtraukite nuorodą į komandą.

      import { SampleCommand } from '../../src/commands/sample'
      
    • Įtraukite „Jest“ bandymų rinkinį.

      describe('Sample', () => {
          test('Execute', async () => {
              // Arrange
              var commands = new CoeCliCommands();
              let mockSampleCommand = mock<SampleCommand>(); 
      
              commands.createSampleCommand = () => { return mockSampleCommand }
      
              mockSampleCommand.execute.mockResolvedValue()
      
              // Act
              await commands.execute(['node', 'commands.spec', 'sample', '-c', 'Some comment'])
      
              // Assert
              expect(mockSampleCommand.execute).toHaveBeenCalled()
          })
      });
      
  4. Paleiskite vienetų bandymus su naujais pakeitimais.

    npm run test