### Basic Commander.js CLI Example (JavaScript) Source: https://github.com/chevgan/render-peek/blob/main/node_modules/commander/Readme.md A comprehensive example illustrating the setup of a command-line interface using Commander.js. It includes defining program version, options, commands with sub-options and descriptions, aliases, and handling wildcard commands. This example demonstrates common patterns for building interactive CLIs. ```javascript const program = require('commander'); program .version('0.1.0') .option('-C, --chdir ', 'change the working directory') .option('-c, --config ', 'set config path. defaults to ./deploy.conf') .option('-T, --no-tests', 'ignore test hook'); program .command('setup [env]') .description('run setup commands for all envs') .option("-s, --setup_mode [mode]", "Which setup mode to use") .action(function(env, options){ const mode = options.setup_mode || "normal"; env = env || 'all'; console.log('setup for %s env(s) with %s mode', env, mode); }); program .command('exec ') .alias('ex') .description('execute the given remote cmd') .option("-e, --exec_mode ", "Which exec mode to use") .action(function(cmd, options){ console.log('exec "%s" using %s mode', cmd, options.exec_mode); }).on('--help', function() { console.log(''); console.log('Examples:'); console.log(''); console.log(' $ deploy exec sequential'); console.log(' $ deploy exec async'); }); program .command('*') .action(function(env){ console.log('deploying "%s"', env); }); program.parse(process.argv); ``` -------------------------------- ### Local development setup Source: https://github.com/chevgan/render-peek/blob/main/node_modules/confbox/README.md Instructions for setting up the local development environment for the project, including cloning the repository, installing Node.js, enabling Corepack, and installing dependencies with pnpm. ```sh # Clone this repository # Install the latest LTS version of [Node.js](https://nodejs.org/en/) # Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` # Install dependencies using `pnpm install` # Run tests using `pnpm dev` or `pnpm test` ``` -------------------------------- ### Install Picomatch Source: https://github.com/chevgan/render-peek/blob/main/node_modules/picomatch/README.md Instructions for installing picomatch using npm. ```APIDOC ## Install Picomatch Install with [npm](https://www.npmjs.com/): ```sh npm install --save picomatch ``` ``` -------------------------------- ### Install joycon with Yarn Source: https://github.com/chevgan/render-peek/blob/main/node_modules/joycon/README.md Installs the joycon package using the yarn package manager. ```bash yarn add joycon ``` -------------------------------- ### Install PostCSS Plugins Source: https://github.com/chevgan/render-peek/blob/main/node_modules/postcss-load-config/README.md Installs a PostCSS plugin and saves it to package.json dependencies. ```bash npm i -S|-D postcss-plugin ``` -------------------------------- ### Install render-peek Package Source: https://github.com/chevgan/render-peek/blob/main/README.md Instructions for installing the render-peek package using npm, yarn, or pnpm. ```bash npm install render-peek # or yarn add render-peek # or pnpm add render-peek ``` -------------------------------- ### Add Command Example with command.example Source: https://github.com/chevgan/render-peek/blob/main/node_modules/cac/README.md Adds an example usage string for a specific command. This example will be displayed at the end of the command's help message, providing users with practical usage guidance. ```javascript command.example('build src/index.js --watch') command.example(name => `${name} build --name `) ``` -------------------------------- ### Usage Example Source: https://github.com/chevgan/render-peek/blob/main/node_modules/picomatch/README.md Basic usage example of picomatch to create a matcher function. ```APIDOC ## Usage The main export is a function that takes a glob pattern and an options object and returns a function for matching strings. ```js const pm = require('picomatch'); const isMatch = pm('*.js'); console.log(isMatch('abcd')); //=> false console.log(isMatch('a.js')); //=> true console.log(isMatch('a.md')); //=> false console.log(isMatch('a/b.js')); //=> false ``` ``` -------------------------------- ### Install Commander.js Source: https://github.com/chevgan/render-peek/blob/main/node_modules/commander/Readme.md This command installs the Commander.js package using npm. It's the first step to using Commander in your Node.js project. ```bash npm install commander ``` -------------------------------- ### Generate Source Map with SourceMapGenerator (Low-Level API) Source: https://github.com/chevgan/render-peek/blob/main/node_modules/source-map/README.md This example shows how to generate a source map using the low-level SourceMapGenerator API. This approach provides more direct control over the source map's structure and mappings. It requires the 'source-map' library to be installed. ```javascript const sourceMap = require('source-map'); const generator = new sourceMap.SourceMapGenerator({ file: 'out.js' }); generator.addMapping({ generated: { line: 1, column: 0 }, original: { line: 1, column: 0 }, source: 'original.js', name: 'x' }); generator.setSourceContent('original.js', 'var x = 1;'); console.log(generator.toString()); ``` -------------------------------- ### Install @jridgewell/trace-mapping Source: https://github.com/chevgan/render-peek/blob/main/node_modules/@jridgewell/trace-mapping/README.md Installs the @jridgewell/trace-mapping package using npm. This is the initial step required before using the library in a project. ```sh npm install @jridgewell/trace-mapping ``` -------------------------------- ### Shortcut Registration for 'q' Promise Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Provides an example of using the 'import' syntax for shortcut registration of the 'q' Promise implementation, suitable for modern JavaScript module systems. ```javascript import 'any-promise/register/q'; ``` -------------------------------- ### Install Consola using npm, yarn, or pnpm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/consola/README.md Demonstrates how to install the Consola package using different package managers like npm, yarn, and pnpm. This is the initial step before using Consola in your project. ```bash npm i consola ``` ```bash yarn add consola ``` ```bash pnpm i consola ``` -------------------------------- ### Install UFO URL Utilities Source: https://github.com/chevgan/render-peek/blob/main/node_modules/ufo/README.md Instructions for installing the 'ufo' package using various package managers like npm, yarn, pnpm, and bun. This is the first step before importing any utility functions. ```shell # npm npm install ufo # yarn yarn add ufo # pnpm pnpm install ufo # bun bun install ufo ``` -------------------------------- ### Install React and React DOM Source: https://github.com/chevgan/render-peek/blob/main/node_modules/react-dom/README.md Installs both the core React library and the react-dom package, which is necessary for rendering React components to the DOM. ```sh npm install react react-dom ``` -------------------------------- ### Generate Source Map with SourceNode (High-Level API) Source: https://github.com/chevgan/render-peek/blob/main/node_modules/source-map/README.md This example illustrates generating a source map using the high-level SourceNode API. SourceNode simplifies the process by allowing developers to build source maps in a more intuitive, tree-like structure. It requires the 'source-map' library to be installed. ```javascript const sourceMap = require('source-map'); const node = new sourceMap.SourceNode(); node.add('var x = 1;'); node.setSourceContent('file.js', 'var x = 1;'); node.add(new sourceMap.SourceNode(1, 0, 'file.js', 'console.log(x);')); const map = node.toStringWithSourceMap({ file: 'out.js' }); console.log(map.code); console.log(map.map.toString()); ``` -------------------------------- ### Install lilconfig Source: https://github.com/chevgan/render-peek/blob/main/node_modules/lilconfig/readme.md Install the lilconfig package using npm. This is a prerequisite for using the library in your project. ```sh npm install lilconfig ``` -------------------------------- ### Install bundle-require and esbuild Source: https://github.com/chevgan/render-peek/blob/main/node_modules/bundle-require/README.md Installs the bundle-require package and its peer dependency esbuild using npm. esbuild is required for bundling the target files. ```bash npm i bundle-require esbuild ``` -------------------------------- ### Install Pathe using npm, yarn, or pnpm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/pathe/README.md This snippet shows how to install the 'pathe' package using popular package managers: npm, yarn, and pnpm. This is the first step before importing and using the library in your project. ```bash # npm npm i pathe # yarn yarn add pathe # pnpm pnpm i pathe ``` -------------------------------- ### Install PostCSS Load Config Source: https://github.com/chevgan/render-peek/blob/main/node_modules/postcss-load-config/README.md Installs the postcss-load-config package as a development dependency using npm. ```bash npm i -D postcss-load-config ``` -------------------------------- ### Install Picomatch using npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/picomatch/README.md This command installs the picomatch library as a dependency for your project using npm. It ensures the library is available for use in your Node.js environment. ```sh npm install --save picomatch ``` -------------------------------- ### Install tinyexec Package Source: https://github.com/chevgan/render-peek/blob/main/node_modules/tinyexec/README.md Installs the tinyexec package as a dependency using npm. This is the standard method for adding the package to your project. ```sh $ npm i -S tinyexec ``` -------------------------------- ### Install lines-and-columns with npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/lines-and-columns/README.md This command installs the 'lines-and-columns' package using npm. It can be saved as a dependency by adding the '--save' flag. ```bash $ npm install [--save] lines-and-columns ``` -------------------------------- ### Run Project Tests with npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/picomatch/README.md Installs project dependencies and runs unit tests using npm. This is useful for understanding the library's API and ensuring code quality. It requires Node.js and npm to be installed. ```sh npm install && npm test ``` -------------------------------- ### Install CSSType using npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/csstype/README.md Command to install the CSSType library. This is the initial step required before using its type definitions in your project. ```sh $ npm install csstype ``` -------------------------------- ### Build Acorn from Source Source: https://github.com/chevgan/render-peek/blob/main/node_modules/acorn/README.md Clones the Acorn repository from GitHub, navigates into the project directory, and installs its dependencies using npm. This method is useful for development or when direct installation is not feasible. ```sh git clone https://github.com/acornjs/acorn.git cd acorn npm install ``` -------------------------------- ### Install Chokidar via npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/chokidar/README.md Installs the Chokidar library using npm. This is the primary method to add Chokidar as a dependency to your Node.js project. ```sh npm install chokidar ``` -------------------------------- ### readdirp Promise API Example Source: https://github.com/chevgan/render-peek/blob/main/node_modules/readdirp/README.md Shows how to use the readdirp Promise API to asynchronously retrieve a list of all files and directories. This method is generally more memory and CPU intensive than the stream API. ```javascript // 3) Promise example. More RAM and CPU than streams / for-await. import { readdirpPromise } from 'readdirp'; const files = await readdirpPromise('.'); console.log(files.map(file => file.path)); ``` -------------------------------- ### Install readdirp via npm and JSR Source: https://github.com/chevgan/render-peek/blob/main/node_modules/readdirp/README.md Installs the readdirp package using either the Node Package Manager (npm) or Jashub Registry (JSR). This is the first step before using the readdirp library in your project. ```shell npm install readdirp jsr add jsr:@paulmillr/readdirp ``` -------------------------------- ### Install pkg-types using Various Package Managers Source: https://github.com/chevgan/render-peek/blob/main/node_modules/pkg-types/README.md Demonstrates how to install the pkg-types package using common Node.js package managers like npx, npm, yarn, pnpm, bun, and deno. Auto-detection is also supported. ```sh # ✨ Auto-detect npx nypm install pkg-types # npm npm install pkg-types # yarn yarn add pkg-types # pnpm pnpm install pkg-types # bun bun install pkg-types # deno deno install pkg-types ``` -------------------------------- ### Build Project Documentation with Verb Source: https://github.com/chevgan/render-peek/blob/main/node_modules/picomatch/README.md Installs the necessary global packages (verbose/verb and verb-generate-readme) and then runs the verb command to generate the project's README.md file. This process is managed by the .verb.md template and should not be edited directly. ```sh npm install -g verbose/verb#dev verb-generate-readme && verb ``` -------------------------------- ### Basic lilconfig Usage (Async and Sync) Source: https://github.com/chevgan/render-peek/blob/main/node_modules/lilconfig/readme.md Demonstrates how to use both the asynchronous `lilconfig` and synchronous `lilconfigSync` functions. It shows how to specify search options like `stopDir`, `searchPlaces`, and `ignoreEmptySearchPlaces` and how to initiate the search or load a specific file. ```js import {lilconfig, lilconfigSync} from 'lilconfig'; // all keys are optional const options = { stopDir: '/Users/you/some/dir', searchPlaces: ['package.json', 'myapp.conf.js'], ignoreEmptySearchPlaces: false } lilconfig( 'myapp', options // optional ).search() // Promise lilconfigSync( 'myapp', options // optional ).load(pathToConfig) // LilconfigResult /** * LilconfigResult * { * config: any; // your config * filepath: string; * } */ ``` -------------------------------- ### Install load-tsconfig Source: https://github.com/chevgan/render-peek/blob/main/node_modules/load-tsconfig/README.md Install the load-tsconfig package using npm. This command fetches and installs the package and its dependencies into your project's node_modules directory. ```bash npm i load-tsconfig ``` -------------------------------- ### Registering Promise Implementation with Ava Test Runner Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Shows how to use the shortcut registration method with the Ava test runner via the `--require` flag, ensuring tests use a specific Promise implementation. ```bash $ ava --require=any-promise/register/bluebird test.js ``` -------------------------------- ### Install @jridgewell/resolve-uri Source: https://github.com/chevgan/render-peek/blob/main/node_modules/@jridgewell/resolve-uri/README.md Install the @jridgewell/resolve-uri package using npm. This is the only dependency required for the package. ```sh npm install @jridgewell/resolve-uri ``` -------------------------------- ### Load configuration files with joycon Source: https://github.com/chevgan/render-peek/blob/main/node_modules/joycon/README.md Demonstrates how to use the joycon library to load configuration files, such as lock files. The result will be an empty object if files do not exist, or an object containing the path and data if they do. ```javascript const JoyCon = require('joycon') const joycon = new JoyCon() joycon.load(['package-lock.json', 'yarn.lock']) .then(result => { // result is {} when files do not exist // otherwise { path, data } }) ``` -------------------------------- ### Install @jridgewell/sourcemap-codec Source: https://github.com/chevgan/render-peek/blob/main/node_modules/@jridgewell/sourcemap-codec/README.md Installs the sourcemap-codec package using npm. This package is a dependency for encoding and decoding sourcemap mappings. ```bash npm install @jridgewell/sourcemap-codec ``` -------------------------------- ### Customizing and Registering Promise Implementation Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Illustrates a more flexible way to register a Promise implementation by providing the library name and an options object containing the specific Promise constructor. This is useful for non-standard or custom Promise setups. ```javascript // top of application index.js or other entry point require('any-promise/register')('bluebird', {Promise: require('bluebird')}) ``` -------------------------------- ### Install @jridgewell/gen-mapping Source: https://github.com/chevgan/render-peek/blob/main/node_modules/@jridgewell/gen-mapping/README.md Install the gen-mapping package using npm. This is the primary dependency for using the library. ```sh npm install @jridgewell/gen-mapping ``` -------------------------------- ### Displaying Help Without Exiting Using Commander.js Source: https://github.com/chevgan/render-peek/blob/main/node_modules/commander/Readme.md This JavaScript example demonstrates the use of `program.outputHelp()` to display help information without terminating the program. It includes an optional callback function to modify the help text before it's shown, such as coloring it red, and shows how to trigger this display when no command-line arguments are provided. ```javascript const program = require('commander'); const colors = require('colors'); program .version('0.1.0') .command('getstream [url]', 'get stream URL') .parse(process.argv); if (!process.argv.slice(2).length) { program.outputHelp(make_red); } function make_red(txt) { return colors.red(txt); //display the help text in red on the console } ``` -------------------------------- ### Using Global Promise with 'any-promise' Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Demonstrates how libraries can use 'any-promise' to leverage the globally available Promise implementation. No explicit registration is needed if the global Promise is the desired one. ```javascript // in library var Promise = require('any-promise') // the global Promise function promiseReturningFunction(){ return new Promise(function(resolve, reject){...}) } ``` -------------------------------- ### Using Registered Promise Implementation Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Demonstrates how, after registration, modules like 'mz/fs' and 'any-promise' itself will utilize the previously registered Promise implementation (e.g., 'bluebird'). ```javascript var fsp = require('mz/fs') // mz/fs will use registered bluebird promises var Promise = require('any-promise') // the registered bluebird promise ``` -------------------------------- ### Basic Usage and Logging with Consola Source: https://github.com/chevgan/render-peek/blob/main/node_modules/consola/README.md Shows the fundamental usage of Consola, including importing the library and using various logging methods like info, start, warn, success, and error. It also demonstrates the box and prompt functionalities. ```javascript // ESM import { consola, createConsola } from "consola"; // CommonJS const { consola, createConsola } = require("consola"); consola.info("Using consola 3.0.0"); consola.start("Building project..."); consola.warn("A new version of consola is available: 3.0.1"); consola.success("Project built!"); consola.error(new Error("This is an example error. Everything is fine!")); consola.box("I am a simple box"); await consola.prompt("Deploy to the production?", { type: "confirm", }); ``` -------------------------------- ### Display Help and Version with CAC Source: https://github.com/chevgan/render-peek/blob/main/node_modules/cac/README.md This JavaScript example shows how to configure CAC to display help messages and version information. It defines options, a command with an action, and then enables the built-in help (`cli.help()`) and version (`cli.version()`) functionalities. ```javascript // examples/help.js const cli = require('cac')() cli.option('--type [type]', 'Choose a project type', { default: 'node', }) cli.option('--name ', 'Provide your name') cli.command('lint [...files]', 'Lint files').action((files, options) => { console.log(files, options) }) // Display help message when `-h` or `--help` appears cli.help() // Display version number when `-v` or `--version` appears // It's also used in help message cli.version('0.0.0') cli.parse() ``` -------------------------------- ### Picomatch POSIX Usage without Node.js Source: https://github.com/chevgan/render-peek/blob/main/node_modules/picomatch/README.md Provides an example of using picomatch in environments without Node.js by importing `picomatch/posix`. This version defaults to POSIX path behavior. It also shows how to configure the matcher to accept Windows paths using an options object. ```javascript const picomatch = require('picomatch/posix'); // the same API, defaulting to posix paths const isMatch = picomatch('a/*'); console.log(isMatch('a\b')); //=> false console.log(isMatch('a/b')); //=> true // you can still configure the matcher function to accept windows paths const isMatch = picomatch('a/*', { options: windows }); console.log(isMatch('a\b')); //=> true console.log(isMatch('a/b')); //=> true ``` -------------------------------- ### Install Acorn with npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/acorn/README.md Installs the Acorn JavaScript parser using npm, the Node Package Manager. This is the recommended method for adding Acorn to your project. ```sh npm install acorn ``` -------------------------------- ### Chokidar FSWatcher Methods Source: https://github.com/chevgan/render-peek/blob/main/node_modules/chokidar/README.md Demonstrates the basic usage of Chokidar's FSWatcher instance methods for adding files, listening to events, unwatching files, closing the watcher, and retrieving watched paths. ```javascript const chokidar = require('chokidar'); // Initialize watcher const watcher = chokidar.watch('.', { ignored: '*.txt', persistent: true }); // Add files/directories watcher.add('file.js'); watcher.add(['dir1', 'dir2']); // Listen for events watcher.on('add', path => console.log(`File ${path} has been added`)); watcher.on('change', path => console.log(`File ${path} has been changed`)); watcher.on('unlink', path => console.log(`File ${path} has been removed`)); watcher.on('error', error => console.error(`Watcher error: ${error}`)); // Get all watched paths const watchedPaths = watcher.getWatched(); console.log('Currently watching:', watchedPaths); // Close the watcher (asynchronous) // await watcher.close(); ``` -------------------------------- ### Ensure URL Starts with Base Source: https://github.com/chevgan/render-peek/blob/main/node_modules/ufo/README.md Prepends a base path or URL to the input if it doesn't already start with it. This utility ensures consistency in URL structures. ```javascript function withBase(input, base) { // Implementation details not provided } ``` -------------------------------- ### Create a New Consola Instance Source: https://github.com/chevgan/render-peek/blob/main/node_modules/consola/README.md Shows how to create a new, independent instance of Consola. This allows for more granular control over logger configurations such as log level, enabling/disabling fancy output, and customizing format options like columns, colors, and date display. ```javascript import { createConsola } from "consola"; const logger = createConsola({ // level: 4, // fancy: true | false // formatOptions: { // columns: 80, // colors: false, // compact: false, // date: false, // }, }); ``` -------------------------------- ### Install Debug Utility using npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/debug/README.md This command installs the 'debug' package from npm. This is the primary method for adding the debugging utility to your Node.js project. ```bash npm install debug ``` -------------------------------- ### Install MZ Node.js Library Source: https://github.com/chevgan/render-peek/blob/main/node_modules/mz/README.md This command installs the 'mz' library as a project dependency using npm. MZ is used to modernize Node.js APIs to ECMAScript specifications. ```bash npm i mz ``` -------------------------------- ### Install CAC CLI Library Source: https://github.com/chevgan/render-peek/blob/main/node_modules/cac/README.md This command installs the CAC library using Yarn. CAC is a dependency for building command-line interface applications with JavaScript. ```bash yarn add cac ``` -------------------------------- ### Registering 'bluebird' Promise Implementation Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Shows how an application can register 'bluebird' as its preferred Promise implementation using a shortcut. This ensures that any package requiring 'any-promise' will use 'bluebird'. ```javascript // top of application index.js or other entry point require('any-promise/register/bluebird') ``` -------------------------------- ### Basic fdir usage: Crawl directory synchronously and asynchronously Source: https://github.com/chevgan/render-peek/blob/main/node_modules/fdir/README.md This example demonstrates the fundamental usage of fdir. It shows how to import the fdir class, create a crawler instance, configure it to include full paths, crawl a specified directory, and then retrieve the files either synchronously using `.sync()` or asynchronously using `.then()`. ```typescript import { fdir } from "fdir"; // create the builder const api = new fdir().withFullPaths().crawl("path/to/dir"); // get all files in a directory synchronously const files = api.sync(); // or asynchronously api.withPromise().then((files) => { // do something with the result here. }); ``` -------------------------------- ### Install object-assign using npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/object-assign/readme.md This command installs the object-assign package as a dependency for your project using npm. It saves the package to your node_modules directory and updates your package.json file. ```bash $ npm install --save object-assign ``` -------------------------------- ### Basic Promise Usage with 'any-promise' Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Demonstrates how to require and use the 'any-promise' library for Promise operations. This includes using `Promise.all` to handle multiple promises concurrently and creating a new Promise with resolve and reject handlers. Assumes standard Promise behavior. ```javascript var Promise = require('any-promise'); return Promise .all([xf, f, init, coll]) .then(fn); return new Promise(function(resolve, reject){ try { resolve(item); } catch(e){ reject(e); } }); ``` -------------------------------- ### Registering 'when' Promise Implementation via Basic Method Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Shows the basic registration method for the 'when' Promise library. This method attempts to detect the Promise constructor by requiring the specified library and does not work in the browser. ```javascript require('any-promise/register')('when') ``` -------------------------------- ### Execute Node.js Module Binaries Source: https://github.com/chevgan/render-peek/blob/main/node_modules/tinyexec/README.md Executes binaries installed within the local `node_modules` directory. This allows direct use of tools like `eslint` without global installation. ```typescript await x('eslint', ['.']); ``` -------------------------------- ### Install ts-interface-builder and ts-interface-checker Source: https://github.com/chevgan/render-peek/blob/main/node_modules/ts-interface-checker/README.md Install the ts-interface-builder for build-time code generation and ts-interface-checker for runtime validation. Use --save-dev for the builder and --save for the checker. ```bash npm install --save-dev ts-interface-builder npm install --save ts-interface-checker ``` -------------------------------- ### Install resolve-from using npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/resolve-from/readme.md This command installs the 'resolve-from' package using npm. It's a common way to add Node.js packages to your project dependencies. ```bash npm install resolve-from ``` -------------------------------- ### Importing Minimal Consola Builds Source: https://github.com/chevgan/render-peek/blob/main/node_modules/consola/README.md Illustrates how to import smaller, core builds of Consola for different environments like basic, browser, or core functionalities, which can significantly reduce bundle size. ```typescript import { consola, createConsola } from "consola/basic"; import { consola, createConsola } from "consola/browser"; import { createConsola } from "consola/core"; ``` -------------------------------- ### Install @types/node for TypeScript - Shell Source: https://github.com/chevgan/render-peek/blob/main/node_modules/cac/README.md Instructions for installing the necessary type definitions for Node.js when using TypeScript with the CLI library. This ensures proper type checking and autocompletion. ```shell yarn add @types/node --dev ``` -------------------------------- ### Install mlly npm package Source: https://github.com/chevgan/render-peek/blob/main/node_modules/mlly/README.md Instructions for installing the mlly npm package using either yarn or npm. Node.js version 14 or higher is recommended for optimal performance. ```shell # using yarn yarn add mlly # using npm npm install mlly ``` -------------------------------- ### Chokidar Watcher Configuration Options (JavaScript) Source: https://github.com/chevgan/render-peek/blob/main/node_modules/chokidar/README.md Presents a comprehensive example of Chokidar's available options for fine-tuning file watching behavior. This includes persistence, ignoring files, handling atomic and chunked writes, polling intervals, and directory depth. ```javascript import chokidar from 'chokidar'; chokidar.watch('file', { persistent: true, // ignore .txt files ignored: (file) => file.endsWith('.txt'), // watch only .txt files // ignored: (file, _stats) => _stats?.isFile() && !file.endsWith('.txt'), awaitWriteFinish: true, // emit single event when chunked writes are completed atomic: true, // emit proper events when "atomic writes" (mv _tmp file) are used // The options also allow specifying custom intervals in ms // awaitWriteFinish: { // stabilityThreshold: 2000, // pollInterval: 100 // }, // atomic: 100, interval: 100, binaryInterval: 300, cwd: '.', depth: 99, followSymlinks: true, ignoreInitial: false, ignorePermissionErrors: false, usePolling: false, alwaysStat: false, }); ``` -------------------------------- ### Advanced Chokidar Watcher with Event Handling (JavaScript) Source: https://github.com/chevgan/render-peek/blob/main/node_modules/chokidar/README.md Shows how to initialize a Chokidar watcher with extended options, including filtering files and handling various file system events like add, change, unlink, and directory events. It also demonstrates error handling and readiness confirmation. ```javascript import chokidar from 'chokidar'; // Initialize watcher. const watcher = chokidar.watch('file, dir, or array', { ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files persistent: true }); // Something to use when events are received. const log = console.log.bind(console); // Add event listeners. watcher .on('add', path => log(`File ${path} has been added`)) .on('change', path => log(`File ${path} has been changed`)) .on('unlink', path => log(`File ${path} has been removed`)); // More possible events. watcher .on('addDir', path => log(`Directory ${path} has been added`)) .on('unlinkDir', path => log(`Directory ${path} has been removed`)) .on('error', error => log(`Watcher error: ${error}`)) // internal .on('ready', () => log('Initial scan complete. Ready for changes')) .on('raw', (event, path, details) => { // internal log('Raw event info:', event, path, details); }); // 'add', 'addDir' and 'change' events also receive stat() results as second // argument when available: https://nodejs.org/api/fs.html#fs_class_fs_stats watcher.on('change', (path, stats) => { if (stats) console.log(`File ${path} changed size to ${stats.size}`); }); ``` -------------------------------- ### Install magic-string via npm Source: https://github.com/chevgan/render-peek/blob/main/node_modules/magic-string/README.md Installs the magic-string package using npm, making it available for use in Node.js projects. This is the standard method for adding the library to your project dependencies. ```bash npm i magic-string ``` -------------------------------- ### Promisify Multiple fs Functions with thenifyAll Source: https://github.com/chevgan/render-peek/blob/main/node_modules/thenify-all/README.md Demonstrates how to use `thenifyAll` to promisify specific functions from the 'fs' module. This allows asynchronous file operations like reading and writing to be handled using Promises. The example shows reading the current file and logging its content. ```javascript var thenifyAll = require('thenify-all'); var fs = thenifyAll(require('fs'), {}, [ 'readFile', 'writeFile', ]); fs.readFile(__filename).then(function (buffer) { console.log(buffer.toString()); }); ``` -------------------------------- ### Advanced Registration with Custom Promise Constructor Source: https://github.com/chevgan/render-peek/blob/main/node_modules/any-promise/README.md Demonstrates advanced registration where a specific Promise constructor ('bluebird') is provided via an options object. This allows for custom Promise implementations or subclasses and works in the browser. ```javascript require('any-promise/register')('bluebird', {Promise: require('bluebird')}) ``` -------------------------------- ### Displaying Help and Version Source: https://github.com/chevgan/render-peek/blob/main/node_modules/cac/README.md Demonstrates how to configure CAC to automatically display help messages and version information based on CLI flags. ```APIDOC ## Displaying Help Message and Version ### Description Configures the CLI to show help messages when `-h` or `--help` is used, and version information when `-v` or `--version` is used. The version is also included in the help message. ### Method - `cli.help(callback?)` - `cli.version(version, customFlags?)` ### Endpoint N/A (JavaScript library usage) ### Parameters #### `cli.help(callback?)` - **callback** (function) - Optional - A callback function to customize the help output. #### `cli.version(version, customFlags?)` - **version** (string) - Required - The version string of the CLI application. - **customFlags** (string or array of strings) - Optional - Custom flags to trigger the version display (defaults to `'-v', '--version'`). ### Request Example ```javascript // examples/help.js const cli = require('cac')() cli.option('--type [type]', 'Choose a project type', { default: 'node', }) cli.option('--name ', 'Provide your name') cli.command('lint [...files]', 'Lint files').action((files, options) => { console.log(files, options) }) // Display help message when `-h` or `--help` appears cli.help() // Display version number when `-v` or `--version` appears // It's also used in help message cli.version('0.0.0') cli.parse() ``` ### Response - **Help Message**: Displayed when `-h` or `--help` is invoked. - **Version Information**: Displayed when `-v` or `--version` is invoked. #### Response Example (Help Message) ``` Usage $ your-cli-command Commands lint Lint files Options --type [type] Choose a project type (default: node) --name Provide your name -h, --help Display this message -v, --version Display version number ``` #### Response Example (Version Information) ``` 0.0.0 ``` ``` -------------------------------- ### Install fast-deep-equal Source: https://github.com/chevgan/render-peek/blob/main/node_modules/fast-deep-equal/README.md Install the fast-deep-equal package using npm. This command adds the library to your project's dependencies, making it available for use in your Node.js or browser applications. ```bash npm install fast-deep-equal ```