1 | import chalk from 'chalk';
|
2 | import { Link } from 'cspell-lib';
|
3 | export const listGlobalImports = Link.listGlobalImports;
|
4 | export const addPathsToGlobalImports = Link.addPathsToGlobalImports;
|
5 | export const removePathsFromGlobalImports = Link.removePathsFromGlobalImports;
|
6 | export function listGlobalImportsResultToTable(results) {
|
7 | const header = ['id', 'package', 'name', 'filename', 'dictionaries', 'errors'];
|
8 | const decorate = (isError) => (isError ? (s) => chalk.red(s) : (s) => s);
|
9 | function toColumns(r) {
|
10 | return [
|
11 | r.id,
|
12 | r.package?.name,
|
13 | r.name,
|
14 | r.filename,
|
15 | r.dictionaryDefinitions?.map((def) => def.name).join(', '),
|
16 | r.error ? 'Failed to read file.' : '',
|
17 | ]
|
18 | .map((c) => c || '')
|
19 | .map(decorate(!!r.error));
|
20 | }
|
21 | return {
|
22 | header,
|
23 | rows: results.map(toColumns),
|
24 | };
|
25 | }
|
26 | export function addPathsToGlobalImportsResultToTable(results) {
|
27 | const header = ['filename', 'errors'];
|
28 | const decorate = (isError) => (isError ? (s) => chalk.red(s) : (s) => s);
|
29 | function toColumns(r) {
|
30 | return [r.resolvedToFilename || r.filename, r.error ? 'Failed to read file.' : '']
|
31 | .map((c) => c || '')
|
32 | .map(decorate(!!r.error));
|
33 | }
|
34 | return {
|
35 | header,
|
36 | rows: results.resolvedSettings.map(toColumns),
|
37 | };
|
38 | }
|
39 |
|
\ | No newline at end of file |