CLI tool for scaffolding JavaScript and TypeScript third-party libraries with modern development practices
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive template processing engine for generating project files with variable substitution. The CLI uses template files with .tmpl extensions to generate customized project files based on user configuration.
Process template files with variable substitution using EJS-style syntax.
/**
* Template variables available during project creation
*/
interface TemplateVariables {
name: string; // Project display name (e.g., "My Awesome Project")
npmname: string; // NPM package name (e.g., "@company/my-project")
umdname: string; // UMD global variable name (e.g., "MyProject")
username: string; // GitHub username (e.g., "johndoe")
type: 'js' | 'ts'; // Template type selection
manager: 'npm' | null; // Package manager preference
version: string; // CLI version used to create project
pathname: string; // Directory name to create
}
// Template syntax (EJS-compatible):
// <%=variable%> - Output variable value with HTML escaping
// <%-variable%> - Output variable value without escaping
// <% if (condition) { %> - Conditional blocks
// <% } %> - End conditional
// <% for (var i=0; i<items.length; i++) { %> - Loop constructs
// <% } %> - End loopUsage Examples:
// In template file (package.json.tmpl):
{
"name": "<%=npmname%>",
"version": "1.0.0",
"description": "<%=name%> - Generated by @js-lib/cli",
"author": "<%=username%>",
"repository": {
"type": "git",
"url": "git://github.com/<%=username%>/<%=name%>.git"
},
"main": "dist/<%=umdname%>.cjs.js",
"module": "dist/<%=umdname%>.esm.js"
}
// In template file (README.md.tmpl):
# [<%=name%>](https://github.com/<%=username%>/<%=name%>)
<% if (type === 'ts') { %>
This project is written in TypeScript for better type safety.
<% } else { %>
This project is written in JavaScript.
<% } %>
## Installation
```bash
npm install <%=npmname%>### JavaScript Template Structure
The JavaScript template (`module-js`) provides a complete project structure with modern tooling.
```javascript { .api }
// JavaScript template files include:
interface JavaScriptTemplate {
// Configuration files
'jslib.json.tmpl': string; // Project metadata
'package.json.tmpl': string; // NPM package configuration
'rollup.config.js.tmpl': string; // Build configuration
'.eslintrc.js.tmpl': string; // Linting rules
// Documentation templates
'README.md.tmpl': string; // English README
'README.zh-CN.md.tmpl': string; // Chinese README
'CHANGELOG.md.tmpl': string; // Change log
'license.tmpl': string; // MIT license
// Source code templates
'src/index.js.tmpl': string; // Main source file
'test/test.js.tmpl': string; // Unit tests
'demo/demo-node.js.tmpl': string; // Node.js demo
// Build and CI templates
'.github/workflows/ci.yml.tmpl': string; // GitHub Actions
'build-rollup.cjs.tmpl': string; // Rollup CommonJS config
'commitlint.config.js.tmpl': string; // Commit linting
}
// Generated project structure:
project-name/
├── src/ # Source code (ES6+)
├── test/ # Unit tests (Mocha)
├── demo/ # Usage examples
├── dist/ # Compiled output
├── .github/ # CI/CD workflows
├── package.json # NPM configuration
├── rollup.config.js # Build configuration
├── .eslintrc.js # Code quality rules
├── jslib.json # Project metadata
└── README.md # DocumentationThe TypeScript template (module-ts) provides the same structure with TypeScript support.
// TypeScript template files include:
interface TypeScriptTemplate {
// Additional TypeScript-specific files
'tsconfig.json.tmpl': string; // TypeScript configuration
'src/index.ts.tmpl': string; // TypeScript source file
'test/test.ts.tmpl': string; // TypeScript unit tests
'typings/index.d.ts.tmpl': string; // Type declarations
// Same structure as JavaScript template but with TypeScript support
// All .js files become .ts files with proper type annotations
}
// Generated TypeScript project includes:
// - Full TypeScript compilation pipeline
// - Type declaration generation (.d.ts files)
// - TypeScript-aware testing setup
// - ESLint with TypeScript parser
// - Source maps for debuggingTemplates use the provided variables to customize generated content.
Common Template Patterns:
// Package.json generation
{
"name": "<%=npmname%>",
"version": "1.0.0",
"main": "dist/<%=umdname%>.cjs.js",
"module": "dist/<%=umdname%>.esm.js",
"browser": "dist/<%=umdname%>.js",
"author": "<%=username%>",
"repository": {
"url": "git://github.com/<%=username%>/<%=name%>.git"
}
}
// README generation with conditional content
# [<%=name%>](https://github.com/<%=username%>/<%=name%>)
<% if (type === 'ts') { %>
[](https://www.typescriptlang.org/)
<% } %>
## Installation
```bash
npm install <%=npmname%><% if (type === 'ts') { %>
import <%=umdname%> from '<%=npmname%>';
<% } else { %>
```javascript
const <%=umdname%> = require('<%=npmname%>');
<% } %>
// Your code here// License generation MIT License
Copyright (c) <%= new Date().getFullYear() %> <%=username%>
Permission is hereby granted, free of charge, to any person obtaining a copy...
### Template Processing Engine
The template system is built on the `template_js` library providing powerful text processing.
```javascript { .api }
/**
* Template processing features:
*/
interface TemplateEngine {
// Variable interpolation
variableSubstitution: true; // <%=variable%> syntax
htmlEscaping: true; // Automatic HTML escaping
rawOutput: true; // <%-variable%> for unescaped output
// Control structures
conditionals: true; // <% if/else/endif %>
loops: true; // <% for/while %>
javascript: true; // <% arbitrary JavaScript %>
// Advanced features
includes: false; // Template inclusion (not used)
filters: false; // Output filters (not used)
helpers: false; // Custom helper functions (not used)
}
// Processing workflow:
// 1. Read .tmpl file from template directory
// 2. Apply variable substitution using provided data
// 3. Execute any embedded JavaScript logic
// 4. Write processed content to destination file
// 5. Remove .tmpl extension from destination filenameTemplates can be extended or modified for specific use cases.
Custom Template Variables:
// Extended template data can include:
const customTemplateData = {
// Standard variables
name: 'my-project',
npmname: '@company/my-project',
umdname: 'MyProject',
username: 'johndoe',
type: 'ts',
version: '3.0.6',
// Custom additions
description: 'My awesome project description',
keywords: ['javascript', 'library', 'utility'],
license: 'MIT',
year: new Date().getFullYear(),
dependencies: {
'lodash': '^4.17.21'
}
};Template File Naming:
# Template files must use .tmpl extension
package.json.tmpl # Becomes package.json
README.md.tmpl # Becomes README.md
src/index.js.tmpl # Becomes src/index.js
.eslintrc.js.tmpl # Becomes .eslintrc.js
# Directory structure is preserved
template/base/src/index.js.tmpl → project/src/index.js
template/base/test/test.js.tmpl → project/test/test.js// Template data structure passed to all templates
interface ProjectTemplateData {
pathname: string; // Directory name for the project
name: string; // Human-readable project name
npmname: string; // NPM package name (may include scope)
umdname: string; // Global variable name for UMD builds
username: string; // GitHub username for repository URLs
type: 'js' | 'ts'; // Template type selection
manager: 'npm' | null; // Package manager choice
version: string; // CLI version that created the project
}
// Template processing options
interface TemplateOptions {
cover?: boolean; // Whether to overwrite existing files (default: true)
encoding?: string; // File encoding (default: 'utf8')
}
// Template file structure
interface TemplateFile {
path: string; // Relative path within template directory
content: string; // Template content with placeholders
destination: string; // Output path (without .tmpl extension)
}