Skip to content

Commit f50cf70

Browse files
committed
refactor(create-cli): unify format definitions
1 parent f4b3065 commit f50cf70

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

packages/create-cli/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#! /usr/bin/env node
22
import yargs from 'yargs';
33
import { hideBin } from 'yargs/helpers';
4+
import { CONFIG_FILE_FORMATS } from './lib/setup/types.js';
45
import { runSetupWizard } from './lib/setup/wizard.js';
56

67
const argv = await yargs(hideBin(process.argv))
@@ -17,7 +18,7 @@ const argv = await yargs(hideBin(process.argv))
1718
})
1819
.option('config-format', {
1920
type: 'string',
20-
choices: ['ts', 'js', 'mjs'],
21+
choices: CONFIG_FILE_FORMATS,
2122
describe: 'Config file format (default: auto-detected from project)',
2223
})
2324
.parse();

packages/create-cli/src/lib/setup/config-format.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { readdir } from 'node:fs/promises';
33
import path from 'node:path';
44
import type { PackageJson } from 'type-fest';
55
import { fileExists, readJsonFile } from '@code-pushup/utils';
6-
import type { CliArgs, ConfigFileFormat } from './types.js';
6+
import {
7+
CONFIG_FILE_FORMATS,
8+
type CliArgs,
9+
type ConfigFileFormat,
10+
} from './types.js';
711

812
const TSCONFIG_PATTERN = /^tsconfig(\..+)?\.json$/;
913

@@ -61,5 +65,6 @@ async function detectDefaultFormat(targetDir: string): Promise<DefaultFormat> {
6165
function isConfigFileFormat(
6266
value: string | undefined,
6367
): value is ConfigFileFormat {
64-
return value === 'ts' || value === 'js' || value === 'mjs';
68+
const validValues: readonly string[] = CONFIG_FILE_FORMATS;
69+
return value != null && validValues.includes(value);
6570
}

packages/create-cli/src/lib/setup/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PluginMeta } from '@code-pushup/models';
22

3-
export type ConfigFileFormat = 'ts' | 'js' | 'mjs';
3+
export const CONFIG_FILE_FORMATS = ['ts', 'js', 'mjs'] as const;
4+
export type ConfigFileFormat = (typeof CONFIG_FILE_FORMATS)[number];
45

56
/** Virtual file system that buffers writes in memory until flushed to disk. */
67
export type Tree = {

0 commit comments

Comments
 (0)