Skip to content

Commit 22cf296

Browse files
committed
✨ Add scaffold command to generate semantic-release settign files.
1 parent e9cfc9b commit 22cf296

File tree

11 files changed

+6935
-40
lines changed

11 files changed

+6935
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
build
1+
build
2+
.playground

.playground/.gitkeep

Whitespace-only changes.

Makefile

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,65 @@
22
V=v3.0.0
33
GITMOJI_VERSION=$(V)
44
F=semver.yml
5-
SEMVER_FILE_PATH=$(F)
5+
SEMVER_FILE=$(F)
6+
O=./
7+
OUT_DIR=$(O)
68

79
BASE_FILE=https://raw.githubusercontent.com/carloscuesta/gitmoji/$(GITMOJI_VERSION)/src/data/gitmojis.json
810

911
# See: https://gist.github.com/rsperl/d2dfe88a520968fbc1f49db0a29345b9
10-
COLOR := $(shell tput -Txterm setaf 5)
12+
# define standard colors
13+
BLACK := $(shell tput -Txterm setaf 0)
14+
RED := $(shell tput -Txterm setaf 1)
15+
GREEN := $(shell tput -Txterm setaf 2)
16+
YELLOW := $(shell tput -Txterm setaf 3)
17+
LIGHTPURPLE := $(shell tput -Txterm setaf 4)
18+
PURPLE := $(shell tput -Txterm setaf 5)
19+
BLUE := $(shell tput -Txterm setaf 6)
20+
WHITE := $(shell tput -Txterm setaf 7)
21+
1122
RESET := $(shell tput -Txterm sgr0)
1223

1324
help:
1425
@echo
15-
@echo "Usage:"
16-
@echo
26+
@echo "$(GREEN)Usage:$(RESET)"
1727
@echo " make COMMAND [Options]"
1828
@echo
19-
@echo "Options:"
29+
@echo "$(GREEN)Commands:$(RESET)"
30+
@echo " gen $(BLUE)Generate gitmojis.json with semver field (alias: g)$(RESET)"
31+
@echo " list $(BLUE)Show generated gitmojis.json (alias: l)$(RESET)"
32+
@echo " scaffold $(BLUE)Generate semantic-release setting files (alias: s)$(RESET)"
2033
@echo
21-
@echo " V=version Specify the base gitmoji version"
22-
@echo " F=filepath Specify semver.yml file path"
34+
@echo "$(GREEN)Options:$(RESET)"
35+
@echo " V=<version> $(BLUE)Specify the base gitmoji version$(RESET)"
36+
@echo " F=<filepath> $(BLUE)Specify semver.yml file path$(RESET)"
37+
@echo " O=<output dir> $(BLUE)Specify semver.yml file path$(RESET)"
2338
@echo
24-
@echo "Commands:"
39+
@echo "$(GREEN)Examples:$(RESET)"
40+
@echo " make gen V=v3.0.0 F=./semver.yml"
41+
@echo " make list"
42+
@echo " make scaffold V=v3.0.0 F=./semver.yml O=[your project directory]"
2543
@echo
26-
@echo " gen Generate gitmojis.json with semver field (alias: g)"
27-
@echo " list Show generated gitmojis.json (alias: l)"
28-
@echo " scaffold Generate semantic-release configs (alias: s)"
29-
30-
# Short commands
31-
l: list
32-
g: gen
33-
s: scaffold
34-
h: help
3544

3645
# Generate gitmojis.json with semver field
3746
gen:
3847
@echo
39-
@echo "$(COLOR)# GEN: 1. Fetch gitmojis.json ($(GITMOJI_VERSION))$(RESET)"
48+
@echo "$(PURPLE)# GEN: 1. Fetch gitmojis.json ($(GITMOJI_VERSION))$(RESET)"
4049
mkdir -p build build/src build/dist
4150
curl -so build/src/gitmojis.json $(BASE_FILE)
4251

4352
@echo
4453
@echo
45-
@echo "$(COLOR)# GEN: 2. Add semver field$(RESET)"
46-
yq '.' $(SEMVER_FILE_PATH) > build/src/semver.json
54+
@echo "$(PURPLE)# GEN: 2. Add semver field$(RESET)"
55+
yq '.' $(SEMVER_FILE) > build/src/semver.json
4756
node gitmoji-semver.js
4857
cat build/dist/tmp.json | jq > build/dist/gitmojis.json
4958
yq -y '.' build/dist/gitmojis.json > build/dist/gitmojis.yml
5059
rm build/dist/tmp.json
5160

5261
@echo
5362
@echo
54-
@echo "$(COLOR)# GEN: 3. Generated!$(RESET)"
63+
@echo "$(PURPLE)# GEN: 3. Generated!$(RESET)"
5564
@echo "Generated gitmojis.json and gitmojis.yml whith semver field"
5665
@echo "See ./build/dist"
5766

@@ -63,7 +72,7 @@ GITMOJI_FILE=build/dist/gitmojis.json
6372

6473
list:
6574
@echo
66-
@echo "$(COLOR)# LIST: show list gitmoji grouped by semver$(RESET)"
75+
@echo "$(PURPLE)# LIST: show list gitmoji grouped by semver$(RESET)"
6776
@echo "\n# Major (Breaking)"
6877
@cat $(GITMOJI_FILE) | jq -c '.gitmojis[] | select(.semver=="major") | $(FORMAT)'
6978
@echo "\n# Minor (Feature)"
@@ -73,11 +82,19 @@ list:
7382
@echo "\n# None"
7483
@cat $(GITMOJI_FILE) | jq -c '.gitmojis[] | select(.semver=="none") | $(FORMAT)'
7584

