Просмотр исходного кода

replace --browser-scripts with --browser-script

Gildas 5 лет назад
Родитель
Сommit
674295adb8
3 измененных файлов с 7 добавлено и 6 удалено
  1. 6 3
      cli/args.js
  2. 1 1
      cli/back-ends/common/scripts.js
  3. 0 2
      cli/single-file

+ 6 - 3
cli/args.js

@@ -40,7 +40,7 @@ const args = require("yargs")
 		"browser-wait-until-fallback": true,
 		"browser-wait-until-fallback": true,
 		"browser-debug": false,
 		"browser-debug": false,
 		"browser-extensions": [],
 		"browser-extensions": [],
-		"browser-scripts": [],
+		"browser-script": [],
 		"browser-args": "",
 		"browser-args": "",
 		"browser-start-minimized": false,
 		"browser-start-minimized": false,
 		"browser-cookie": [],
 		"browser-cookie": [],
@@ -103,8 +103,8 @@ const args = require("yargs")
 	.boolean("browser-debug")
 	.boolean("browser-debug")
 	.options("browser-extensions", { description: "List of extension paths separated by a space and relative to the 'cli' folder (webdriver-gecko, webdriver-chromium)" })
 	.options("browser-extensions", { description: "List of extension paths separated by a space and relative to the 'cli' folder (webdriver-gecko, webdriver-chromium)" })
 	.array("browser-extensions")
 	.array("browser-extensions")
-	.options("browser-scripts", { description: "List of script paths separated by a space and relative to the 'cli' folder. They will be executed in all the frames." })
-	.array("browser-scripts")
+	.options("browser-script", { description: "Path of a script executed before the page is loaded (and all the frames)." })
+	.array("browser-script")
 	.options("browser-args", { description: "Arguments provided as a JSON array and passed to the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
 	.options("browser-args", { description: "Arguments provided as a JSON array and passed to the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
 	.string("browser-args")
 	.string("browser-args")
 	.options("browser-start-minimized", { description: "Minimize the browser (puppeteer)" })
 	.options("browser-start-minimized", { description: "Minimize the browser (puppeteer)" })
@@ -234,6 +234,9 @@ args.browserCookies = cookies.map(cookieValue => {
 		url: value[8] || undefined
 		url: value[8] || undefined
 	};
 	};
 });
 });
+const scripts = args.browserScript;
+delete args.browserScript;
+args.browserScripts = scripts;
 Object.keys(args).filter(optionName => optionName.includes("-"))
 Object.keys(args).filter(optionName => optionName.includes("-"))
 	.forEach(optionName => delete args[optionName]);
 	.forEach(optionName => delete args[optionName]);
 delete args["$0"];
 delete args["$0"];

+ 1 - 1
cli/back-ends/common/scripts.js

@@ -82,7 +82,7 @@ async function readScriptFiles(paths, basePath = "../../../") {
 
 
 function readScriptFile(path, basePath) {
 function readScriptFile(path, basePath) {
 	return new Promise((resolve, reject) =>
 	return new Promise((resolve, reject) =>
-		fs.readFile(require.resolve(basePath + path), (err, data) => {
+		fs.readFile(basePath ? require.resolve(basePath + path) : path, (err, data) => {
 			if (err) {
 			if (err) {
 				reject(err);
 				reject(err);
 			} else {
 			} else {

+ 0 - 2
cli/single-file

@@ -42,8 +42,6 @@ async function run(options) {
 		urls = [options.url];
 		urls = [options.url];
 	}
 	}
 	options.retrieveLinks = true;
 	options.retrieveLinks = true;
-	options.browserScripts = options.browserScripts.map(path => require.resolve(path));
-
 	await singlefile.capture(urls);
 	await singlefile.capture(urls);
 	await singlefile.finish();
 	await singlefile.finish();
 }
 }