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

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

相关推荐
程序员清洒1 小时前
Flutter for OpenHarmony:GridView — 网格布局实现
android·前端·学习·flutter·华为
VX:Fegn08951 小时前
计算机毕业设计|基于ssm + vue超市管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·后端·课程设计
0思必得01 小时前
[Web自动化] 反爬虫
前端·爬虫·python·selenium·自动化
LawrenceLan2 小时前
Flutter 零基础入门(二十六):StatefulWidget 与状态更新 setState
开发语言·前端·flutter·dart
heart_fly_in_sky2 小时前
Mali GPU架构深度解析:Bifrost架构与优化策略(Lesson 4)
架构
秋秋小事2 小时前
TypeScript 模版字面量与类型操作
前端·typescript
2401_892000522 小时前
Flutter for OpenHarmony 猫咪管家App实战 - 添加提醒实现
前端·javascript·flutter
2501_933329552 小时前
企业级AI舆情中台架构实践:Infoseek系统如何实现亿级数据实时监测与智能处置?
人工智能·架构
Yolanda942 小时前
【项目经验】vue h5移动端禁止缩放
前端·javascript·vue.js
广州华水科技4 小时前
单北斗GNSS形变监测一体机在基础设施安全中的应用与技术优势
前端