Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-command-line-args

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-command-line-args - npm Package Compare versions

Comparing version 2.3.1 to 2.4.0

8

coverage/lcov-report/block-navigation.js

@@ -66,2 +66,10 @@ /* eslint-disable */

return function jump(event) {
if (
document.getElementById('fileSearch') === document.activeElement &&
document.activeElement != null
) {
// if we're currently focused on the search input, we don't want to navigate
return;
}
switch (event.which) {

@@ -68,0 +76,0 @@ case 78: // n

@@ -27,2 +27,27 @@ /* eslint-disable */

function onFilterInput() {
const searchValue = document.getElementById('fileSearch').value;
const rows = document.getElementsByTagName('tbody')[0].children;
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
if (
row.textContent
.toLowerCase()
.includes(searchValue.toLowerCase())
) {
row.style.display = '';
} else {
row.style.display = 'none';
}
}
}
// loads the search box
function addSearchBox() {
var template = document.getElementById('filterTemplate');
var templateClone = template.content.cloneNode(true);
templateClone.getElementById('fileSearch').oninput = onFilterInput;
template.parentElement.appendChild(templateClone);
}
// loads all columns

@@ -166,2 +191,3 @@ function loadColumns() {

loadData();
addSearchBox();
addSortIndicators();

@@ -168,0 +194,0 @@ enableUI();

14

dist/helpers/add-content.helper.js
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -35,4 +33,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

var linesAfter = replaceAboveIndex >= 0 ? lines.slice(replaceAboveIndex) : [];
var contentLines = content.reduce(function (lines, currentContent) { return __spreadArrays(lines, line_ending_helper_1.splitContent(currentContent)); }, new Array());
var allLines = __spreadArrays(linesBefore, contentLines, linesAfter);
var contentLines = content.reduce(function (lines, currentContent) { return __spreadArray(__spreadArray([], lines), line_ending_helper_1.splitContent(currentContent)); }, new Array());
var allLines = __spreadArray(__spreadArray(__spreadArray([], linesBefore), contentLines), linesAfter);
if (options.removeDoubleBlankLines) {

@@ -39,0 +37,0 @@ allLines = allLines.filter(function (line, index, lines) { return line_ending_helper_1.filterDoubleBlankLines(line, index, lines); });

@@ -13,8 +13,6 @@ "use strict";

};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -115,3 +113,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

else {
return { args: __spreadArrays(argsAndLastValue.args, [arg]), lastOption: argOptions };
return { args: __spreadArray(__spreadArray([], argsAndLastValue.args), [arg]), lastOption: argOptions };
}

@@ -118,0 +116,0 @@ }

@@ -49,8 +49,6 @@ "use strict";

};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -141,3 +139,3 @@ var __importDefault = (this && this.__importDefault) || function (mod) {

linesAfter = insertCodeAboveResult != null ? lines.slice(insertCodeAboveResult.lineIndex) : [];
lines = __spreadArrays(linesBefore, linesFromFile, linesAfter);
lines = __spreadArray(__spreadArray(__spreadArray([], linesBefore), linesFromFile), linesAfter);
return [2 /*return*/, insertCodeAboveResult == null

@@ -152,6 +150,7 @@ ? lines

var codeCommentRegExp = /codeComment(="([^"]+)")?/; //https://regex101.com/r/3MVdBO/1
var snippetRegExp = /snippetName="([^"]+)"/;
function loadLines(targetFilePath, options, result) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var partialPathResult, codeCommentResult, partialPath, filePath, fileBuffer, contentLines, copyBelowMarker, copyAboveMarker, copyBelowIndex, copyAboveIndex;
var partialPathResult, codeCommentResult, snippetResult, partialPath, filePath, fileBuffer, contentLines, copyBelowMarker, copyAboveMarker, copyBelowIndex, copyAboveIndex;
return __generator(this, function (_b) {

@@ -165,4 +164,5 @@ switch (_b.label) {

codeCommentResult = codeCommentRegExp.exec(result.line);
partialPath = path_1.normalize(partialPathResult[1]);
filePath = path_1.normalize(path_1.isAbsolute(partialPath) ? partialPath : path_1.join(path_1.dirname(targetFilePath), partialPathResult[1]));
snippetResult = snippetRegExp.exec(result.line);
partialPath = partialPathResult[1];
filePath = path_1.isAbsolute(partialPath) ? partialPath : path_1.join(path_1.dirname(targetFilePath), partialPathResult[1]);
console.log("Inserting code from '" + chalk_1.default.blue(filePath) + "' into '" + chalk_1.default.blue(targetFilePath) + "'");

@@ -175,3 +175,3 @@ return [4 /*yield*/, asyncReadFile(filePath)];

copyAboveMarker = options.copyCodeAbove;
copyBelowIndex = copyBelowMarker != null ? contentLines.findIndex(function (line) { return line.indexOf(copyBelowMarker) === 0; }) : -1;
copyBelowIndex = copyBelowMarker != null ? contentLines.findIndex(findLine(copyBelowMarker, snippetResult === null || snippetResult === void 0 ? void 0 : snippetResult[1])) : -1;
copyAboveIndex = copyAboveMarker != null ? contentLines.findIndex(function (line) { return line.indexOf(copyAboveMarker) === 0; }) : -1;

@@ -181,5 +181,11 @@ if (copyAboveIndex > -1 && copyBelowIndex > -1 && copyAboveIndex < copyBelowIndex) {

}
if (snippetResult != null && copyBelowIndex < 0) {
console.log("snippetResult: ", snippetResult);
console.log("snippetResult[1]: ", snippetResult[1]);
console.log("line: ", result.line);
throw new Error("The copyCodeBelow marker '" + options.copyCodeBelow + "' was not found with the requested snippet " + snippetResult[1]);
}
contentLines = contentLines.slice(copyBelowIndex + 1, copyAboveIndex > 0 ? copyAboveIndex : undefined);
if (codeCommentResult != null) {
contentLines = __spreadArrays(['```' + ((_a = codeCommentResult[2]) !== null && _a !== void 0 ? _a : '')], contentLines, ['```']);
contentLines = __spreadArray(__spreadArray(['```' + ((_a = codeCommentResult[2]) !== null && _a !== void 0 ? _a : '')], contentLines), ['```']);
}

@@ -191,2 +197,7 @@ return [2 /*return*/, contentLines];

}
function findLine(copyBelowMarker, snippetName) {
return function (line) {
return line.indexOf(copyBelowMarker) === 0 && (snippetName == null || line.indexOf(snippetName) > 0);
};
}
function findIndex(lines, predicate, startLine) {

@@ -193,0 +204,0 @@ for (var lineIndex = startLine; lineIndex < lines.length; lineIndex++) {

@@ -7,3 +7,3 @@ import { UsageGuideConfig, IWriteMarkDown, ArgumentConfig, CommandLineOption, ParseOptions, Content, HeaderLevel, OptionContent, SectionHeader } from '../contracts';

export declare function createOptionsSections<T>(cliArguments: ArgumentConfig<T>, options: ParseOptions<any>): string[];
export declare function createOptionsSection<T>(optionList: CommandLineOption<any>[], content: OptionContent, options: ParseOptions<any>): string;
export declare function createOptionsSection(optionList: CommandLineOption<any>[], content: OptionContent, options: ParseOptions<any>): string;
export declare function createHeading(section: SectionHeader, defaultLevel: HeaderLevel): string;

@@ -10,0 +10,0 @@ export declare function createOptionRow(option: CommandLineOption, includeAlias?: boolean, includeDescription?: boolean): string;

"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -19,3 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var footerSections = options.footerContentSections || [];
return __spreadArrays(headerSections.filter(filterMarkdownSections).map(function (section) { return createSection(section, config); }), createOptionsSections(config.arguments, options), footerSections.filter(filterMarkdownSections).map(function (section) { return createSection(section, config); })).join('\n');
return __spreadArray(__spreadArray(__spreadArray([], headerSections.filter(filterMarkdownSections).map(function (section) { return createSection(section, config); })), createOptionsSections(config.arguments, options)), footerSections.filter(filterMarkdownSections).map(function (section) { return createSection(section, config); })).join('\n');
}

@@ -117,3 +115,3 @@ exports.createUsageGuide = createUsageGuide;

function mapJsImports(imports, jsFile) {
return __spreadArrays(imports, args.configImportName.map(function (importName) { return ({ jsFile: jsFile, importName: importName }); }));
return __spreadArray(__spreadArray([], imports), args.configImportName.map(function (importName) { return ({ jsFile: jsFile, importName: importName }); }));
}

@@ -120,0 +118,0 @@ return args.jsFile

@@ -24,8 +24,6 @@ "use strict";

};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};

@@ -129,3 +127,3 @@ var __importDefault = (this && this.__importDefault) || function (mod) {

if (additionalHeaderSections === void 0) { additionalHeaderSections = []; }
var sections = __spreadArrays(additionalHeaderSections, (((_a = options.headerContentSections) === null || _a === void 0 ? void 0 : _a.filter(filterCliSections)) || []), options_helper_1.getOptionSections(options).map(function (option) { return options_helper_1.addOptions(option, optionList, options); }), options_helper_1.getOptionFooterSection(optionList, options), (((_b = options.footerContentSections) === null || _b === void 0 ? void 0 : _b.filter(filterCliSections)) || []));
var sections = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], additionalHeaderSections), (((_a = options.headerContentSections) === null || _a === void 0 ? void 0 : _a.filter(filterCliSections)) || [])), options_helper_1.getOptionSections(options).map(function (option) { return options_helper_1.addOptions(option, optionList, options); })), options_helper_1.getOptionFooterSection(optionList, options)), (((_b = options.footerContentSections) === null || _b === void 0 ? void 0 : _b.filter(filterCliSections)) || []));
helpers_1.visit(sections, function (value) {

@@ -132,0 +130,0 @@ switch (typeof value) {

{
"name": "ts-command-line-args",
"version": "2.3.1",
"version": "2.4.0",
"description": "A Typescript wrapper around command-line-args with additional support for markdown usage guide generation",

@@ -31,6 +31,7 @@ "bin": {

"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"test": "jest --ci --coverage && tsc --noemit",
"watch-test": "jest --watch",
"prebuild-release": "npm run clean",
"build-release": "concurrently --kill-others-on-fail npm:test npm:lint npm:build npm:build:example npm:verify-markdown && codecov",
"build-release": "concurrently --kill-others-on-fail npm:test npm:lint npm:build npm:build:example npm:verify-markdown",
"prewrite-markdown": "npm run build",

@@ -53,2 +54,3 @@ "preverify-markdown": "npm run build",

"dependencies": {
"@morgan-stanley/ts-mocking-bird": "^0.6.2",
"chalk": "^4.1.0",

@@ -60,12 +62,9 @@ "command-line-args": "^5.1.1",

"devDependencies": {
"@morgan-stanley/ts-mocking-bird": "^0.2.3",
"@types/chalk": "^2.2.0",
"@types/command-line-args": "^5.0.0",
"@types/command-line-usage": "^5.0.1",
"@types/jest": "^26.0.10",
"@types/jest": "^27.5.1",
"@types/string-format": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"ansi-regex": "^5.0.1",
"codecov": "^3.8.3",
"concurrently": "^6.3.0",

@@ -81,8 +80,8 @@ "eslint": "^7.7.0",

"hosted-git-info": "^2.8.9",
"jest": "^26.4.2",
"jest": "^27.5.1",
"lodash": "^4.17.21",
"prettier": "^2.1.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.3.0",
"typescript": "^4.0.3"
"ts-jest": "^27.1.5",
"typescript": "4.3"
},

@@ -89,0 +88,0 @@ "markdownConfig": {

@@ -357,7 +357,7 @@ # ts-command-line-args

export const someExport = "not copied";
// ts-command-line-args_write-markdown_copyCodeBelow;
// ts-command-line-args_write-markdown_copyCodeBelow
export function (){
//this function will be copied
}
// ts-command-line-args_write-markdown_copyCodeAbove;
// ts-command-line-args_write-markdown_copyCodeAbove
```

@@ -381,2 +381,19 @@

#### Snippets
If you have a file that you want to copy multiple chunks of code from `snippetName` can be used to specify which section of code you want to copy:
```
[//]: # (ts-command-line-args_write-markdown_insertCodeBelow file="path/from/markdown/to/file.ts" snippetName="mySnippet" )
```
```ts
export const someExport = "not copied";
// ts-command-line-args_write-markdown_copyCodeBelow mySnippet
export function (){
//this function will be copied
}
// ts-command-line-args_write-markdown_copyCodeAbove
```
### String Formatting

@@ -383,0 +400,0 @@

@@ -20,3 +20,3 @@ import { IInsertCodeOptions } from '../contracts';

const insertBelowToken = `${insertCodeBelowDefault} file="someFile.ts" )`;
let insertBelowToken = `${insertCodeBelowDefault} file="someFile.ts" )`;

@@ -30,7 +30,11 @@ const sampleDirName = `sample/dirname`;

let mockedFs: IMocked<typeof originalFs>;
let insertCodeFromContent: string;
beforeEach(() => {
insertBelowToken = `${insertCodeBelowDefault} file="someFile.ts" )`;
insertCodeFromContent = `${insertLineOne}${EOL}${insertLineTwo}`;
mockedFs = Mock.create<typeof originalFs>().setup(
setupFunction('readFile', ((_path: string, callback: (err: Error | null, data: Buffer) => void) => {
callback(null, Buffer.from(`${insertLineOne}${EOL}${insertLineTwo}`));
callback(null, Buffer.from(insertCodeFromContent));
}) as any),

@@ -247,2 +251,9 @@ setupFunction('writeFile', ((_path: string, _data: any, callback: () => void) => {

it(`should should only insert file content between copyAbove and copyBelow tokens`, async () => {
insertCodeFromContent = [
'randomFirstLine',
copyCodeBelowDefault,
insertLineOne,
copyCodeAboveDefault,
insertLineTwo,
].join('\n');
const fileContent = [beforeInsertionLine, insertBelowToken, insertCodeAboveDefault, afterInsertionLine].join(

@@ -252,8 +263,38 @@ '\n',

const fileLines = ['randomFirstLine', copyCodeBelowDefault, insertLineOne, copyCodeAboveDefault, insertLineTwo];
const result = await insertCode(
{ fileContent, filePath: `${sampleDirName}/'originalFilePath.ts` },
createOptions(),
);
mockedFs.setupFunction('readFile', ((_path: string, callback: (err: Error | null, data: Buffer) => void) => {
callback(null, Buffer.from(fileLines.join(EOL)));
}) as any);
expect(
mockedFs.withFunction('readFile').withParameters(join(sampleDirName, 'someFile.ts'), any()),
).wasCalledOnce();
const expectedContent = [
beforeInsertionLine,
insertBelowToken,
insertLineOne,
insertCodeAboveDefault,
afterInsertionLine,
].join('\n');
expect(result).toEqual(expectedContent);
});
it(`should insert selected snippet when snippet defined`, async () => {
insertCodeFromContent = [
'randomFirstLine',
`// ts-command-line-args_write-markdown_copyCodeBelow expectedSnippet`,
insertLineOne,
copyCodeAboveDefault,
copyCodeBelowDefault,
insertLineTwo,
copyCodeAboveDefault,
].join('\n');
insertBelowToken = `${insertCodeBelowDefault} file="someFile.ts" snippetName="expectedSnippet" )`;
const fileContent = [beforeInsertionLine, insertBelowToken, insertCodeAboveDefault, afterInsertionLine].join(
'\n',
);
const result = await insertCode(

@@ -260,0 +301,0 @@ { fileContent, filePath: `${sampleDirName}/'originalFilePath.ts` },

import { IInsertCodeOptions } from '../contracts';
import { filterDoubleBlankLines, findEscapeSequence, splitContent } from './line-ending.helper';
import { isAbsolute, resolve, dirname, join, normalize } from 'path';
import { isAbsolute, resolve, dirname, join } from 'path';
import { promisify } from 'util';

@@ -99,2 +99,3 @@ import { readFile, writeFile } from 'fs';

const codeCommentRegExp = /codeComment(="([^"]+)")?/; //https://regex101.com/r/3MVdBO/1
const snippetRegExp = /snippetName="([^"]+)"/;

@@ -114,8 +115,6 @@ async function loadLines(

const codeCommentResult = codeCommentRegExp.exec(result.line);
const partialPath = normalize(partialPathResult[1]);
const snippetResult = snippetRegExp.exec(result.line);
const partialPath = partialPathResult[1];
const filePath = normalize(
isAbsolute(partialPath) ? partialPath : join(dirname(targetFilePath), partialPathResult[1]),
);
const filePath = isAbsolute(partialPath) ? partialPath : join(dirname(targetFilePath), partialPathResult[1]);
console.log(`Inserting code from '${chalk.blue(filePath)}' into '${chalk.blue(targetFilePath)}'`);

@@ -131,3 +130,3 @@

const copyBelowIndex =
copyBelowMarker != null ? contentLines.findIndex((line) => line.indexOf(copyBelowMarker) === 0) : -1;
copyBelowMarker != null ? contentLines.findIndex(findLine(copyBelowMarker, snippetResult?.[1])) : -1;
const copyAboveIndex =

@@ -142,2 +141,12 @@ copyAboveMarker != null ? contentLines.findIndex((line) => line.indexOf(copyAboveMarker) === 0) : -1;

if (snippetResult != null && copyBelowIndex < 0) {
console.log(`snippetResult: `, snippetResult);
console.log(`snippetResult[1]: `, snippetResult[1]);
console.log(`line: `, result.line);
throw new Error(
`The copyCodeBelow marker '${options.copyCodeBelow}' was not found with the requested snippet ${snippetResult[1]}`,
);
}
contentLines = contentLines.slice(copyBelowIndex + 1, copyAboveIndex > 0 ? copyAboveIndex : undefined);

@@ -152,2 +161,8 @@

function findLine(copyBelowMarker: string, snippetName?: string): (line: string) => boolean {
return (line: string): boolean => {
return line.indexOf(copyBelowMarker) === 0 && (snippetName == null || line.indexOf(snippetName) > 0);
};
}
type FindLineResults = { line: string; lineIndex: number };

@@ -154,0 +169,0 @@

@@ -80,3 +80,3 @@ import {

export function createOptionsSection<T>(
export function createOptionsSection(
optionList: CommandLineOption<any>[],

@@ -83,0 +83,0 @@ content: OptionContent,

@@ -38,3 +38,3 @@ import {

const optionalProps = optionList.some((option) => ((option as unknown) as OptionalProperty).optional === true);
const optionalProps = optionList.some((option) => (option as unknown as OptionalProperty).optional === true);
const defaultProps = optionList.some((option) => option.defaultOption === true);

@@ -88,3 +88,3 @@

if (((definition as unknown) as OptionalProperty).optional === true) {
if ((definition as unknown as OptionalProperty).optional === true) {
definition.description = `Optional. ${definition.description}`;

@@ -111,3 +111,3 @@ }

if (((definition as unknown) as OptionalProperty).optional === true) {
if ((definition as unknown as OptionalProperty).optional === true) {
definition.typeLabel = `${definition.typeLabel} (O)`;

@@ -114,0 +114,0 @@ }

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 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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc