or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

file-utilities.mdindex.mdinteractive-configuration.mdproject-creation.mdproject-updates.mdtemplate-system.md
tile.json

tessl/npm-js-lib--cli

CLI tool for scaffolding JavaScript and TypeScript third-party libraries with modern development practices

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@js-lib/cli@3.0.x

To install, run

npx @tessl/cli install tessl/npm-js-lib--cli@3.0.0

index.mddocs/

@js-lib/cli

@js-lib/cli is a comprehensive command-line interface tool for scaffolding JavaScript and TypeScript third-party libraries. It provides developers with a complete framework for quickly creating new library projects with modern development practices including linting, testing, build systems, and CI/CD integration.

Package Information

  • Package Name: @js-lib/cli
  • Package Type: npm
  • Language: JavaScript
  • Installation: npx @js-lib/cli new mylib
  • Node.js Requirement: >= 18.0.0

Core Imports

This package is a CLI tool and is not intended for programmatic import. It is executed via npx:

# Execute the CLI tool
npx @js-lib/cli [command] [options]

For programmatic access to internal utilities (advanced usage):

// Not recommended - internal APIs may change
const { checkProjectExists } = require('@js-lib/cli/util/file');
const { init } = require('@js-lib/cli/util/log');

Basic Usage

# Interactive project creation
npx @js-lib/cli new my-awesome-lib
# Follow the interactive prompts to configure:
# - Project name
# - NPM package name
# - UMD name
# - GitHub username  
# - Template type (JavaScript or TypeScript)
# - Package manager preference

cd my-awesome-lib
npm install
npm run build
npm test

Architecture

@js-lib/cli is built around several key components:

  • CLI Interface: Command-line argument parsing and interactive prompts using yargs and inquirer
  • Template System: Separate JavaScript and TypeScript project templates with complete scaffolding
  • File Operations: Comprehensive file copying, template processing, and JSON manipulation utilities
  • Project Management: Initialize new projects and update existing ones with version migrations
  • Build Integration: Modern build toolchain with Rollup, ESLint, Prettier, Mocha, and GitHub Actions

Capabilities

File Utilities

Internal utilities for file operations, template processing, and JSON manipulation used by the CLI.

// File existence checking
function checkProjectExists(cmdPath: string, name: string): boolean;

// Template processing and file operations
function copyDir(from: string, to: string, options?: object): void;
function copyFile(from: string, to: string, opt?: {cover: boolean}): void;
function copyTmpl(from: string, to: string, data?: object, opt?: {cover: boolean}): void;
function readTmpl(from: string, data?: object): string;
function readJSON(from: string): object;

// JSON manipulation
function mergeObj2JSON(object: object, to: string): void;
function mergeJSON2JSON(from: string, to: string): void;
function mergeTmpl2JSON(from: string, to: string, data?: object): void;
function deleteJSONKeys(keysObj: object, to: string): void;

// File content manipulation
function replaceFileLine(filepath: string, match: RegExp, to: string): void;
function deleteFileLine(filepath: string, match: RegExp): void;
function replaceFileText(filepath: string, replacerList: Array<{from: RegExp|string, to: string|Function}>): void;
function insertText2File(text: string, filepath: string, line?: number): void;

// Directory operations
function deleteFile(filePath: string): void;
function deleteDir(dirPath: string): void;

File Utilities

Project Creation

Create new JavaScript or TypeScript library projects with complete scaffolding including build systems, testing, linting, and CI/CD.

jslib new [projectname] [options]
jslib n [projectname] [options]

Options:
  --force, -f              Force create (overwrite existing)
  --config, -c             Initialize only configuration file  
  --npmname, -n <name>     NPM package name
  --umdname, --umd <name>  UMD name for package
  --username, -u <name>    GitHub username
  --type, -t <type>        Template type (js/ts)
  --manager, -m <manager>  Package manager (npm/no install)

Project Creation

Project Updates

Update existing jslib projects to the latest template version and tooling configuration.

jslib update
jslib u

Requirements:
- Must be run in directory containing jslib.json
- Project must have been created with @js-lib/cli

Project Updates

Interactive Configuration

Prompt-based configuration system for collecting project metadata and preferences when creating new projects.

# Interactive prompts are automatically triggered when:
# - Required information is not provided via command line options
# - Creating a new project without all necessary parameters

# The CLI will prompt for:
# - Project name (if not provided as argument)
# - NPM package name (with validation)  
# - UMD global variable name
# - GitHub username
# - Template type (JavaScript or TypeScript)
# - Package manager preference (npm or no install)

Interactive Configuration

Template System

Template processing engine for generating project files with variable substitution using EJS-style syntax.

// Template variables available during project creation
interface TemplateVariables {
  name: string;        // Project display name
  npmname: string;     // NPM package name  
  umdname: string;     // UMD global variable name
  username: string;    // GitHub username
  type: 'js' | 'ts';  // Template type (JavaScript or TypeScript)
  manager: 'npm' | null; // Package manager
  version: string;     // CLI version
  pathname: string;    // Directory name
}

// Template files use EJS-style syntax:
// <%=variable%>     - Output variable value
// <% if (condition) { %> - Conditional blocks  
// <% for (var i=0; i<items.length; i++) { %> - Loop constructs

Template System

Module System

Internal module structure for organizing template generation and project scaffolding functionality.

// Module initialization and update functions
interface ProjectModule {
  init(cmdPath: string, name: string, option: ProjectOptions): void | Promise<void>;
  update?(cmdPath: string, option: ProjectOptions): void;
}

// Available modules:
// - config: Project configuration (jslib.json)
// - root: Root files (README, LICENSE, etc.)
// - lint: ESLint and Prettier configuration
// - packagejson: package.json generation and updates
// - demo: Demo files and usage examples
// - build: Rollup build configuration
// - test: Mocha testing setup
// - manager: Package manager integration (npm install)

Package Manager Integration

Automated dependency installation and git repository initialization during project creation.

/**
 * Initialize git repository and install dependencies
 * @param cmdPath - Base directory path
 * @param name - Project directory name
 * @param option - Project configuration including manager preference
 * @returns Promise that resolves when installation completes
 */
function managerInit(
  cmdPath: string, 
  name: string, 
  option: ProjectOptions
): Promise<void>;

// Manager options:
// - 'npm': Run npm install after project creation
// - null: Skip dependency installation

Types

// Project initialization options
interface ProjectOptions {
  pathname: string;    // Directory name to create
  name: string;        // Project display name
  npmname: string;     // NPM package name
  umdname: string;     // UMD global variable name  
  username: string;    // GitHub username
  type: 'js' | 'ts';  // Template type
  manager: 'npm' | null; // Package manager
  version: string;     // CLI version
}

// Command line arguments structure
interface CLIArguments {
  _: string[];         // Positional arguments
  force?: boolean;     // Force overwrite flag
  config?: boolean;    // Config-only flag
  npmname?: string;    // NPM name option
  umdname?: string;    // UMD name option  
  username?: string;   // Username option
  type?: string;       // Type option
  manager?: string;    // Manager option
}