logo
0
0
WeChat Login

create-jtemplate

A CLI tool to initialize a new project from jtemplate boilerplate.

Usage

# Using npm init (recommended) npm init jtemplate <project-name> # Or with options (note the -- separator) npm init jtemplate -- --h5 my-h5-project npm init jtemplate -- --web --dev my-project # Or using npx npx create-jtemplate <project-name> # Or install globally npm install -g create-jtemplate create-jtemplate <project-name> # Show help npm init jtemplate -- --help

Options

OptionDescription
--webInitialize only web directory (no backend)
--h5Initialize H5 mobile template
--devAuto install dependencies and start dev server
--testTest mode, output parsed arguments only
--helpShow help message

Quick Start

# Initialize a full-stack project npm init jtemplate my-project # Initialize only web directory (no backend) npm init jtemplate -- --web my-web-project # Initialize H5 mobile template npm init jtemplate -- --h5 my-h5-project # Initialize and auto-start dev server npm init jtemplate -- --dev my-project npm init jtemplate -- --web --dev my-web-project

How it works

  1. First attempt: Tries to clone from the primary repository via SSH:

    git@git.ciccjinteng.cn:jvfe/base/template/boilerplate.git
  2. Fallback: If the primary repository is unavailable or you don't have SSH access, it automatically falls back to:

    https://cnb.cool/yc_null/base/template
  3. Clean up: After cloning, the .git directory is removed to give you a fresh start.

  4. Options handling:

    • --web: Only copies the web directory content to the target directory, suitable for front-end only projects
    • --h5: Clones from the H5 template repository for mobile web projects
    • --dev: Automatically installs dependencies and starts the development server after initialization

Option Details

--web

Initializes only the web directory from the template, excluding the backend part. This is ideal for front-end only projects where you don't need the backend code.

Example:

create-jtemplate --web my-web-project

--h5

Initializes a project from the H5 template repository. This is designed for H5 mobile web projects.

Repository: git@git.ciccjinteng.cn:js-group/base/h5-template.git

Requirements:

  • SSH key must be configured (no fallback available)

Example:

create-jtemplate --h5 my-h5-project

--dev

Automatically installs dependencies and starts the development server after initialization. It checks if pnpm is installed and uses it if available, otherwise falls back to npm.

Behavior:

  • For regular projects: Executes npm run install:all or pnpm run install:all:pnpm
  • For web-only projects: Executes npm install or pnpm install directly in the web directory
  • After installation: Starts the development server with npm run dev

Example:

create-jtemplate --dev my-dev-project

Combined usage

You can combine both options to create a web-only project and start the development server immediately:

Example:

create-jtemplate --web --dev my-web-dev-project

Requirements

  • Node.js >= 14.0.0
  • Git installed and available in PATH

Repository Priority

Default Mode

The tool attempts repositories in this order:

  1. Primary (SSH): git@git.ciccjinteng.cn:jvfe/base/template/boilerplate.git

    • Requires SSH key configured
    • Faster and more secure
  2. Fallback (HTTPS): https://cnb.cool/yc_null/base/template

    • No authentication required
    • Public access

H5 Mode (--h5)

When using --h5 option, the tool clones from:

  • H5 Template (SSH): git@git.ciccjinteng.cn:js-group/base/h5-template.git
    • Requires SSH key configured
    • No fallback available

License

MIT

About

初始化项目模板库

Language
JavaScript100%