canvasxpress-cli 63.1.1 → 63.2.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/io.js +39 -35
- package/package.json +1 -1
- package/src/canvasXpress.css +1280 -1346
- package/src/canvasXpress.js +4 -4
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
|
|
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
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//page.on("console", (consoleObj) => console.log(consoleObj.text()));
|
|
41
|
+
const context = await browser.newContext({
|
|
42
|
+
viewport: { width: 1000, height: 1000 }
|
|
43
|
+
});
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (consoleObj.type() !== 'warning') {
|
|
54
|
-
console.log(consoleObj.text());
|
|
55
|
-
}
|
|
45
|
+
await context.route('**/*', route => {
|
|
46
|
+
route.continue({ headers: { ...route.request().headers() } });
|
|
56
47
|
});
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
const page = await context.newPage();
|
|
50
|
+
|
|
51
|
+
await page.context().setDefaultDownloadDirectory(obj.output);
|
|
52
|
+
|
|
60
53
|
page.on('console', consoleObj => {
|
|
61
|
-
if (consoleObj.type()
|
|
62
|
-
|
|
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,37 @@ module.exports = async (obj) => {
|
|
|
128
120
|
}
|
|
129
121
|
}
|
|
130
122
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
123
|
+
const downloadDir = path.resolve(obj.output);
|
|
124
|
+
await page.route('**/*', async route => {
|
|
125
|
+
const response = await route.fetch();
|
|
126
|
+
const headers = response.headers();
|
|
127
|
+
if (headers['content-disposition'] && headers['content-disposition'].includes('attachment')) {
|
|
128
|
+
const buffer = await response.body();
|
|
129
|
+
const disposition = headers['content-disposition'];
|
|
130
|
+
const match = disposition.match(/filename="?([^"]+)"?/);
|
|
131
|
+
const filename = match ? match[1] : 'download';
|
|
132
|
+
fs.writeFileSync(path.join(downloadDir, filename), buffer);
|
|
133
|
+
route.abort();
|
|
134
|
+
} else {
|
|
135
|
+
route.continue();
|
|
136
|
+
}
|
|
134
137
|
});
|
|
135
138
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
139
|
+
const targetUrl = obj.input
|
|
140
|
+
? (obj.cmd == 'csv' ? defhtml : obj.cmd == 'reproduce' ? obj.input + '?showTransition=false' : obj.input)
|
|
141
|
+
: defhtml;
|
|
142
|
+
|
|
143
|
+
await page.goto(targetUrl, { waitUntil: 'networkidle' });
|
|
141
144
|
|
|
142
|
-
await page.
|
|
145
|
+
await page.waitForFunction(() => typeof CanvasXpress !== 'undefined' && CanvasXpress.ready);
|
|
143
146
|
|
|
144
147
|
await page.evaluate(`(${func.toString()})(${JSON.stringify(obj)})`);
|
|
145
148
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
const delay = obj.cmd == 'csv' || obj.cmd == 'reproduce' ? obj.tmout + 2500 : obj.tmout;
|
|
150
|
+
await page.waitForTimeout(delay);
|
|
151
|
+
|
|
152
|
+
await browser.close();
|
|
153
|
+
spinner.stop();
|
|
150
154
|
|
|
151
155
|
} catch (err) {
|
|
152
156
|
|