76-
scaffold:
77-
@echo
78-
@echo "$(COLOR)# SCAFFOLD: Generate semantic-release configs$(RESET)"
79-
# cp templates/commit-template.hbs build/dist/commit-template.hbs
80-
node gen-semantic-release-template.js
81-
ls -l build/dist/
85+
scaffold: gen
8286
@echo
87+
@echo "$(PURPLE)# SCAFFOLD: Generate semantic-release configs$(RESET)"
88+
node gen-template.js
89+
mkdir -p $(OUT_DIR)/.release $(OUT_DIR)/.github $(OUT_DIR)/.github/workflows
90+
cp ./semantic-release-template/* $(OUT_DIR)/.release
91+
mkdir -p $(OUT_DIR)/.github $(OUT_DIR)/.github/workflows
92+
mv $(OUT_DIR)/.release/release.yml $(OUT_DIR)/.github/workflows
93+
cp ./build/dist/release-template.hbs $(OUT_DIR)/.release
94+
cp ./build/src/semver.json $(OUT_DIR)/.release
8395

96+
# Short commands
97+
l: list
98+
g: gen
99+
s: scaffold
100+
h: help

gen-semantic-release-template.js renamed to gen-template.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const fs = require('fs');
22
const gitmojisObj = JSON.parse(fs.readFileSync('./build/dist/gitmojis.json', 'utf8'));
3-
const commits = '{{subject}} - ' +
4-
'[`{{commit.short}}`](https://github.com/{{owner}}/{{repo}}/commit/{{commit.short}}) ' +
5-
'`{{shortDate committerDate}}`'
6-
const header = '# {{releaseTypeEmoji nextRelease.type}}v{{nextRelease.version}} ({{datetime "UTC:yyyy-mm-dd"}}) ' +
7-
'**{{releaseTypeText nextRelease.type}}** ({{nextRelease.type}} version up) - [`v{{lastRelease.version}}`...`v{{nextRelease.version}}`]({{compareUrl}})' +
8-
'## Changes'
3+
4+
const header = `# {{releaseTypeEmoji nextRelease.type}}v{{nextRelease.version}} ({{datetime "UTC:yyyy-mm-dd"}})
5+
6+
**{{releaseTypeText nextRelease.type}}** ({{nextRelease.type}} version up) - [\`v{{lastRelease.version}}\`...\`v{{nextRelease.version}}\`]({{compareUrl}})
7+
8+
## Changes
9+
`
910

1011
function run() {
1112
let res = header + "{{#with commits}}\n"
@@ -26,15 +27,15 @@ function run() {
2627
}
2728
}
2829
res += "{{/with}}"
29-
fs.writeFileSync('./build/dist/semver-template.hbs', res);
30+
fs.writeFileSync('./build/dist/release-template.hbs', res);
3031
}
3132

3233
function buildH3Template(gitmojiObj) {
3334
return `
3435
{{#if ${gitmojiObj.name}}}
3536
### ${gitmojiObj.emoji} ${gitmojiObj.description}
3637
{{#each ${gitmojiObj.name}}}
37-
- ${commits}
38+
- {{> commitTemplate}}
3839
{{/each}}
3940
{{/if}}
4041
`
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// in ".releaserc.js" or "release.config.js"
2+
3+
const fs = require('fs');
4+
const path = require('path')
5+
const {promisify} = require('util')
6+
const dateFormat = require('dateformat')
7+
const readFileAsync = promisify(require('fs').readFile)
8+
9+
const templateDir = "./"
10+
const template = readFileAsync(path.join(templateDir, 'release-template.hbs'))
11+
const commitTemplate = readFileAsync(path.join(templateDir, 'commit-template.hbs'))
12+
const semverObj = JSON.parse(fs.readFileSync('./semver.json', 'utf8'));
13+
14+
const releaseRules = {
15+
major: convert(semverObj.semver.major),
16+
minor: convert(semverObj.semver.minor),
17+
patch: convert(semverObj.semver.patch)
18+
}
19+
20+
function convert(arr){
21+
const res=[]
22+
for (const v of arr) {
23+
res.push(`:${v}:`)
24+
}
25+
return res
26+
}
27+
28+
const releaseNotes = {
29+
template,
30+
partials: {commitTemplate},
31+
helpers: {
32+
datetime: function (format = 'UTC:yyyy-mm-dd') {
33+
return dateFormat(new Date(), format)
34+
},
35+
shortDate: function (date) {
36+
// See: https://www.npmjs.com/package/dateformat/v/3.0.0
37+
return dateFormat(date, 'mmm dd')
38+
},
39+
releaseTypeText: function (type) {
40+
if (type === 'major'){
41+
return "Breaking Release!"
42+
}
43+
if (type === 'minor'){
44+
return "Feature Release!"
45+
}
46+
if (type === 'patch'){
47+
return "Patch Release"
48+
}
49+
},
50+
releaseTypeEmoji: function (type) {
51+
if (type === 'major'){
52+
return ":confetti_ball: "
53+
}
54+
if (type === 'minor'){
55+
return ":star2: "
56+
}
57+
if (type === 'patch'){
58+
return ""
59+
}
60+
},
61+
},
62+
issueResolution: {
63+
template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
64+
baseUrl: 'https://github.com',
65+
source: 'github.com'
66+
}
67+
}
68+
69+
module.exports = {
70+
branches: semverObj.branches,
71+
plugins: [
72+
['semantic-release-gitmoji', {releaseRules, releaseNotes}],
73+
'@semantic-release/github'
74+
]
75+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# .release
2+
3+
Check Next Release
4+
5+
```sh
6+
npm install
7+
npx semantic-release
8+
```
9+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{subject}} - [`{{commit.short}}`](https://github.com/{{owner}}/{{repo}}/commit/{{commit.short}}) `{{shortDate committerDate}}`

0 commit comments

Comments
 (0)