@ca-plant-list/ca-plant-list 0.1.7 → 0.1.9

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.
@@ -7,7 +7,7 @@ class BasePageRenderer {
7
7
  static render( outputDir, Taxa ) {
8
8
 
9
9
  // Copy static files
10
- fs.rmSync( outputDir, { force: true, recursive: true, maxRetries: 2, retryDelay: 400 } );
10
+ fs.rmSync( outputDir, { force: true, recursive: true, maxRetries: 2, retryDelay: 1000 } );
11
11
  // First copy default Jekyll files from package.
12
12
  fs.cpSync( Config.getPackageDir() + "/jekyll", outputDir, { recursive: true } );
13
13
  // Then copy Jekyll files from current dir (which may override default files).
package/lib/files.js CHANGED
@@ -1,17 +1,53 @@
1
1
  import * as fs from "node:fs";
2
+ import { default as unzipper } from "unzipper";
2
3
 
3
4
  class Files {
4
5
 
6
+ static createFileFromStream( fileName, inStream ) {
7
+
8
+ function implementation( fileName, inStream, resolve ) {
9
+ const outStream = fs.createWriteStream( fileName );
10
+ outStream.on( "finish", () => { resolve( true ); } );
11
+ inStream.pipe( outStream );
12
+ }
13
+
14
+ return new Promise( ( resolve ) => { implementation( fileName, inStream, resolve ); } );
15
+ }
16
+
17
+ static exists( path ) {
18
+ return fs.existsSync( path );
19
+ }
20
+
5
21
  static async fetch( url, targetFileName ) {
6
22
  const response = await fetch( url );
7
- const data = await response.text();
8
- fs.writeFileSync( targetFileName, data );
23
+ const data = await response.blob();
24
+ const buffer = await data.arrayBuffer();
25
+ fs.writeFileSync( targetFileName, Buffer.from( buffer ) );
9
26
  }
10
27
 
11
28
  static read( path ) {
12
29
  return fs.readFileSync( path, "utf8" );
13
30
  }
14
31
 
32
+ static write( path, data ) {
33
+ if ( this.exists( path ) ) {
34
+ throw new Error( path + " already exists" );
35
+ }
36
+ fs.writeFileSync( path, data );
37
+ }
38
+
39
+ static async zipFileExtract( zipFilePath, fileNameToUnzip, targetFilePath ) {
40
+
41
+ const zipDir = await unzipper.Open.file( zipFilePath );
42
+ for ( const entry of zipDir.files ) {
43
+ if ( entry.path === fileNameToUnzip ) {
44
+ await this.createFileFromStream( targetFilePath, entry.stream() );
45
+ break;
46
+ }
47
+ }
48
+
49
+ }
50
+
15
51
  }
16
52
 
17
53
  export { Files };
package/lib/html.js CHANGED
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * @deprecated
3
3
  */
4
- const HTML_OPTIONS = {
4
+ export const HTML_OPTIONS = {
5
5
  OPEN_NEW: 1,
6
6
  NO_ESCAPE: 2,
7
7
  };
8
8
 
9
- class HTML {
9
+ /** HTML utility functions. */
10
+ export class HTML {
10
11
 
11
12
  static arrayToLI( items ) {
12
13
  return items.reduce( ( itemHTML, currVal ) => itemHTML + "<li>" + currVal + "</li>", "" );
@@ -77,5 +78,3 @@ class HTML {
77
78
  }
78
79
 
79
80
  }
80
-
81
- export { HTML, HTML_OPTIONS };
package/lib/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ export class Files {
2
+ static createFileFromStream(fileName: any, inStream: any): Promise<any>;
3
+ static exists(path: any): boolean;
4
+ static fetch(url: any, targetFileName: any): Promise<void>;
5
+ static read(path: any): string;
6
+ static write(path: any, data: any): void;
7
+ static zipFileExtract(zipFilePath: any, fileNameToUnzip: any, targetFilePath: any): Promise<void>;
8
+ }
9
+ export namespace HTML_OPTIONS {
10
+ const OPEN_NEW: number;
11
+ const NO_ESCAPE: number;
12
+ }
13
+ /** HTML utility functions. */
14
+ export class HTML {
15
+ static arrayToLI(items: any): any;
16
+ static escapeAttribute(value: any): any;
17
+ static escapeText(text: any): any;
18
+ /**
19
+ * @deprecated
20
+ */
21
+ static getElement(elName: any, text: any, attributes?: {}, options?: number): string;
22
+ static "__#2@#getElement"(elName: any, text: any, attributes: any, escape: any): string;
23
+ static getLink(href: any, linkText: any, attributes?: {}, options?: number): string;
24
+ static renderAttribute(n: any, v: any): string;
25
+ static renderAttributes(attributes: any): string;
26
+ static textElement(elName: any, text: any, attributes?: {}): string;
27
+ static wrap(elName: any, text: any, attributes?: {}): string;
28
+ }
29
+ export class Jekyll {
30
+ static hasInclude(baseDir: any, path: any): boolean;
31
+ static include(path: any): string;
32
+ }
package/lib/index.js CHANGED
@@ -6,7 +6,8 @@ import { ErrorLog } from "./errorlog.js";
6
6
  import { Exceptions } from "./exceptions.js";
7
7
  import { Files } from "./files.js";
8
8
  import { HTML, HTML_OPTIONS } from "./html.js";
9
+ import { Jekyll } from "./jekyll.js";
9
10
  import { Taxa } from "./taxa.js";
10
11
  import { Taxon } from "./taxon.js";
11
12
 
12
- export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Files, HTML, HTML_OPTIONS, Taxa, Taxon };
13
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Files, HTML, HTML_OPTIONS, Jekyll, Taxa, Taxon };
package/lib/jekyll.js ADDED
@@ -0,0 +1,15 @@
1
+ import { Files } from "./files.js";
2
+
3
+ class Jekyll {
4
+
5
+ static hasInclude( baseDir, path ) {
6
+ return Files.exists( baseDir + "/_includes/" + path );
7
+ }
8
+
9
+ static include( path ) {
10
+ return "{%include " + path + "%}";
11
+ }
12
+
13
+ }
14
+
15
+ export { Jekyll };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
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": {
@@ -10,16 +10,23 @@
10
10
  "homepage": "https://github.com/ca-plants/ca-plant-list",
11
11
  "type": "module",
12
12
  "exports": {
13
- ".": "./lib/index.js"
13
+ ".": "./lib/index.js",
14
+ "./Files": "./lib/files.js",
15
+ "./HTML": "./lib/html.js",
16
+ "./Jekyll": "./lib/jekyll.js"
14
17
  },
18
+ "types": "./lib/index.d.ts",
15
19
  "bin": {
16
20
  "ca-plant-list": "build-site.js"
17
21
  },
18
22
  "dependencies": {
19
23
  "command-line-args": "^5.2.1",
20
- "csv-parse": "^5.3.1"
24
+ "csv-parse": "^5.3.1",
25
+ "unzipper": "^0.10.11"
21
26
  },
22
27
  "devDependencies": {
23
- "eslint": "^8.26.0"
28
+ "@types/node": "^18.11.9",
29
+ "eslint": "^8.26.0",
30
+ "typescript": "^4.9.3"
24
31
  }
25
32
  }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
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
+ }