1
1
const fs = require ( 'fs' ) ;
2
- const gitmojisObj = JSON . parse ( fs . readFileSync ( './build/src/gitmojis.json' , 'utf8' ) ) ;
3
- const semverObj = JSON . parse ( fs . readFileSync ( './build/src/semver.json' , 'utf8' ) ) ;
4
2
5
- function run ( ) {
3
+ const srcGitmojisObj = JSON . parse ( fs . readFileSync ( './build/src/gitmojis.json' , 'utf8' ) ) ;
4
+ const srcSemverObj = JSON . parse ( fs . readFileSync ( './build/src/semver.json' , 'utf8' ) ) ;
5
+
6
+ function genGitmojisJson ( ) {
6
7
const res = { gitmojis : [ ] } ;
7
- for ( const v of gitmojisObj . gitmojis ) {
8
- if ( v . semver === null ) {
8
+ for ( const v of srcGitmojisObj . gitmojis ) {
9
+ if ( v . semver === null ) {
9
10
v . semver = "none"
10
11
}
11
- let s = semver ( v . name . replace ( / - / g, '_' ) )
12
- if ( s !== null ) {
12
+ let s = getSemverByName ( v . name . replace ( / - / g, '_' ) )
13
+ if ( s !== null ) {
13
14
v . semver = s
14
15
}
15
16
res . gitmojis . push ( v )
16
17
}
17
18
18
- fs . writeFileSync ( './build/dist/tmp .json' , JSON . stringify ( res ) ) ;
19
+ fs . writeFileSync ( './build/dist/gitmojis .json' , JSON . stringify ( res , null , 2 ) ) ;
19
20
}
20
21
21
- function semver ( name ) {
22
- for ( const v of Object . keys ( semverObj . semver ) ) {
23
- if ( semverObj . semver [ v ] . includes ( name ) ) {
22
+ function getSemverByName ( name ) {
23
+ for ( const v of Object . keys ( srcSemverObj . semver ) ) {
24
+ if ( srcSemverObj . semver [ v ] . includes ( name ) ) {
24
25
return v
25
26
}
26
27
}
27
28
return null
28
29
}
29
30
30
- // TODO: semver.jsonにフィールドを追加する
31
+ function genSemverJson ( ) {
32
+ const distGitmojisObj = JSON . parse ( fs . readFileSync ( './build/dist/gitmojis.json' , 'utf8' ) ) ;
33
+ const res = {
34
+ branch : srcSemverObj . branch ,
35
+ semver : {
36
+ major : [ ] ,
37
+ minor : [ ] ,
38
+ patch : [ ] ,
39
+ none : [ ] ,
40
+ ignore : [ ] ,
41
+ }
42
+ } ;
43
+
44
+ for ( const v of distGitmojisObj . gitmojis ) {
45
+ if ( v . semver === 'major' ) {
46
+ res . semver . major . push ( v . name . replace ( / - / g, '_' ) )
47
+ }
48
+ if ( v . semver === 'minor' ) {
49
+ res . semver . minor . push ( v . name . replace ( / - / g, '_' ) )
50
+ }
51
+ if ( v . semver === 'patch' ) {
52
+ res . semver . patch . push ( v . name . replace ( / - / g, '_' ) )
53
+ }
54
+ if ( v . semver === 'none' ) {
55
+ res . semver . none . push ( v . name . replace ( / - / g, '_' ) )
56
+ }
57
+ if ( v . semver === 'ignore' ) {
58
+ res . semver . ignore . push ( v . name . replace ( / - / g, '_' ) )
59
+ }
60
+ }
61
+
62
+ fs . writeFileSync ( './build/dist/semver.json' , JSON . stringify ( res , null , 2 ) ) ;
63
+ }
64
+
65
+ function run ( ) {
66
+ genGitmojisJson ( )
67
+ genSemverJson ( )
68
+ }
69
+
31
70
32
71
run ( )
0 commit comments