@jts-studios/node-kit
v1.0.5
Published
JTS Studios utility library: Logger, filesystem helpers, and path utilities.
Maintainers
Readme
@jts-studios/node-kit
JTS Studios utility library for Node.js — Logger, filesystem helpers, path utilities, and Vite plugins.
Installation
npm install @jts-studios/node-kitFor the PHP Vite plugin, also install the peer dependency:
npm install --save-dev html-minifier-terser viteModules
Logger — @jts-studios/node-kit/components/logger
ANSI-colored tagged logger for CLI and build tools.
import { Logger } from "@jts-studios/node-kit"
const log = new Logger("MyApp", "cyan")
log.info("Server started")
log.warn("Deprecated API used")
log.error("Connection failed")Constructor: new Logger(name, color?)
| Param | Type | Default |
|---------|--------------|------------|
| name | string | — |
| color | ColorName | "green" |
Available colors: black red green yellow blue magenta cyan white
brightRed brightGreen brightYellow brightBlue brightMagenta brightCyan brightWhite
Filesystem utils — @jts-studios/node-kit/utils
directory_copy(src, dest)
Recursively copy a file, directory, or symlink tree from src to dest.
import { directory_copy } from "@jts-studios/node-kit/utils/directory"
await directory_copy("./src/assets", "./dist/assets")ensure_parent_dir(p) / mkdirp(dirPath)
Create directories (mkdir -p).
import { ensure_parent_dir, mkdirp } from "@jts-studios/node-kit/utils/fs"
await ensure_parent_dir("./dist/pages/index.html") // creates ./dist/pages/
await mkdirp("./dist/assets/images")lstat_exists(p) / lstat_safe(p) / safe_stat(p)
Safe stat helpers that return null / false instead of throwing.
import { lstat_exists, lstat_safe, safe_stat } from "@jts-studios/node-kit/utils/fs"
if (await lstat_exists("./output.txt")) { /* ... */ }
const stats = await lstat_safe("./output.txt") // Stats | null (lstat, no symlink follow)
const stats2 = await safe_stat("./output.txt") // Stats | null (stat, follows symlinks)path_exists(p) / path_resolve(p)
import { path_exists, path_resolve } from "@jts-studios/node-kit/utils/path"
await path_exists("./config.json") // true | false
path_resolve("./src") // absolute path string
path_resolve(null) // undefinedPHP Vite plugin — @jts-studios/node-kit/plugins/php
Vite plugin for PHP projects. Provides dev-server hot reload and final .php file assembly on build.
// vite.config.js
import { PHP } from "@jts-studios/node-kit/plugins/php"
export default {
plugins: [
PHP({
entries: ["pages/index.php", "pages/about.php"],
verbose: true,
minifyHtml: true,
hotReload: true,
}),
],
}| Option | Type | Default | Description |
|---------------|------------|---------|------------------------------------------|
| entries | string[] | — | PHP entry file paths |
| verbose | boolean | false | Enable detailed build logging |
| minifyHtml | boolean | true | Minify HTML before injecting PHP |
| hotReload | boolean | true | Full-reload on PHP change, CSS HMR |
Deep imports
Every module is individually importable:
import { Logger } from "@jts-studios/node-kit/components/logger"
import { directory_copy } from "@jts-studios/node-kit/utils/directory"
import { mkdirp } from "@jts-studios/node-kit/utils/fs"
import { path_resolve } from "@jts-studios/node-kit/utils/path"
import { PHP } from "@jts-studios/node-kit/plugins/php"Requirements
- Node.js >= 18
vite >= 5andhtml-minifier-terser >= 7(optional peer deps, required for the PHP plugin)
License
MIT © JTS Studios
