diff2html-cli
Advanced tools
Comparing version 5.2.14 to 5.2.15
@@ -13,2 +13,40 @@ import { createRequire } from 'node:module'; | ||
const defaultArgs = ['-M', '-C', 'HEAD']; | ||
const lightGitHubTheme = `<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" />`; | ||
const darkGitHubTheme = `<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css" />`; | ||
const autoGitHubTheme = `<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" media="screen and (prefers-color-scheme: light)" /> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css" media="screen and (prefers-color-scheme: dark)" />`; | ||
const lightBaseStyle = `<style> | ||
body { | ||
background-color: var(--d2h-bg-color); | ||
} | ||
h1 { | ||
color: var(--d2h-light-color); | ||
} | ||
</style>`; | ||
const darkBaseStyle = `<style> | ||
body { | ||
background-color: rgb(13, 17, 23); | ||
} | ||
h1 { | ||
color: var(--d2h-dark-color); | ||
} | ||
</style>`; | ||
const autoBaseStyle = `<style> | ||
@media screen and (prefers-color-scheme: light) { | ||
body { | ||
background-color: var(--d2h-bg-color); | ||
} | ||
h1 { | ||
color: var(--d2h-light-color); | ||
} | ||
} | ||
@media screen and (prefers-color-scheme: dark) { | ||
body { | ||
background-color: rgb(13, 17, 23); | ||
} | ||
h1 { | ||
color: var(--d2h-dark-color); | ||
} | ||
} | ||
</style>`; | ||
function generateGitDiffArgs(gitArgsArr, ignore) { | ||
@@ -32,3 +70,3 @@ const gitDiffArgs = ['diff']; | ||
} | ||
function prepareHTML(diffHTMLContent, config) { | ||
function prepareHTML(diffHTMLContent, config, colorScheme) { | ||
const template = utils.readFile(config.htmlWrapperTemplate); | ||
@@ -42,5 +80,10 @@ const diff2htmlPath = path.join(path.dirname(require.resolve('diff2html')), '..'); | ||
const pageHeader = config.pageHeader; | ||
const gitHubTheme = colorScheme === 'light' ? lightGitHubTheme : colorScheme === 'dark' ? darkGitHubTheme : autoGitHubTheme; | ||
const baseStyle = colorScheme === 'light' ? lightBaseStyle : colorScheme === 'dark' ? darkBaseStyle : autoBaseStyle; | ||
return [ | ||
{ searchValue: '<!--diff2html-title-->', replaceValue: pageTitle }, | ||
{ searchValue: '<!--diff2html-css-->', replaceValue: `<style>\n${cssContent}\n</style>` }, | ||
{ | ||
searchValue: '<!--diff2html-css-->', | ||
replaceValue: `${baseStyle}\n${gitHubTheme}\n<style>\n${cssContent}\n</style>`, | ||
}, | ||
{ searchValue: '<!--diff2html-js-ui-->', replaceValue: `<script>\n${jsUiContent}\n</script>` }, | ||
@@ -86,3 +129,3 @@ { | ||
const htmlContent = html(diffJson, { ...options }); | ||
return prepareHTML(htmlContent, config); | ||
return prepareHTML(htmlContent, config, options.colorScheme); | ||
} | ||
@@ -89,0 +132,0 @@ case 'json': { |
@@ -28,2 +28,3 @@ import { dirname, resolve } from 'path'; | ||
maxLineLengthHighlight: argv.maxLineLengthHighlight, | ||
colorScheme: argv.colorScheme, | ||
}; | ||
@@ -30,0 +31,0 @@ const defaultPageTitle = 'Diff to HTML by rtfpessoa'; |
@@ -0,1 +1,2 @@ | ||
import { ColorSchemeType } from 'diff2html/lib/types.js'; | ||
import { StyleType, SummaryType, LineMatchingType, FormatType, InputType, OutputType, DiffyType, DiffStyleType } from './types.js'; | ||
@@ -26,4 +27,5 @@ export type Argv = { | ||
extraArguments: string[]; | ||
colorScheme: ColorSchemeType; | ||
}; | ||
export declare function setup(): Promise<Argv>; | ||
//# sourceMappingURL=yargs.d.ts.map |
import yargs from 'yargs'; | ||
import { ColorSchemeType } from 'diff2html/lib/types.js'; | ||
const defaults = { | ||
@@ -24,2 +25,3 @@ style: 'line', | ||
extraArguments: [], | ||
colorScheme: ColorSchemeType.AUTO, | ||
}; | ||
@@ -35,2 +37,3 @@ const choices = { | ||
diffy: ['browser', 'pbcopy', 'print'], | ||
colorScheme: [ColorSchemeType.AUTO, ColorSchemeType.DARK, ColorSchemeType.LIGHT], | ||
}; | ||
@@ -66,2 +69,8 @@ export async function setup() { | ||
}) | ||
.option('colorScheme', { | ||
alias: 'cs', | ||
describe: 'Color scheme of HTML output', | ||
choices: choices.colorScheme, | ||
default: defaults.colorScheme, | ||
}) | ||
.option('summary', { | ||
@@ -68,0 +77,0 @@ alias: 'su', |
{ | ||
"name": "diff2html-cli", | ||
"version": "5.2.14", | ||
"version": "5.2.15", | ||
"homepage": "https://diff2html.xyz/index.html#cli", | ||
@@ -5,0 +5,0 @@ "description": "Fast Diff to colorized HTML", |
@@ -77,2 +77,3 @@ # diff2html-cli | ||
| --hc | --highlightCode | Highlight code | `true`, `false` | `true` | | ||
| --cs | --colorScheme | Color scheme | `auto`, `dark`, `light` | `auto` | | ||
| --su | --summary | Show files summary | `closed`, `open`, `hidden` | `closed` | | ||
@@ -79,0 +80,0 @@ | -d | --diffStyle | Diff style | `word`, `char` | `word` | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58918
603
191