File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 6262 "merge-deep" : " ^3.0.2" ,
6363 "micromatch" : " ^4.0.2" ,
6464 "mustache" : " ^3.0.1" ,
65+ "node-yaml" : " ^3.2.0" ,
6566 "sanitization" : " ^0.3.0" ,
6667 "semver" : " ^6.0.0" ,
6768 "sha1" : " ^1.1.1" ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const createHandler = require('../create-handler')
44const readTargetFile = require ( '../read-target-file' )
55const mergeJson = require ( './merge-json' )
66const mergeIgnore = require ( './merge-ignore' )
7+ const mergeYaml = require ( './merge-yaml' )
78
89
910module . exports = createHandler ( file => {
@@ -12,6 +13,8 @@ module.exports = createHandler(file => {
1213 if ( file . targetFile . exist ) {
1314 if ( extname ( file . targetPath ) === '.json' ) {
1415 return mergeJson ( file )
16+ } else if ( [ '.yaml' , '.yml' ] . includes ( extname ( file . targetPath ) ) ) {
17+ return mergeYaml ( file )
1518 } else if ( [ '.gitignore' , '.npmignore' ] . includes ( basename ( file . targetPath ) ) ) {
1619 return mergeIgnore ( file )
1720 } else {
Original file line number Diff line number Diff line change 1+ const yaml = require ( 'node-yaml' )
2+ const merge = require ( 'merge-deep' )
3+ const log = require ( '../../utils/log' )
4+
5+
6+ module . exports = file => {
7+ let content = ''
8+ let targetFileContent = ''
9+
10+ try {
11+ content = yaml . parse ( file . content )
12+ } catch ( e ) {
13+ log . error ( 'merge' , [
14+ 'The template file and the project file failed to merge due to a json syntax error in the template file.' ,
15+ 'The project file will be overwritten directly by the template file.' ,
16+ `path: ${ file . targetPath } ` ,
17+ ] . join ( '\n' ) )
18+ return file
19+ }
20+
21+ try {
22+ targetFileContent = yaml . parse ( file . targetFile . content )
23+ } catch ( e ) {
24+ log . error ( 'merge' , [
25+ 'The template file and the project file failed to merge due to a yaml syntax error in the project file.' ,
26+ 'The project file will be overwritten directly by the template file.' ,
27+ `path: ${ file . targetPath } ` ,
28+ ] . join ( '\n' ) )
29+ return file
30+ }
31+
32+ return {
33+ ...file ,
34+ content : yaml . dump ( merge ( targetFileContent , content ) ) ,
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments