webforai 1.5.0 → 1.5.1

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.
Files changed (47) hide show
  1. package/dist/bin.js +1032 -216
  2. package/dist/cjs/cli/bin.js +34 -0
  3. package/dist/cjs/cli/commands/handlers/index.js +84 -0
  4. package/dist/cjs/cli/commands/handlers/loadHtml.js +127 -0
  5. package/dist/cjs/cli/constants.js +34 -0
  6. package/dist/cjs/cli/helpers/assertContinue.js +34 -0
  7. package/dist/cjs/cli/helpers/inputOutputPath.js +89 -0
  8. package/dist/cjs/cli/helpers/inputSourcePath.js +64 -0
  9. package/dist/cjs/cli/helpers/selectExtractMode.js +39 -0
  10. package/dist/cjs/cli/helpers/selectLoader.js +44 -0
  11. package/dist/cjs/{utils/bin-utils.js → cli/utils.js} +31 -33
  12. package/dist/cjs/html-to-markdown.test.js +6 -34
  13. package/dist/cli/bin.js +12 -0
  14. package/dist/cli/commands/handlers/index.js +51 -0
  15. package/dist/cli/commands/handlers/loadHtml.js +94 -0
  16. package/dist/cli/constants.js +9 -0
  17. package/dist/cli/helpers/assertContinue.js +11 -0
  18. package/dist/cli/helpers/inputOutputPath.js +56 -0
  19. package/dist/cli/helpers/inputSourcePath.js +31 -0
  20. package/dist/cli/helpers/selectExtractMode.js +16 -0
  21. package/dist/cli/helpers/selectLoader.js +21 -0
  22. package/dist/{utils/bin-utils.js → cli/utils.js} +28 -30
  23. package/dist/html-to-markdown.test.js +6 -12
  24. package/dist/types/cli/bin.js.map +1 -0
  25. package/dist/types/cli/commands/handlers/index.d.ts +13 -0
  26. package/dist/types/cli/commands/handlers/index.js.map +1 -0
  27. package/dist/types/cli/commands/handlers/loadHtml.d.ts +2 -0
  28. package/dist/types/cli/commands/handlers/loadHtml.js.map +1 -0
  29. package/dist/types/cli/constants.d.ts +5 -0
  30. package/dist/types/cli/constants.js.map +1 -0
  31. package/dist/types/cli/helpers/assertContinue.d.ts +1 -0
  32. package/dist/types/cli/helpers/assertContinue.js.map +1 -0
  33. package/dist/types/cli/helpers/inputOutputPath.d.ts +1 -0
  34. package/dist/types/cli/helpers/inputOutputPath.js.map +1 -0
  35. package/dist/types/cli/helpers/inputSourcePath.d.ts +1 -0
  36. package/dist/types/cli/helpers/inputSourcePath.js.map +1 -0
  37. package/dist/types/cli/helpers/selectExtractMode.d.ts +1 -0
  38. package/dist/types/cli/helpers/selectExtractMode.js.map +1 -0
  39. package/dist/types/cli/helpers/selectLoader.d.ts +1 -0
  40. package/dist/types/cli/helpers/selectLoader.js.map +1 -0
  41. package/dist/types/{utils/bin-utils.d.ts → cli/utils.d.ts} +3 -3
  42. package/dist/types/cli/utils.js.map +1 -0
  43. package/package.json +7 -17
  44. package/dist/cjs/bin.js +0 -254
  45. package/dist/types/bin.js.map +0 -1
  46. package/dist/types/utils/bin-utils.js.map +0 -1
  47. /package/dist/types/{bin.d.ts → cli/bin.d.ts} +0 -0
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_prompts = require("@clack/prompts");
25
+ var import_commander = require("commander");
26
+ var import_picocolors = __toESM(require("picocolors"), 1);
27
+ var import_package = __toESM(require("../../package.json"), 1);
28
+ var import_handlers = require("./commands/handlers");
29
+ var import_constants = require("./constants");
30
+ import_commander.program.name("webforai").description("CLI tool for ultra-precise HTML to Markdown conversion").version(import_package.default.version, "-v, --version", "output the current version").argument("[source]", "URL or path to process").argument("[outputPath]", "Path to output file or directory").option("--mode <mode>", `Processing mode (${import_constants.MODES.join(", ")})`).option("--loader <loader>", `Loader to use (${import_constants.LOADERS.join(", ")})`).option("--baseUrl <baseUrl>", "Base URL for relative links").option("-o, --stdout", "output to stdout").option("-d, --debug", "output extra debugging information").on("option:debug", () => {
31
+ process.env.DEBUG = "true";
32
+ }).action(import_handlers.webforaiCommand);
33
+ (0, import_prompts.intro)(import_picocolors.default.inverse(`webforai CLI version ${import_package.default.version}`));
34
+ import_commander.program.parse();
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var handlers_exports = {};
30
+ __export(handlers_exports, {
31
+ webforaiCommand: () => webforaiCommand
32
+ });
33
+ module.exports = __toCommonJS(handlers_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
35
+ var import_node_path = __toESM(require("node:path"), 1);
36
+ var import_prompts = require("@clack/prompts");
37
+ var import_html_to_markdown = require("../../../html-to-markdown");
38
+ var import_inputOutputPath = require("../../helpers/inputOutputPath");
39
+ var import_inputSourcePath = require("../../helpers/inputSourcePath");
40
+ var import_selectExtractMode = require("../../helpers/selectExtractMode");
41
+ var import_selectLoader = require("../../helpers/selectLoader");
42
+ var import_utils = require("../../utils");
43
+ var import_loadHtml = require("./loadHtml");
44
+ const aiModeOptions = { linkAsText: true, tableAsText: true, hideImage: true };
45
+ const readabilityModeOptions = { linkAsText: false, tableAsText: false, hideImage: false };
46
+ const webforaiCommand = async (initialPath, initialOutputPath, options) => {
47
+ const sourcePath = initialPath ?? await (0, import_inputSourcePath.inputSourcePath)();
48
+ if (options.debug) {
49
+ console.debug(`sourcePath: ${sourcePath}`);
50
+ }
51
+ const loader = (0, import_utils.isUrl)(sourcePath) ? { type: "web", loader: options.loader ?? await (0, import_selectLoader.selectLoader)() } : { type: "local", loader: null };
52
+ if (options.debug) {
53
+ console.debug(`loader: ${loader}`);
54
+ }
55
+ const outputPath = initialOutputPath ?? await (0, import_inputOutputPath.inputOutputPath)(sourcePath);
56
+ if (options.debug) {
57
+ console.debug(`outputPath: ${outputPath}`);
58
+ }
59
+ const mode = options.mode ?? await (0, import_selectExtractMode.selectExtractMode)();
60
+ if (options.debug) {
61
+ console.debug(`mode: ${mode}`);
62
+ }
63
+ const content = await (0, import_loadHtml.loadHtml)(sourcePath, loader);
64
+ if (options.debug) {
65
+ console.debug(`content: ${content}`);
66
+ }
67
+ const markdown = (0, import_html_to_markdown.htmlToMarkdown)(content, {
68
+ baseUrl: (0, import_utils.isUrl)(sourcePath) ? sourcePath : options.baseUrl,
69
+ ...mode === "ai" ? aiModeOptions : readabilityModeOptions
70
+ });
71
+ if (options.debug) {
72
+ console.debug(`markdown: ${markdown}`);
73
+ }
74
+ const directory = import_node_path.default.dirname(outputPath);
75
+ if (!import_node_fs.default.existsSync(directory)) {
76
+ import_node_fs.default.mkdirSync(directory, { recursive: true });
77
+ }
78
+ import_node_fs.default.writeFileSync(outputPath, markdown);
79
+ (0, import_prompts.outro)("Markdown conversion is complete!");
80
+ };
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ webforaiCommand
84
+ });
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var loadHtml_exports = {};
30
+ __export(loadHtml_exports, {
31
+ loadHtml: () => loadHtml
32
+ });
33
+ module.exports = __toCommonJS(loadHtml_exports);
34
+ var import_promises = __toESM(require("node:fs/promises"), 1);
35
+ var import_prompts = require("@clack/prompts");
36
+ var import_picocolors = __toESM(require("picocolors"), 1);
37
+ var import_zx = require("zx");
38
+ const loadHtml = async (sourcePath, loader) => {
39
+ const loadSpinner = (0, import_prompts.spinner)();
40
+ try {
41
+ switch (loader.type) {
42
+ case "local":
43
+ return await loadLocalHtml(sourcePath, loadSpinner);
44
+ case "web":
45
+ switch (loader.loader) {
46
+ case "fetch":
47
+ return await loadFetchHtml(sourcePath, loadSpinner);
48
+ case "playwright":
49
+ return await loadPlaywrightHtml(sourcePath, loadSpinner);
50
+ default:
51
+ throw new Error("Invalid loader");
52
+ }
53
+ default:
54
+ throw new Error("Invalid loader type");
55
+ }
56
+ } catch (error) {
57
+ loadSpinner.stop(import_picocolors.default.red("Content loading failed!"));
58
+ console.error(error);
59
+ process.exit(1);
60
+ }
61
+ };
62
+ const loadLocalHtml = async (sourcePath, loadSpinner) => {
63
+ loadSpinner.start("Retrieving content.");
64
+ try {
65
+ await import_promises.default.access(sourcePath);
66
+ } catch {
67
+ throw new Error("The file does not exist");
68
+ }
69
+ const stats = await import_promises.default.stat(sourcePath);
70
+ if (!stats.isFile()) {
71
+ throw new Error("The source must be a file");
72
+ }
73
+ const content = await import_promises.default.readFile(sourcePath, "utf-8");
74
+ loadSpinner.stop("Content retrieval is complete!");
75
+ return content;
76
+ };
77
+ const loadFetchHtml = async (sourcePath, loadSpinner) => {
78
+ loadSpinner.start("Downloading content.");
79
+ const { loadHtml: loadHtml2 } = await import("../../../loaders/fetch");
80
+ const content = await loadHtml2(sourcePath);
81
+ loadSpinner.stop("Content download is complete!");
82
+ return content;
83
+ };
84
+ const loadPlaywrightHtml = async (sourcePath, loadSpinner) => {
85
+ const launchSpinner = (0, import_prompts.spinner)();
86
+ launchSpinner.start("Launching playwright.");
87
+ const playwright = await import("playwright");
88
+ let browser;
89
+ try {
90
+ browser = await playwright.chromium.launch();
91
+ launchSpinner.stop("Playwright launched!");
92
+ } catch (error) {
93
+ await handlePlaywrightLaunchError(error);
94
+ browser = await playwright.chromium.launch();
95
+ }
96
+ loadSpinner.start("Loading content.");
97
+ const { loadHtml: loadHtml2 } = await import("../../../loaders/playwright");
98
+ const content = await loadHtml2(sourcePath, browser);
99
+ loadSpinner.stop("Content download is complete!");
100
+ await browser.close();
101
+ return content;
102
+ };
103
+ const handlePlaywrightLaunchError = async (error) => {
104
+ if (!error.message.includes("npx playwright install")) {
105
+ throw error;
106
+ }
107
+ const isInstall = await (0, import_prompts.confirm)({
108
+ message: "To continue, you will need to download a browser. Do you wish to continue?"
109
+ });
110
+ if (!isInstall) {
111
+ (0, import_prompts.cancel)("End of process.");
112
+ process.exit(1);
113
+ }
114
+ const installDepsSpinner = (0, import_prompts.spinner)();
115
+ installDepsSpinner.start("Installing browser dependencies.");
116
+ try {
117
+ await import_zx.$`npx playwright install`;
118
+ installDepsSpinner.stop("Browser dependencies installed!");
119
+ } catch (error2) {
120
+ installDepsSpinner.stop(import_picocolors.default.red("Browser dependencies failed to install!"));
121
+ throw error2;
122
+ }
123
+ };
124
+ // Annotate the CommonJS export names for ESM import in node:
125
+ 0 && (module.exports = {
126
+ loadHtml
127
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ DEFAULT_PATH: () => DEFAULT_PATH,
22
+ LOADERS: () => LOADERS,
23
+ MODES: () => MODES
24
+ });
25
+ module.exports = __toCommonJS(constants_exports);
26
+ const DEFAULT_PATH = "https://example.com";
27
+ const LOADERS = ["fetch", "playwright"];
28
+ const MODES = ["default", "ai"];
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ DEFAULT_PATH,
32
+ LOADERS,
33
+ MODES
34
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var assertContinue_exports = {};
20
+ __export(assertContinue_exports, {
21
+ assertContinue: () => assertContinue
22
+ });
23
+ module.exports = __toCommonJS(assertContinue_exports);
24
+ var import_prompts = require("@clack/prompts");
25
+ function assertContinue(message, cancelMessage = "Canceled.") {
26
+ if ((0, import_prompts.isCancel)(message)) {
27
+ (0, import_prompts.cancel)(cancelMessage);
28
+ process.exit(1);
29
+ }
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ assertContinue
34
+ });
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var inputOutputPath_exports = {};
30
+ __export(inputOutputPath_exports, {
31
+ inputOutputPath: () => inputOutputPath
32
+ });
33
+ module.exports = __toCommonJS(inputOutputPath_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
35
+ var import_prompts = require("@clack/prompts");
36
+ var import_utils = require("../utils");
37
+ var import_assertContinue = require("./assertContinue");
38
+ const inputOutputPath = async (sourcePath) => {
39
+ const outputPath = await (0, import_prompts.text)({
40
+ message: "Enter the output file path:",
41
+ placeholder: "output.md",
42
+ initialValue: (0, import_utils.sourcePathToOutputPath)(sourcePath),
43
+ validate: (value) => {
44
+ if (value.trim() === "") {
45
+ return "Output path is required";
46
+ }
47
+ if (import_node_fs.default.existsSync(value) && import_node_fs.default.statSync(value).isDirectory()) {
48
+ return "No directory can be specified.";
49
+ }
50
+ if (!import_node_fs.default.existsSync(value) && value.endsWith("/")) {
51
+ return "No directory can be specified.";
52
+ }
53
+ }
54
+ });
55
+ (0, import_assertContinue.assertContinue)(outputPath);
56
+ if (!import_node_fs.default.existsSync(outputPath)) {
57
+ return outputPath;
58
+ }
59
+ const isOutputFileOverwrite = await (0, import_prompts.confirm)({
60
+ message: "The file already exists. Overwrite?",
61
+ initialValue: false
62
+ });
63
+ (0, import_assertContinue.assertContinue)(isOutputFileOverwrite);
64
+ if (isOutputFileOverwrite) {
65
+ return outputPath;
66
+ }
67
+ const escapedOutputPath = await (0, import_prompts.text)({
68
+ message: "Enter the output file path:",
69
+ placeholder: "output.md",
70
+ initialValue: (0, import_utils.getNextAvailableFilePath)(outputPath),
71
+ validate: (value) => {
72
+ if (value.trim() === "") {
73
+ return "Output path is required";
74
+ }
75
+ if (import_node_fs.default.existsSync(value)) {
76
+ return "The file already exists";
77
+ }
78
+ if (!import_node_fs.default.existsSync(value) && value.endsWith("/")) {
79
+ return "No directory can be specified.";
80
+ }
81
+ }
82
+ });
83
+ (0, import_assertContinue.assertContinue)(escapedOutputPath);
84
+ return escapedOutputPath;
85
+ };
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ inputOutputPath
89
+ });
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var inputSourcePath_exports = {};
30
+ __export(inputSourcePath_exports, {
31
+ inputSourcePath: () => inputSourcePath
32
+ });
33
+ module.exports = __toCommonJS(inputSourcePath_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
35
+ var import_prompts = require("@clack/prompts");
36
+ var import_constants = require("../constants");
37
+ var import_utils = require("../utils");
38
+ var import_assertContinue = require("./assertContinue");
39
+ const inputSourcePath = async () => {
40
+ const result = await (0, import_prompts.text)({
41
+ message: "Enter the URL or html path to be converted to markdown:",
42
+ placeholder: import_constants.DEFAULT_PATH,
43
+ initialValue: "",
44
+ validate: (value) => {
45
+ if (value.trim() === "") {
46
+ return "Source is required";
47
+ }
48
+ if (!(0, import_utils.isUrl)(value)) {
49
+ if (!import_node_fs.default.existsSync(value)) {
50
+ return "It appears that you are specifying a local file, but the file cannot be found. hint: when specifying a url, start with http or https.";
51
+ }
52
+ if (import_node_fs.default.statSync(value).isDirectory()) {
53
+ return "You are specifying a local file, but you cannot specify a directory. hint: when specifying a url, start with http or https.";
54
+ }
55
+ }
56
+ }
57
+ });
58
+ (0, import_assertContinue.assertContinue)(result);
59
+ return result;
60
+ };
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ inputSourcePath
64
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var selectExtractMode_exports = {};
20
+ __export(selectExtractMode_exports, {
21
+ selectExtractMode: () => selectExtractMode
22
+ });
23
+ module.exports = __toCommonJS(selectExtractMode_exports);
24
+ var import_prompts = require("@clack/prompts");
25
+ var import_constants = require("../constants");
26
+ var import_assertContinue = require("./assertContinue");
27
+ const selectExtractMode = async () => {
28
+ const result = await (0, import_prompts.select)({
29
+ message: "Select processing mode:",
30
+ options: import_constants.MODES.map((mode) => ({ value: mode, label: mode })),
31
+ initialValue: import_constants.MODES[0]
32
+ });
33
+ (0, import_assertContinue.assertContinue)(result);
34
+ return result;
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ selectExtractMode
39
+ });
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var selectLoader_exports = {};
20
+ __export(selectLoader_exports, {
21
+ selectLoader: () => selectLoader
22
+ });
23
+ module.exports = __toCommonJS(selectLoader_exports);
24
+ var import_prompts = require("@clack/prompts");
25
+ var import_constants = require("../constants");
26
+ var import_assertContinue = require("./assertContinue");
27
+ const loadersHint = {
28
+ fetch: "Fetch HTML content from the given URL",
29
+ playwright: "Retrieve HTML content after rendering using Playwright; Playwright must be installed in advance.",
30
+ puppeteer: "Retrieve HTML content after rendering using Puppeteer; Puppeteer must be installed in advance."
31
+ };
32
+ const selectLoader = async () => {
33
+ const result = await (0, import_prompts.select)({
34
+ message: "Select loader:",
35
+ initialValue: "fetch",
36
+ options: import_constants.LOADERS.map((mode) => ({ value: mode, label: mode, hint: loadersHint[mode] || "" }))
37
+ });
38
+ (0, import_assertContinue.assertContinue)(result);
39
+ return result;
40
+ };
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ selectLoader
44
+ });
@@ -26,50 +26,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var bin_utils_exports = {};
30
- __export(bin_utils_exports, {
29
+ var utils_exports = {};
30
+ __export(utils_exports, {
31
31
  changeFileExtension: () => changeFileExtension,
32
32
  getNextAvailableFilePath: () => getNextAvailableFilePath,
33
33
  isUrl: () => isUrl,
34
- logError: () => logError,
34
+ sourcePathToOutputPath: () => sourcePathToOutputPath,
35
35
  urlToFilename: () => urlToFilename
36
36
  });
37
- module.exports = __toCommonJS(bin_utils_exports);
37
+ module.exports = __toCommonJS(utils_exports);
38
38
  var import_node_fs = __toESM(require("node:fs"), 1);
39
39
  var import_node_path = __toESM(require("node:path"), 1);
40
- var import_prompts = require("@clack/prompts");
41
- function logError(error) {
42
- import_prompts.log.error("An error occurred during processing");
43
- console.error(error.message);
44
- }
45
- function isUrl(str) {
40
+ const isUrl = (maybeUrl) => {
46
41
  try {
47
- new URL(str);
42
+ new URL(maybeUrl);
48
43
  return true;
49
44
  } catch {
50
45
  return false;
51
46
  }
52
- }
53
- function getNextAvailableFilePath(filePath) {
54
- const parsedPath = import_node_path.default.parse(filePath);
55
- const directory = parsedPath.dir;
56
- const fullName = parsedPath.base;
57
- const [firstPart, ...restParts] = fullName.split(".");
58
- const restName = restParts.length > 0 ? `.${restParts.join(".")}` : "";
59
- const baseName = firstPart.replace(/_\d+$/, "");
60
- let counter = 1;
61
- let nextFilePath = filePath;
62
- while (import_node_fs.default.existsSync(nextFilePath)) {
63
- const match = firstPart.match(/_(\d+)$/);
64
- if (match) {
65
- counter = Number.parseInt(match[1], 10) + 1;
66
- }
67
- const newName = `${baseName}_${counter}${restName}`;
68
- nextFilePath = import_node_path.default.join(directory, newName);
69
- counter++;
70
- }
71
- return nextFilePath;
72
- }
47
+ };
73
48
  function changeFileExtension(filePath, newExtension) {
74
49
  const parsedPath = filePath.split("/");
75
50
  const fileName = parsedPath[parsedPath.length - 1];
@@ -114,11 +89,34 @@ function urlToFilename(url) {
114
89
  return "output";
115
90
  }
116
91
  }
92
+ const sourcePathToOutputPath = (sourcePath) => {
93
+ return isUrl(sourcePath) ? `${urlToFilename(sourcePath)}.md` : changeFileExtension(sourcePath, "md");
94
+ };
95
+ function getNextAvailableFilePath(filePath) {
96
+ const parsedPath = import_node_path.default.parse(filePath);
97
+ const directory = parsedPath.dir;
98
+ const fullName = parsedPath.base;
99
+ const [firstPart, ...restParts] = fullName.split(".");
100
+ const restName = restParts.length > 0 ? `.${restParts.join(".")}` : "";
101
+ const baseName = firstPart.replace(/_\d+$/, "");
102
+ let counter = 1;
103
+ let nextFilePath = filePath;
104
+ while (import_node_fs.default.existsSync(nextFilePath)) {
105
+ const match = firstPart.match(/_(\d+)$/);
106
+ if (match) {
107
+ counter = Number.parseInt(match[1], 10) + 1;
108
+ }
109
+ const newName = `${baseName}_${counter}${restName}`;
110
+ nextFilePath = import_node_path.default.join(directory, newName);
111
+ counter++;
112
+ }
113
+ return nextFilePath;
114
+ }
117
115
  // Annotate the CommonJS export names for ESM import in node:
118
116
  0 && (module.exports = {
119
117
  changeFileExtension,
120
118
  getNextAvailableFilePath,
121
119
  isUrl,
122
- logError,
120
+ sourcePathToOutputPath,
123
121
  urlToFilename
124
122
  });