view-ignored 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Argument, Option, Command } from 'commander';
1
+ import { Argument, Command, Option } from 'commander';
2
2
  import * as Config from './config.js';
3
3
  import { type DecorName, type StyleName } from './browser/styling.js';
4
4
  import { type SortName } from './browser/sorting.js';
@@ -57,7 +57,6 @@ export declare const argumentConfigKey: Argument;
57
57
  export declare const cfgRealOption: Option;
58
58
  export declare const cfgTypesOption: Option;
59
59
  export declare function parseArgumentArrayString(argument: string): string[];
60
- export declare function parseArgumentBoolean(argument: string): boolean;
61
60
  export declare function parseArgumentInteger(argument: string): number;
62
61
  export declare function createArgumentParserStringLiteral(choices: string[]): (argument: string) => string;
63
62
  export declare function parseArgumentKey(key: string): string;
package/out/cli.js CHANGED
@@ -2,15 +2,15 @@ import { format } from 'node:util';
2
2
  import * as process from 'node:process';
3
3
  import { icons } from '@m234/nerd-fonts';
4
4
  import { Chalk } from 'chalk';
5
- import { Argument, InvalidArgumentError, Option, Command, } from 'commander';
6
- import { Listr } from 'listr2';
5
+ import { Argument, Command, InvalidArgumentError, Option } from 'commander';
7
6
  import * as Config from './config.js';
8
- import { targetGet, loadPlugins, loadBuiltIns, targetList, } from './browser/binds/index.js';
7
+ import { loadBuiltIns, loadPlugins, targetGet, targetList, } from './browser/binds/index.js';
9
8
  import { decorCondition, formatFiles, } from './browser/styling.js';
10
9
  import { sortNameList } from './browser/sorting.js';
11
10
  import { boxError, decorNameList, highlight, stringTime, styleNameList, } from './styling.js';
12
- import { Directory, package_, makeOptionsReal, scan, Sorting, ViewIgnoredError, } from './lib.js';
11
+ import { Directory, makeOptionsReal, package_, scan, Sorting, ViewIgnoredError, } from './lib.js';
13
12
  import { filterNameList } from './browser/filtering.js';
13
+ import { oraPromise } from 'ora';
14
14
  /**
15
15
  * @internal
16
16
  */
