@cenk1cenk2/oclif-common 1.7.2 → 1.9.0

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/dist/index.d.ts CHANGED
@@ -205,14 +205,14 @@ declare class FileSystemService {
205
205
  readSync(file: string): string;
206
206
  write(file: string, data: string | Buffer, options?: fs.WriteFileOptions): Promise<void>;
207
207
  writeSync(file: string, data: string | Buffer, options?: fs.WriteFileOptions): void;
208
- append(file: string, data: string | Buffer): Promise<void>;
208
+ append(file: string, data: string | Buffer, options?: fs.WriteFileOptions): Promise<void>;
209
209
  appendSync(file: string, data: string | Buffer): void;
210
- remove(file: string): Promise<void>;
211
- removeSync(file: string): void;
212
- removeFile(file: string): Promise<void>;
213
- removeFileSync(file: string): void;
214
- removeDirectory(directory: string): Promise<void>;
215
- removeDirectorySync(directory: string): void;
210
+ remove(file: string, options?: fs.RmOptions): Promise<void>;
211
+ removeSync(file: string, options?: fs.RmOptions): void;
212
+ emptyDir(directory: string): Promise<void>;
213
+ emptyDirSync(directory: string): void;
214
+ mkdir(directory: string): Promise<void>;
215
+ mkdirSync(directory: string): void;
216
216
  }
217
217
 
218
218
  interface ValidatorServiceOptions {
package/dist/index.js CHANGED
@@ -505,8 +505,7 @@ var FileSystemService = class {
505
505
  const raw = await import_fs_extra.default.readFile(file, "utf-8");
506
506
  return raw;
507
507
  } catch (e) {
508
- this.logger.fatal('Error while reading file from "%s": %s', file, e.message);
509
- throw e;
508
+ throw new Error(`Error while reading file from "${file}": ${e.message}`);
510
509
  }
511
510
  }
512
511
  readSync(file) {
@@ -514,106 +513,77 @@ var FileSystemService = class {
514
513
  const raw = import_fs_extra.default.readFileSync(file, "utf-8");
515
514
  return raw;
516
515
  } catch (e) {
517
- this.logger.fatal('Error while reading file from "%s": %s', file, e.message);
518
- throw e;
516
+ throw new Error(`Error while reading file from "${file}": ${e.message}`);
519
517
  }
520
518
  }
521
519
  async write(file, data, options = {}) {
522
520
  try {
523
521
  await import_fs_extra.default.writeFile(file, data, { encoding: "utf-8", ...options });
524
522
  } catch (e) {
525
- this.logger.fatal('Error while writing file to "%s": %s', file, e.message);
526
- throw e;
523
+ throw new Error(`Error while writing file to "${file}": ${e.message}`);
527
524
  }
528
525
  }
529
526
  writeSync(file, data, options = {}) {
530
527
  try {
531
528
  import_fs_extra.default.writeFileSync(file, data, { encoding: "utf-8", ...options });
532
529
  } catch (e) {
533
- this.logger.fatal('Error while writing file to "%s": %s', file, e.message);
534
- throw e;
530
+ throw new Error(`Error while writing file to "${file}": ${e.message}`);
535
531
  }
536
532
  }
