-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #599 from marp-team/debug-option
Add `--debug` (`-d`) option to CLI interface
- Loading branch information
Showing
12 changed files
with
348 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
{ | ||
const prepare = require('./lib/prepare.js') | ||
const cli = prepare.cliPrepare() | ||
|
||
require('./lib/marp-cli.js') | ||
.cliInterface(process.argv.slice(2)) | ||
.then((exitCode) => process.on('exit', () => process.exit(exitCode))) | ||
if (cli.debug) | ||
process.env.DEBUG = `${process.env.DEBUG ? `${process.env.DEBUG},` : ''}${cli.debug}` | ||
|
||
require('./lib/marp-cli.js') | ||
.cliInterface(cli.args) | ||
.then((exitCode) => process.on('exit', () => process.exit(exitCode))) | ||
} |
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
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,25 @@ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { exec } from '@yao-pkg/pkg' | ||
import { fetchIcu } from './icu.mjs' | ||
|
||
// Clean up bin directory | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
const binDir = path.join(__dirname, '../bin') | ||
|
||
await fs.promises.rm(binDir, { recursive: true, force: true }) | ||
|
||
// Fetch the ICU data | ||
const icuDat = await fetchIcu() | ||
|
||
// Run pkg | ||
await exec([ | ||
'--options', | ||
`icu-data-dir=${icuDat}`, | ||
'-C', | ||
'gzip', | ||
'--out-path', | ||
binDir, | ||
path.join(__dirname, '../'), | ||
]) |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export const defaultDebug = 'marp-cli*' | ||
|
||
const debugOptionMatcher = /^(?:-d|--debug)(?:$|=)/ | ||
|
||
const enableValues = ['true', '1'] | ||
const falseValues = ['false', '0'] | ||
const starValues = ['all', 'full'] | ||
|
||
const parseDebugValue = (value: string) => { | ||
const trimmedValue = value.trim() | ||
const normalizedValue = trimmedValue.toLowerCase() | ||
|
||
if (starValues.includes(normalizedValue)) return '*' | ||
if (enableValues.includes(normalizedValue)) return defaultDebug | ||
if (falseValues.includes(normalizedValue)) return false | ||
|
||
return trimmedValue || defaultDebug | ||
} | ||
|
||
export const cliPrepare = (args = process.argv.slice(2)) => { | ||
// Parse debug option | ||
let debug: string | false = false | ||
|
||
const normalizedArgs = [...args] | ||
const dbgIdx = normalizedArgs.findIndex((arg) => debugOptionMatcher.test(arg)) | ||
|
||
if (dbgIdx >= 0) { | ||
const dbgOption = normalizedArgs[dbgIdx] | ||
|
||
if (dbgOption.startsWith('-d=') || dbgOption.startsWith('--debug=')) { | ||
debug = parseDebugValue(dbgOption.slice(dbgOption.indexOf('=') + 1)) | ||
normalizedArgs.splice(dbgIdx, 1) | ||
} else { | ||
const nextArg = normalizedArgs[dbgIdx + 1] | ||
|
||
if (!nextArg || nextArg.startsWith('-')) { | ||
debug = defaultDebug | ||
normalizedArgs.splice(dbgIdx, 1) | ||
} else { | ||
debug = parseDebugValue(nextArg) | ||
normalizedArgs.splice(dbgIdx, 2) | ||
} | ||
} | ||
} | ||
|
||
return { args: normalizedArgs, debug } | ||
} |
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
Oops, something went wrong.