@ca-plant-list/ca-plant-list 0.1.7 → 0.1.8
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/basepagerenderer.js +1 -1
- package/lib/files.js +34 -2
- package/lib/html.js +3 -4
- package/lib/index.d.ts +27 -0
- package/package.json +10 -5
- package/tsconfig.json +14 -0
package/lib/basepagerenderer.js
CHANGED
@@ -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:
|
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,49 @@
|
|
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
|
+
|
5
17
|
static async fetch( url, targetFileName ) {
|
6
18
|
const response = await fetch( url );
|
7
|
-
const data = await response.
|
8
|
-
|
19
|
+
const data = await response.blob();
|
20
|
+
const buffer = await data.arrayBuffer();
|
21
|
+
fs.writeFileSync( targetFileName, Buffer.from( buffer ) );
|
9
22
|
}
|
10
23
|
|
11
24
|
static read( path ) {
|
12
25
|
return fs.readFileSync( path, "utf8" );
|
13
26
|
}
|
14
27
|
|
28
|
+
static write( path, data ) {
|
29
|
+
if ( fs.existsSync( path ) ) {
|
30
|
+
throw new Error( path + " already exists" );
|
31
|
+
}
|
32
|
+
fs.writeFileSync( path, data );
|
33
|
+
}
|
34
|
+
|
35
|
+
static async zipFileExtract( zipFilePath, fileNameToUnzip, targetFilePath ) {
|
36
|
+
|
37
|
+
const zipDir = await unzipper.Open.file( zipFilePath );
|
38
|
+
for ( const entry of zipDir.files ) {
|
39
|
+
if ( entry.path === fileNameToUnzip ) {
|
40
|
+
await this.createFileFromStream( targetFilePath, entry.stream() );
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
15
47
|
}
|
16
48
|
|
17
49
|
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
|
-
|
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,27 @@
|
|
1
|
+
export class Files {
|
2
|
+
static createFileFromStream(fileName: any, inStream: any): Promise<any>;
|
3
|
+
static fetch(url: any, targetFileName: any): Promise<void>;
|
4
|
+
static read(path: any): string;
|
5
|
+
static write(path: any, data: any): void;
|
6
|
+
static zipFileExtract(zipFilePath: any, fileNameToUnzip: any, targetFilePath: any): Promise<void>;
|
7
|
+
}
|
8
|
+
export namespace HTML_OPTIONS {
|
9
|
+
const OPEN_NEW: number;
|
10
|
+
const NO_ESCAPE: number;
|
11
|
+
}
|
12
|
+
/** HTML utility functions. */
|
13
|
+
export class HTML {
|
14
|
+
static arrayToLI(items: any): any;
|
15
|
+
static escapeAttribute(value: any): any;
|
16
|
+
static escapeText(text: any): any;
|
17
|
+
/**
|
18
|
+
* @deprecated
|
19
|
+
*/
|
20
|
+
static getElement(elName: any, text: any, attributes?: {}, options?: number): string;
|
21
|
+
static "__#2@#getElement"(elName: any, text: any, attributes: any, escape: any): string;
|
22
|
+
static getLink(href: any, linkText: any, attributes?: {}, options?: number): string;
|
23
|
+
static renderAttribute(n: any, v: any): string;
|
24
|
+
static renderAttributes(attributes: any): string;
|
25
|
+
static textElement(elName: any, text: any, attributes?: {}): string;
|
26
|
+
static wrap(elName: any, text: any, attributes?: {}): string;
|
27
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ca-plant-list/ca-plant-list",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.8",
|
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,21 @@
|
|
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
|
+
"./HTML": "./lib/HTML.js"
|
14
15
|
},
|
16
|
+
"types": "./lib/index.d.ts",
|
15
17
|
"bin": {
|
16
18
|
"ca-plant-list": "build-site.js"
|
17
19
|
},
|
18
20
|
"dependencies": {
|
19
21
|
"command-line-args": "^5.2.1",
|
20
|
-
"csv-parse": "^5.3.1"
|
22
|
+
"csv-parse": "^5.3.1",
|
23
|
+
"unzipper": "^0.10.11"
|
21
24
|
},
|
22
25
|
"devDependencies": {
|
23
|
-
"
|
26
|
+
"@types/node": "^18.11.9",
|
27
|
+
"eslint": "^8.26.0",
|
28
|
+
"typescript": "^4.9.3"
|
24
29
|
}
|
25
|
-
}
|
30
|
+
}
|
package/tsconfig.json
ADDED