Productive-Box 项目教程

Productive-Box 项目教程

productive-boxAre you an early 🐤 or a night 🦉? Let's check out in gist项目地址:https://gitcode.com/gh_mirrors/pr/productive-box

1、项目的目录结构及介绍

productive-box/
├── .github/
│   └── workflows/
│       └── update-gist.yml
├── src/
│   ├── index.ts
│   ├── gist.ts
│   ├── github.ts
│   └── utils.ts
├── .gitignore
├── package.json
├── tsconfig.json
└── README.md

目录结构介绍

  • .github/workflows/: 包含GitHub Actions的工作流配置文件,用于定时更新Gist。
  • src/: 项目的源代码目录,包含主要的TypeScript文件。
    • index.ts: 项目的入口文件,负责初始化和启动项目。
    • gist.ts: 处理与Gist相关的操作,如更新Gist内容。
    • github.ts: 处理与GitHub API的交互,获取提交历史信息。
    • utils.ts: 包含一些通用的工具函数。
  • .gitignore: 指定Git忽略的文件和目录。
  • package.json: 项目的依赖管理文件,包含项目的依赖包和脚本命令。
  • tsconfig.json: TypeScript的配置文件,定义编译选项。
  • README.md: 项目的说明文档,包含项目的介绍、使用方法等。

2、项目的启动文件介绍

src/index.ts

index.ts 是项目的入口文件,负责初始化和启动项目。它主要完成以下任务:

  • 读取配置文件中的GitHub Token和Gist ID。
  • 调用 github.ts 中的函数获取用户的提交历史。
  • 调用 gist.ts 中的函数更新Gist内容,展示用户的代码活动时间轴。
import { updateGist } from './gist';
import { getCommitHistory } from './github';
import { getConfig } from './utils';

async function main() {
    const config = getConfig();
    const commitHistory = await getCommitHistory(config.GH_TOKEN);
    await updateGist(config.GIST_ID, commitHistory, config.TIMEZONE);
}

main();

3、项目的配置文件介绍

package.json

package.json 是项目的依赖管理文件,包含项目的依赖包和脚本命令。以下是一些关键字段的介绍:

  • name: 项目的名称。
  • version: 项目的版本号。
  • scripts: 定义了一些常用的脚本命令,如 start 用于启动项目。
  • dependencies: 项目运行所需的依赖包。
  • devDependencies: 开发环境所需的依赖包。
{
  "name": "productive-box",
  "version": "1.0.0",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "dependencies": {
    "@octokit/rest": "^18.0.0",
    "dotenv": "^8.2.0",
    "moment-timezone": "^0.5.31"
  },
  "devDependencies": {
    "ts-node": "^9.0.0",
    "typescript": "^4.0.0"
  }
}

.github/workflows/update-gist.yml

update-gist.yml 是GitHub Actions的工作流配置文件,用于定时更新Gist。以下是一些关键字段的介绍:

  • on: 定义触发工作流的事件,如 schedule 表示定时触发。
  • jobs: 定义工作流中的任务,如 update-gist 任务。
  • steps: 定义任务中的具体步骤,如签出代码、安装依赖、运行脚本等。
name: Update Gist

on:
  schedule:
    - cron: '0 * * * *'

jobs:
  update-gist:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: Install dependencies
        run: npm install
      - name: Run script
        run: npm start
        env:
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
          GIST_ID: ${{ secrets.GIST_ID }}
          TIMEZONE: ${{ vars.TIMEZONE }}

通过以上配置,项目可以自动定时更新Gist,展示用户的代码活动时间轴。

productive-boxAre you an early 🐤 or a night 🦉? Let's check out in gist项目地址:https://gitcode.com/gh_mirrors/pr/productive-box

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

韶丰业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值