@@ -95,6 +95,10 @@ function addPreamble(fileStr, fileExt) {
95
95
96
96
const addFns = {
97
97
98
+ ts : function ( headStr , fileStr ) {
99
+ return headStr + fileStr ;
100
+ } ,
101
+
98
102
js : function ( headStr , fileStr ) {
99
103
return headStr + fileStr ;
100
104
} ,
@@ -107,17 +111,11 @@ const addFns = {
107
111
return headStr + fileStr ;
108
112
} ,
109
113
110
- sh : function ( headStr , fileStr ) {
111
- // Git diff enables manual check.
112
- if ( / ^ # \! / . test ( fileStr ) ) {
113
- const lines = fileStr . split ( '\n' ) ;
114
- lines . splice ( 1 , 0 , headStr ) ;
115
- return lines . join ( '\n' ) ;
116
- }
117
- else {
118
- return headStr + fileStr ;
119
- }
120
- } ,
114
+ yml : addShellLikeHeader ,
115
+
116
+ yaml : addShellLikeHeader ,
117
+
118
+ sh : addShellLikeHeader ,
121
119
122
120
html : function ( headStr , fileStr ) {
123
121
// Git diff enables manual check.
@@ -134,6 +132,18 @@ const addFns = {
134
132
xsl : xmlAddFn
135
133
} ;
136
134
135
+ function addShellLikeHeader ( headStr , fileStr ) {
136
+ // Git diff enables manual check.
137
+ if ( / ^ # \! / . test ( fileStr ) ) {
138
+ const lines = fileStr . split ( '\n' ) ;
139
+ lines . splice ( 1 , 0 , headStr ) ;
140
+ return lines . join ( '\n' ) ;
141
+ }
142
+ else {
143
+ return headStr + fileStr ;
144
+ }
145
+ }
146
+
137
147
function xmlAddFn ( headStr , fileStr ) {
138
148
// Git diff enables manual check.
139
149
let resultStr = fileStr . replace ( / ^ \s * < \? x m l \s [ ^ < > ] + \? > / i, '$&' + headStr ) ;
@@ -145,9 +155,12 @@ function xmlAddFn(headStr, fileStr) {
145
155
}
146
156
147
157
const preambleMap = {
158
+ ts : cStyleComment ,
148
159
js : cStyleComment ,
149
160
css : cStyleComment ,
150
161
java : cStyleComment ,
162
+ yml : hashComment ,
163
+ yaml : hashComment ,
151
164
sh : hashComment ,
152
165
html : mlComment ,
153
166
xml : mlComment ,
@@ -180,9 +193,12 @@ const cStyleCommentReg = /\/\*[\S\s]*?\*\//;
180
193
const hashCommentReg = / ^ \s * # .* $ / gm;
181
194
const mlCommentReg = / < \! \- \- [ \S \s ] * ?\- \- > / ;
182
195
const commentReg = {
196
+ ts : cStyleCommentReg ,
183
197
js : cStyleCommentReg ,
184
198
css : cStyleCommentReg ,
185
199
java : cStyleCommentReg ,
200
+ yml : hashCommentReg ,
201
+ yaml : hashCommentReg ,
186
202
sh : hashCommentReg ,
187
203
html : mlCommentReg ,
188
204
xml : mlCommentReg ,
@@ -198,7 +214,7 @@ function extractComment(str, fileExt) {
198
214
199
215
reg . lastIndex = 0 ;
200
216
201
- if ( fileExt === 'sh' ) {
217
+ if ( fileExt === 'sh' || fileExt === 'yml' || fileExt === 'yaml' ) {
202
218
let result = str . match ( reg ) ;
203
219
return result && result . join ( '\n' ) ;
204
220
}
0 commit comments