single-file-cli 2.0.4 → 2.0.6
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/Dockerfile +0 -1
- package/build-lib.sh +3 -2
- package/deno.json +1 -1
- package/{back-ends/chromium-browser.js → lib/browser.js} +4 -3
- package/{back-ends/chromium-back-end.js → lib/cdp-client.js} +17 -20
- package/{deno-polyfill.js → lib/deno-polyfill.js} +61 -61
- package/lib/single-file-bundle.js +1 -1
- package/{back-ends → lib}/single-file-script.js +3 -2
- package/{args.js → options.js} +31 -24
- package/package.json +1 -1
- package/single-file +5 -3
- package/single-file-cli-api.js +5 -4
- /package/{back-ends/chromium-constants.js → lib/constants.js} +0 -0
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
/* global singlefile, XMLHttpRequest */
|
|
25
25
|
|
|
26
26
|
import { script, hookScript, zipScript } from "../lib/single-file-bundle.js";
|
|
27
|
-
import {
|
|
27
|
+
import { Deno } from "./deno-polyfill.js";
|
|
28
28
|
|
|
29
|
+
const { readTextFile } = Deno;
|
|
29
30
|
export { getScriptSource, getHookScriptSource, getZipScriptSource };
|
|
30
31
|
|
|
31
32
|
function initSingleFile() {
|
|
@@ -75,7 +76,7 @@ async function getHookScriptSource() {
|
|
|
75
76
|
|
|
76
77
|
async function getZipScriptSource() {
|
|
77
78
|
return zipScript;
|
|
78
|
-
}
|
|
79
|
+
}
|
|
79
80
|
|
|
80
81
|
async function readScriptFiles(paths) {
|
|
81
82
|
return (await Promise.all(paths.map(path => readTextFile(path)))).join("");
|
package/{args.js → options.js}
RENAMED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Source.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { Deno } from "./lib/deno-polyfill.js";
|
|
25
25
|
|
|
26
26
|
const USAGE_TEXT = `single-file [url] [output]
|
|
27
27
|
|
|
@@ -53,6 +53,7 @@ const OPTIONS_INFO = {
|
|
|
53
53
|
"browser-debug": { description: "Enable debug mode", type: "boolean" },
|
|
54
54
|
"browser-script": { description: "Path of a script executed in the page (and all the frames) before it is loaded", type: "string[]" },
|
|
55
55
|
"browser-stylesheet": { description: "Path of a stylesheet file inserted into the page (and all the frames) after it is loaded", type: "string[]" },
|
|
56
|
+
"browser-arg": { description: "Argument passed to the browser", type: "string[]", alias: "browser-argument" },
|
|
56
57
|
"browser-args": { description: "Arguments provided as a JSON array and passed to the browser", type: "string" },
|
|
57
58
|
"browser-start-minimized": { description: "Minimize the browser", type: "boolean" },
|
|
58
59
|
"browser-cookie": { description: "Ordered list of cookie parameters separated by a comma (name,value,domain,path,expires,httpOnly,secure,sameSite,url)", type: "string[]" },
|
|
@@ -122,11 +123,12 @@ const OPTIONS_INFO = {
|
|
|
122
123
|
"output-directory": { description: "Path to where to save files, this path must exist.", type: "string" }
|
|
123
124
|
};
|
|
124
125
|
|
|
126
|
+
const { args, exit } = Deno;
|
|
125
127
|
const options = getOptions();
|
|
126
128
|
export default options;
|
|
127
129
|
|
|
128
130
|
function getOptions() {
|
|
129
|
-
const { positionals, options } = parseArgs();
|
|
131
|
+
const { positionals, options } = parseArgs(Array.from(args));
|
|
130
132
|
if ((!positionals.length && !Object.keys(options).length) || positionals.length > 2 || options.help) {
|
|
131
133
|
console.log(USAGE_TEXT + "\n"); // eslint-disable-line no-console
|
|
132
134
|
console.log("Options:"); // eslint-disable-line no-console
|
|
@@ -144,12 +146,10 @@ function getOptions() {
|
|
|
144
146
|
exit(0);
|
|
145
147
|
}
|
|
146
148
|
Object.keys(OPTIONS_INFO).forEach(optionName => {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
|
|
152
|
-
}
|
|
149
|
+
const optionInfo = getOptionInfo(optionName);
|
|
150
|
+
const optionKey = getOptionKey(optionName, optionInfo);
|
|
151
|
+
if (optionInfo.defaultValue !== undefined) {
|
|
152
|
+
options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
|
|
153
153
|
}
|
|
154
154
|
});
|
|
155
155
|
options.acceptHeaders = {
|
|
@@ -159,6 +159,16 @@ function getOptions() {
|
|
|
159
159
|
script: options.acceptHeaderScript,
|
|
160
160
|
document: options.acceptHeaderDocument
|
|
161
161
|
};
|
|
162
|
+
if (options.browserArgs) {
|
|
163
|
+
const browserArguments = options.browserArguments || [];
|
|
164
|
+
browserArguments.push(...JSON.parse(options.browserArgs));
|
|
165
|
+
options.browserArgs = browserArguments;
|
|
166
|
+
delete options.browserArguments;
|
|
167
|
+
}
|
|
168
|
+
if (options.browserArguments) {
|
|
169
|
+
options.browserArgs = options.browserArguments;
|
|
170
|
+
delete options.browserArguments;
|
|
171
|
+
}
|
|
162
172
|
delete options.acceptHeaderFont;
|
|
163
173
|
delete options.acceptHeaderImage;
|
|
164
174
|
delete options.acceptHeaderStylesheet;
|
|
@@ -167,14 +177,13 @@ function getOptions() {
|
|
|
167
177
|
return { ...options, url: positionals[0], output: positionals[1] };
|
|
168
178
|
}
|
|
169
179
|
|
|
170
|
-
function parseArgs() {
|
|
171
|
-
const parsedArgs = Array.from(args);
|
|
180
|
+
function parseArgs(args) {
|
|
172
181
|
const positionals = [];
|
|
173
182
|
const options = {};
|
|
174
183
|
const result = { positionals, options: {} };
|
|
175
184
|
let argIndex = 0;
|
|
176
|
-
while (argIndex <
|
|
177
|
-
const arg =
|
|
185
|
+
while (argIndex < args.length) {
|
|
186
|
+
const arg = args[argIndex];
|
|
178
187
|
const { argName, argValue, optionInfo } = parseArg(arg);
|
|
179
188
|
if (optionInfo) {
|
|
180
189
|
if (options[argName] === undefined) {
|
|
@@ -183,12 +192,12 @@ function parseArgs() {
|
|
|
183
192
|
let nextArgName;
|
|
184
193
|
if (argValue === undefined) {
|
|
185
194
|
while (
|
|
186
|
-
argIndex + 1 <
|
|
187
|
-
({ argName: nextArgName } = parseArg(
|
|
195
|
+
argIndex + 1 < args.length &&
|
|
196
|
+
({ argName: nextArgName } = parseArg(args[argIndex + 1])) &&
|
|
188
197
|
(nextArgName === undefined || !getOptionInfo(nextArgName)) &&
|
|
189
|
-
isValid(optionInfo.type,
|
|
198
|
+
isValid(optionInfo.type, args[argIndex + 1]) &&
|
|
190
199
|
(isArray(optionInfo.type) || !options[argName].length)) {
|
|
191
|
-
options[argName].push(
|
|
200
|
+
options[argName].push(args[argIndex + 1]);
|
|
192
201
|
argIndex++;
|
|
193
202
|
}
|
|
194
203
|
} else if (isValid(optionInfo.type, argValue) && (isArray(optionInfo.type) || !options[argName].length)) {
|
|
@@ -202,8 +211,8 @@ function parseArgs() {
|
|
|
202
211
|
argIndex++;
|
|
203
212
|
}
|
|
204
213
|
Object.keys(options).forEach(optionName => {
|
|
205
|
-
const optionKey = getOptionKey(optionName);
|
|
206
214
|
const optionInfo = getOptionInfo(optionName);
|
|
215
|
+
const optionKey = getOptionKey(optionName, optionInfo);
|
|
207
216
|
let optionValue = options[optionName];
|
|
208
217
|
const isArrayType = isArray(optionInfo.type);
|
|
209
218
|
if (optionInfo.type.startsWith("boolean")) {
|
|
@@ -226,16 +235,14 @@ function parseArgs() {
|
|
|
226
235
|
return result;
|
|
227
236
|
}
|
|
228
237
|
|
|
229
|
-
function getOptionKey(
|
|
230
|
-
let optionKey;
|
|
231
|
-
const optionInfo = getOptionInfo(optionName);
|
|
238
|
+
function getOptionKey(optionKeyName, optionInfo) {
|
|
232
239
|
if (optionInfo) {
|
|
240
|
+
const optionName = optionInfo.alias || optionKeyName;
|
|
233
241
|
if (isArray(optionInfo.type)) {
|
|
234
|
-
|
|
242
|
+
return kebabToCamelCase(optionName + "s");
|
|
235
243
|
} else {
|
|
236
|
-
|
|
244
|
+
return kebabToCamelCase(optionName);
|
|
237
245
|
}
|
|
238
|
-
return optionKey;
|
|
239
246
|
}
|
|
240
247
|
}
|
|
241
248
|
|
|
@@ -247,7 +254,7 @@ function parseArg(arg) {
|
|
|
247
254
|
const optionInfo = getOptionInfo(argName);
|
|
248
255
|
if (argValue !== undefined &&
|
|
249
256
|
((argValue.startsWith("\"") && argValue.endsWith("\"")) ||
|
|
250
|
-
|
|
257
|
+
(argValue.startsWith("'") && argValue.endsWith("'")))) {
|
|
251
258
|
argValue = argValue.substring(1, argValue.length - 1);
|
|
252
259
|
}
|
|
253
260
|
return { argName, argValue, optionInfo };
|
package/package.json
CHANGED
package/single-file
CHANGED
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { VALID_URL_TEST, initialize } from "./single-file-cli-api.js";
|
|
27
|
-
import { initGlobalThisProperties,
|
|
28
|
-
import
|
|
27
|
+
import { initGlobalThisProperties, Deno, path } from "./lib/deno-polyfill.js";
|
|
28
|
+
import options from "./options.js";
|
|
29
29
|
|
|
30
|
+
const { readTextFile } = Deno;
|
|
31
|
+
const { toFileUrl } = path;
|
|
30
32
|
await initGlobalThisProperties();
|
|
31
|
-
await run(
|
|
33
|
+
await run(options);
|
|
32
34
|
|
|
33
35
|
async function run(options = {}) {
|
|
34
36
|
let urls;
|
package/single-file-cli-api.js
CHANGED
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
|
|
24
24
|
/* global URL */
|
|
25
25
|
|
|
26
|
-
import * as backend from "./
|
|
27
|
-
import { getZipScriptSource } from "./
|
|
28
|
-
import {
|
|
26
|
+
import * as backend from "./lib/cdp-client.js";
|
|
27
|
+
import { getZipScriptSource } from "./lib/single-file-script.js";
|
|
28
|
+
import { Deno, path } from "./lib/deno-polyfill.js";
|
|
29
29
|
|
|
30
30
|
const VALID_URL_TEST = /^(https?|file):\/\//;
|
|
31
31
|
|
|
@@ -76,6 +76,7 @@ const DEFAULT_OPTIONS = {
|
|
|
76
76
|
const STATE_PROCESSING = "processing";
|
|
77
77
|
const STATE_PROCESSED = "processed";
|
|
78
78
|
|
|
79
|
+
const { readTextFile, writeTextFile, stdout, mkdir, stat } = Deno;
|
|
79
80
|
let tasks = [], maxParallelWorkers, sessionFilename;
|
|
80
81
|
|
|
81
82
|
export { DEFAULT_OPTIONS, VALID_URL_TEST, initialize };
|
|
@@ -253,7 +254,7 @@ async function capturePage(options) {
|
|
|
253
254
|
filename = await getFilename(pageData.filename, options);
|
|
254
255
|
}
|
|
255
256
|
if (filename) {
|
|
256
|
-
const directoryName = await dirname(filename);
|
|
257
|
+
const directoryName = await path.dirname(filename);
|
|
257
258
|
if (directoryName !== ".") {
|
|
258
259
|
await mkdir(directoryName, { recursive: true });
|
|
259
260
|
}
|
|
File without changes
|