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

本篇文章主要来分享一下自己近期开发的一个小工具,可帮助大家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...

相关推荐
nashane8 分钟前
HarmonyOS 6学习:Web组件同层渲染事件处理与智能长截图实现
前端·学习·harmonyos·harmonyos 5
大家的林语冰11 分钟前
Node 2026 发布,JS 三大新功能上线,最后一个奇偶版本
前端·javascript·node.js
nashane28 分钟前
HarmonyOS 6学习:Web组件同层渲染触摸事件与长截图拼接实战
前端·学习·harmonyos·harmonyos 5
GISer_Jing1 小时前
浏览器 Agent 插件开发规格书 (SPEC)
前端·ai·前端框架·edge浏览器
别叫我->学废了->lol在线等1 小时前
评估总结模块(暂不做)
前端
清灵xmf1 小时前
CC Switch:解决 AI 编程工具配置
前端·人工智能·cc switch
IT_陈寒2 小时前
Redis缓存击穿把我坑惨了,原来这样解决才靠谱
前端·人工智能·后端
mfxcyh2 小时前
Vue3 右键菜单实现方案(基于 vue3-context-menu)
前端
treesforest2 小时前
从IP地址归属地查询到IP地理位置精准查询指南
服务器·前端·网络
LF男男2 小时前
WindmillBullect.cs
前端