ts-command-line-args
Advanced tools
Comparing version 1.6.1 to 1.7.0
@@ -202,2 +202,3 @@ export declare type ArgumentConfig<T extends { | ||
replaceAbove: string; | ||
removeDoubleBlankLines: boolean; | ||
} | ||
@@ -204,0 +205,0 @@ export declare type JsImport = { |
@@ -16,4 +16,6 @@ "use strict"; | ||
var lines = line_ending_helper_1.splitContent(inputString); | ||
var replaceBelowIndex = lines.indexOf(options.replaceBelow); | ||
var replaceAboveIndex = lines.indexOf(options.replaceAbove); | ||
var replaceBelowLine = lines.filter(function (line) { return line.indexOf(options.replaceBelow) === 0; })[0]; | ||
var replaceBelowIndex = replaceBelowLine != null ? lines.indexOf(replaceBelowLine) : -1; | ||
var replaceAboveLine = lines.filter(function (line) { return line.indexOf(options.replaceAbove) === 0; })[0]; | ||
var replaceAboveIndex = replaceAboveLine != null ? lines.indexOf(replaceAboveLine) : -1; | ||
if (replaceAboveIndex > -1 && replaceBelowIndex > -1 && replaceAboveIndex < replaceBelowIndex) { | ||
@@ -25,4 +27,13 @@ throw new Error("The replaceAbove marker '" + options.replaceAbove + "' was found before the replaceBelow marker '" + options.replaceBelow + "'. The replaceBelow marked must be before the replaceAbove."); | ||
var constantLines = content.reduce(function (lines, currentContent) { return __spreadArrays(lines, line_ending_helper_1.splitContent(currentContent)); }, new Array()); | ||
return __spreadArrays(linesBefore, constantLines, linesAfter).join(lineBreak); | ||
var allLines = __spreadArrays(linesBefore, constantLines, linesAfter); | ||
if (options.removeDoubleBlankLines) { | ||
allLines = allLines.filter(function (line, index, lines) { return filterDoubleBlankLines(line, index, lines); }); | ||
} | ||
return allLines.join(lineBreak); | ||
} | ||
exports.addContent = addContent; | ||
var nonWhitespaceRegExp = /[^ \t]/; | ||
function filterDoubleBlankLines(line, index, lines) { | ||
var previousLine = index > 0 ? lines[index - 1] : undefined; | ||
return nonWhitespaceRegExp.test(line) || previousLine == null || nonWhitespaceRegExp.test(previousLine); | ||
} |
import { ArgumentConfig, IWriteMarkDown, ParseOptions, UsageGuideConfig } from './contracts'; | ||
export declare const replaceBelowDefault = "[//]: ####ts-command-line-args_write-markdown_replaceBelow "; | ||
export declare const replaceAboveDefault = "[//]: ####ts-command-line-args_write-markdown_replaceAbove "; | ||
export declare const replaceBelowDefault = "[//]: ####ts-command-line-args_write-markdown_replaceBelow"; | ||
export declare const replaceAboveDefault = "[//]: ####ts-command-line-args_write-markdown_replaceAbove"; | ||
export declare const configImportNameDefault = "usageGuideInfo"; | ||
@@ -5,0 +5,0 @@ export declare const argumentConfig: ArgumentConfig<IWriteMarkDown>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.usageGuideInfo = exports.parseOptions = exports.argumentConfig = exports.configImportNameDefault = exports.replaceAboveDefault = exports.replaceBelowDefault = void 0; | ||
exports.replaceBelowDefault = "[//]: ####ts-command-line-args_write-markdown_replaceBelow "; | ||
exports.replaceAboveDefault = "[//]: ####ts-command-line-args_write-markdown_replaceAbove "; | ||
exports.replaceBelowDefault = "[//]: ####ts-command-line-args_write-markdown_replaceBelow"; | ||
exports.replaceAboveDefault = "[//]: ####ts-command-line-args_write-markdown_replaceAbove"; | ||
exports.configImportNameDefault = "usageGuideInfo"; | ||
@@ -58,2 +58,6 @@ exports.argumentConfig = { | ||
}, | ||
removeDoubleBlankLines: { | ||
type: Boolean, | ||
description: 'When replacing content removes any more than a single blank line', | ||
}, | ||
help: { type: Boolean, alias: 'h', description: "Show this usage guide." }, | ||
@@ -82,3 +86,3 @@ }; | ||
header: 'Default Replacement Markers', | ||
content: "replaceBelow defaults to:\n{code '" + exports.replaceBelowDefault + "'}\nreplaceAbove defaults to:\n{code '" + exports.replaceAboveDefault + "'}\nNote the double spaces at the end to signify to markdown that there should be a new line.", | ||
content: "replaceBelow defaults to:\n{code '" + exports.replaceBelowDefault + "'}\nreplaceAbove defaults to:\n{code '" + exports.replaceAboveDefault + "'}", | ||
}, | ||
@@ -85,0 +89,0 @@ { |
@@ -23,17 +23,18 @@ #!/usr/bin/env node | ||
var contentMatch = markdownFileContent === modifiedFileContent ? "match" : "nonMatch"; | ||
var relativePath = path_1.relative(process.cwd(), markdownPath); | ||
switch (action + "_" + contentMatch) { | ||
case 'verify_match': | ||
console.log("'" + args.markdownPath + "' content as expected. No update required."); | ||
console.log(chalk_1.default.green("'" + relativePath + "' content as expected. No update required.")); | ||
break; | ||
case 'verify_nonMatch': | ||
console.warn(chalk_1.default.yellow(string_format_1.default(args.verifyMessage || "'{fileName}' file out of date. Rerun write-markdown to update.", { | ||
fileName: args.markdownPath, | ||
console.warn(chalk_1.default.yellow(string_format_1.default(args.verifyMessage || "'{relativePath}' file out of date. Rerun write-markdown to update.", { | ||
fileName: relativePath, | ||
}))); | ||
return process.exit(1); | ||
case 'write_match': | ||
console.log("'" + args.markdownPath + "' content not modified, not writing to file."); | ||
console.log(chalk_1.default.blue("'" + relativePath + "' content not modified, not writing to file.")); | ||
break; | ||
case 'write_nonMatch': | ||
console.log("Writing file to '" + markdownPath + "'"); | ||
fs_1.writeFileSync(markdownPath, modifiedFileContent); | ||
console.log(chalk_1.default.green("Writing file to '" + relativePath + "'")); | ||
fs_1.writeFileSync(relativePath, modifiedFileContent); | ||
break; | ||
@@ -40,0 +41,0 @@ } |
{ | ||
"name": "ts-command-line-args", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "A Typescript wrapper around command-line-args with additional support for markdown usage guide generation", | ||
@@ -83,4 +83,5 @@ "bin": { | ||
"jsFile": "dist/write-markdown.constants.js", | ||
"verifyMessage": "'{fileName}' is out of date. Please regenerate by running 'npm run write-markdown'" | ||
"verifyMessage": "'{fileName}' is out of date. Please regenerate by running 'npm run write-markdown'", | ||
"removeDoubleBlankLines": true | ||
} | ||
} |
@@ -213,3 +213,2 @@ # ts-command-line-args | ||
```bash | ||
@@ -272,7 +271,4 @@ $ node exampleConfig.js --configFile package.json --jsonPath copyFileConfig.copyFileOne --resetPermissions | ||
`write-markdown -m README.MD -j usageGuideConstants.js` | ||
### write-markdown cli options | ||
@@ -291,5 +287,5 @@ | ||
| **verifyMessage** | | string | Optional message that is printed when markdown verification fails. Use '{fileName}' to refer to the file being processed. | | ||
| **removeDoubleBlankLines** | | boolean | When replacing content removes any more than a single blank line | | ||
| **help** | **h** | boolean | Show this usage guide. | | ||
### Default Replacement Markers | ||
@@ -300,3 +296,3 @@ | ||
``` | ||
'[//]: ####ts-command-line-args_write-markdown_replaceBelow ' | ||
'[//]: ####ts-command-line-args_write-markdown_replaceBelow' | ||
``` | ||
@@ -307,8 +303,5 @@ | ||
``` | ||
'[//]: ####ts-command-line-args_write-markdown_replaceAbove ' | ||
'[//]: ####ts-command-line-args_write-markdown_replaceAbove' | ||
``` | ||
Note the double spaces at the end to signify to markdown that there should be a new line. | ||
### String Formatting | ||
@@ -329,4 +322,2 @@ | ||
### Additional Modifiers | ||
@@ -333,0 +324,0 @@ |
@@ -232,2 +232,3 @@ export type ArgumentConfig<T extends { [name: string]: any }> = { | ||
replaceAbove: string; | ||
removeDoubleBlankLines: boolean; | ||
} | ||
@@ -234,0 +235,0 @@ |
@@ -15,2 +15,3 @@ import { addContent } from './content.helper'; | ||
replaceBelow: '##replaceBelow', | ||
removeDoubleBlankLines: false, | ||
}; | ||
@@ -143,3 +144,64 @@ }); | ||
}); | ||
it('should not remove empty lines', () => { | ||
const initial = `content line 1 | ||
content line 2 | ||
##replaceBelow | ||
##replaceAbove | ||
content line 3`; | ||
const result = addContent( | ||
initial, | ||
`new content line one | ||
new content line two`, | ||
config, | ||
); | ||
expect(result).toBe(`content line 1 | ||
content line 2 | ||
##replaceBelow | ||
new content line one | ||
new content line two | ||
##replaceAbove | ||
content line 3`); | ||
}); | ||
it('should remove empty lines when passed in config', () => { | ||
const initial = `content line 1 | ||
content line 2 | ||
##replaceBelow | ||
##replaceAbove | ||
content line 3`; | ||
const result = addContent( | ||
initial, | ||
`new content line one | ||
new content line two`, | ||
{ ...config, removeDoubleBlankLines: true }, | ||
); | ||
expect(result).toBe(`content line 1 | ||
content line 2 | ||
##replaceBelow | ||
new content line one | ||
new content line two | ||
##replaceAbove | ||
content line 3`); | ||
}); | ||
}); | ||
}); |
@@ -9,4 +9,6 @@ import { IReplaceOptions } from '../contracts'; | ||
const lines = splitContent(inputString); | ||
const replaceBelowIndex = lines.indexOf(options.replaceBelow); | ||
const replaceAboveIndex = lines.indexOf(options.replaceAbove); | ||
const replaceBelowLine: string | undefined = lines.filter((line) => line.indexOf(options.replaceBelow) === 0)[0]; | ||
const replaceBelowIndex = replaceBelowLine != null ? lines.indexOf(replaceBelowLine) : -1; | ||
const replaceAboveLine: string | undefined = lines.filter((line) => line.indexOf(options.replaceAbove) === 0)[0]; | ||
const replaceAboveIndex = replaceAboveLine != null ? lines.indexOf(replaceAboveLine) : -1; | ||
@@ -27,3 +29,17 @@ if (replaceAboveIndex > -1 && replaceBelowIndex > -1 && replaceAboveIndex < replaceBelowIndex) { | ||
return [...linesBefore, ...constantLines, ...linesAfter].join(lineBreak); | ||
let allLines = [...linesBefore, ...constantLines, ...linesAfter]; | ||
if (options.removeDoubleBlankLines) { | ||
allLines = allLines.filter((line, index, lines) => filterDoubleBlankLines(line, index, lines)); | ||
} | ||
return allLines.join(lineBreak); | ||
} | ||
const nonWhitespaceRegExp = /[^ \t]/; | ||
function filterDoubleBlankLines(line: string, index: number, lines: string[]): boolean { | ||
const previousLine = index > 0 ? lines[index - 1] : undefined; | ||
return nonWhitespaceRegExp.test(line) || previousLine == null || nonWhitespaceRegExp.test(previousLine); | ||
} |
@@ -78,2 +78,3 @@ /* eslint-disable no-useless-escape */ | ||
| **verifyMessage** | | string | Optional message that is printed when markdown verification fails. Use '{fileName}' to refer to the file being processed. | | ||
| **removeDoubleBlankLines** | | boolean | When replacing content removes any more than a single blank line | | ||
| **help** | **h** | boolean | Show this usage guide. | | ||
@@ -87,3 +88,3 @@ | ||
\`\`\` | ||
'[//]: ####ts-command-line-args_write-markdown_replaceBelow ' | ||
'[//]: ####ts-command-line-args_write-markdown_replaceBelow' | ||
\`\`\` | ||
@@ -94,8 +95,7 @@ | ||
\`\`\` | ||
'[//]: ####ts-command-line-args_write-markdown_replaceAbove ' | ||
'[//]: ####ts-command-line-args_write-markdown_replaceAbove' | ||
\`\`\` | ||
Note the double spaces at the end to signify to markdown that there should be a new line. | ||
### String Formatting | ||
@@ -102,0 +102,0 @@ |
import { ArgumentConfig, IWriteMarkDown, ParseOptions, UsageGuideConfig } from './contracts'; | ||
export const replaceBelowDefault = `[//]: ####ts-command-line-args_write-markdown_replaceBelow `; | ||
export const replaceAboveDefault = `[//]: ####ts-command-line-args_write-markdown_replaceAbove `; | ||
export const replaceBelowDefault = `[//]: ####ts-command-line-args_write-markdown_replaceBelow`; | ||
export const replaceAboveDefault = `[//]: ####ts-command-line-args_write-markdown_replaceAbove`; | ||
export const configImportNameDefault = `usageGuideInfo`; | ||
@@ -59,2 +59,6 @@ | ||
}, | ||
removeDoubleBlankLines: { | ||
type: Boolean, | ||
description: 'When replacing content removes any more than a single blank line', | ||
}, | ||
help: { type: Boolean, alias: 'h', description: `Show this usage guide.` }, | ||
@@ -88,4 +92,3 @@ }; | ||
replaceAbove defaults to: | ||
{code '${replaceAboveDefault}'} | ||
Note the double spaces at the end to signify to markdown that there should be a new line.`, | ||
{code '${replaceAboveDefault}'}`, | ||
}, | ||
@@ -92,0 +95,0 @@ { |
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
import { IWriteMarkDown } from './contracts'; | ||
import { resolve } from 'path'; | ||
import { resolve, relative } from 'path'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
@@ -27,5 +27,7 @@ import { addContent, generateUsageGuides } from './helpers'; | ||
const relativePath = relative(process.cwd(), markdownPath); | ||
switch (`${action}_${contentMatch}`) { | ||
case 'verify_match': | ||
console.log(`'${args.markdownPath}' content as expected. No update required.`); | ||
console.log(chalk.green(`'${relativePath}' content as expected. No update required.`)); | ||
break; | ||
@@ -35,4 +37,4 @@ case 'verify_nonMatch': | ||
chalk.yellow( | ||
format(args.verifyMessage || `'{fileName}' file out of date. Rerun write-markdown to update.`, { | ||
fileName: args.markdownPath, | ||
format(args.verifyMessage || `'{relativePath}' file out of date. Rerun write-markdown to update.`, { | ||
fileName: relativePath, | ||
}), | ||
@@ -43,7 +45,7 @@ ), | ||
case 'write_match': | ||
console.log(`'${args.markdownPath}' content not modified, not writing to file.`); | ||
console.log(chalk.blue(`'${relativePath}' content not modified, not writing to file.`)); | ||
break; | ||
case 'write_nonMatch': | ||
console.log(`Writing file to '${markdownPath}'`); | ||
writeFileSync(markdownPath, modifiedFileContent); | ||
console.log(chalk.green(`Writing file to '${relativePath}'`)); | ||
writeFileSync(relativePath, modifiedFileContent); | ||
break; | ||
@@ -50,0 +52,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
586074
4740
585