use-template

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Use Template

使用模板

Clone a game template from the gallery into a new project. This is a fast copy — working code in seconds, not an AI pipeline.
从模板库中克隆游戏模板到新项目中。这是快速复制操作——几秒钟就能获得可运行代码,而非通过AI流程生成。

Behavior

操作流程

  1. Parse arguments:
    <template-id> [project-name]
    • If no arguments provided, read
      gallery/manifest.json
      , display a numbered list of all templates with their engine/complexity/description, and ask the user to pick one.
    • template-id
      is required.
      project-name
      defaults to
      template-id
      .
  2. Look up template in
    gallery/manifest.json
    by
    id
    . If not found, show available IDs and abort.
  3. Determine target directory:
    • If current working directory is inside the
      game-creator
      repository →
      examples/<project-name>/
    • Otherwise →
      ./<project-name>/
    • If target already exists, abort with error.
  4. Copy the template source directory to the target, excluding:
    • node_modules/
    • dist/
    • output/
    • .herenow/
    • progress.md
    • test-results/
    • playwright-report/
  5. Update project metadata:
    • In
      package.json
      : set
      "name"
      to the project name
    • In
      index.html
      (if exists): update
      <title>
      to a formatted version of the project name
  6. Install dependencies: Run
    npm install
    in the target directory.
  7. Print next steps:
    Template cloned successfully!
    
    cd <project-name>
    npm run dev
  1. 解析参数
    <template-id> [项目名称]
    • 若未提供参数,则读取
      gallery/manifest.json
      ,显示所有模板的编号列表(包含引擎、复杂度和描述信息),并让用户选择其一。
    • template-id
      为必填项。
      项目名称
      默认值为
      template-id
  2. 查找模板:通过
    id
    gallery/manifest.json
    中查找模板。若未找到,则显示可用的ID并终止操作。
  3. 确定目标目录
    • 若当前工作目录位于
      game-creator
      仓库内 → 目标目录为
      examples/<project-name>/
    • 否则 → 目标目录为
      ./<project-name>/
    • 若目标目录已存在,则报错并终止操作。
  4. 复制模板源目录到目标位置,排除以下内容
    • node_modules/
    • dist/
    • output/
    • .herenow/
    • progress.md
    • test-results/
    • playwright-report/
  5. 更新项目元数据
    • package.json
      中:将
      "name"
      设置为项目名称
    • index.html
      (若存在)中:将
      <title>
      更新为格式化后的项目名称
  6. 安装依赖:在目标目录中运行
    npm install
  7. 打印后续步骤
    Template cloned successfully!
    
    cd <project-name>
    npm run dev

Implementation

实现代码

javascript
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// Find game-creator root (contains gallery/manifest.json)
function findRoot(dir) {
  let d = dir;
  while (d !== path.dirname(d)) {
    if (fs.existsSync(path.join(d, 'gallery', 'manifest.json'))) return d;
    d = path.dirname(d);
  }
  return null;
}

const root = findRoot(process.cwd());
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'gallery', 'manifest.json'), 'utf-8'));

// Parse args
const [templateId, projectName] = args; // provided by the agent
const template = manifest.find(t => t.id === templateId);
const name = projectName || templateId;

// Determine target
const inGameCreator = process.cwd().startsWith(root);
const target = inGameCreator
  ? path.join(root, 'examples', name)
  : path.join(process.cwd(), name);

// Copy with exclusions
const EXCLUDE = ['node_modules', 'dist', 'output', '.herenow', 'progress.md', 'test-results', 'playwright-report'];

function copyDir(src, dst) {
  fs.mkdirSync(dst, { recursive: true });
  for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
    if (EXCLUDE.includes(entry.name)) continue;
    const s = path.join(src, entry.name);
    const d = path.join(dst, entry.name);
    if (entry.isDirectory()) copyDir(s, d);
    else fs.copyFileSync(s, d);
  }
}

copyDir(path.join(root, template.source), target);

// Update package.json
const pkgPath = path.join(target, 'package.json');
if (fs.existsSync(pkgPath)) {
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
  pkg.name = name;
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
}

