@slyte/cli-utils
v2.1.0
Published
Shared utility library for the Slyte CLI toolchain, providing filesystem abstractions, build-pipeline helpers, CLI argument parsing, and code generation utilities
Readme
@slyte/cli-utils
Shared utility library for the Slyte CLI toolchain. Provides filesystem abstractions, build-pipeline helpers, CLI argument parsing, code generation utilities, and terminal UI components used across Slyte CLI packages.
Installation
This package is consumed internally within the @slyte/cli repo.
npm install @slyte/cli-utilsUsage
const { fileManipulation, commonCliUtils, cliSpinner, errorClass, commonObj, stringManipulation } = require('@slyte/cli-utils');
// Initialize before using file I/O or fingerprinting features
fileManipulation.init(options);Initialization Options
| Option | Type | Description |
|---|---|---|
| fingerPrint | boolean | Enable content-hash fingerprinting on output files |
| skipTheFingerPrint | string[] \| RegExp[] | Glob patterns or RegExps for files to exclude from fingerprinting |
| log | { system, user } | Logger instances for system and user-facing output |
| sourceMap | boolean | Enable source map generation |
| production | boolean | Enable production mode (errors reject rather than log) |
API
fileManipulation
Filesystem abstraction layer with async and sync variants for all common file operations.
File I/O
read(file, callback)/readSync(file, type)— read a filewrite(file, data, callback)/writeSync(file, content)— write a fileappend(file, data, callback)/appendSync(file, content)— append to a filetruncate(file)— empty a filefileExist(file)— check if a file exists (sync)access(file, callback)— check file accessibility (async)
Directories
mkdir(dir, callback)/mkdirSync(dir)— create directory (recursive)readdir(dir, callback)/readdirSync(dir)— list directory contentsremove(file, callback)/removeSync(file)— delete a file or directory recursively
Copy & Move
copy(options, obj, callback)— copy a file with optional minification, transpilation, and fingerprinting hookscopySync(src, dest)— synchronous file copycopyFolder(src, dest, callback)— recursive folder copycopyWithSymbolicLink(obj, callback)— create a symlink fromdisttosrcrename(oldPath, newPath, callback)— rename/move a file
File Listing
getFilesList(dir, validationFn, done, callback)— async recursive directory walkgetFilesListSync(dir, ignoreArr)— sync recursive file listgetOnlyFilesListSync(dir, ignoreArr)— sync, returns only files (not directories)
Minification
minify(options, obj, callback)— minify JS, CSS, or HTML based on file extensionminifyJs(...)— JS minification via Terser, with source map support
Concatenation
concat(options, obj)— concatenate source files into a single output with optional source map and transpilation
Merge Utilities
merge_object(obj, obj1)— deep merge two objectsmerge_array(arr, arr1)— merge two arrays (unique values)pushIfNotExist(arr, value)— append a value if not already present
commonCliUtils
General-purpose CLI utilities.
Argument Parsing
getParams(options, args)— parse a CLI argument array into an options object; supports--key value,--key=value,-k, and boolean coercion
Name Validation
validateComponentName(name)— validates lowercase hyphenated component namesvalidateWidgetName(name)— validates widget namesvalidateHelperName(name)— blocks reserved/special characters in helper namesvalidateFolderName(name)— validates folder names against reserved JS keywordsvalidatePackageName(name, options)— validates npm package naming conventionsvalidateClassName(name)— validates and converts to camelCaseisReservedKeyword(name)— checks against the full JS reserved word list
String Utilities
convertStringToCamelCase(input)— convert any string to camelCasereplaceSpecialChar(name)— convert hyphenated names to camelCase
File Utilities
removeEmptyFolder(dir, baseRoute, options)— remove empty parent directories up to a base pathconvertFileSizeTypeFromBytes(bytes)— returns{ size, sizeType }(Bytes/KB/MB/GB/TB)
Terminal
isUnicodeSupported()— detect unicode terminal supportconsoletable(table, row, column)— formatted table output
cliSpinner
Animated terminal spinner for tracking multi-step build progress.
const spinner = cliSpinner(options);
spinner.add('task-name', { label: 'Compiling...' });
spinner.success('task-name');
spinner.error('task-name', err);In production or --nospinner mode, output is buffered and written as plain text lines.
errorClass
Build-time error and warning formatting.
createErrorObj(options, obj)— format a structured error with a highlighted code framehandleWarnings(options, obj)— log a build warninghandleErrors(options, obj, reject, resolve)— route errors toreject(production) or log (watch/dev mode)
stringManipulation
Simple string helpers.
pluralize(str)— append"s"or"S"based on casingisUpperCase(str)— check if a string is all uppercaseescapeSpecialChar(content)— JSON-stringify a valuereplaceSpecialCharWithHTML(str)— replace>,<,>=,<=,"with HTML entities
commonObj
Shared in-process singleton holding build state.
{
fileOriginalContent: {}, // file content cache
errorObj: {}, // structured errors by file path
errorCount: 0,
warningCount: 0,
minifyCount: 0,
fingerPrintMapping: {} // maps original paths to hashed output paths
}Note: This is a process-level singleton. For multiple sequential builds in the same process, reset this object between runs.
isSkipFingerPrint(file, skipOptions)
Check whether a file path matches the configured skip list and should be excluded from fingerprinting.
const { isSkipFingerPrint } = require('@slyte/cli-utils');
isSkipFingerPrint('assets/vendor.js', ['vendor/**']); // trueDirect Imports
Some sub-modules can be imported directly:
// Babel AST parse/generate utilities
const { stringToAst, astToString } = require('@slyte/cli-utils/src/astToStr');
// @babel/types wrappers with location info
const nodeExpression = require('@slyte/cli-utils/src/nodeExpression');License
Copyright 2026 Zoho Corporation Private Limited. Licensed under the Apache License, Version 2.0.
