single-file-cli 2.0.3 → 2.0.5
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 +1 -1
- 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} +18 -22
- package/{deno-polyfill.js → lib/deno-polyfill.js} +62 -72
- package/lib/single-file-bundle.js +1 -1
- package/{back-ends → lib}/single-file-script.js +3 -2
- package/{args.js → options.js} +27 -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,12 @@ 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
|
+
}
|
|
162
168
|
delete options.acceptHeaderFont;
|
|
163
169
|
delete options.acceptHeaderImage;
|
|
164
170
|
delete options.acceptHeaderStylesheet;
|
|
@@ -167,14 +173,13 @@ function getOptions() {
|
|
|
167
173
|
return { ...options, url: positionals[0], output: positionals[1] };
|
|
168
174
|
}
|
|
169
175
|
|
|
170
|
-
function parseArgs() {
|
|
171
|
-
const parsedArgs = Array.from(args);
|
|
176
|
+
function parseArgs(args) {
|
|
172
177
|
const positionals = [];
|
|
173
178
|
const options = {};
|
|
174
179
|
const result = { positionals, options: {} };
|
|
175
180
|
let argIndex = 0;
|
|
176
|
-
while (argIndex <
|
|
177
|
-
const arg =
|
|
181
|
+
while (argIndex < args.length) {
|
|
182
|
+
const arg = args[argIndex];
|
|
178
183
|
const { argName, argValue, optionInfo } = parseArg(arg);
|
|
179
184
|
if (optionInfo) {
|
|
180
185
|
if (options[argName] === undefined) {
|
|
@@ -183,12 +188,12 @@ function parseArgs() {
|
|
|
183
188
|
let nextArgName;
|
|
184
189
|
if (argValue === undefined) {
|
|
185
190
|
while (
|
|
186
|
-
argIndex + 1 <
|
|
187
|
-
({ argName: nextArgName } = parseArg(
|
|
191
|
+
argIndex + 1 < args.length &&
|
|
192
|
+
({ argName: nextArgName } = parseArg(args[argIndex + 1])) &&
|
|
188
193
|
(nextArgName === undefined || !getOptionInfo(nextArgName)) &&
|
|
189
|
-
isValid(optionInfo.type,
|
|
194
|
+
isValid(optionInfo.type, args[argIndex + 1]) &&
|
|
190
195
|
(isArray(optionInfo.type) || !options[argName].length)) {
|
|
191
|
-
options[argName].push(
|
|
196
|
+
options[argName].push(args[argIndex + 1]);
|
|
192
197
|
argIndex++;
|
|
193
198
|
}
|
|
194
199
|
} else if (isValid(optionInfo.type, argValue) && (isArray(optionInfo.type) || !options[argName].length)) {
|
|
@@ -202,8 +207,8 @@ function parseArgs() {
|
|
|
202
207
|
argIndex++;
|
|
203
208
|
}
|
|
204
209
|
Object.keys(options).forEach(optionName => {
|
|
205
|
-
const optionKey = getOptionKey(optionName);
|
|
206
210
|
const optionInfo = getOptionInfo(optionName);
|
|
211
|
+
const optionKey = getOptionKey(optionName, optionInfo);
|
|
207
212
|
let optionValue = options[optionName];
|
|
208
213
|
const isArrayType = isArray(optionInfo.type);
|
|
209
214
|
if (optionInfo.type.startsWith("boolean")) {
|
|
@@ -226,16 +231,14 @@ function parseArgs() {
|
|
|
226
231
|
return result;
|
|
227
232
|
}
|
|
228
233
|
|
|
229
|
-
function getOptionKey(
|
|
230
|
-
let optionKey;
|
|
231
|
-
const optionInfo = getOptionInfo(optionName);
|
|
234
|
+
function getOptionKey(optionKeyName, optionInfo) {
|
|
232
235
|
if (optionInfo) {
|
|
236
|
+
const optionName = optionInfo.alias || optionKeyName;
|
|
233
237
|
if (isArray(optionInfo.type)) {
|
|
234
|
-
|
|
238
|
+
return kebabToCamelCase(optionName + "s");
|
|
235
239
|
} else {
|
|
236
|
-
|
|
240
|
+
return kebabToCamelCase(optionName);
|
|
237
241
|
}
|
|
238
|
-
return optionKey;
|
|
239
242
|
}
|
|
240
243
|
}
|
|
241
244
|
|
|
@@ -247,7 +250,7 @@ function parseArg(arg) {
|
|
|
247
250
|
const optionInfo = getOptionInfo(argName);
|
|
248
251
|
if (argValue !== undefined &&
|
|
249
252
|
((argValue.startsWith("\"") && argValue.endsWith("\"")) ||
|
|
250
|
-
|
|
253
|
+
(argValue.startsWith("'") && argValue.endsWith("'")))) {
|
|
251
254
|
argValue = argValue.substring(1, argValue.length - 1);
|
|
252
255
|
}
|
|
253
256
|
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
|