diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ea8cc9..37acb51 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Publish Release +name: release on: push: tags: diff --git a/src/__snapshots__/index.test.ts.snap b/src/__snapshots__/index.test.ts.snap index cecabd2..c6909de 100644 --- a/src/__snapshots__/index.test.ts.snap +++ b/src/__snapshots__/index.test.ts.snap @@ -46,399 +46,6 @@ exports[`cli module calls tree() and formats as list, with custom visibility lev exports[`cli module calls tree() and formats as tree 1`] = ` "ts-print-tree/ -├── node_modules/ -│ ├── @jest/ -│ │ ├── environment/ -│ │ │ └── build/ -│ │ │ └── index.d.ts -│ │ │ ├── interface Jest -│ │ │ ├── class JestEnvironment -│ │ │ ├── interface JestEnvironmentConfig -│ │ │ └── interface JestImportMeta -│ │ ├── expect/ -│ │ │ └── build/ -│ │ │ └── index.d.ts -│ │ │ └── const jestExpect -│ │ ├── expect-utils/ -│ │ │ └── build/ -│ │ │ └── index.d.ts -│ │ │ ├── const arrayBufferEquality -│ │ │ ├── function emptyObject(obj: unknown): boolean -│ │ │ ├── const equals -│ │ │ ├── const getObjectKeys -│ │ │ ├── const getObjectSubset -│ │ │ ├── const getPath -│ │ │ ├── function isA(typeName: string, value: unknown): boolean -│ │ │ ├── const isError -│ │ │ ├── const isOneline -│ │ │ ├── const iterableEquality -│ │ │ ├── const partition -│ │ │ ├── const pathAsArray -│ │ │ ├── const sparseArrayEquality -│ │ │ ├── const subsetEquality -│ │ │ ├── interface TesterContext -│ │ │ └── const typeEquality -│ │ ├── fake-timers/ -│ │ │ └── build/ -│ │ │ └── index.d.ts -│ │ │ ├── class LegacyFakeTimers -│ │ │ └── class ModernFakeTimers -│ │ ├── globals/ -│ │ │ └── build/ -│ │ │ └── index.d.ts -│ │ │ ├── const expect -│ │ │ ├── const it -│ │ │ ├── const test -│ │ │ ├── const fit -│ │ │ ├── const xit -│ │ │ ├── const xtest -│ │ │ ├── const describe -│ │ │ ├── const xdescribe -│ │ │ ├── const fdescribe -│ │ │ ├── const beforeAll -│ │ │ ├── const beforeEach -│ │ │ ├── const afterEach -│ │ │ └── const afterAll -│ │ └── schemas/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ └── const SnapshotFormat -│ ├── @sinclair/ -│ │ └── typebox/ -│ │ └── typebox.d.ts -│ │ ├── const Modifier -│ │ ├── const Hint -│ │ ├── const Kind -│ │ ├── const PatternBoolean -│ │ ├── const PatternNumber -│ │ ├── const PatternString -│ │ ├── const PatternBooleanExact -│ │ ├── const PatternNumberExact -│ │ ├── const PatternStringExact -│ │ ├── interface SchemaOptions -│ │ ├── interface TKind -│ │ ├── interface TSchema -│ │ ├── interface NumericOptions -│ │ ├── interface TAny -│ │ ├── interface ArrayOptions -│ │ ├── interface TArray -│ │ ├── interface TBigInt -│ │ ├── interface TBoolean -│ │ ├── interface TComposite -│ │ ├── interface TConstructor -│ │ ├── interface DateOptions -│ │ ├── interface TDate -│ │ ├── interface TEnumOption -│ │ ├── interface TEnum -│ │ ├── interface TFunction -│ │ ├── interface TInteger -│ │ ├── interface IntersectOptions -│ │ ├── interface TIntersect -│ │ ├── interface TLiteral -│ │ ├── interface TNever -│ │ ├── interface TNot -│ │ ├── interface TNull -│ │ ├── interface TNumber -│ │ ├── interface ObjectOptions -│ │ ├── interface TObject -│ │ ├── interface TPromise -│ │ ├── interface TRecord -│ │ ├── interface TThis -│ │ ├── interface TRecursive -│ │ ├── interface TRef -│ │ ├── interface StringOptions -│ │ ├── interface TString -│ │ ├── interface TSymbol -│ │ ├── interface TTemplateLiteral -│ │ ├── interface TTuple -│ │ ├── interface TUndefined -│ │ ├── interface TUnion -│ │ ├── interface Uint8ArrayOptions -│ │ ├── interface TUint8Array -│ │ ├── interface TUnknown -│ │ ├── interface UnsafeOptions -│ │ ├── interface TUnsafe -│ │ ├── interface TVoid -│ │ ├── class TypeGuardUnknownTypeError -│ │ ├── class TemplateLiteralParserError -│ │ ├── class TypeBuilder -│ │ ├── class StandardTypeBuilder -│ │ ├── class ExtendedTypeBuilder -│ │ ├── const StandardType -│ │ └── const Type -│ ├── @types/ -│ │ ├── babel__core/ -│ │ │ └── index.d.ts -│ │ │ ├── const version -│ │ │ ├── const DEFAULT_EXTENSIONS -│ │ │ ├── interface TransformOptions -│ │ │ ├── interface TransformCaller -│ │ │ ├── interface MatchPatternContext -│ │ │ ├── function transform(code: string, callback: FileResultCallback): void -│ │ │ ├── function transform(code: string, opts: TransformOptions, callback: FileResultCallback): void -│ │ │ ├── function transform(code: string, opts: TransformOptions): BabelFileResult -│ │ │ ├── function transformSync(code: string, opts: TransformOptions): BabelFileResult -│ │ │ ├── function transformAsync(code: string, opts: TransformOptions): Promise -│ │ │ ├── function transformFile(filename: string, callback: FileResultCallback): void -│ │ │ ├── function transformFile(filename: string, opts: TransformOptions, callback: FileResultCallback): void -│ │ │ ├── function transformFileSync(filename: string, opts: TransformOptions): BabelFileResult -│ │ │ ├── function transformFileAsync(filename: string, opts: TransformOptions): Promise -│ │ │ ├── function transformFromAst(ast: Node, code: string, callback: FileResultCallback): void -│ │ │ ├── function transformFromAst(ast: Node, code: string, opts: TransformOptions, callback: FileResultCallback): void -│ │ │ ├── function transformFromAstSync(ast: Node, code: string, opts: TransformOptions): BabelFileResult -│ │ │ ├── function transformFromAstAsync(ast: Node, code: string, opts: TransformOptions): Promise -│ │ │ ├── interface PluginObj -│ │ │ ├── interface BabelFile -│ │ │ ├── interface PluginPass -│ │ │ ├── interface BabelFileResult -│ │ │ ├── interface BabelFileMetadata -│ │ │ ├── interface BabelFileModulesMetadata -│ │ │ ├── function parse(code: string, callback: FileParseCallback): void -│ │ │ ├── function parse(code: string, options: TransformOptions, callback: FileParseCallback): void -│ │ │ ├── function parse(code: string, options: TransformOptions): ParseResult -│ │ │ ├── function parseSync(code: string, options: TransformOptions): ParseResult -│ │ │ ├── function parseAsync(code: string, options: TransformOptions): Promise> -│ │ │ ├── function loadOptions(options: TransformOptions): object -│ │ │ ├── function loadPartialConfig(options: TransformOptions): Readonly -│ │ │ ├── function loadPartialConfigAsync(options: TransformOptions): Promise> -│ │ │ ├── interface PartialConfig -│ │ │ ├── interface ConfigItem -│ │ │ ├── function resolvePlugin(name: string, dirname: string): string -│ │ │ ├── function resolvePreset(name: string, dirname: string): string -│ │ │ ├── interface CreateConfigItemOptions -│ │ │ ├── function createConfigItem(value: PluginTarget | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string], options: CreateConfigItemOptions): ConfigItem -│ │ │ ├── interface ConfigAPI -│ │ │ ├── interface SimpleCacheConfigurator -│ │ │ └── interface EnvFunction -│ │ ├── babel__generator/ -│ │ │ └── index.d.ts -│ │ │ ├── interface GeneratorOptions -│ │ │ ├── class CodeGenerator -│ │ │ ├── function generate(ast: Node, opts: GeneratorOptions, code: string | { [filename: string]: string; }): GeneratorResult -│ │ │ └── interface GeneratorResult -│ │ ├── babel__template/ -│ │ │ └── index.d.ts -│ │ │ ├── interface TemplateBuilderOptions -│ │ │ ├── interface TemplateBuilder -│ │ │ ├── const smart -│ │ │ ├── const statement -│ │ │ ├── const statements -│ │ │ ├── const expression -│ │ │ └── const program -│ │ ├── babel__traverse/ -│ │ │ └── index.d.ts -│ │ │ ├── class Scope -│ │ │ ├── class Binding -│ │ │ ├── interface VisitNodeObject -│ │ │ ├── class NodePath -│ │ │ ├── interface HubInterface -│ │ │ ├── class Hub -│ │ │ ├── interface TraversalContext -│ │ │ └── interface VirtualTypeAliases -│ │ ├── graceful-fs/ -│ │ │ └── index.d.ts -│ │ │ └── function gracefulify(fsModule: T): T -│ │ ├── istanbul-lib-coverage/ -│ │ │ └── index.d.ts -│ │ │ ├── interface CoverageSummaryData -│ │ │ ├── class CoverageSummary -│ │ │ ├── interface CoverageMapData -│ │ │ ├── class CoverageMap -│ │ │ ├── interface Location -│ │ │ ├── interface Range -│ │ │ ├── interface BranchMapping -│ │ │ ├── interface FunctionMapping -│ │ │ ├── interface FileCoverageData -│ │ │ ├── interface Totals -│ │ │ ├── interface Coverage -│ │ │ ├── class FileCoverage -│ │ │ ├── const classes -│ │ │ ├── function createCoverageMap(data: CoverageMap | CoverageMapData): CoverageMap -│ │ │ ├── function createCoverageSummary(obj: CoverageSummary | CoverageSummaryData): CoverageSummary -│ │ │ └── function createFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): FileCoverage -│ │ ├── istanbul-lib-report/ -│ │ │ └── index.d.ts -│ │ │ ├── function createContext(options: Partial): Context -│ │ │ ├── function getDefaultWatermarks(): Watermarks -│ │ │ ├── class ReportBase -│ │ │ ├── interface ReportBaseOptions -│ │ │ ├── interface ContextOptions -│ │ │ ├── interface Context -│ │ │ ├── class ContentWriter -│ │ │ ├── class FileContentWriter -│ │ │ ├── class ConsoleWriter -│ │ │ ├── class FileWriter -│ │ │ ├── interface XmlWriter -│ │ │ ├── interface Watermarks -│ │ │ ├── interface Node -│ │ │ ├── interface ReportNode -│ │ │ ├── interface Visitor -│ │ │ └── interface Tree -│ │ └── istanbul-reports/ -│ │ └── index.d.ts -│ │ ├── function create(name: T, options: Partial): ReportBase -│ │ ├── interface FileOptions -│ │ ├── interface ProjectOptions -│ │ ├── interface ReportOptions -│ │ ├── interface CloverOptions -│ │ ├── interface CoberturaOptions -│ │ ├── interface HtmlSpaOptions -│ │ ├── interface HtmlOptions -│ │ ├── interface LcovOptions -│ │ ├── interface LcovOnlyOptions -│ │ ├── interface TeamcityOptions -│ │ ├── interface TextOptions -│ │ └── interface LinkMapper -│ ├── expect/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ ├── class AsymmetricMatcher -│ │ ├── interface AsymmetricMatchers -│ │ ├── interface BaseExpect -│ │ ├── class JestAssertionError -│ │ ├── interface Matchers -│ │ ├── interface MatcherState -│ │ └── interface MatcherUtils -│ ├── jest-diff/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ ├── class Diff -│ │ ├── function diff(a: any, b: any, options: DiffOptions): string -│ │ ├── const DIFF_DELETE -│ │ ├── const DIFF_EQUAL -│ │ ├── const DIFF_INSERT -│ │ ├── const diffLinesRaw -│ │ ├── const diffLinesUnified -│ │ ├── const diffLinesUnified2 -│ │ ├── const diffStringsRaw -│ │ └── const diffStringsUnified -│ ├── jest-matcher-utils/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ ├── const BOLD_WEIGHT -│ │ ├── const diff -│ │ ├── const DIM_COLOR -│ │ ├── const ensureActualIsNumber -│ │ ├── const ensureExpectedIsNonNegativeInteger -│ │ ├── const ensureExpectedIsNumber -│ │ ├── const ensureNoExpected -│ │ ├── const ensureNumbers -│ │ ├── const EXPECTED_COLOR -│ │ ├── const getLabelPrinter -│ │ ├── const highlightTrailingWhitespace -│ │ ├── const INVERTED_COLOR -│ │ ├── const matcherErrorMessage -│ │ ├── const matcherHint -│ │ ├── const pluralize -│ │ ├── const printDiffOrStringify -│ │ ├── const printExpected -│ │ ├── const printReceived -│ │ ├── function printWithType(name: string, value: T, print: (value: T) => string): string -│ │ ├── const RECEIVED_COLOR -│ │ ├── function replaceMatchedToAsymmetricMatcher(replacedExpected: unknown, replacedReceived: unknown, expectedCycles: unknown[], receivedCycles: unknown[]): { replacedExpected: unknown; replacedReceived: unknown; } -│ │ ├── const stringify -│ │ └── const SUGGEST_TO_CONTAIN_EQUAL -│ ├── jest-message-util/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ ├── const formatExecError -│ │ ├── const formatPath -│ │ ├── const formatResultsErrors -│ │ ├── const formatStackTrace -│ │ ├── interface Frame -│ │ ├── const getStackTraceLines -│ │ ├── const getTopFrame -│ │ ├── const indentAllLines -│ │ └── const separateMessageFromStack -│ ├── jest-mock/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ ├── const fn -│ │ ├── interface Mock -│ │ ├── const mocked -│ │ ├── interface MockInstance -│ │ ├── class ModuleMocker -│ │ ├── interface Replaced -│ │ ├── const replaceProperty -│ │ ├── interface SpyInstance -│ │ └── const spyOn -│ ├── jest-snapshot/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ ├── const addSerializer -│ │ ├── const buildSnapshotResolver -│ │ ├── const cleanup -│ │ ├── interface Context -│ │ ├── const EXTENSION -│ │ ├── const getSerializers -│ │ ├── const isSnapshotPath -│ │ ├── interface SnapshotMatchers -│ │ ├── class SnapshotState -│ │ ├── const toMatchInlineSnapshot -│ │ ├── const toMatchSnapshot -│ │ ├── const toThrowErrorMatchingInlineSnapshot -│ │ └── const toThrowErrorMatchingSnapshot -│ ├── pretty-format/ -│ │ └── build/ -│ │ └── index.d.ts -│ │ ├── const DEFAULT_OPTIONS -│ │ ├── interface Options -│ │ ├── const plugins -│ │ └── interface PrettyFormatOptions -│ └── undici-types/ -│ ├── cache.d.ts -│ │ ├── interface CacheStorage -│ │ ├── interface Cache -│ │ ├── interface CacheQueryOptions -│ │ ├── interface MultiCacheQueryOptions -│ │ └── const caches -│ ├── client.d.ts -│ │ └── class Client -│ ├── content-type.d.ts -│ │ ├── function parseMIMEType(input: string): "failure" | MIMEType -│ │ └── function serializeAMimeType(mimeType: MIMEType): string -│ ├── cookies.d.ts -│ │ ├── interface Cookie -│ │ ├── function deleteCookie(headers: Headers, name: string, attributes: { name?: string; domain?: string; }): void -│ │ ├── function getCookies(headers: Headers): Record -│ │ ├── function getSetCookies(headers: Headers): Cookie[] -│ │ └── function setCookie(headers: Headers, cookie: Cookie): void -│ ├── fetch.d.ts -│ │ ├── function fetch(input: RequestInfo, init: RequestInit): Promise -│ │ ├── interface BodyMixin -│ │ ├── interface SpecIterator -│ │ ├── interface SpecIterableIterator -│ │ ├── interface SpecIterable -│ │ ├── class Headers -│ │ ├── interface RequestInit -│ │ ├── class Request -│ │ ├── interface ResponseInit -│ │ └── class Response -│ ├── file.d.ts -│ │ ├── interface BlobPropertyBag -│ │ ├── interface FilePropertyBag -│ │ └── class File -│ ├── filereader.d.ts -│ │ ├── class FileReader -│ │ ├── interface ProgressEventInit -│ │ └── class ProgressEvent -│ ├── formdata.d.ts -│ │ └── class FormData -│ ├── handlers.d.ts -│ │ ├── class RedirectHandler -│ │ └── class DecoratorHandler -│ ├── interceptors.d.ts -│ │ └── function createRedirectInterceptor(opts: RedirectInterceptorOpts): DispatchInterceptor -│ ├── patch.d.ts -│ │ ├── interface EventInit -│ │ ├── interface EventListenerOptions -│ │ ├── interface AddEventListenerOptions -│ │ ├── interface EventListenerObject -│ │ └── interface EventListener -│ └── websocket.d.ts -│ ├── const WebSocket -│ ├── const CloseEvent -│ └── const MessageEvent └── src/ ├── cli.ts │ ├── const pathFilter diff --git a/src/cli.ts b/src/cli.ts index 7f69c53..60eabbc 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -6,12 +6,14 @@ import { tree, VisibilityLevel, TreeNode } from "."; const args = process.argv.slice(2); -const defaultIgnore = ["node_modules", +const defaultIgnore = [ + "node_modules", /\.git/, /\.vscode/, /\.DS_Store/, /\.test\.ts$/, - /\.spec\.ts$/]; + /\.spec\.ts$/, +]; function printHelp() { console.log("Usage: ts-print-tree [options]"); @@ -33,20 +35,32 @@ function printVersion() { console.log(`Version: ${packageJson.version}`); } -export const pathFilter = (ignorePatterns: (string | RegExp)[]) => - (path: string) => !ignorePatterns.some(pattern => - typeof pattern === "string" ? path.includes(pattern) : pattern.test(path) - ); +export const pathFilter = + (ignorePatterns: (string | RegExp)[]) => (path: string) => + !ignorePatterns.some((pattern) => + typeof pattern === "string" ? path.includes(pattern) : pattern.test(path), + ); function formatNodeName(node: TreeNode): string { - const visibilityPrefix = node.visibility && node.visibility !== 'public' ? `${node.visibility} ` : ''; - const typePrefix = node.type !== 'directory' && node.type !== 'file' ? `${node.type} ` : ''; + const visibilityPrefix = + node.visibility && node.visibility !== "public" + ? `${node.visibility} ` + : ""; + const typePrefix = + node.type !== "directory" && node.type !== "file" ? `${node.type} ` : ""; return `${visibilityPrefix}${typePrefix}${node.name}`; } -export function formatAsTree(node: TreeNode, prefix = "", isLast = true, isRoot = true): string { +export function formatAsTree( + node: TreeNode, + prefix = "", + isLast = true, + isRoot = true, +): string { const formattedName = formatNodeName(node); - let output = isRoot ? `${formattedName}${node.signature ? node.signature : ""}\n` : `${prefix}${isLast ? "└── " : "├── "}${formattedName}${node.signature ? node.signature : ""}\n`; + let output = isRoot + ? `${formattedName}${node.signature ? node.signature : ""}\n` + : `${prefix}${isLast ? "└── " : "├── "}${formattedName}${node.signature ? node.signature : ""}\n`; if (node.children) { node.children.forEach((child, index) => { @@ -62,7 +76,7 @@ export function formatAsList(node: TreeNode, depth = 0): string { const formattedName = formatNodeName(node); let output = `${" ".repeat(depth)}${depth === 0 ? "" : "- "}${formattedName}${node.signature ? node.signature : ""}\n`; if (node.children) { - node.children.forEach(child => { + node.children.forEach((child) => { output += formatAsList(child, depth + 1); }); } @@ -94,9 +108,7 @@ if (args.includes("--help")) { } if (!args.includes("--no-default")) { - ignorePatterns.push( - ...defaultIgnore - ); + ignorePatterns.push(...defaultIgnore); } const cwdIndex = args.indexOf("--cwd"); @@ -114,11 +126,16 @@ if (args.includes("--help")) { outputFormat = "list"; } - const projectStructure = tree(cwd, pathFilter(ignorePatterns), visibilityLevel); + const projectStructure = tree( + cwd, + pathFilter(ignorePatterns), + visibilityLevel, + ); - const output = outputFormat === "tree" - ? formatAsTree(projectStructure) - : formatAsList(projectStructure); + const output = + outputFormat === "tree" + ? formatAsTree(projectStructure) + : formatAsList(projectStructure); console.log(output); } diff --git a/src/index.test.ts b/src/index.test.ts index 71b8460..c25f07e 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,8 +1,8 @@ -import { jest, describe, expect, test } from "@jest/globals"; +import { describe, expect, test } from "@jest/globals"; import { tree, VisibilityLevel } from "."; import { formatAsList, formatAsTree, pathFilter } from "./cli"; -const ignoredPatterns = [ +const defaultIgnore = [ "node_modules", /\.git/, /\.vscode/, @@ -13,7 +13,7 @@ const ignoredPatterns = [ describe("cli module", () => { test("calls tree() and formats as tree", () => { - const result = tree(); + const result = tree(process.cwd(), pathFilter(defaultIgnore)); const formattedResult = formatAsTree(result); expect(formattedResult).toMatchSnapshot(); }); @@ -23,7 +23,7 @@ describe("cli module", () => { const result = tree( process.cwd(), - pathFilter(ignoredPatterns), + pathFilter(defaultIgnore), customVisibilityLevel, ); const formattedResult = formatAsList(result); @@ -49,7 +49,7 @@ describe("tree module", () => { const result = tree( process.cwd(), - pathFilter(ignoredPatterns), + pathFilter(defaultIgnore), customVisibilityLevel, ); expect(result).toMatchSnapshot();