@ca-plant-list/ca-plant-list 0.1.22 → 0.2.1

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/lib/index.d.ts CHANGED
@@ -1,3 +1,50 @@
1
+ export class BasePageRenderer {
2
+ static render(outputDir: any, Taxa: any, familyCols: any): void;
3
+ static renderTools(outputDir: any, Taxa: any): void;
4
+ }
5
+ export class Config {
6
+ static "__#1@#config": {};
7
+ static "__#1@#packageDir": string;
8
+ static getConfigValue(prefix: any, name: any, subcat: any, dflt: any): any;
9
+ static getCountyCodes(): any;
10
+ static getLabel(name: any, dflt: any): any;
11
+ static getPackageDir(): string;
12
+ }
13
+ export class CSV {
14
+ static getMap(dir: any, fileName: any): {};
15
+ static "__#8@#getOptions"(fileName: any, columns: any, delimiter: any): {
16
+ relax_column_count_less: boolean;
17
+ };
18
+ static parseFile(dir: any, fileName: any, columns: boolean, delimiter: any): any;
19
+ static parseStream(dir: any, fileName: any, columns: boolean, delimiter: any, callback: any): Promise<void>;
20
+ }
21
+ export class DataLoader {
22
+ static getOptionDefs(): {
23
+ name: string;
24
+ type: StringConstructor;
25
+ defaultValue: string;
26
+ }[];
27
+ static init(taxaDir: any): void;
28
+ static load(options: any): void;
29
+ }
30
+ export class ErrorLog {
31
+ static "__#7@#errors": any[];
32
+ static log(...args: any[]): void;
33
+ static write(fileName: any): void;
34
+ }
35
+ export class Exceptions {
36
+ static "__#16@#exceptions": {};
37
+ static getExceptions(): [string, any][];
38
+ static getValue(name: any, cat: any, subcat: any, defaultValue: any): any;
39
+ static hasException(name: any, cat: any, subcat: any): boolean;
40
+ static init(dir: any): void;
41
+ }
42
+ export class Families {
43
+ static "__#10@#families": any;
44
+ static getFamily(familyName: any): any;
45
+ static init(): void;
46
+ static renderPages(outputDir: any, taxaColumns: any): void;
47
+ }
1
48
  export class Files {
2
49
  static copyDir(srcDir: any, targetDir: any): void;
3
50
  static createFileFromStream(fileName: any, inStream: any): Promise<any>;
@@ -10,12 +57,35 @@ export class Files {
10
57
  * @returns {Promise<Headers>} The Response headers.
11
58
  */
12
59
  static fetch(url: string | URL, targetFileName: string | undefined, headers?: any): Promise<Headers>;
60
+ static getDirEntries(path: any): string[];
13
61
  static mkdir(path: any): void;
14
62
  static read(path: any): string;
15
63
  static rmDir(dir: any): void;
16
64
  static write(path: any, data: any, overwrite?: boolean): void;
17
65
  static zipFileExtract(zipFilePath: any, fileNameToUnzip: any, targetFilePath: any): Promise<void>;
18
66
  }
67
+ export class Genera {
68
+ static "__#4@#genera": any;
69
+ static addTaxon(taxon: any): void;
70
+ static getGenus(genusName: any): Genus;
71
+ static getFamily(genusName: any): any;
72
+ static init(dataDir: any): void;
73
+ }
74
+ declare class Genus {
75
+ constructor(data: any);
76
+ getTaxa(): any;
77
+ #private;
78
+ }
79
+ export {};
80
+ export class GenericPage {
81
+ constructor(outputDir: any, title: any, baseFileName: any, js: any);
82
+ getBaseFileName(): any;
83
+ getDefaultIntro(): string;
84
+ getOutputDir(): any;
85
+ getTitle(): any;
86
+ writeFile(html: any): void;
87
+ #private;
88
+ }
19
89
  export namespace HTML_OPTIONS {
20
90
  const OPEN_NEW: number;
21
91
  const NO_ESCAPE: number;
@@ -55,8 +125,130 @@ export class HTML {
55
125
  static textElement(elName: any, text: any, attributes?: {}): string;
56
126
  static wrap(elName: any, text: any, attributes?: {}): string;
57
127
  }
128
+ import { BasePageRenderer } from "./basepagerenderer.js";
129
+ import { Config } from "./config.js";
130
+ import { CSV } from "./csv.js";
131
+ import { DataLoader } from "./dataloader.js";
132
+ import { ErrorLog } from "./errorlog.js";
133
+ import { Exceptions } from "./exceptions.js";
134
+ import { Families } from "./families.js";
135
+ import { Files } from "./files.js";
136
+ import { HTML } from "./html.js";
137
+ import { Jekyll } from "./jekyll.js";
138
+ import { PlantBook } from "./ebook/plantbook.js";
139
+ import { Taxa } from "./taxa.js";
140
+ import { TAXA_COLNAMES } from "./taxon.js";
141
+ import { Taxon } from "./taxon.js";
142
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Families, Files, HTML, Jekyll, PlantBook, Taxa, TAXA_COLNAMES, Taxon };
58
143
  export class Jekyll {
59
144
  static hasInclude(baseDir: any, path: any): boolean;
60
145
  static include(path: any): string;
61
146
  static writeInclude(baseDir: any, path: any, data: any): void;
62
147
  }
148
+ export class Jepson {
149
+ static getEFloraLink(id: any): string;
150
+ }
151
+ export class RarePlants {
152
+ static getCESADescription(cesa: any): any;
153
+ static getFESADescription(fesa: any): any;
154
+ static getRPIRankDescription(rank: any): any;
155
+ static getRPIRankAndThreatDescriptions(rank: any): any[];
156
+ }
157
+ export class Taxa {
158
+ static "__#9@#taxa": {};
159
+ static "__#9@#sortedTaxa": any;
160
+ static getHTMLTable(taxa: any, columns?: {
161
+ title: string;
162
+ data: (t: any) => any;
163
+ }[]): string;
164
+ static getTaxa(): any;
165
+ static getTaxon(name: any): any;
166
+ static init(inclusionList: any, taxaMeta?: {}, taxonClass?: typeof Taxon, extraTaxa?: any[], extraSynonyms?: any[]): void;
167
+ static "__#9@#loadSyns"(synCSV: any, inclusionList: any): void;
168
+ static "__#9@#loadTaxa"(taxaCSV: any, inclusionList: any, taxaMeta: any, taxonClass: any): void;
169
+ }
170
+ export namespace TAXA_LIST_COLS {
171
+ namespace CESA {
172
+ const title: string;
173
+ function data(t: any): any;
174
+ }
175
+ namespace COMMON_NAME {
176
+ const title_1: string;
177
+ export { title_1 as title };
178
+ export function data_1(t: any): any;
179
+ export { data_1 as data };
180
+ }
181
+ namespace CNPS_RANK {
182
+ const title_2: string;
183
+ export { title_2 as title };
184
+ export function data_2(t: any): string;
185
+ export { data_2 as data };
186
+ }
187
+ namespace FESA {
188
+ const title_3: string;
189
+ export { title_3 as title };
190
+ export function data_3(t: any): any;
191
+ export { data_3 as data };
192
+ }
193
+ namespace SPECIES {
194
+ const title_4: string;
195
+ export { title_4 as title };
196
+ export function data_4(t: any): any;
197
+ export { data_4 as data };
198
+ }
199
+ namespace SPECIES_BARE {
200
+ const title_5: string;
201
+ export { title_5 as title };
202
+ export function data_5(t: any): any;
203
+ export { data_5 as data };
204
+ }
205
+ }
206
+ import { Taxon } from "./taxon.js";
207
+ export namespace TAXA_COLNAMES {
208
+ const COMMON_NAME: string;
209
+ const FLOWER_COLOR: string;
210
+ }
211
+ export class Taxon {
212
+ constructor(data: any);
213
+ addSynonym(syn: any, type: any): void;
214
+ getBaseFileName(): any;
215
+ getCalfloraName(): any;
216
+ getCalfloraID(): any;
217
+ getCalfloraTaxonLink(): string;
218
+ getCESA(): any;
219
+ getCNDDBRank(): any;
220
+ getCommonNames(): any;
221
+ getFamily(): any;
222
+ getFESA(): any;
223
+ getFileName(ext?: string): string;
224
+ getFlowerColors(): any;
225
+ getGenus(): {
226
+ "__#5@#data": any;
227
+ getTaxa(): any;
228
+ };
229
+ getGenusName(): any;
230
+ getGlobalRank(): any;
231
+ getHTMLLink(href?: boolean, includeRPI?: boolean): string;
232
+ getINatID(): any;
233
+ getINatName(): any;
234
+ getINatSyn(): any;
235
+ getINatTaxonLink(): string;
236
+ getJepsonID(): any;
237
+ getName(): any;
238
+ getRPIID(): any;
239
+ getRPIRank(): any;
240
+ getRPIRankAndThreat(): any;
241
+ getRPIRankAndThreatTooltip(): string;
242
+ getRPITaxonLink(): string;
243
+ getStatus(): any;
244
+ getStatusDescription(): any;
245
+ getSynonyms(): any[];
246
+ isCANative(): boolean;
247
+ /**
248
+ * Determine whether a species is a local native.
249
+ * @returns {boolean} true if taxon is a local native; false if not a CA native, or native elsewhere in CA.
250
+ */
251
+ isNative(): boolean;
252
+ isRare(): boolean;
253
+ #private;
254
+ }
package/lib/index.js CHANGED
@@ -6,9 +6,10 @@ import { ErrorLog } from "./errorlog.js";
6
6
  import { Exceptions } from "./exceptions.js";
7
7
  import { Families } from "./families.js";
8
8
  import { Files } from "./files.js";
9
- import { HTML, HTML_OPTIONS } from "./html.js";
9
+ import { HTML } from "./html.js";
10
10
  import { Jekyll } from "./jekyll.js";
11
+ import { PlantBook } from "./ebook/plantbook.js";
11
12
  import { Taxa } from "./taxa.js";
12
- import { Taxon } from "./taxon.js";
13
+ import { Taxon, TAXA_COLNAMES } from "./taxon.js";
13
14
 
14
- export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Families, Files, HTML, HTML_OPTIONS, Jekyll, Taxa, Taxon };
15
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Families, Files, HTML, Jekyll, PlantBook, Taxa, TAXA_COLNAMES, Taxon };
package/lib/taxa.js CHANGED
@@ -1,9 +1,9 @@
1
+ import { Config } from "./config.js";
1
2
  import { Taxon } from "./taxon.js";
