backstage

Форк
0
77 строк · 2.3 Кб
1
/*
2
 * Copyright 2020 The Backstage Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
/**
18
 * A collection of codemods for Backstage projects
19
 *
20
 * @packageDocumentation
21
 */
22

23
import { program } from 'commander';
24
import chalk from 'chalk';
25
import { codemods } from './codemods';
26
import { exitWithError } from './errors';
27
import { createCodemodAction } from './action';
28
import { version } from '../package.json';
29

30
async function main(argv: string[]) {
31
  program.name('backstage-codemods').version(version);
32

33
  const applyCommand = program
34
    .command('apply <codemod> [target-dirs...]')
35
    .description(
36
      'Apply a codemod to target directories, defaulting to the current directory',
37
    );
38

39
  for (const codemod of codemods) {
40
    applyCommand
41
      .command(`${codemod.name} [target-dirs...]`)
42
      .description(codemod.description)
43
      .option('-d, --dry', 'Dry run, no changes written to files')
44
      .action(createCodemodAction(codemod.name));
45
  }
46

47
  program
48
    .command('list')
49
    .description('List available codemods')
50
    .action(() => {
51
      const maxNameLength = Math.max(...codemods.map(m => m.name.length));
52
      for (const codemod of codemods) {
53
        const paddedName = codemod.name.padEnd(maxNameLength, ' ');
54
        console.log(`${paddedName} - ${codemod.description}`);
55
      }
56
    });
57

58
  program.on('command:*', () => {
59
    console.log();
60
    console.log(chalk.red(`Invalid command: ${program.args.join(' ')}`));
61
    console.log();
62
    program.outputHelp();
63
    process.exit(1);
64
  });
65

66
  program.parse(argv);
67
}
68

69
process.on('unhandledRejection', (rejection: unknown) => {
70
  if (rejection instanceof Error) {
71
    exitWithError(rejection);
72
  } else {
73
    exitWithError(new Error(`Unknown rejection: '${rejection}'`));
74
  }
75
});
76

77
main(process.argv).catch(exitWithError);
78

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.