@ca-plant-list/ca-plant-list 0.2.17 → 0.2.18

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.
@@ -1,35 +1,20 @@
1
1
  import { CommandProcessor } from "./commandprocessor.js";
2
2
  import { TaxaProcessor } from "./taxaprocessor.js";
3
3
 
4
- class GenericTaxaProcessor extends TaxaProcessor {
5
-
6
- #fnCustomProcess;
7
-
8
- constructor( fnCustomProcess, options, taxaLoaderClass ) {
9
- super( options, taxaLoaderClass );
10
- this.#fnCustomProcess = fnCustomProcess;
11
- }
12
-
13
- async customProcess() {
14
- await this.#fnCustomProcess( this );
15
- }
16
-
17
- }
18
-
19
4
  class CommandAndTaxaProcessor extends CommandProcessor {
20
5
 
21
6
  #taxaProcessor;
22
7
 
23
- constructor( commandName, commandDesc, fnCustomProcess, optionDefs = [], optionHelp = [], commandHelp = [], taxaLoaderClass ) {
8
+ constructor( commandName, commandDesc, optionDefs = [], optionHelp = [], commandHelp = [], taxaLoaderClass ) {
24
9
  super( commandName, commandDesc, optionDefs, optionHelp, commandHelp );
25
- this.#taxaProcessor = new GenericTaxaProcessor( fnCustomProcess, this.getOptions(), taxaLoaderClass );
10
+ this.#taxaProcessor = new TaxaProcessor( this.getOptions(), taxaLoaderClass );
26
11
  }
27
12
 
28
- async process() {
13
+ async process( commandRunner ) {
29
14
  if ( this.helpShown() ) {
30
15
  return;
31
16
  }
32
- await this.#taxaProcessor.process();
17
+ await this.#taxaProcessor.process( commandRunner );
33
18
  }
34
19
 
35
20
  }
package/lib/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export class BasePageRenderer {
3
3
  static renderTools(outputDir: any, taxa: any): void;
4
4
  }
5
5
  export class CommandAndTaxaProcessor extends CommandProcessor {
6
- constructor(commandName: any, commandDesc: any, fnCustomProcess: any, optionDefs: any[], optionHelp: any[], commandHelp: any[], taxaLoaderClass: any);
7
- process(): Promise<void>;
6
+ constructor(commandName: any, commandDesc: any, optionDefs: any[], optionHelp: any[], commandHelp: any[], taxaLoaderClass: any);
7
+ process(commandRunner: any): Promise<void>;
8
8
  #private;
9
9
  }
10
10
  import { CommandProcessor } from "./commandprocessor.js";
@@ -156,6 +156,7 @@ export class HTML {
156
156
  static wrap(elName: any, text: any, attributes?: {}): string;
157
157
  }
158
158
  import { BasePageRenderer } from "./basepagerenderer.js";
159
+ import { CommandProcessor } from "./commandprocessor.js";
159
160
  import { CommandAndTaxaProcessor } from "./commandandtaxaprocessor.js";
160
161
  import { Config } from "./config.js";
161
162
  import { CSV } from "./csv.js";
@@ -168,9 +169,11 @@ import { HTML } from "./html.js";
168
169
  import { Jekyll } from "./jekyll.js";
169
170
  import { PlantBook } from "./ebook/plantbook.js";
170
171
  import { Taxa } from "./taxa.js";
172
+ import { TaxaLoader } from "./taxaloader.js";
173
+ import { TaxaProcessor } from "./taxaprocessor.js";
171
174
  import { TAXA_COLNAMES } from "./taxon.js";
172
175
  import { Taxon } from "./taxon.js";
173
- export { BasePageRenderer, CommandAndTaxaProcessor, Config, CSV, ErrorLog, Exceptions, Families, Files, GenericTaxaLoader, HTML, Jekyll, PlantBook, Taxa, TAXA_COLNAMES, Taxon };
176
+ export { BasePageRenderer, CommandProcessor, CommandAndTaxaProcessor, Config, CSV, ErrorLog, Exceptions, Families, Files, GenericTaxaLoader, HTML, Jekyll, PlantBook, Taxa, TaxaLoader, TaxaProcessor, TAXA_COLNAMES, Taxon };
174
177
  export class Jekyll {
175
178
  static getFrontMatter(atts: any): string;
176
179
  static hasInclude(baseDir: any, path: any): boolean;
@@ -247,11 +250,10 @@ import { GenericTaxaLoader } from "./generictaxaloader.js";
247
250
  import { Taxa } from "./taxa.js";
248
251
  export class TaxaProcessor {
249
252
  constructor(options: any, taxaLoaderClass?: typeof TaxaLoader);
250
- customProcess(): Promise<void>;
251
253
  getErrorLog(): any;
252
254
  getOptions(): any;
253
255
  getTaxa(): any;
254
- process(): Promise<void>;
256
+ process(commandRunner: any): Promise<void>;
255
257
  #private;
256
258
  }
257
259
  import { TaxaLoader } from "./taxaloader.js";
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BasePageRenderer } from "./basepagerenderer.js";
2
+ import { CommandProcessor } from "./commandprocessor.js";
2
3
  import { CommandAndTaxaProcessor } from "./commandandtaxaprocessor.js";
3
4
  import { Config } from "./config.js";
4
5
  import { CSV } from "./csv.js";
@@ -11,6 +12,11 @@ import { HTML } from "./html.js";
11
12
  import { Jekyll } from "./jekyll.js";
12
13
  import { PlantBook } from "./ebook/plantbook.js";
13
14
  import { Taxa } from "./taxa.js";
15
+ import { TaxaLoader } from "./taxaloader.js";
16
+ import { TaxaProcessor } from "./taxaprocessor.js";
14
17
  import { Taxon, TAXA_COLNAMES } from "./taxon.js";
15
18
 
16
- export { BasePageRenderer, CommandAndTaxaProcessor, Config, CSV, ErrorLog, Exceptions, Families, Files, GenericTaxaLoader, HTML, Jekyll, PlantBook, Taxa, TAXA_COLNAMES, Taxon };
19
+ export {
20
+ BasePageRenderer, CommandProcessor, CommandAndTaxaProcessor, Config, CSV, ErrorLog, Exceptions, Families, Files,
21
+ GenericTaxaLoader, HTML, Jekyll, PlantBook, Taxa, TaxaLoader, TaxaProcessor, TAXA_COLNAMES, Taxon
22
+ };
@@ -11,10 +11,6 @@ class TaxaProcessor {
11
11
  this.#taxaLoaderClass = taxaLoaderClass;
12
12
  }
13
13
 
14
- async customProcess() {
15
- throw new Error( "must be implemented by subclass" );
16
- }
17
-
18
14
  getErrorLog() {
19
15
  return this.#taxaLoader.getErrorLog();
20
16
  }
@@ -27,11 +23,11 @@ class TaxaProcessor {
27
23
  return this.#taxaLoader.getTaxa();
28
24
  }
29
25
 
30
- async process() {
26
+ async process( commandRunner ) {
31
27
  console.log( "loading data" );
32
28
  this.#taxaLoader = new this.#taxaLoaderClass( this.#options );
33
29
  await this.#taxaLoader.load();
34
- await this.customProcess();
30
+ await commandRunner( this );
35
31
  this.#taxaLoader.writeErrorLog();
36
32
  }
37
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "Tools to create Jekyll files for a website listing plants in an area of California.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,14 +29,10 @@ class BookCommand extends CommandProcessor {
29
29
 
30
30
  }
31
31
 
32
- class BookGenerator extends TaxaProcessor {
33
-
34
- async customProcess() {
35
- const options = this.getOptions();
36
- const ebook = new PlantBook( options.outputdir, new Config( options.datadir ), this.getTaxa() );
37
- await ebook.create();
38
- }
39
-
32
+ async function commandRunner( tp ) {
33
+ const options = tp.getOptions();
34
+ const ebook = new PlantBook( options.outputdir, new Config( options.datadir ), tp.getTaxa() );
35
+ await ebook.create();
40
36
  }
41
37
 
42
38
  async function generateEBooks( options ) {
@@ -54,14 +50,14 @@ async function generateEBooks( options ) {
54
50
  if ( Files.isDir( path ) ) {
55
51
  options.datadir = path;
56
52
  options.outputdir = outputBase + suffix;
57
- const gen = new BookGenerator( options );
58
- await gen.process( options );
53
+ const gen = new TaxaProcessor( options );
54
+ await gen.process( commandRunner );
59
55
  }
60
56
  }
61
57
  } else {
62
58
  // Otherwise use the default directory.
63
- const gen = new BookGenerator( options );
64
- await gen.process( options );
59
+ const gen = new TaxaProcessor( options );
60
+ await gen.process( commandRunner );
65
61
  }
66
62
 
67
63
  }
@@ -52,4 +52,4 @@ async function generateSite( taxaProcessor ) {
52
52
  }
53
53
 
54
54
  const gen = new CommandAndTaxaProcessor( "ca-plant-list", "A tool to generate a website with local plant data.", generateSite );
55
- await gen.process();
55
+ await gen.process( generateSite );
package/lib/dataloader.js DELETED
@@ -1,46 +0,0 @@
1
- import { CSV } from "./csv.js";
2
- import { Taxa } from "./taxa.js";
3
- import { Files } from "./files.js";
4
- import { ErrorLog } from "./errorlog.js";
5
-
6
- class DataLoader {
7
-
8
- static #errorLog = new ErrorLog();
9
-
10
- static getErrorLog() {
11
- return DataLoader.#errorLog;
12
- }
13
-
14
- static load( options ) {
15
-
16
- function getIncludeList( dataDir ) {
17
- // Read inclusion list.
18
- const includeFileName = "taxa_include.csv";
19
- const includeFilePath = dataDir + "/" + includeFileName;
20
- if ( !Files.exists( includeFilePath ) ) {
21
- console.log( includeFilePath + " not found; loading all taxa" );
22
- return true;
23
- }
24
- const includeCSV = CSV.parseFile( dataDir, includeFileName );
25
- const include = {};
26
- for ( const row of includeCSV ) {
27
- include[ row[ "taxon_name" ] ] = row;
28
- }
29
- return include;
30
- }
31
-
32
- const showFlowerErrors = options[ "show-flower-errors" ];
33
-
34
- console.log( "loading data" );
35
-
36
- return new Taxa( getIncludeList( options.datadir ), this.getErrorLog(), showFlowerErrors );
37
-
38
- }
39
-
40
- static writeErrorLog() {
41
- DataLoader.#errorLog.write();
42
- }
43
-
44
- }
45
-
46
- export { DataLoader };