@@ -23,14 +23,17 @@ export function logError(message, options) {
23
23
  */
24
24
  export async function programInit() {
25
25
  try {
26
- const { configManager, configDefault, configValueArray, configValueString, configValueLiteral } = Config;
26
+ const { configManager, configDefault, configValueArray, configValueString, configValueLiteral, } = Config;
27
27
  const flags = program.optsWithGlobals();
28
28
  const chalk = new Chalk();
29
29
  configManager.keySetValidator('plugins', configDefault.plugins, configValueArray(configValueString()));
30
30
  const loadResultConfig = configManager.load();
31
31
  const builtInPlugins = await loadBuiltIns();
32
32
  const configPlugins = configManager.get('plugins');
33
- const loadResultPlugins = [...(flags.plugins ? await loadPlugins(flags.plugins) : []), ...builtInPlugins];
33
+ const loadResultPlugins = [
34
+ ...(flags.plugins ? await loadPlugins(flags.plugins) : []),
35
+ ...builtInPlugins,
36
+ ];
34
37
  for (const loadResult of loadResultPlugins) {
35
38
  if (loadResult.isLoaded) {
36
39
  continue;
@@ -47,9 +50,15 @@ export async function programInit() {
47
50
  configManager.keySetValidator('target', configDefault.target, configValueLiteral(targets));
48
51
  {
49
52
  const title = 'view-ignored - Configuration loading failed.';
50
- const infoSymbol = decorCondition(flags.decor, { ifEmoji: 'ℹ️', ifNerd: icons['nf-seti-info'].value, postfix: ' ' });
53
+ const infoSymbol = decorCondition(flags.decor, {
54
+ ifEmoji: 'ℹ️',
55
+ ifNerd: icons['nf-seti-info'].value,
56
+ postfix: ' ',
57
+ });
51
58
  const errorIcon = decorCondition(flags.decor, {
52
- ifNerd: icons['nf-seti-error'].value, ifEmoji: '⚠️', postfix: ' ',
59
+ ifNerd: icons['nf-seti-error'].value,
60
+ ifEmoji: '⚠️',
61
+ postfix: ' ',
53
62
  });
54
63
  const footer = `\n\n${chalk.blue(infoSymbol)}Configuration path: ${Config.configManager.path}`;
55
64
  if (typeof loadResultConfig === 'string') {
@@ -58,25 +67,31 @@ export async function programInit() {
58
67
  }
59
68
  if (loadResultConfig && loadResultConfig?.size > 0) {
60
69
  const propertiesErrors = [...loadResultConfig.entries()].map(([key, message]) => {
61
- const pair = Config.configManager.getPairString(key, { chalk, types: false, real: true });
70
+ const pair = Config.configManager.getPairString(key, {
71
+ chalk,
72
+ types: false,
73
+ real: true,
74
+ });
62
75
  return `${pair} - ${chalk.red(errorIcon)}${message}`;
63
76
  }).join('\n');
64
- logError(`Invalid properties:\n${propertiesErrors}${footer}`, { title });
77
+ logError(`Invalid properties:\n${propertiesErrors}${footer}`, {
78
+ title,
79
+ });
65
80
  process.exit(1);
66
81
  }
67
82
  }
68
83
  program.version('v' + package_.version, '-v');
69
- configManager.setOption('noColor', program, new Option('--no-color', 'force disable colors'), parseArgumentBoolean);
70
- configManager.setOption('posix', program, new Option('--posix', 'use unix path separator'), parseArgumentBoolean);
84
+ configManager.setOption('noColor', program, new Option('--no-color', 'force disable colors'));
85
+ configManager.setOption('posix', program, new Option('--posix', 'use unix path separator'));
71
86
  configManager.setOption('plugins', program, new Option('--plugins <modules...>', 'import modules to modify behavior'), parseArgumentArrayString);
72
87
  configManager.setOption('decor', program, new Option('--decor <decor>', 'the interface decorations'), createArgumentParserStringLiteral([...decorNameList]));
73
- configManager.setOption('parsable', program, new Option('-p, --parsable [parsable]', 'print parsable text'), parseArgumentBoolean);
88
+ configManager.setOption('parsable', program, new Option('-p, --parsable', 'print parsable text'));
74
89
  configManager.setOption('target', scanProgram, new Option('-t, --target <ignorer>', 'the scan target'), createArgumentParserStringLiteral(targets));
75
90
  configManager.setOption('filter', scanProgram, new Option('--filter <filter>', 'filter results'), createArgumentParserStringLiteral([...filterNameList]));
76
91
  configManager.setOption('sort', scanProgram, new Option('--sort <sorter>', 'sort results'), createArgumentParserStringLiteral([...sortNameList]));
77
92
  configManager.setOption('style', scanProgram, new Option('--style <style>', 'results view mode'), createArgumentParserStringLiteral([...styleNameList]));
78
93
  configManager.setOption('depth', scanProgram, new Option('--depth <depth>', 'the max results depth'), parseArgumentInteger);
79
- configManager.setOption('showSources', scanProgram, new Option('--show-sources [show]', 'show scan sources'), parseArgumentBoolean);
94
+ configManager.setOption('showSources', scanProgram, new Option('--show-sources', 'show scan sources'));
80
95
  configManager.setOption('concurrency', scanProgram, new Option('--concurrency [limit]', 'the limit for the signgle directory operations'), parseArgumentInteger);
81
96
  program.parse();
82
97
  }
@@ -140,13 +155,6 @@ cfgProgram
140
155
  export function parseArgumentArrayString(argument) {
141
156
  return argument.split(/[ ,|]/).filter(Boolean);
142
157
  }
143
- export function parseArgumentBoolean(argument) {
144
- const errorMessage = Config.configValueSwitch()(argument);
145
- if (errorMessage !== undefined) {
146
- throw new InvalidArgumentError(errorMessage);
147
- }
148
- return Config.switchTrueValues.includes(argument);
149
- }
150
158
  export function parseArgumentInteger(argument) {
151
159
  const value = Number.parseInt(argument, 10);
152
160
  const errorMessage = Config.configValueInteger()(value);
@@ -205,7 +213,10 @@ export async function actionScan() {
205
213
  logError(format(`Bad target '${flags.target}'. Registered targets: ${targetList().join(', ')}.`), { title: 'view-ignored - Fatal error.' });
206
214
  process.exit(1);
207
215
  }
208
- const optionsReal = makeOptionsReal({ posix: flags.posix || flags.parsable, concurrency: flags.concurrency });
216
+ const optionsReal = makeOptionsReal({
217
+ posix: flags.posix || flags.parsable,
218
+ concurrency: flags.concurrency,
219
+ });
209
220
  const stream = Directory.deepStream('.', {
210
221
  concurrency: optionsReal.concurrency,
211
222
  cwd: optionsReal.cwd,
@@ -218,17 +229,18 @@ export async function actionScan() {
218
229
  filter: flags.filter,
219
230
  maxDepth: flags.depth,
220
231
  });
221
- console.log(fileInfoList.map(fileInfo => fileInfo.relativePath + (flags.showSources && fileInfo.source !== undefined ? '<' + (fileInfo.source.relativePath) : '')).join(','));
232
+ console.log(fileInfoList.map(fileInfo => fileInfo.relativePath + (flags.showSources && fileInfo.source !== undefined
233
+ ? '<' + (fileInfo.source.relativePath)
234
+ : '')).join(','));
222
235
  }
223
236
  else {
224
- let name = decorCondition(flags.decor, { ifNerd: bind.icon?.value, postfix: ' ' }) + bind.name;
237
+ let name = decorCondition(flags.decor, { ifNerd: bind.icon?.value, postfix: ' ' })
238
+ + bind.name;
225
239
  if (bind.icon?.color !== undefined) {
226
240
  name = chalk.hex('#' + bind.icon.color)(name);
227
241
  }
228
242
  const context = {
229
- count: {
230
- files: 0, directories: 0, current: 0, total: 0,
231
- },
243
+ progress: { current: 0, directories: 0, files: 0, total: 0 },
232
244
  fileInfoList: [],
233
245
  stream,
234
246
  message: '',
@@ -238,76 +250,61 @@ export async function actionScan() {
238
250
  });
239
251
  }),
240
252
  };
241
- const progress = new Listr([
242
- {
243
- title: `${name} ${chalk.hex('#73A7DE')(flags.filter)} ${cwd}`,
244
- async task(context, task) {
245
- return task.newListr([
246
- {
247
- title: 'Preparing',
248
- async task() {
249
- const { progress } = await context.reading;
250
- Object.assign(context.count, progress);
251
- },
252
- },
253
- {
254
- title: 'Scanning',
255
- async task() {
256
- context.fileInfoList = await scan(context.stream, {
257
- ...optionsReal,
258
- target: flags.target,
259
- filter: flags.filter,
260
- maxDepth: flags.depth,
261
- });
262
- },
263
- },
264
- {
265
- title: 'Printing',
266
- async task() {
267
- const sorter = Sorting[flags.sort];
268
- const cache = new Map();
269
- if (flags.sort === 'modified') {
270
- const { tree } = await context.reading;
271
- await tree.deepModifiedTime(cache, optionsReal);
272
- }
273
- const time = Date.now() - start;
274
- const fileInfoListSorted = context.fileInfoList.sort((a, b) => sorter(String(a), String(b), cache));
275
- const files = formatFiles(fileInfoListSorted, {
276
- chalk,
277
- posix: flags.posix,
278
- style: flags.style,
279
- decor: flags.decor,
280
- showSources: flags.showSources,
281
- });
282
- const fastSymbol = decorCondition(flags.decor, { ifEmoji: '⚡', ifNerd: icons['nf-md-lightning_bolt'].value });
283
- const infoSymbol = decorCondition(flags.decor, { ifEmoji: 'ℹ️', ifNerd: icons['nf-seti-info'].value, postfix: ' ' });
284
- let message = '';
285
- message += files;
286
- message += '\n';
287
- message += `Done in ${time < 2000 ? chalk.yellow(fastSymbol) : ''}${stringTime(time, chalk)}.`;
288
- message += '\n';
289
- message += `Listed ${highlight(String(context.fileInfoList.length), chalk)} files.`;
290
- message += '\n';
291
- message += `Processed ${highlight(String(context.count.files), chalk)} files and ${highlight(String(context.count.directories), chalk)} directories.`;
292
- message += '\n';
293
- if (bind.testCommand) {
294
- message += '\n';
295
- message += `${chalk.blue(infoSymbol)}You can use ${highlight(`'${bind.testCommand}'`, chalk)} to check if the list is valid.`;
296
- }
297
- message += '\n';
298
- context.message = message;
299
- },
300
- },
301
- ]);
302
- },
303
- },
304
- ], {
305
- ctx: context,
306
- exitOnError: true,
307
- });
308
253
  try {
309
254
  context.stream.run();
310
- await progress.run();
255
+ console.log(`${name} ${chalk.hex('#73A7DE')(flags.filter)} ${cwd}`);
256
+ await oraPromise(async (spinner) => {
257
+ const proc = scan(context.stream, {
258
+ ...optionsReal,
259
+ target: flags.target,
260
+ filter: flags.filter,
261
+ maxDepth: flags.depth,
262
+ });
263
+ context.stream.on('progress', (progress) => {
264
+ spinner.text = `Scanning ${progress.current}/${progress.total}`;
265
+ context.progress = progress;
266
+ });
267
+ context.fileInfoList = await proc;
268
+ }, 'Scanning');
269
+ const sorter = Sorting[flags.sort];
270
+ const cache = new Map();
271
+ if (flags.sort === 'modified') {
272
+ const { tree } = await context.reading;
273
+ await tree.deepModifiedTime(cache, optionsReal);
274
+ }
275
+ const time = Date.now() - start;
276
+ const fileInfoListSorted = context.fileInfoList.sort((a, b) => sorter(String(a), String(b), cache));
277
+ const files = formatFiles(fileInfoListSorted, {
278
+ chalk,
279
+ posix: flags.posix,
280
+ style: flags.style,
281
+ decor: flags.decor,
282
+ showSources: flags.showSources,
283
+ });
284
+ const fastSymbol = decorCondition(flags.decor, {
285
+ ifEmoji: '⚡',
286
+ ifNerd: icons['nf-md-lightning_bolt'].value,
287
+ });
288
+ const infoSymbol = decorCondition(flags.decor, {
289
+ ifEmoji: 'ℹ️',
290
+ ifNerd: icons['nf-seti-info'].value,
291
+ postfix: ' ',
292
+ });
293
+ let message = '';
294
+ message += files;
295
+ message += '\n';
296
+ message += `Done in ${time < 2000 ? chalk.yellow(fastSymbol) : ''}${stringTime(time, chalk)}.`;
297
+ message += '\n';
298
+ message += `Listed ${highlight(String(context.fileInfoList.length), chalk)} files.`;
299
+ message += '\n';
300
+ message += `Processed ${highlight(String(context.progress.files), chalk)} files and ${highlight(String(context.progress.directories), chalk)} directories.`;
301
+ message += '\n';
302
+ if (bind.testCommand) {
303
+ message += '\n';
304
+ message += `${chalk.blue(infoSymbol)}You can use ${highlight(`'${bind.testCommand}'`, chalk)} to check if the list is valid.`;
305
+ message += '\n';
306
+ }
307
+ context.message = message;
311
308
  }
312
309
  catch (error) {
313
310
  if (!(error instanceof ViewIgnoredError)) {
@@ -341,7 +338,10 @@ export function actionCfgSet(pair, options) {
341
338
  const chalk = new Chalk();
342
339
  Config.configManager.save();
343
340
  console.log(Config.configManager.getPairString(key, {
344
- chalk, real: options.real, types: options.types, parsable: flags.parsable,
341
+ chalk,
342
+ real: options.real,
343
+ types: options.types,
344
+ parsable: flags.parsable,
345
345
  }));
346
346
  }
347
347
  /**
@@ -355,7 +355,10 @@ export function actionCfgUnset(key, options) {
355
355
  const chalk = new Chalk();
356
356
  Config.configManager.unset(key).save();
357
357
  console.log(Config.configManager.getPairString(key, {
358
- chalk, real: options.real, types: options.types, parsable: flags.parsable,
358
+ chalk,
359
+ real: options.real,
360
+ types: options.types,
361
+ parsable: flags.parsable,
359
362
  }));
360
363
  }
361
364
  /**
@@ -365,6 +368,9 @@ export function actionCfgGet(key, options) {
365
368
  const flags = scanProgram.optsWithGlobals();
366
369
  const chalk = new Chalk();
367
370
  console.log(Config.configManager.getPairString(key, {
368
- chalk, real: options.real, types: options.types, parsable: flags.parsable,
371
+ chalk,
372
+ real: options.real,
373
+ types: options.types,
374
+ parsable: flags.parsable,
369
375
  }));
370
376
  }
package/out/config.d.ts CHANGED
@@ -22,7 +22,10 @@ export declare function isShowSources(value: unknown): value is ShowSourcesType;
22
22
  /**
23
23
  * Represents array with the key nad the value.
24
24
  */
25
- export type ConfigPair<KeyT extends ConfigKey = ConfigKey> = [key: KeyT, value: ConfigValue<KeyT>];
25
+ export type ConfigPair<KeyT extends ConfigKey = ConfigKey> = [
26
+ key: KeyT,
27
+ value: ConfigValue<KeyT>
28
+ ];
26
29
  /**
27
30
  * Command-line configuration structure.
28
31
  * @see {@link configKeyList} Before adding new properties.
package/out/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as os from 'node:os';
2
2
  import path from 'node:path';
3
- import { existsSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
3
+ import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
4
  import { format } from 'node:util';
5
5
  import * as yaml from 'yaml';
6
6
  import { decorNameList, highlight, styleNameList, } from './styling.js';
@@ -81,8 +81,24 @@ export const configValueLiteral = (choices) => {
81
81
  validator.typeName = choices.map(choice => format('%o', choice)).join('|');
82
82
  return validator;
83
83
  };
84
- export const switchTrueValues = ['true', 'on', 'yes', 'y', 'enable', 'enabled', '1'];
85
- export const switchFalseValues = ['false', 'off', 'no', 'n', 'disable', 'disabled', '0'];
84
+ export const switchTrueValues = [
85
+ 'true',
86
+ 'on',
87
+ 'yes',
88
+ 'y',
89
+ 'enable',
90
+ 'enabled',
91
+ '1',
92
+ ];
93
+ export const switchFalseValues = [
94
+ 'false',
95
+ 'off',
96
+ 'no',
97
+ 'n',
98
+ 'disable',
99
+ 'disabled',
100
+ '0',
101
+ ];
86
102
  export const booleanValues = [...switchTrueValues, ...switchFalseValues];
87
103
  export const configValueSwitch = () => {
88
104
  const validator = (value) => {
@@ -136,7 +152,8 @@ export const configValueNumber = () => {
136
152
  };
137
153
  export const configValueInteger = () => {
138
154
  const validator = (value) => {
139
- if (typeof value === 'number' && (Number.isSafeInteger(value) || Math.abs(value) === Infinity)) {
155
+ if (typeof value === 'number'
156
+ && (Number.isSafeInteger(value) || Math.abs(value) === Infinity)) {
140
157
  return;
141
158
  }
142
159
  return 'The value should be an integer.';
@@ -242,7 +259,9 @@ export class ConfigManager {
242
259
  * @returns The error message for each invalid property.
243
260
  */
244
261
  load() {
245
- const parsed = existsSync(this.path) ? yaml.parse(readFileSync(this.path).toString()) : undefined;
262
+ const parsed = existsSync(this.path)
263
+ ? yaml.parse(readFileSync(this.path).toString())
264
+ : undefined;
246
265
  if (parsed === undefined) {
247
266
  return;
248
267
  }
@@ -294,7 +313,9 @@ export class ConfigManager {
294
313
  * @returns An array of properties which defined in the configuration file.
295
314
  */
296
315
  keyList(real = true) {
297
- const keys = real ? [...this.configValidation.keys()] : Object.keys(this.data);
316
+ const keys = real
317
+ ? [...this.configValidation.keys()]
318
+ : Object.keys(this.data);
298
319
  return keys;
299
320
  }
300
321
  get(key, options) {
@@ -332,8 +353,8 @@ export class ConfigManager {
332
353
  const type = this.getType(key);
333
354
  const pad = keyMaxLength - key.length;
334
355
  const line = types
335
- ? format(`${' '.repeat(pad)}%s ${highlight('=', chalk)} %s${highlight(':', chalk)} %s`, (chalk ? chalk.hex('#FFBC42')(key) : key), chalk ? highlight(value, chalk) : value, (chalk ? chalk.dim(highlight(type, chalk)) : type))
336
- : format(`${' '.repeat(pad)}%s ${highlight('=', chalk)} %s`, (chalk ? chalk.hex('#FFBC42')(key) : key), chalk ? highlight(value, chalk) : value);
356
+ ? format(`${' '.repeat(pad)}%s ${highlight('=', chalk)} %s${highlight(':', chalk)} %s`, chalk ? chalk.hex('#FFBC42')(key) : key, chalk ? highlight(value, chalk) : value, chalk ? chalk.dim(highlight(type, chalk)) : type)
357
+ : format(`${' '.repeat(pad)}%s ${highlight('=', chalk)} %s`, chalk ? chalk.hex('#FFBC42')(key) : key, chalk ? highlight(value, chalk) : value);
337
358
  return line;
338
359
  }).join('\n');
339
360
  }
package/out/styling.js CHANGED
@@ -13,9 +13,9 @@ export function highlight(text, chalk) {
13
13
  const rbracketsSquare = /(\[|])/g;
14
14
  const rnumber = /\d+/g;
15
15
  const rspecial = /(true|false|null|Infinity)/g;
16
- const rall = new RegExp(`${[ansiRegex(), rstring, rseparator, rbracketsSquare, rnumber, rspecial]
16
+ const rall = new RegExp([ansiRegex(), rstring, rseparator, rbracketsSquare, rnumber, rspecial]
17
17
  .map(r => `(${typeof r === 'string' ? r : r.source})`)
18
- .join('|')}`, 'g');
18
+ .join('|'), 'g');
19
19
  const colored = text.replaceAll(rall, (match) => {
20
20
  if (match.match(ansiRegex()) !== null) {
21
21
  return match;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};