canvasxpress-cli 63.1.1 → 63.3.0

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/cmds/help.js CHANGED
@@ -22,7 +22,7 @@ const menus = {
22
22
  --graph, -g ........ [optional] graph name
23
23
  --number, -n ....... [optional] number for the graph
24
24
  --timeout, -t ...... [optional] timeout in millisecods to close browser
25
- {default} 500
25
+ {default} 2500
26
26
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
27
27
 
28
28
  Examples:
@@ -46,7 +46,7 @@ const menus = {
46
46
  --data, -d ......... [optional - required] json string with the data for CanvasXpress
47
47
  --config, -c ....... [optional] json string with configuration for CanvasXpress
48
48
  --timeout, -t ...... [optional] timeout in millisecods to close browser
49
- {default} 500
49
+ {default} 2500
50
50
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
51
51
 
52
52
  Examples:
@@ -68,7 +68,7 @@ const menus = {
68
68
  --output, -o ....... [optional] directory path to save image
69
69
  {default} './'
70
70
  --timeout, -t ...... [optional] timeout in millisecods to close browser
71
- {default} 500
71
+ {default} 2500
72
72
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
73
73
 
74
74
  Examples:
@@ -92,10 +92,9 @@ const menus = {
92
92
  --height, -y ....... [optional] integer for image height
93
93
  {default} 800
94
94
  --data, -d ......... [optional - required] json string with the data for CanvasXpress
95
- --config, -c ....... [optional] json string with configuration for CanvasXpress --timeout, -t ...... [optional] timeout in millisecods to close browser
96
- {default} 500
95
+ --config, -c ....... [optional] json string with configuration for CanvasXpress
97
96
  --timeout, -t ...... [optional] timeout in millisecods to close browser
98
- {default} 500
97
+ {default} 2500
99
98
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
100
99
 
101
100
  Examples:
@@ -124,7 +123,7 @@ const menus = {
124
123
  --data, -d ......... [optional - required] json string with the data for CanvasXpress
125
124
  --config, -c ....... [optional] json string with configuration for CanvasXpress
126
125
  --timeout, -t ...... [optional] timeout in millisecods to close browser
127
- {default} 500
126
+ {default} 2500
128
127
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
129
128
 
130
129
  Examples:
@@ -153,7 +152,7 @@ const menus = {
153
152
  --data, -d ......... [optional - required] json string with the data for CanvasXpress
154
153
  --config, -c ....... [optional] json string with configuration for CanvasXpress
155
154
  --timeout, -t ...... [optional] timeout in millisecods to close browser
156
- {default} 500
155
+ {default} 2500
157
156
  --browser, -b ...... [optional] boolean to do not run headless and pause for debugging
158
157
 
159
158
  Examples:
package/cmds/io.js CHANGED
@@ -2,7 +2,7 @@ const util = require('util');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
  const ora = require('ora');
5
- const puppeteer = require('puppeteer');
5
+ const { chromium } = require('playwright');
6
6
 
7
7
  module.exports = async (obj) => {
8
8
 
@@ -30,39 +30,31 @@ module.exports = async (obj) => {
30
30
 
31
31
  try {
32
32
 
33
- const browser = await puppeteer.launch({
33
+ const browser = await chromium.launch({
34
34
  headless: obj.debug ? false : true,
35
35
  devtools: obj.debug ? true : false,
36
- executablePath: puppeteer.executablePath(),
37
- defaultViewport: {
38
- width: 1000,
39
- height: 1000
40
- },
41
36
  args: ['--no-sandbox',
42
37
  '--allow-file-access-from-files',
43
38
  '--enable-local-file-accesses']
44
39
  });
45
40
 
46
- const page = await browser.newPage();
41
+ const context = await browser.newContext({
42
+ viewport: { width: 1000, height: 1000 }
43
+ });
47
44
 
48
- // Print All
49
- //page.on("console", (consoleObj) => console.log(consoleObj.text()));
45
+ const page = await context.newPage();
50
46
 
51
- // Print All except warnings
52
- page.on('console', consoleObj => {
53
- if (consoleObj.type() !== 'warning') {
54
- console.log(consoleObj.text());
55
- }
47
+ const downloadDir = path.resolve(obj.output);
48
+ const downloads = [];
49
+ page.on('download', (dl) => {
50
+ downloads.push(dl.saveAs(path.join(downloadDir, dl.suggestedFilename())));
56
51
  });
57
52
 
58
- /*
59
- // Print only logs
60
53
  page.on('console', consoleObj => {
61
- if (consoleObj.type() === 'log') {
62
- console.log(consoleObj.text());
54
+ if (consoleObj.type() !== 'warning') {
55
+ console.log(consoleObj.text());
63
56
  }
64
57
  });
65
- */
66
58
 
67
59
  if (obj.input && !obj.input.match(/^file|^http/)) {
68
60
  obj.input = "file://" + path.resolve(obj.input);
@@ -107,7 +99,7 @@ module.exports = async (obj) => {
107
99
  cx.dataURL = obj.input;
108
100
  cx.remoteTransitionEffect = 'none';
109
101
  cx.getDataFromURLOrString(obj.target || cx.target, obj.config, false, false, clbk);
110
- } else {
102
+ } else {
111
103
  console.log("Creating " + (obj.cmd == 'csv' ? 'png' : obj.cmd) + " file from " + (obj.input ? obj.input : 'input data') + " (" + obj.output + (obj.target || cx.target) + "." + obj.cmd + ")");
112
104
  exec(cx, obj.target || cx.target);
113
105
  }
@@ -128,25 +120,32 @@ module.exports = async (obj) => {
128
120
  }
129
121
  }
130
122
 
131
- await page._client.send('Page.setDownloadBehavior', {
132
- behavior: 'allow',
133
- downloadPath: obj.output
134
- });
123
+ const targetUrl = obj.input
124
+ ? (obj.cmd == 'csv' ? defhtml : obj.cmd == 'reproduce' ? obj.input + '?showTransition=false' : obj.input)
125
+ : defhtml;
135
126
 
136
- if (obj.input) {
137
- await page.goto(obj.cmd == 'csv' ? defhtml : obj.cmd == 'reproduce' ? obj.input + '?showTransition=false' : obj.input);
138
- } else {
139
- await page.goto(defhtml);
140
- }
127
+ await page.goto(targetUrl, { waitUntil: 'networkidle' });
128
+
129
+ await page.waitForFunction(() => typeof CanvasXpress !== 'undefined');
141
130
 
142
- await page.waitFor(() => typeof (CanvasXpress) !== undefined && CanvasXpress.ready);
131
+ // Create a CX instance if one doesn't already exist (onReady in template
132
+ // has a circular dependency that prevents auto-instantiation in headless)
133
+ await page.evaluate(() => {
134
+ if (!CanvasXpress.instances || CanvasXpress.instances.length === 0) {
135
+ new CanvasXpress("cX", {y:{vars:["V"],smps:["S"],data:[[0]]}}, {});
136
+ }
137
+ });
138
+ await page.waitForFunction(() => CanvasXpress.ready);
143
139
 
144
140
  await page.evaluate(`(${func.toString()})(${JSON.stringify(obj)})`);
145
141
 
146
- await setTimeout(() => {
147
- browser.close();
148
- spinner.stop();
149
- }, obj.cmd == 'csv' || obj.cmd == 'reproduce' ? obj.tmout + 2500 : obj.tmout);
142
+ const delay = obj.cmd == 'csv' || obj.cmd == 'reproduce' ? obj.tmout + 2500 : obj.tmout;
143
+ await page.waitForTimeout(delay);
144
+
145
+ await Promise.all(downloads);
146
+
147
+ await browser.close();
148
+ spinner.stop();
150
149
 
151
150
  } catch (err) {
152
151
 
package/index.js CHANGED
@@ -14,7 +14,7 @@ module.exports = () => {
14
14
 
15
15
  let output = args.output || args.o || "./";
16
16
 
17
- let target = args.target || args.t || false;
17
+ let target = args.target || false;
18
18
 
19
19
  let dat = args.data || args.d || false;
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasxpress-cli",
3
- "version": "63.1.1",
3
+ "version": "63.3.0",
4
4
  "license": {
5
5
  "type": "Dual licensing",
6
6
  "url": "https://www.canvasxpress.org/docs/license.html"