两分钟构建你自己的前端脚手架

本篇文章主要来分享一下自己近期开发的一个小工具,可帮助大家2分钟部署一个属于自己简易脚手架

仓库地址:github.com/gong9/swift...

使用视频:www.bilibili.com/video/BV1Ap...

Swift-Core 是一个用于构建命令行界面(CLI)应用的工具包,可以帮助你快速搭建 CLI 脚手架下载器。要开始使用,你需要:

1. 配置你的仓库地址

  • 对于 GitHub 个人账号:打开你的仓库主页,复制地址栏中的 如:https://github.com/gong9
  • 对于 Gitee 个人账号:同理操作,复制地址栏中的 如:https://gitee.com/gong9
  • 对于 GitHub 组织账号:同样打开主页,复制地址栏中的 https://github.com/gong-cli

2. 配置你的 CLI 组件的 JSON 格式配置

如下定义你的 CLI 组件配置:

json 复制代码
[
  {
    "name": "frame",
    "label": "框架类型",
    "type": "select",
    "title": "请选择框架",
    "items": [
      {
        "label": "React",
        "value": "react"
      },
      {
        "label": "Vue",
        "value": "vue"
      },
      {
        "label": "None",
        "value": "none"
      }
    ]
  },
  {
    "name": "demo",
    "label": "demo",
    "type": "input",
    "title": "demo"
  }
]

3. 仓库模版项目名称规定

cli会找所有以template-开头的开源项目模版,然后根据你的选择进行下载

Swift-Core 将为你的 CLI 自动生成 GUI 组件。通过 GUI 进行选择时(例如,select 组件选择 "React" , input 组件中输入 "111"),它将从你指定的仓库中搜索并下载符合条件的项目(本例中为包含 "react" 和 "111" 的项目,如template-react-111)。

none 代表不选择任何项目,匹配所有项目。

安装

确保你安装了 Node.js 版本 18.0.0 或更高:

bash 复制代码
pnpm add swift-core

使用

index.js

js 复制代码
#!/usr/bin/env node

const SwiftCore = require('swift-core').default

const swiftCore = new SwiftCore({
  name: 'swift-core',
  path: 'https://github.com/gong9', //目前仅支持 gitee 和 github
  version: '0.0.1',
  description: 'CLI 工具,用于项目脚手架搭建',
});

swiftCore.setConfig({
  configData: [
    {
      name: 'frame',
      label: '框架类型',
      type: 'select',
      title: '请选择框架',
      items: [
        {
          label: 'React',
          value: 'react',
        },
        {
          label: 'Vue',
          value: 'vue',
        },
        {
          label: 'None',
          value: 'none',
        },
      ],
    },
  ],
});

swiftCore.run();

执行

node index.js

上传部署自己的脚手架

你可以 clone https://github.com/gong-cli/template-cli 此项目,修改为你的配置和package.json。 然后npm publish

当然也可以用我的脚手架: github.com/gong9/swift...

相关推荐
omnijk8 分钟前
前端工程化
前端
做前端的娜娜子10 分钟前
前端必看!我把一段"能跑不敢动"的报表代码用 AI 重构成了组件(附完整 Prompt)
前端·ai编程
hunterandroid27 分钟前
[鸿蒙从零到一] ArkUI 动画与转场实战:状态驱动、组件过渡与页面衔接
前端
何时梦醒27 分钟前
React + TypeScript + Vite 实战:从零构建 Color Picker 应用
前端·javascript·架构
谁在黄金彼岸30 分钟前
Nuxt.js 详解(一):Vue 开发者为什么要关注 Nuxt
前端
英勇无比的消炎药32 分钟前
TinyRobot v0.5.0 深度解读(三):Layout 组件——如何组织复杂工作区的页面布局
前端·vue.js
默_笙34 分钟前
😋 我让 DeepSeek-R1 在浏览器本地跑了起来,后端同事说"你认真的?"
前端·javascript
英勇无比的消炎药34 分钟前
TinyRobot v0.5.0 深度解读(四):CLI 脚手架——从零搭建 AI 应用的工程化实践
前端·vue.js·github
程序员黑豆1 小时前
鸿蒙应用开发之双向绑定实战:从 V1 到 V2 的完整迁移指南
前端·harmonyos