@hpcc-js/observablehq-compiler 3.7.6 → 3.7.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/LICENSE CHANGED
@@ -1,43 +1,43 @@
1
- HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
14
-
15
-
16
- Intersection Algorithms Provided by Kevin Lindsey
17
- Copyright (c) 2000-2011, Kevin Lindsey
18
- All rights reserved.
19
-
20
- Redistribution and use in source and binary forms, with or without
21
- modification, are permitted provided that the following conditions are met:
22
-
23
- - Redistributions of source code must retain the above copyright notice,
24
- this list of conditions and the following disclaimer.
25
-
26
- - Redistributions in binary form must reproduce the above copyright
27
- notice, this list of conditions and the following disclaimer in the
28
- documentation and/or other materials provided with the distribution.
29
-
30
- - Neither the name of this software nor the names of its contributors
31
- may be used to endorse or promote products derived from this software
32
- without specific prior written permission.
33
-
34
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
35
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
38
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+
16
+ Intersection Algorithms Provided by Kevin Lindsey
17
+ Copyright (c) 2000-2011, Kevin Lindsey
18
+ All rights reserved.
19
+
20
+ Redistribution and use in source and binary forms, with or without
21
+ modification, are permitted provided that the following conditions are met:
22
+
23
+ - Redistributions of source code must retain the above copyright notice,
24
+ this list of conditions and the following disclaimer.
25
+
26
+ - Redistributions in binary form must reproduce the above copyright
27
+ notice, this list of conditions and the following disclaimer in the
28
+ documentation and/or other materials provided with the distribution.
29
+
30
+ - Neither the name of this software nor the names of its contributors
31
+ may be used to endorse or promote products derived from this software
32
+ without specific prior written permission.
33
+
34
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
35
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
38
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,106 +1,106 @@
1
- # @hpcc-js/observablehq-compiler
2
-
3
- An unofficial compiler, interpreter and download tool for [Observable HQ](https://observablehq.com/) notebooks.
4
-
5
- * [Quick Start](#quick-start)
6
- * [Compiler](./src/compiler)
7
- * [Utilities](./src/util)
8
-
9
- ## Quick Start
10
-
11
- This library contains a command line tool (`ojscc`) for downloading and compiling notebooks and an interpreter for rendering notebooks in the browser:
12
- * [Command line interface](#command-line-interface)
13
- * [JS Interpreter](#js-interpreter)
14
-
15
- ## Command line interface
16
-
17
- To call `ojscc` without installing:
18
-
19
- ```sh
20
- npx -p @hpcc-js/observablehq-compiler ojscc [download | compile] ...
21
- ```
22
-
23
- To install `ojscc` as a global command:
24
- ```sh
25
- npm install --global @hpcc-js/observablehq-compiler
26
- ```
27
-
28
- Then it can be called by:
29
- ```sh
30
- ojscc [download | compile] ...
31
- ```
32
-
33
- ### Usage:
34
-
35
- General:
36
- ```sh
37
- ojscc [command]
38
-
39
- Commands:
40
- ojscc download Download ObservableHQ Notebook
41
- ojscc compile Compile ObservableHQ Notebook
42
-
43
- Options:
44
- --version Show version number [boolean]
45
- -h, --help Show help [boolean]
46
- ```
47
-
48
- Download:
49
- ```sh
50
- ojscc download [-o myfile.ojsnb] https://observablehq.com/@user/notebook
51
-
52
- Options:
53
- --version Show version number [boolean]
54
- -h, --help Show help [boolean]
55
- -o, --output Optional output file path
56
- ```
57
-
58
- Compile:
59
- ```sh
60
- ojscc compile [-o myfile.js] myfile.ojsnb
61
-
62
- Options:
63
- --version Show version number [boolean]
64
- -h, --help Show help [boolean]
65
- -o, --output Optional output file path
66
- ```
67
-
68
- ## JS Interpreter
69
-
70
- To install with npm :
71
- ```
72
- npm install --save @hpcc-js/observablehq-compiler
73
- ```
74
-
75
- The interpreter is 100% compatible with:
76
- * [ObservableHQ Runtime](https://github.com/observablehq/runtime)
77
- * [ObservableHQ Inspector](https://github.com/observablehq/inspector)
78
- * [ObservableHQ Library](https://github.com/observablehq/library)
79
-
80
- It also supports fetching notebooks directly from the ObservableHQ repository.
81
-
82
- ```js
83
- import { Library, Runtime, Inspector } from "@observablehq/runtime";
84
- import { download, compile } from "@hpcc-js/observablehq-compiler";
85
-
86
- const placeholder = document.getElementById("placeholder");
87
-
88
- const ohqnb = await download("https://observablehq.com/@observablehq/summary-table");
89
- const compiledNB = await compile(ohqnb);
90
-
91
- const library = new Library();
92
- const runtime = new Runtime(library);
93
- compiledNB(runtime, name => {
94
- const div = document.createElement("div");
95
- placeholder.appendChild(div);
96
- return new Inspector(div);
97
- });
98
- ```
99
-
100
- Which produces (screenshot):
101
-
102
- ---
103
-
104
- ![Sumary Table](./resources/summary-table.png)
105
-
1
+ # @hpcc-js/observablehq-compiler
2
+
3
+ An unofficial compiler, interpreter and download tool for [Observable HQ](https://observablehq.com/) notebooks.
4
+
5
+ * [Quick Start](#quick-start)
6
+ * [Compiler](./src/compiler)
7
+ * [Utilities](./src/util)
8
+
9
+ ## Quick Start
10
+
11
+ This library contains a command line tool (`ojscc`) for downloading and compiling notebooks and an interpreter for rendering notebooks in the browser:
12
+ * [Command line interface](#command-line-interface)
13
+ * [JS Interpreter](#js-interpreter)
14
+
15
+ ## Command line interface
16
+
17
+ To call `ojscc` without installing:
18
+
19
+ ```sh
20
+ npx -p @hpcc-js/observablehq-compiler ojscc [download | compile] ...
21
+ ```
22
+
23
+ To install `ojscc` as a global command:
24
+ ```sh
25
+ npm install --global @hpcc-js/observablehq-compiler
26
+ ```
27
+
28
+ Then it can be called by:
29
+ ```sh
30
+ ojscc [download | compile] ...
31
+ ```
32
+
33
+ ### Usage:
34
+
35
+ General:
36
+ ```sh
37
+ ojscc [command]
38
+
39
+ Commands:
40
+ ojscc download Download ObservableHQ Notebook
41
+ ojscc compile Compile ObservableHQ Notebook
42
+
43
+ Options:
44
+ --version Show version number [boolean]
45
+ -h, --help Show help [boolean]
46
+ ```
47
+
48
+ Download:
49
+ ```sh
50
+ ojscc download [-o myfile.ojsnb] https://observablehq.com/@user/notebook
51
+
52
+ Options:
53
+ --version Show version number [boolean]
54
+ -h, --help Show help [boolean]
55
+ -o, --output Optional output file path
56
+ ```
57
+
58
+ Compile:
59
+ ```sh
60
+ ojscc compile [-o myfile.js] myfile.ojsnb
61
+
62
+ Options:
63
+ --version Show version number [boolean]
64
+ -h, --help Show help [boolean]
65
+ -o, --output Optional output file path
66
+ ```
67
+
68
+ ## JS Interpreter
69
+
70
+ To install with npm :
71
+ ```
72
+ npm install --save @hpcc-js/observablehq-compiler
73
+ ```
74
+
75
+ The interpreter is 100% compatible with:
76
+ * [ObservableHQ Runtime](https://github.com/observablehq/runtime)
77
+ * [ObservableHQ Inspector](https://github.com/observablehq/inspector)
78
+ * [ObservableHQ Library](https://github.com/observablehq/library)
79
+
80
+ It also supports fetching notebooks directly from the ObservableHQ repository.
81
+
82
+ ```js
83
+ import { Library, Runtime, Inspector } from "@observablehq/runtime";
84
+ import { download, compile } from "@hpcc-js/observablehq-compiler";
85
+
86
+ const placeholder = document.getElementById("placeholder");
87
+
88
+ const ohqnb = await download("https://observablehq.com/@observablehq/summary-table");
89
+ const compiledNB = await compile(ohqnb);
90
+
91
+ const library = new Library();
92
+ const runtime = new Runtime(library);
93
+ compiledNB(runtime, name => {
94
+ const div = document.createElement("div");
95
+ placeholder.appendChild(div);
96
+ return new Inspector(div);
97
+ });
98
+ ```
99
+
100
+ Which produces (screenshot):
101
+
102
+ ---
103
+
104
+ ![Sumary Table](./resources/summary-table.png)
105
+
106
106
  ---
package/bin/ojscc.mjs CHANGED
@@ -1,68 +1,68 @@
1
1
  #!/usr/bin/env node
2
- // import fetch, { Headers, Request, Response } from "node-fetch";
3
- // if (!globalThis.fetch) {
4
- // globalThis.fetch = fetch;
5
- // globalThis.Headers = Headers;
6
- // globalThis.Request = Request;
7
- // globalThis.Response = Response;
8
- // }
9
- import { promises as fs } from "fs";
10
- import { compile, download } from "../dist/node/index.js";
11
- import yargsMode from "yargs/yargs";
12
-
13
- async function doDownload(url, filePath) {
14
- const nb = await download(url);
15
- if (filePath) {
16
- await fs.writeFile(filePath, JSON.stringify(nb, undefined, 4));
17
- } else {
18
- console.info(nb);
19
- }
20
- }
21
-
22
- async function doCompile(url, filePath) {
23
- const nb = await download(url);
24
- const define = await compile(nb, process.cwd());
25
- const js = define.toString();
26
- if (filePath) {
27
- await fs.writeFile(filePath, js);
28
- } else {
29
- console.info(js);
30
- }
31
- }
32
-
33
- const yargs = yargsMode(process.argv.slice(2));
34
- yargs
35
- .scriptName("ojscc")
36
- .wrap(Math.min(90, yargs.terminalWidth()))
37
- .demandCommand(1, "You need to provide at least one command...")
38
- .command("download", "Download ObservableHQ Notebook",
39
- function (yargs) {
40
- return yargs
41
- .usage("ojscc download [-o myfile.ojsnb] https://observablehq.com/@user/notebook")
42
- .demandCommand(1, "URL required")
43
- .option("o", {
44
- alias: "output",
45
- describe: "Optional output file path"
46
- });
47
- }, function (argv) {
48
- doDownload(argv._[1], argv.o);
49
- }
50
- )
51
- .command("compile", "Compile ObservableHQ Notebook",
52
- function (yargs) {
53
- return yargs
54
- .usage("ojscc compile [-o myfile.js] myfile.ojsnb")
55
- .demandCommand(1, "URL required")
56
- .option("o", {
57
- alias: "output",
58
- describe: "Optional output file path"
59
- });
60
- },
61
- async function (argv) {
62
- doCompile(argv._[1], argv.o);
63
- }
64
- )
65
- .help("h")
66
- .alias("h", "help")
67
- .epilog("https://github.com/hpcc-systems/Visualization/tree/main/packages/observablehq-compiler")
68
- .parse();
2
+ // import fetch, { Headers, Request, Response } from "node-fetch";
3
+ // if (!globalThis.fetch) {
4
+ // globalThis.fetch = fetch;
5
+ // globalThis.Headers = Headers;
6
+ // globalThis.Request = Request;
7
+ // globalThis.Response = Response;
8
+ // }
9
+ import { promises as fs } from "fs";
10
+ import { compile, download } from "../dist/node/index.js";
11
+ import yargsMode from "yargs/yargs";
12
+
13
+ async function doDownload(url, filePath) {
14
+ const nb = await download(url);
15
+ if (filePath) {
16
+ await fs.writeFile(filePath, JSON.stringify(nb, undefined, 4));
17
+ } else {
18
+ console.info(nb);
19
+ }
20
+ }
21
+
22
+ async function doCompile(url, filePath) {
23
+ const nb = await download(url);
24
+ const define = await compile(nb, process.cwd());
25
+ const js = define.toString();
26
+ if (filePath) {
27
+ await fs.writeFile(filePath, js);
28
+ } else {
29
+ console.info(js);
30
+ }
31
+ }
32
+
33
+ const yargs = yargsMode(process.argv.slice(2));
34
+ yargs
35
+ .scriptName("ojscc")
36
+ .wrap(Math.min(90, yargs.terminalWidth()))
37
+ .demandCommand(1, "You need to provide at least one command...")
38
+ .command("download", "Download ObservableHQ Notebook",
39
+ function (yargs) {
40
+ return yargs
41
+ .usage("ojscc download [-o myfile.ojsnb] https://observablehq.com/@user/notebook")
42
+ .demandCommand(1, "URL required")
43
+ .option("o", {
44
+ alias: "output",
45
+ describe: "Optional output file path"
46
+ });
47
+ }, function (argv) {
48
+ doDownload(argv._[1], argv.o);
49
+ }
50
+ )
51
+ .command("compile", "Compile ObservableHQ Notebook",
52
+ function (yargs) {
53
+ return yargs
54
+ .usage("ojscc compile [-o myfile.js] myfile.ojsnb")
55
+ .demandCommand(1, "URL required")
56
+ .option("o", {
57
+ alias: "output",
58
+ describe: "Optional output file path"
59
+ });
60
+ },
61
+ async function (argv) {
62
+ doCompile(argv._[1], argv.o);
63
+ }
64
+ )
65
+ .help("h")
66
+ .alias("h", "help")
67
+ .epilog("https://github.com/hpcc-systems/Visualization/tree/main/packages/observablehq-compiler")
68
+ .parse();