537
- async append(file, data) {
533
+ async append(file, data, options) {
538
534
  try {
539
- await import_fs_extra.default.appendFile(file, data);
535
+ await import_fs_extra.default.appendFile(file, data, options);
540
536
  } catch (e) {
541
- this.logger.fatal('Error while appending file to "%s": %s', file, e.message);
542
- throw e;
537
+ throw new Error(`Error while appending to file "${file}": ${e.message}`);
543
538
  }
544
539
  }
545
540
  appendSync(file, data) {
546
541
  try {
547
542
  import_fs_extra.default.appendFileSync(file, data);
548
543
  } catch (e) {
549
- this.logger.fatal('Error while appending file to "%s": %s', file, e.message);
550
- throw e;
544
+ throw new Error(`Error while appending to file "${file}": ${e.message}`);
551
545
  }
552
546
  }
553
- async remove(file) {
554
- const stats = this.stats(file);
555
- if (stats.isFile()) {
556
- return this.removeFile(file);
557
- } else if (stats.isDirectory()) {
558
- return this.removeDirectory(file);
547
+ async remove(file, options) {
548
+ try {
549
+ await import_fs_extra.default.rm(file, options);
550
+ } catch (e) {
551
+ throw new Error(`Error while deleting the file "${file}": ${e.message}`);
559
552
  }
560
- throw new Error("Not implemented!");
561
- }
562
- removeSync(file) {
563
- const stats = this.stats(file);
564
- if (stats.isFile()) {
565
- return this.removeFileSync(file);
566
- } else if (stats.isDirectory()) {
567
- return this.removeDirectorySync(file);
553
+ }
554
+ removeSync(file, options) {
555
+ try {
556
+ import_fs_extra.default.rmSync(file, options);
557
+ } catch (e) {
558
+ throw new Error(`Error while deleting the file "${file}": ${e.message}`);
568
559
  }
569
- throw new Error("Not implemented!");
570
560
  }
571
- async removeFile(file) {
561
+ async emptyDir(directory) {
572
562
  try {
573
- if (this.stats(file).isFile()) {
574
- await import_fs_extra.default.unlink(file);
575
- } else {
576
- throw new Error("Not a file.");
577
- }
563
+ await import_fs_extra.default.emptyDir(directory);
578
564
  } catch (e) {
579
- this.logger.fatal('Error while deleting file from "%s": %s', file, e.message);
580
- throw e;
565
+ throw new Error(`Error while deleting the directory "${directory}": ${e.message}`);
581
566
  }
582
567
  }
583
- removeFileSync(file) {
568
+ emptyDirSync(directory) {
584
569
  try {
585
- if (this.stats(file).isFile()) {
586
- import_fs_extra.default.unlinkSync(file);
587
- } else {
588
- throw new Error("Not a file.");
589
- }
570
+ import_fs_extra.default.emptyDirSync(directory);
590
571
  } catch (e) {
591
- this.logger.fatal('Error while deleting file from "%s": %s', file, e.message);
592
- throw e;
572
+ throw new Error(`Error while deleting the directory "${directory}": ${e.message}`);
593
573
  }
594
574
  }
595
- async removeDirectory(directory) {
575
+ async mkdir(directory) {
596
576
  try {
597
- if (this.stats(directory).isDirectory()) {
598
- await import_fs_extra.default.emptyDir(directory);
599
- } else {
600
- throw new Error("Not a folder.");
601
- }
577
+ await import_fs_extra.default.mkdirp(directory);
602
578
  } catch (e) {
603
- this.logger.fatal('Error while deleting directory from "%s": %s', directory, e.message);
604
- throw e;
579
+ throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
605
580
  }
606
581
  }
607
- removeDirectorySync(directory) {
582
+ mkdirSync(directory) {
608
583
  try {
609
- if (this.stats(directory).isDirectory()) {
610
- import_fs_extra.default.emptyDirSync(directory);
611
- } else {
612
- throw new Error("Not a folder.");
613
- }
584
+ import_fs_extra.default.mkdirSync(directory);
614
585
  } catch (e) {
615
- this.logger.fatal('Error while deleting directory from "%s": %s', directory, e.message);
616
- throw e;
586
+ throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
617
587
  }
618
588
  }
619
589
  };
@@ -670,7 +640,7 @@ function isVerbose(config2) {
670
640
  return config2.loglevel === "VERBOSE" /* VERBOSE */;
671
641
  }
672
642
  function isDebug(config2) {
673
- return config2.loglevel === "DEBUG" /* DEBUG */;
643
+ return ["DEBUG" /* DEBUG */, "TRACE" /* TRACE */].includes(config2.loglevel);
674
644
  }
675
645
  function isSilent(config2) {
676
646
  return config2.loglevel === "SILENT" /* SILENT */;
@@ -707,7 +677,6 @@ var ConfigService = class {
707
677
  } else {
708
678
  ConfigService.instance = this;
709
679
  }
710
- process.env.SUPPRESS_NO_CONFIG_WARNING = "1";
711
680
  this.command = command.ctor;
712
681
  this.oclif = command.config;
713
682
  this.config = import_config.default.util.loadFileConfigs(this.dir);
@@ -887,32 +856,33 @@ var ValidatorService = class {
887
856
 
888
857
  // src/lib/setup.ts
889
858
  function setup() {
890
- const trace = process.argv.indexOf("--trace");
891
- const debug = process.argv.indexOf("--debug");
892
- const silent = process.argv.indexOf("--silent");
859
+ process.env.SUPPRESS_NO_CONFIG_WARNING = "1";
893
860
  const inspect = process.argv.indexOf("--inspect");
894
- const sourceMaps = process.argv.indexOf("--source-map");
895
- const verbose = process.argv.indexOf("--verbose");
896
861
  if (inspect !== -1) {
897
862
  require("inspector").open();
898
863
  process.argv.splice(inspect, 1);
899
864
  }
865
+ const verbose = process.argv.indexOf("--verbose");
900
866
  if (verbose !== -1) {
901
867
  process.env.LOG_LEVEL = "verbose";
902
868
  process.argv.splice(verbose, 1);
903
869
  }
870
+ const debug = process.argv.indexOf("--debug");
904
871
  if (debug !== -1) {
905
872
  process.env.LOG_LEVEL = "debug";
906
873
  process.argv.splice(debug, 1);
907
874
  }
875
+ const trace = process.argv.indexOf("--trace");
908
876
  if (trace !== -1) {
909
877
  process.env.LOG_LEVEL = "trace";
910
878
  process.argv.splice(trace, 1);
911
879
  }
880
+ const silent = process.argv.indexOf("--silent");
912
881
  if (silent !== -1) {
913
882
  process.env.LOG_LEVEL = "silent";
914
883
  process.argv.splice(silent, 1);
915
884
  }
885
+ const sourceMaps = process.argv.indexOf("--source-map");
916
886
  if (sourceMaps !== -1) {
917
887
  require("source-map-support").install();
918
888
  process.argv.splice(sourceMaps, 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "1.7.2",
3
+ "version": "1.9.0",
4
4
  "description": "Oclif common package for oclif2 projects.",
5
5
  "repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
6
6
  "author": {