Skip to content

Commit

Permalink
chore: logger and debuggable
Browse files Browse the repository at this point in the history
  • Loading branch information
coltenkrauter committed Nov 3, 2024
1 parent e1b11d5 commit 78f5137
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 243 deletions.
203 changes: 105 additions & 98 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@krauters/utils",
"description": "A versatile TypeScript utility package packed with reusable, type-safe functions, scripts useful for all kinds of TypeScript projects, and precommit scripts to streamline your development workflow.",
"version": "0.9.1",
"version": "1.0.0",
"main": "dist/src/index.js",
"type": "commonjs",
"scripts": {
Expand Down Expand Up @@ -49,7 +49,8 @@
],
"dependencies": {
"@krauters/debuggable": "^0.3.0",
"@krauters/logger": "^0.3.1",
"@krauters/monkey-patcher": "^0.1.0"
"@krauters/logger": "^0.3.2",
"@krauters/monkey-patcher": "^0.1.0",
"@krauters/structures": "^1.0.2"
}
}
2 changes: 1 addition & 1 deletion src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { debuggable } from '@krauters/debuggable'
import { log } from '@krauters/logger'
import { FileEncoding } from '@krauters/structures'
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs'

import {
FileEncoding,
MakeDirectoryOptionsExtended,
ReadDirectoryOptions,
ReadJsonFileOptions,
Expand Down
3 changes: 1 addition & 2 deletions src/package-json.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { debuggable } from '@krauters/debuggable'
import { log } from '@krauters/logger'
import { PackageJson as PackageJsonType } from '@krauters/structures'
import { existsSync, readFileSync } from 'fs'
import { dirname, join } from 'path'

import type { PackageJsonType as PackageJsonType } from './structures'

interface PackageJsonOptions {
maxDepth?: number
scopeRegex?: RegExp
Expand Down
16 changes: 6 additions & 10 deletions src/readme-validator.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { debuggable } from '@krauters/debuggable'
import { log } from '@krauters/logger'
import { FileEncoding, PackageJson as PackageJsonType } from '@krauters/structures'
import { existsSync, readFileSync, writeFileSync } from 'fs'
import { join } from 'path'

import type { ParsedReadme, Section, ValidateAndUpdateReadmeOptions } from './structures'

import { PackageJson } from './package-json'
import {
FileEncoding,
type PackageJsonType,
type ParsedReadme,
type Section,
type ValidateAndUpdateReadmeOptions,
} from './structures'

@debuggable(log)
export class ReadmeValidator {
Expand Down Expand Up @@ -47,7 +43,7 @@ export class ReadmeValidator {
throw new Error(`README.md file not found in the repository at [${path}]`)
}

const content = readFileSync(path, FileEncoding.UTF8)
const content = readFileSync(path, { encoding: FileEncoding.UTF8 })
log.info(`Successfully loaded README.md`)

return { content, packageJson, path }
Expand All @@ -61,7 +57,7 @@ export class ReadmeValidator {
*/
public static save(path: string, content: string) {
log.info(`Saving README.md to [${path}]...`)
writeFileSync(path, content, FileEncoding.UTF8)
writeFileSync(path, content, { encoding: FileEncoding.UTF8 })
log.info(`Successfully saved README.md`)
}

Expand Down Expand Up @@ -157,7 +153,7 @@ export class ReadmeValidator {
validateOnly = false,
): string {
const expectedTitle = `# ${packageJson.name}`
const expectedDescription = packageJson.description ?? ''
const expectedDescription: string = packageJson.description ?? ''

const titleExists = readmeContent.includes(expectedTitle)
const descriptionExists = expectedDescription === '' || readmeContent.includes(expectedDescription)
Expand Down
98 changes: 3 additions & 95 deletions src/structures.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { MakeDirectoryOptions } from 'fs'

export interface PackageJsonType {
[key: string]: any
author?: Person | string
bin?: Bin | string
browser?: Browser | string
bugs?: Bugs | string
bundledDependencies?: string[]
config?: Record<string, any>
contributors?: Person[] | string[]
cpu?: string[]
dependencies?: Dependencies
description?: string
devDependencies?: Dependencies
directories?: Directories
engines?: Engines
files?: string[]
homepage?: string
keywords?: string[]
license?: string
main?: string
man?: string | string[]
module?: string
name: string
optionalDependencies?: Dependencies
os?: string[]
peerDependencies?: Dependencies
private?: boolean
publishConfig?: PublishConfig
repository?: Repository | string
scripts?: Scripts
type?: 'commonjs' | 'module'
types?: string
version: string
}

interface Bugs {
email?: string
url?: string
}

interface Person {
email?: string
name?: string
url?: string
}

interface Repository {
type: string
url: string
}

type Scripts = Record<string, string>

type Dependencies = Record<string, string>

type Browser = Record<string, string>

type Bin = Record<string, string>

interface Directories {
bin?: string
doc?: string
example?: string
lib?: string
man?: string
}

interface Engines {
[engine: string]: string | undefined
node?: string
npm?: string
yarn?: string
}

interface PublishConfig {
[key: string]: any
access?: 'public' | 'restricted'
registry?: string
}
import type { PackageJson } from '@krauters/structures'
import type { MakeDirectoryOptions } from 'fs'

export interface Section {
content?: string
Expand Down Expand Up @@ -113,10 +35,6 @@ export interface ParsedReadme {
title: string
}

export enum FileEncoding {
UTF8 = 'utf8',
}

export interface ValidateAndUpdateReadmeOptions {
autoCreateMissing?: boolean
badgeSection?: string
Expand Down Expand Up @@ -154,7 +72,7 @@ export enum BadgeType {
export interface BadgeSectionOptions {
badgeTypes: BadgeType[]
linkedInUsername?: string
packageJson: PackageJsonType
packageJson: PackageJson
repoPath?: string
}

Expand All @@ -179,16 +97,6 @@ export interface SnapDateOptions {
snap?: SnapType
}

export enum Env {
Alpha = 'Alpha',
Beta = 'Beta',
Development = 'Development',
Gamma = 'Gamma',
Pipeline = 'Pipeline',
Production = 'Production',
Unknown = 'Unknown',
}

export interface Batch<T> {
index: number
items: T[]
Expand Down
6 changes: 4 additions & 2 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { PackageJson as PackageJsonType } from '@krauters/structures'

import { debuggable } from '@krauters/debuggable'
import { log } from '@krauters/logger'
import { execSync } from 'child_process'

import type { PackageJsonType as PackageJsonType } from './structures'

import { PackageJson } from './package-json'

@debuggable(log)
Expand Down Expand Up @@ -70,6 +70,7 @@ export class Version {
static getLocalVersion(dir: string = process.cwd()): string {
const packageJson: PackageJsonType = PackageJson.getPackageJson({ startDir: dir })

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return packageJson.version
}

Expand All @@ -94,6 +95,7 @@ export class Version {
const packageJsonContent: string = execSync(`git show ${ref}:package.json`, { encoding: 'utf8' })
const data: PackageJsonType = JSON.parse(packageJsonContent)

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return data.version
} catch (error: unknown) {
if (error instanceof Error) {
Expand Down
Loading

0 comments on commit 78f5137

Please sign in to comment.