From 4c70f638b6afb7471fee53414f389439e4d2d889 Mon Sep 17 00:00:00 2001 From: Nikola Date: Wed, 17 Apr 2024 02:36:49 +0300 Subject: [PATCH] squash! Signed-off-by: Nikola --- Source/Class/Error/File.ts | 17 +++++----- Source/Class/Error/FileNotFound.ts | 6 ++-- Source/Class/Error/InvaliadAlias.ts | 15 +++++---- Source/Class/Error/InvalidAliasError.ts | 15 +++++---- Source/Class/Error/Step.ts | 11 ++++--- Source/Class/Error/TSConfigPropertyError.ts | 13 +++++--- Source/Class/Logger.ts | 12 +++---- Source/Class/Resolve.ts | 16 +++++----- Source/Function/Resolve/Path.ts | 12 +++---- Source/Interface/Alias.ts | 10 +++--- Source/Interface/Change.ts | 14 +++++---- Source/Interface/ProgramOptions.ts | 25 ++++++++++----- Source/Interface/ProgramPaths.ts | 35 +++++++++++++++------ Source/Interface/TextChange.ts | 7 +++-- 14 files changed, 126 insertions(+), 82 deletions(-) diff --git a/Source/Class/Error/File.ts b/Source/Class/Error/File.ts index c850229..2a33488 100644 --- a/Source/Class/Error/File.ts +++ b/Source/Class/Error/File.ts @@ -1,9 +1,12 @@ -export class FileError extends Step { - constructor( - public readonly step: string, - public readonly path: string, - message: string - ) { - super(step, `Error processing ${path}: ${message}`); +export default class FileError extends (await import("@Class/Error/Step.js")) + .default { + public override readonly Step; + public readonly Path; + + constructor(Step: string, Path: string, Message: string) { + super(Step, `Error processing ${Path}: ${Message}`); + + this.Step = Step; + this.Path = Path; } } diff --git a/Source/Class/Error/FileNotFound.ts b/Source/Class/Error/FileNotFound.ts index 653f6bb..3c957d9 100644 --- a/Source/Class/Error/FileNotFound.ts +++ b/Source/Class/Error/FileNotFound.ts @@ -1,5 +1,5 @@ -export class FileNotFoundError extends FileError { - constructor(step: string, path: string) { - super(step, path, `Not found`); +export default class extends (await import("@Class/Error/File.js")).default { + constructor(Step: string, Path: string) { + super(Step, Path, "Not found"); } } diff --git a/Source/Class/Error/InvaliadAlias.ts b/Source/Class/Error/InvaliadAlias.ts index 9d3eb2c..99b20b1 100644 --- a/Source/Class/Error/InvaliadAlias.ts +++ b/Source/Class/Error/InvaliadAlias.ts @@ -1,8 +1,11 @@ -export class InvalidAliasError extends Step { - constructor( - public readonly step: string, - public readonly alias: string - ) { - super(step, `The alias ${alias} is not permitted`); +export default class extends (await import("@Class/Error/Step.js")).default { + public override readonly Step: string; + public readonly Alias: string; + + constructor(Step: string, Alias: string) { + super(Step, `The alias ${Alias} is not permitted`); + + this.Step = Step; + this.Alias = Alias; } } diff --git a/Source/Class/Error/InvalidAliasError.ts b/Source/Class/Error/InvalidAliasError.ts index 9d3eb2c..99b20b1 100644 --- a/Source/Class/Error/InvalidAliasError.ts +++ b/Source/Class/Error/InvalidAliasError.ts @@ -1,8 +1,11 @@ -export class InvalidAliasError extends Step { - constructor( - public readonly step: string, - public readonly alias: string - ) { - super(step, `The alias ${alias} is not permitted`); +export default class extends (await import("@Class/Error/Step.js")).default { + public override readonly Step: string; + public readonly Alias: string; + + constructor(Step: string, Alias: string) { + super(Step, `The alias ${Alias} is not permitted`); + + this.Step = Step; + this.Alias = Alias; } } diff --git a/Source/Class/Error/Step.ts b/Source/Class/Error/Step.ts index d977e78..a5942e7 100644 --- a/Source/Class/Error/Step.ts +++ b/Source/Class/Error/Step.ts @@ -1,8 +1,9 @@ export default class extends Error { - constructor( - public readonly step: string, - message: string - ) { - super(message); + public readonly Step: string; + + constructor(Step: string, Message: string) { + super(Message); + + this.Step = Step; } } diff --git a/Source/Class/Error/TSConfigPropertyError.ts b/Source/Class/Error/TSConfigPropertyError.ts index 1805dcc..a72ba85 100644 --- a/Source/Class/Error/TSConfigPropertyError.ts +++ b/Source/Class/Error/TSConfigPropertyError.ts @@ -1,8 +1,11 @@ export default class extends (await import("@Class/Error/Step.js")).default { - constructor( - public override readonly step: string, - public readonly property: string - ) { - super(step, `${property} is not set in tsconfig`); + public override readonly Step: string; + public readonly Property: string; + + constructor(Step: string, Property: string) { + super(Step, `${Property} is not set in tsconfig`); + + this.Step = Step; + this.Property = Property; } } diff --git a/Source/Class/Logger.ts b/Source/Class/Logger.ts index 775e63a..3f662f9 100644 --- a/Source/Class/Logger.ts +++ b/Source/Class/Logger.ts @@ -1,22 +1,22 @@ import { bold, dim, green, red } from "ansi-colors"; -export type LoggerLevel = "verbose" | "info" | "error"; +export type Level = "verbose" | "info" | "error"; export default class { - public readonly level; + public readonly Level; - constructor(level: LoggerLevel) { - this.level = level; + constructor(level: Level) { + this.Level = level; } verbose(...args: (string | undefined)[]) { - if (this.level === "verbose") { + if (this.Level === "verbose") { console.log(...args); } } info(...args: (string | number)[]) { - if (["verbose", "info"].includes(this.level)) { + if (["verbose", "info"].includes(this.Level)) { console.log(...args); } } diff --git a/Source/Class/Resolve.ts b/Source/Class/Resolve.ts index 3040b54..1f52c87 100644 --- a/Source/Class/Resolve.ts +++ b/Source/Class/Resolve.ts @@ -4,7 +4,7 @@ import { bold } from "ansi-colors"; import Step from "@Class/Error/Step.js"; import Logger from "@Class/Logger.js"; -import type ProgramOptions from "@Interface/ProgramOptions.js"; +import type Interface from "@Interface/ProgramOptions.js"; import Apply from "@Function/Apply.js"; import Compute from "@Function/Compute.js"; @@ -15,15 +15,15 @@ import Load from "@Function/Load.js"; import Path from "@Function/Resolve/Path.js"; export const main = () => { - const options = Create().parse().opts(); + const options = Create().parse().opts(); - const logger = new Logger(options.verbose ? "verbose" : "info"); + const logger = new Logger(options.Verbose ? "verbose" : "info"); logger.verbose(); logger.fancyParams("options", options); try { - const tsConfig = Load(options.project); + const tsConfig = Load(options.Project); const { rootDir, outDir, baseUrl, paths } = tsConfig.options ?? {}; @@ -39,13 +39,13 @@ export const main = () => { logger.fancyParams("programPaths", programPaths); const aliases = Compute( - programPaths.basePath, + programPaths.Base, tsConfig?.options?.paths ?? {} ); logger.fancyParams("aliases", aliases); - const files = Get(programPaths.outPath, options.ext); + const files = Get(programPaths.Target, options.Extension); logger.fancyParams("filesToProcess", files); @@ -56,7 +56,7 @@ export const main = () => { changes.map(({ file, changes }) => ({ file, changes })) ); - if (options.noEmit) { + if (options.NoEmit) { logger.info( bold("Resolve:"), "discovered", @@ -71,7 +71,7 @@ export const main = () => { } catch (_Error) { if (_Error instanceof Step) { logger.fancyError( - `Error during step '${bold(_Error.step)}'`, + `Error during step '${bold(_Error.Step)}'`, _Error.message ); } else { diff --git a/Source/Function/Resolve/Path.ts b/Source/Function/Resolve/Path.ts index 4d6e39f..924818d 100644 --- a/Source/Function/Resolve/Path.ts +++ b/Source/Function/Resolve/Path.ts @@ -3,7 +3,7 @@ import { dirname, resolve } from "path"; import Step from "@Class/Error/Step"; import TSConfigPropertyError from "@Class/Error/TSConfigPropertyError.js"; -import type ProgramOptions from "@Interface/ProgramOptions.js"; +import type Interface from "@Interface/ProgramOptions.js"; import type ProgramPaths from "@Interface/ProgramPaths.js"; import type TSConfig from "@Interface/TSConfig.js"; @@ -11,12 +11,12 @@ import type TSConfig from "@Interface/TSConfig.js"; * Resolve paths provided to the program to absolute paths. */ export const _Function = ( - options: Pick, + options: Pick, tsConfig: TSConfig ): ProgramPaths => { const { baseUrl = "", outDir, paths } = tsConfig.options ?? {}; - const out = options.out ?? outDir; + const out = options.Out ?? outDir; if (!out) { throw new Step( @@ -32,17 +32,17 @@ export const _Function = ( ); } - const configFile = resolve(process.cwd(), options.project); + const configFile = resolve(process.cwd(), options.Project); const configPath = dirname(configFile); const basePath = resolve(configPath, baseUrl); - const srcPath = resolve(options.src ?? tsConfig?.options?.rootDir ?? "src"); + const srcPath = resolve(options.Source ?? tsConfig?.options?.rootDir ?? "src"); const outPath = resolve(out); - return { basePath, configPath, configFile, srcPath, outPath }; + return { Base: basePath, PathConfig: configPath, FileConfig: configFile, Source: srcPath, Target: outPath }; }; export default _Function; diff --git a/Source/Interface/Alias.ts b/Source/Interface/Alias.ts index 48f6b93..811779f 100644 --- a/Source/Interface/Alias.ts +++ b/Source/Interface/Alias.ts @@ -1,8 +1,10 @@ -export interface Alias { +export default interface Interface { /** The original path alias. */ - alias: string; + Alias: string; + /** The alias prefix that has been matched. */ - prefix: string; + Prefix: string; + /** The paths that the alias points to. */ - aliasPaths: string[]; + Path: string[]; } diff --git a/Source/Interface/Change.ts b/Source/Interface/Change.ts index 43b27e3..7f2fee1 100644 --- a/Source/Interface/Change.ts +++ b/Source/Interface/Change.ts @@ -1,10 +1,12 @@ -import type { TextChange } from "@Interface/TextChange.js"; - -export interface Change { +export default interface Interface { /** The source of the file being changed. */ - file: string; + File: string; + /** The new content of the file. */ - text: string; + Text: string; + /** A list of text changes in the file. */ - changes?: TextChange[]; + Change?: TextChange[]; } + +import type TextChange from "@Interface/TextChange.js"; diff --git a/Source/Interface/ProgramOptions.ts b/Source/Interface/ProgramOptions.ts index a52fb04..3e37578 100644 --- a/Source/Interface/ProgramOptions.ts +++ b/Source/Interface/ProgramOptions.ts @@ -1,32 +1,43 @@ -export default interface ProgramOptions { +export default interface Interface { /** * Path to the project's tsconfig file. Defaults to "tsconfig.json" * if not provided. + * */ - project: string; + Project: string; + /** * Path to the source directory. Defaults to `compilerOptions.rootDir` * from tsconfig. If `rootDir` is not defined in tsconfig, it will * default to "src". + * */ - src?: string; + Source?: string; + /** * Path to the output directory. Defaults to `compilerOptions.outDir` * from tsconfig if not provided. + * */ - out?: string; + Target?: string; + /** * A list of file extensions that will be matched for replacement. * Defaults to `["js", "d.ts"]` to handle js and type declaration * files. + * */ - ext: string[]; + Extension: string[]; + /** * If `true`, verbose logs will be printed for degugging. + * */ - verbose: boolean; + Verbose: boolean; + /** * If `true`, changes will not be emitted. + * */ - noEmit: boolean; + NoEmit: boolean; } diff --git a/Source/Interface/ProgramPaths.ts b/Source/Interface/ProgramPaths.ts index e857757..42cc94f 100644 --- a/Source/Interface/ProgramPaths.ts +++ b/Source/Interface/ProgramPaths.ts @@ -1,16 +1,31 @@ export default interface Interface { - /** Absolute path to `baseUrl` as defined in the tsconfig file. */ - basePath: string; + /** + * Absolute path to `baseUrl` as defined in the tsconfig file. + * + */ + Base: string; - /** Absolute path to the directory the tsconfig file is in. */ - configPath: string; + /** + * Absolute path to the directory the tsconfig file is in. + * + */ + PathConfig: string; - /** Absolute path to the tsconfig file. */ - configFile: string; + /** + * Absolute path to the tsconfig file. + * + */ + FileConfig: string; - /** Absolute path to the source directory. */ - srcPath: string; + /** + * Absolute path to the source directory. + * + */ + Source: string; - /** Absolute path to the output directory. */ - outPath: string; + /** + * Absolute path to the output directory. + * + */ + Target: string; } diff --git a/Source/Interface/TextChange.ts b/Source/Interface/TextChange.ts index 5b0188e..2326794 100644 --- a/Source/Interface/TextChange.ts +++ b/Source/Interface/TextChange.ts @@ -1,6 +1,7 @@ -export interface TextChange { +export default interface Interface { /** The original text. */ - original: string; + Original: string; + /** The modified text. */ - modified: string; + Modify: string; }