-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cli for @extractus/extractus
- Loading branch information
1 parent
7c4a8b3
commit 1e738c1
Showing
7 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"test": { | ||
"DEBUG": true, | ||
"NODE_OPTIONS": "--loader=ts-node/esm --no-warnings=ExperimentalWarning --experimental-wasm-modules" | ||
}, | ||
"debug": { | ||
"DEBUG": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
], | ||
"search.exclude": { | ||
"**/node_modules": false | ||
} | ||
}, | ||
"typescript.tsdk": "node_modules\\typescript\\lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { defineCommand, runMain } from 'citty' | ||
import { isURLString } from 'extra-utils' | ||
import { ofetch } from 'ofetch' | ||
import path from 'path' | ||
import fs from 'fs/promises' | ||
import { extract } from './index.js' | ||
import objectInspect from 'object-inspect' | ||
import logger from './logger.js' | ||
|
||
const main = defineCommand({ | ||
args: { | ||
input: { | ||
type: 'positional', | ||
description: 'Url, html string, html file path', | ||
required: true | ||
} | ||
}, | ||
async run({ args }) { | ||
let input = args.input | ||
if (isURLString(args.input)) { | ||
input = await ofetch(args.input) | ||
} | ||
try { | ||
const filepath = path.format(path.parse(input)) | ||
input = (await fs.readFile(filepath)).toString() | ||
} catch (error) {} | ||
logger.info(objectInspect(await extract(input), { indent: 2 })) | ||
} | ||
}) | ||
|
||
runMain(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ const colors = { | |
WARN: chalk.yellow, | ||
ERROR: chalk.red | ||
} | ||
|
||
logPrefix.reg(log) | ||
log.enableAll() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.