2
3
  import { ErrorLog } from "./errorlog.js";
3
4
  import { HTML } from "./html.js";
4
5
  import { CSV } from "./csv.js";
5
6
  import { RarePlants } from "./rareplants.js";
6
- import { Exceptions } from "./exceptions.js";
7
7
 
8
8
  const TAXA_LIST_COLS = {
9
9
  CESA: {
@@ -75,57 +75,72 @@ class Taxa {
75
75
  return this.#taxa[ name ];
76
76
  }
77
77
 
78
- static init( dataDir ) {
78
+ static init( inclusionList, taxaMeta = {}, taxonClass = Taxon, extraTaxa = [], extraSynonyms = [] ) {
79
+
80
+ const dataDir = Config.getPackageDir() + "/data";
81
+
79
82
  const taxaCSV = CSV.parseFile( dataDir, "taxa.csv" );
80
- for ( const row of taxaCSV ) {
81
- const name = row[ "taxon" ];
82
- const status = row[ "status" ];
83
- const jepsonID = row[ "jepson id" ];
84
- switch ( status ) {
85
- case "N":
86
- case "NC":
87
- case "X": {
88
- if ( this.#taxa[ name ] ) {
89
- ErrorLog.log( name, "has multiple entries" );
90
- }
91
- const commonName = row[ "common name" ];
92
- this.#taxa[ name ] = new Taxon(
93
- name,
94
- commonName,
95
- status,
96
- jepsonID,
97
- row[ "calrecnum" ],
98
- row[ "inat id" ],
99
- row[ "RPI ID" ],
100
- row[ "CRPR" ],
101
- row[ "CESA" ],
102
- row[ "FESA" ]
103
- );
104
- if ( !jepsonID && !Exceptions.hasException( name, "jepson", "badjepsonid" ) ) {
105
- ErrorLog.log( name, "has no Jepson ID" );
106
- }
107
- break;
108
- }
109
- default:
110
- ErrorLog.log( name, "has unrecognized status", status );
83
+ this.#loadTaxa( taxaCSV, inclusionList, taxaMeta, taxonClass );
84
+ this.#loadTaxa( extraTaxa, inclusionList, taxaMeta, taxonClass );
85
+
86
+ // Make sure everything in the inclusionList has been loaded.
87
+ for ( const name of Object.keys( inclusionList ) ) {
88
+ if ( !this.getTaxon( name ) ) {
89
+ ErrorLog.log( name, "not found in taxon list" );
111
90
  }
112
91
  }
113
92
 
114
93
  this.#sortedTaxa = Object.values( this.#taxa ).sort( ( a, b ) => a.getName().localeCompare( b.getName() ) );
115
94
 
116
95
  const synCSV = CSV.parseFile( dataDir, "synonyms.csv" );
96
+ this.#loadSyns( synCSV, inclusionList );
97
+ this.#loadSyns( extraSynonyms, inclusionList );
98
+
99
+ }
100
+
101
+ static #loadSyns( synCSV, inclusionList ) {
117
102
  for ( const syn of synCSV ) {
118
103
  const currName = syn[ "Current" ];
119
104
  const taxon = this.getTaxon( currName );
120
105
  if ( !taxon ) {
121
- ErrorLog.log( currName, "has synonym but not in taxa.csv" );
106
+ if ( inclusionList === true ) {
107
+ // If including all taxa, note the error.
108
+ console.log( "synonym target not found: " + currName );
109
+ }
122
110
  continue;
123
111
  }
124
112
  taxon.addSynonym( syn[ "Former" ], syn[ "Type" ] );
125
113
  }
114
+ }
115
+
116
+ static #loadTaxa( taxaCSV, inclusionList, taxaMeta, taxonClass ) {
117
+ for ( const row of taxaCSV ) {
118
+
119
+ const name = row[ "taxon_name" ];
120
+
121
+ let taxon_overrides = {};
122
+ if ( inclusionList !== true ) {
123
+ taxon_overrides = inclusionList[ name ];
124
+ if ( !taxon_overrides ) {
125
+ continue;
126
+ }
127
+ }
128
+
129
+ if ( this.#taxa[ name ] ) {
130
+ ErrorLog.log( name, "has multiple entries" );
131
+ }
132
+
133
+ const status = taxon_overrides[ "status" ];
134
+ if ( status !== undefined ) {
135
+ row[ "status" ] = status;
136
+ }
137
+ this.#taxa[ name ] = new taxonClass( row, taxaMeta[ name ] );
138
+
139
+ }
126
140
 
127
141
  }
128
142
 
143
+
129
144
  }
130
145
 
131
146
  export { Taxa, TAXA_LIST_COLS };
package/lib/taxon.js CHANGED
@@ -3,6 +3,11 @@ import { Genera } from "./genera.js";
3
3
  import { HTML } from "./html.js";
4
4
  import { RarePlants } from "./rareplants.js";
5
5
 
6
+ const TAXA_COLNAMES = {
7
+ COMMON_NAME: "common name",
8
+ FLOWER_COLOR: "flower_color",
9
+ };
10
+
6
11
  class Taxon {
7
12
 
8
13
  #name;
@@ -14,6 +19,7 @@ class Taxon {
14
19
  #cfSyn;
15
20
  #iNatID;
16
21
  #iNatSyn;
22
+ #flowerColors;
17
23
  #rpiID;
18
24
  #rankRPI;
19
25
  #cesa;
@@ -22,16 +28,24 @@ class Taxon {
22
28
  #rankGlobal;
23
29
  #synonyms = [];
24
30
 
25
- constructor( name, commonNames, status, jepsonID, calRecNum, iNatID, rpiID, rankRPI, cesa, fesa, rankCNDDB, rankGlobal ) {
31
+ constructor( data ) {
32
+ const name = data[ "taxon_name" ];
33
+ const commonNames = data[ TAXA_COLNAMES.COMMON_NAME ];
34
+ const cesa = data[ "CESA" ];
35
+ const fesa = data[ "FESA" ];
36
+ const rankGlobal = data[ "GRank" ];
37
+ const rankCNDDB = data[ "SRank" ];
26
38
  this.#name = name;
27
39
  this.#genus = name.split( " " )[ 0 ];
28
40
  this.#commonNames = commonNames ? commonNames.split( "," ).map( t => t.trim() ) : [];
29
- this.#status = status;
30
- this.#jepsonID = jepsonID;
31
- this.#calRecNum = calRecNum;
32
- this.#iNatID = iNatID;
33
- this.#rpiID = rpiID;
34
- this.#rankRPI = rankRPI;
41
+ this.#status = data[ "status" ];
42
+ this.#jepsonID = data[ "jepson id" ];
43
+ this.#calRecNum = data[ "calrecnum" ];
44
+ this.#iNatID = data[ "inat id" ];
45
+ const colors = data[ TAXA_COLNAMES.FLOWER_COLOR ];
46
+ this.#flowerColors = colors ? colors.split( "," ) : undefined;
47
+ this.#rpiID = data[ "RPI ID" ];
48
+ this.#rankRPI = data[ "CRPR" ];
35
49
  this.#cesa = cesa ? cesa : undefined;
36
50
  this.#fesa = fesa ? fesa : undefined;
37
51
  this.#rankCNDDB = rankCNDDB ? rankCNDDB : undefined;
@@ -102,6 +116,10 @@ class Taxon {
102
116
  return this.getBaseFileName() + "." + ext;
103
117
  }
104
118
 
119
+ getFlowerColors() {
120
+ return this.#flowerColors;
121
+ }
122
+
105
123
  getGenus() {
106
124
  return Genera.getGenus( this.#genus );
107
125
  }
@@ -224,4 +242,4 @@ class Taxon {
224
242
 
225
243
  }
226
244
 
227
- export { Taxon };
245
+ export { TAXA_COLNAMES, Taxon };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.1.22",
3
+ "version": "0.2.1",
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": {
@@ -18,12 +18,18 @@
18
18
  },
19
19
  "types": "./lib/index.d.ts",
20
20
  "bin": {
21
- "ca-plant-list": "build-site.js"
21
+ "ca-plant-list": "scripts/build-site.js",
22
+ "ca-plant-book": "scripts/build-ebook.js"
22
23
  },
23
24
  "dependencies": {
25
+ "@ca-plant-list/tools": "file:../ca-tools",
26
+ "archiver": "^5.3.1",
24
27
  "command-line-args": "^5.2.1",
25
28
  "command-line-usage": "^6.1.3",
26
29
  "csv-parse": "^5.3.1",
30
+ "image-size": "^1.0.2",
31
+ "markdown-it": "^13.0.1",
32
+ "sharp": "^0.32.1",
27
33
  "unzipper": "^0.10.11"
28
34
  },
29
35
  "devDependencies": {
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+
3
+ import commandLineArgs from "command-line-args";
4
+ import { PlantBook } from "@ca-plant-list/ca-plant-list";
5
+ import { DataLoader } from "../lib/dataloader.js";
6
+
7
+ const options = commandLineArgs( DataLoader.getOptionDefs() );
8
+
9
+ DataLoader.load( options );
10
+
11
+ const ebook = new PlantBook();
12
+ await ebook.create();
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { DataLoader } from "./lib/dataloader.js";
4
- import { ErrorLog } from "./lib/errorlog.js";
5
- import { PageRenderer } from "./lib/pagerenderer.js";
3
+ import { DataLoader } from "../lib/dataloader.js";
4
+ import { ErrorLog } from "../lib/errorlog.js";
5
+ import { PageRenderer } from "../lib/pagerenderer.js";
6
6
  import commandLineArgs from "command-line-args";
7
7
 
8
8
  const options = commandLineArgs( DataLoader.getOptionDefs() );
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- // Change this to match your project
3
- "files": [
4
- "lib/index.js",
5
- ],
6
- "compilerOptions": {
7
- "allowJs": true,
8
- "declaration": true,
9
- "emitDeclarationOnly": true,
10
- "outDir": "output",
11
- "module": "es6",
12
- "newLine": "lf"
13
- }
14
- }