Skip to content

Commit

Permalink
fix: 增加 docker hub 相关配置和徽章
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Jul 16, 2024
1 parent 823c796 commit b90fa8a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ ct create
"PATREON_USERNAME": "",
"WEIBO_USERNAME": "",
"TWITTER_USERNAME": "",
"NPM_USERNAME": ""
"NPM_USERNAME": "",
"DOCKER_USERNAME": ""
}
```

Expand All @@ -90,6 +91,8 @@ TWITTER_USERNAME:Twitter 用户名,可空,默认值为空

NPM_USERNAME:Npm 用户名,可空,默认会使用 `GITHUB_USERNAME` 的用户名

DOCKER_USERNAME:Docker Hub 用户名,可空,默认会使用**小写的** `GITHUB_USERNAME` 的用户名

**如果不使用自动初始化远程仓库功能,可以跳过该配置**

## 开发
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type TemplateCliConfig = {
WEIBO_USERNAME: string
TWITTER_USERNAME: string
NPM_USERNAME: string
DOCKER_USERNAME: string
}

type GiteeRepo = {
Expand Down Expand Up @@ -840,7 +841,8 @@ async function getProjectInfo(projectPath: string, answers: InitAnswers) {
const twitterUsername = config?.TWITTER_USERNAME
const afdianUsername = config?.AFDIAN_USERNAME
const patreonUsername = config?.PATREON_USERNAME
const npmUsername = config?.NPM_USERNAME || author
const npmUsername = config?.NPM_USERNAME || githubUsername
const dockerUsername = config?.DOCKER_USERNAME || githubUsername?.toLowerCase()

const repositoryUrl = `https://github.com/${githubUsername}/${projectName}`
const gitUrl = `git+${repositoryUrl}.git`
Expand Down Expand Up @@ -908,6 +910,7 @@ async function getProjectInfo(projectPath: string, answers: InitAnswers) {
weiboUsername,
twitterUsername,
npmUsername,
dockerUsername,
templateMeta,
mainFile,
}
Expand Down
8 changes: 8 additions & 0 deletions templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
<a href="https://www.npmjs.com/package/<%= packageName %>" target="_blank">
<img alt="Version" src="https://img.shields.io/npm/v/<%= packageName %>.svg">
</a>
<a href="https://www.npmjs.com/package/<%= packageName %>" target="_blank">
<img alt="npm downloads" src="https://img.shields.io/npm/dt/<%= packageName %>?label=npm%20downloads&color=yellow">
</a>
<% } -%>
<% if (projectVersion && isJSProject) { -%>
<img alt="Version" src="https://img.shields.io/github/package-json/v/<%= authorGithubUsername %>/<%= packageName %>.svg" />
<% } -%>
<% if (isOpenSource && isInitDocker) { -%>
<a href="https://hub.docker.com/r/<%= dockerUsername %>/<%= projectName %>" target="_blank">
<img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/<%= dockerUsername %>/<%= projectName %>">
</a>
<% } -%>
<% if (isGithubRepos && isInitSemanticRelease) { -%>
<a href="<%= repositoryUrl %>/actions?query=workflow%3ARelease" target="_blank">
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/<%= authorGithubUsername %>/<%= projectName %>/release.yml?branch=master">
Expand Down

0 comments on commit b90fa8a

Please sign in to comment.