@@ -7,6 +7,7 @@ const decodeIgnoreSyncFile = require('./decodeIgnoreSyncFile')
7
7
const formatRelativeIgnoreFile = require ( './utils/formatRelativeIgnoreFile' )
8
8
const github = require ( './utils/github' )
9
9
const highlightComments = require ( './utils/highlightComments' )
10
+ const isIgnoreSyncFile = require ( './isIgnoreSyncFile' )
10
11
const joinLinesWithEOF = require ( './utils/joinLinesWithEOF' )
11
12
const { COMMENT_HEADER_ALERT } = require ( './constants' )
12
13
const { dynamicComposeP, promiseMap } = require ( './utils/ramdaHelper' )
@@ -19,29 +20,60 @@ const sourceIs = (...args) => R.compose(...args, R.prop('source'))
19
20
const inlineSourceFetcher = R . compose ( joinLinesWithEOF , R . prop ( 'data' ) )
20
21
const githubSourceFetcher = async ( block ) => {
21
22
const [ owner , repo ] = block . source . split ( '/' )
22
- const files = await promiseMap (
23
- ( relativePath ) =>
24
- github . getContentFile ( { owner, repo, path : relativePath } ) ,
25
- block . data ,
23
+ const files = await Promise . all (
24
+ block . data . map ( ( relativeFilePath ) => {
25
+ return github . getContentFile ( { owner, repo, path : relativeFilePath } )
26
+ } ) ,
26
27
)
27
28
return joinLinesWithEOF ( files )
28
29
}
29
30
const localSourceFetcher = async ( block , directory ) => {
30
- const files = await promiseMap (
31
- ( relativeFilePath ) => readFile ( path . join ( directory , relativeFilePath ) ) ,
32
- block . data ,
31
+ const files = await Promise . all (
32
+ block . data . map ( async ( relativeFilePath ) => {
33
+ const fileContent = await readFile ( path . join ( directory , relativeFilePath ) )
34
+ if ( isIgnoreSyncFile ( relativeFilePath ) ) {
35
+ return generateIgnoreFile ( fileContent , directory , {
36
+ isRootIgnoreSyncFile : false ,
37
+ } )
38
+ } else {
39
+ return fileContent
40
+ }
41
+ } ) ,
33
42
)
34
43
return joinLinesWithEOF ( files )
35
44
}
36
45
const relativeSourceFetcher = async ( block , directory ) => {
37
- const files = await promiseMap ( async ( relativeFilePath ) => {
38
- const fileContent = await readFile ( path . join ( directory , relativeFilePath ) )
39
- return formatRelativeIgnoreFile ( fileContent , path . dirname ( relativeFilePath ) )
40
- } , block . data )
46
+ const files = await Promise . all (
47
+ block . data . map ( async ( relativeFilePath ) => {
48
+ const fileContent = await readFile ( path . join ( directory , relativeFilePath ) )
49
+ if ( isIgnoreSyncFile ( relativeFilePath ) ) {
50
+ const ignoreFileContent = await generateIgnoreFile (
51
+ fileContent ,
52
+ directory ,
53
+ {
54
+ isRootIgnoreSyncFile : false ,
55
+ } ,
56
+ )
57
+ return formatRelativeIgnoreFile (
58
+ ignoreFileContent ,
59
+ path . dirname ( relativeFilePath ) ,
60
+ )
61
+ } else {
62
+ return formatRelativeIgnoreFile (
63
+ fileContent ,
64
+ path . dirname ( relativeFilePath ) ,
65
+ )
66
+ }
67
+ } ) ,
68
+ )
41
69
return joinLinesWithEOF ( files )
42
70
}
43
71
44
- const generateIgnoreFile = ( ignoreSyncFile , directory ) => {
72
+ const generateIgnoreFile = (
73
+ ignoreSyncFile ,
74
+ directory ,
75
+ { isRootIgnoreSyncFile = true } = { } ,
76
+ ) => {
45
77
const fetchIgnorePatternsBySource = promiseMap (
46
78
R . cond ( [
47
79
[ sourceIs ( R . equals ( 'inline' ) ) , inlineSourceFetcher ] ,
@@ -65,7 +97,7 @@ const generateIgnoreFile = (ignoreSyncFile, directory) => {
65
97
66
98
return dynamicComposeP (
67
99
joinLinesWithEOF ,
68
- prependAlert ,
100
+ isRootIgnoreSyncFile ? prependAlert : R . identity ,
69
101
fetchIgnorePatternsBySource ,
70
102
decodeIgnoreSyncFile ,
71
103
) ( ignoreSyncFile )
0 commit comments