defuddle-cli 0.1.3 → 0.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/dist/index.js +8 -3
- package/package.json +2 -2
- package/src/index.ts +10 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { JSDOM, VirtualConsole } from 'jsdom';
|
|
4
|
-
import
|
|
5
|
-
const { Defuddle } = pkg;
|
|
4
|
+
import Defuddle from 'defuddle';
|
|
6
5
|
import chalk from 'chalk';
|
|
7
6
|
import { readFile, writeFile } from 'fs/promises';
|
|
8
7
|
import { fileURLToPath } from 'url';
|
|
@@ -702,8 +701,10 @@ program
|
|
|
702
701
|
}
|
|
703
702
|
// Parse content with debug mode if enabled
|
|
704
703
|
try {
|
|
704
|
+
// @ts-ignore - Module interop issue between ES modules and CommonJS
|
|
705
705
|
const defuddle = new Defuddle(doc, {
|
|
706
|
-
debug: options.debug
|
|
706
|
+
debug: options.debug,
|
|
707
|
+
...(source.startsWith('http') ? { url: source } : {})
|
|
707
708
|
});
|
|
708
709
|
const result = await defuddle.parse();
|
|
709
710
|
// If in debug mode, don't show content output
|
|
@@ -767,6 +768,10 @@ program
|
|
|
767
768
|
else {
|
|
768
769
|
console.log(output);
|
|
769
770
|
}
|
|
771
|
+
// Clean up JSDOM resources
|
|
772
|
+
contentDom.window.close();
|
|
773
|
+
dom.window.close();
|
|
774
|
+
process.exit(0);
|
|
770
775
|
}
|
|
771
776
|
catch (error) {
|
|
772
777
|
console.error(chalk.red('Error during parsing:'), error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "defuddle-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Command line interface for Defuddle - extract article content from web pages",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"chalk": "^5.3.0",
|
|
23
23
|
"commander": "^12.0.0",
|
|
24
|
-
"defuddle": "^0.
|
|
24
|
+
"defuddle": "^0.4.0",
|
|
25
25
|
"jsdom": "^24.0.0",
|
|
26
26
|
"turndown": "^7.2.0"
|
|
27
27
|
},
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { JSDOM, VirtualConsole, DOMWindow } from 'jsdom';
|
|
5
|
-
import
|
|
6
|
-
const { Defuddle } = pkg;
|
|
5
|
+
import Defuddle from 'defuddle';
|
|
7
6
|
import chalk from 'chalk';
|
|
8
7
|
import { readFile, writeFile } from 'fs/promises';
|
|
9
8
|
import { fileURLToPath } from 'url';
|
|
@@ -801,8 +800,10 @@ program
|
|
|
801
800
|
|
|
802
801
|
// Parse content with debug mode if enabled
|
|
803
802
|
try {
|
|
803
|
+
// @ts-ignore - Module interop issue between ES modules and CommonJS
|
|
804
804
|
const defuddle = new Defuddle(doc, {
|
|
805
|
-
debug: options.debug
|
|
805
|
+
debug: options.debug,
|
|
806
|
+
...(source.startsWith('http') ? { url: source } : {})
|
|
806
807
|
});
|
|
807
808
|
|
|
808
809
|
const result = await defuddle.parse();
|
|
@@ -870,6 +871,12 @@ program
|
|
|
870
871
|
} else {
|
|
871
872
|
console.log(output);
|
|
872
873
|
}
|
|
874
|
+
|
|
875
|
+
// Clean up JSDOM resources
|
|
876
|
+
contentDom.window.close();
|
|
877
|
+
dom.window.close();
|
|
878
|
+
|
|
879
|
+
process.exit(0);
|
|
873
880
|
} catch (error) {
|
|
874
881
|
console.error(chalk.red('Error during parsing:'), error);
|
|
875
882
|
process.exit(1);
|