|
| 1 | +/* eslint-disable no-lonely-if */ |
1 | 2 | /* eslint-disable @typescript-eslint/no-var-requires */
|
2 | 3 | import chalk from 'chalk';
|
3 | 4 | import logSymbols from 'log-symbols';
|
@@ -72,13 +73,51 @@ export function serve(options: ProgramOptions | undefined): void {
|
72 | 73 | let entries: number[] = [];
|
73 | 74 |
|
74 | 75 | if (options?.entries) {
|
75 |
| - entries = options.entries.map(e => { |
76 |
| - let entry = Number.parseInt(e, 10); |
77 |
| - if (Number.isNaN(entry)) { |
78 |
| - entry = 0; |
79 |
| - } |
80 |
| - return entry; |
81 |
| - }); |
| 76 | + console.log( |
| 77 | + `${logSymbols.info} ${chalk.bold('cli')}: ${chalk.cyan( |
| 78 | + `starting with selective ${options.entries.length} ${ |
| 79 | + options.entries.length === 1 ? 'entry' : 'entries' |
| 80 | + }` |
| 81 | + )}` |
| 82 | + ); |
| 83 | + // make sure to remove duplicates from the entries before looping |
| 84 | + entries = [...new Set(options.entries)] |
| 85 | + .map(e => { |
| 86 | + let entry = Number.parseInt(e, 10); |
| 87 | + if (Number.isNaN(entry)) { |
| 88 | + entry = projectConfig.files.findIndex(file => file.name === e); |
| 89 | + if (entry === -1) { |
| 90 | + console.log( |
| 91 | + `${logSymbols.error} ${chalk.bold('cli')}: ${chalk.red( |
| 92 | + `no entry found for ` |
| 93 | + )}${chalk.bold(chalk.yellow(e))} ${chalk.bold('skipping...')}` |
| 94 | + ); |
| 95 | + return false; |
| 96 | + } |
| 97 | + console.log( |
| 98 | + `${logSymbols.success} ${chalk.bold('cli')}: ${chalk.green( |
| 99 | + `entry found for ` |
| 100 | + )}${chalk.bold(chalk.yellow(e))}` |
| 101 | + ); |
| 102 | + } else { |
| 103 | + if (projectConfig.files[entry]) { |
| 104 | + console.log( |
| 105 | + `${logSymbols.success} ${chalk.bold('cli')}: ${chalk.green( |
| 106 | + `entry found for ${chalk.bold(e)} is` |
| 107 | + )} ${chalk.bold(chalk.yellow(projectConfig.files[entry].name))}` |
| 108 | + ); |
| 109 | + } else { |
| 110 | + console.log( |
| 111 | + `${logSymbols.error} ${chalk.bold('cli')}: ${chalk.red( |
| 112 | + `no entry found for ` |
| 113 | + )}${chalk.bold(chalk.yellow(e))} ${chalk.bold('skipping...')}` |
| 114 | + ); |
| 115 | + return false; |
| 116 | + } |
| 117 | + } |
| 118 | + return entry; |
| 119 | + }) |
| 120 | + .filter(entry => typeof entry === 'number') as number[]; |
82 | 121 | } else if (projectConfig.files.length > 1) {
|
83 | 122 | serveEntryInfo();
|
84 | 123 | }
|
|
0 commit comments