// Update index.html title
const indexPath = path.join(target, 'index.html');
if (fs.existsSync(indexPath)) {
  let html = fs.readFileSync(indexPath, 'utf-8');
  const prettyName = name.replace(/[-_]/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
  html = html.replace(/<title>[^<]*<\/title>/, `<title>${prettyName}</title>`);
  fs.writeFileSync(indexPath, html);
}

// Install
execSync('npm install', { cwd: target, stdio: 'inherit' });

// Fire-and-forget telemetry (respects DO_NOT_TRACK / DISABLE_TELEMETRY)
if (!process.env.DO_NOT_TRACK && !process.env.DISABLE_TELEMETRY) {
  const https = require('https');
  const telemetryUrl = process.env.TELEMETRY_URL || 'https://gallery-telemetry.up.railway.app';
  https.get(`${telemetryUrl}/t?event=clone&template=${encodeURIComponent(templateId)}&source=skill&v=1`)
    .on('error', () => {});
}
javascript
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// Find game-creator root (contains gallery/manifest.json)
function findRoot(dir) {
  let d = dir;
  while (d !== path.dirname(d)) {
    if (fs.existsSync(path.join(d, 'gallery', 'manifest.json'))) return d;
    d = path.dirname(d);
  }
  return null;
}

const root = findRoot(process.cwd());
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'gallery', 'manifest.json'), 'utf-8'));

// Parse args
const [templateId, projectName] = args; // provided by the agent
const template = manifest.find(t => t.id === templateId);
const name = projectName || templateId;

// Determine target
const inGameCreator = process.cwd().startsWith(root);
const target = inGameCreator
  ? path.join(root, 'examples', name)
  : path.join(process.cwd(), name);

// Copy with exclusions
const EXCLUDE = ['node_modules', 'dist', 'output', '.herenow', 'progress.md', 'test-results', 'playwright-report'];

function copyDir(src, dst) {
  fs.mkdirSync(dst, { recursive: true });
  for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
    if (EXCLUDE.includes(entry.name)) continue;
    const s = path.join(src, entry.name);
    const d = path.join(dst, entry.name);
    if (entry.isDirectory()) copyDir(s, d);
    else fs.copyFileSync(s, d);
  }
}

copyDir(path.join(root, template.source), target);

// Update package.json
const pkgPath = path.join(target, 'package.json');
if (fs.existsSync(pkgPath)) {
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
  pkg.name = name;
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
}

// Update index.html title
const indexPath = path.join(target, 'index.html');
if (fs.existsSync(indexPath)) {
  let html = fs.readFileSync(indexPath, 'utf-8');
  const prettyName = name.replace(/[-_]/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
  html = html.replace(/<title>[^<]*<\/title>/, `<title>${prettyName}</title>`);
  fs.writeFileSync(indexPath, html);
}

// Install
execSync('npm install', { cwd: target, stdio: 'inherit' });

// Fire-and-forget telemetry (respects DO_NOT_TRACK / DISABLE_TELEMETRY)
if (!process.env.DO_NOT_TRACK && !process.env.DISABLE_TELEMETRY) {
  const https = require('https');
  const telemetryUrl = process.env.TELEMETRY_URL || 'https://gallery-telemetry.up.railway.app';
  https.get(`${telemetryUrl}/t?event=clone&template=${encodeURIComponent(templateId)}&source=skill&v=1`)
    .on('error', () => {});
}

Example Usage

示例用法

/use-template flappy-bird my-game
/use-template threejs-3d-starter space-shooter
/use-template castle-siege
/use-template flappy-bird my-game
/use-template threejs-3d-starter space-shooter
/use-template castle-siege

Key Difference from /make-game

与/make-game的核心区别

/use-template
is a 10-second copy. You get working, runnable code instantly and customize it manually.
/make-game
is a 10-minute AI pipeline that scaffolds, designs, adds audio, tests, deploys, and monetizes from a text prompt.
/use-template
10秒级的复制操作。你能立即获得可运行的代码,然后手动进行自定义修改。
/make-game
10分钟级的AI流程,它能根据文本提示完成项目搭建、设计、添加音频、测试、部署和变现等一系列操作。