-
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.
- Loading branch information
1 parent
aec1b05
commit 13a1293
Showing
5 changed files
with
56 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
import camelCase from 'camelcase'; | ||
import fs from 'node:fs/promises'; | ||
import minimist from 'minimist'; | ||
import stringify from 'json-stringify-pretty-compact'; | ||
import {Deck, generateDataDragon} from './index.mjs'; | ||
|
||
const parameters = process.argv.slice(2); | ||
const [code, ...parameters] = process.argv.slice(2); | ||
|
||
if (parameters[0] === 'show') { | ||
console.log(Deck.fromCode(parameters[1])); | ||
} | ||
if (parameters[0] === 'json') { | ||
await fs.writeFile(parameters[1], stringify(await generateDataDragon().fetchData(parameters[2], parameters[3]), {indent: 2, maxLength: 180})); | ||
} | ||
if (parameters[0] === 'html') { | ||
await fs.writeFile(parameters[1], await generateDataDragon().generatePageFromCode(parameters[2], parameters[3])); | ||
console.log(Deck.fromCode(code)); | ||
|
||
if (parameters?.length) { | ||
const dragon = generateDataDragon(); | ||
|
||
const {style, language, outFile} = Object.fromEntries(Object.entries(minimist(parameters)).map(([k, v]) => [camelCase(k), v])); | ||
|
||
const data = | ||
style === 'html' || outFile.endsWith('.html') | ||
? await dragon.generatePageFromCode(code, language) | ||
: stringify(await dragon.fetchData(code, language), {indent: 2, maxLength: 180}); | ||
|
||
await fs.writeFile(outFile, data); | ||
} |
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