File tree 3 files changed +56
-1
lines changed
3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ const checkNewFilesAndDependencies = async (pkg, rootDir) => {
93
93
94
94
const messages = [ ] ;
95
95
if ( newFiles . unpublished . length > 0 ) {
96
- messages . push ( `The following new files will not be part of your published package:\n${ util . joinList ( newFiles . unpublished ) } \n\nIf you intended to publish them, add them to the \`files\` field in package.json.` ) ;
96
+ messages . push ( `The following new files will not be part of your published package:\n${ util . groupFilesInFolders ( newFiles . unpublished ) } \n\nIf you intended to publish them, add them to the \`files\` field in package.json.` ) ;
97
97
}
98
98
99
99
if ( newFiles . firstTime . length > 0 ) {
Original file line number Diff line number Diff line change @@ -76,6 +76,28 @@ export const getTagVersionPrefix = pMemoize(async options => {
76
76
77
77
export const joinList = list => chalk . reset ( list . map ( item => `- ${ item } ` ) . join ( '\n' ) ) ;
78
78
79
+ export const groupFilesInFolders = ( files , groupingMinimumDepth = 1 , groupingThresholdCount = 5 ) => {
80
+ const groups = { } ;
81
+ for ( const file of files ) {
82
+ const groupKey = path . join ( ...file . split ( path . sep ) . slice ( 0 , groupingMinimumDepth ) ) ;
83
+ groups [ groupKey ] = [ ...groups [ groupKey ] ?? [ ] , file ] ;
84
+ }
85
+
86
+ const lines = [ ] ;
87
+ for ( const [ folder , filesInFolder ] of Object . entries ( groups ) ) {
88
+ if ( filesInFolder . length > groupingThresholdCount ) {
89
+ lines . push ( `- ${ folder } /* ${ chalk . bold . white ( `(${ filesInFolder . length } files)` ) } ` ) ;
90
+ continue ;
91
+ }
92
+
93
+ for ( const file of filesInFolder ) {
94
+ lines . push ( `- ${ file } ` ) ;
95
+ }
96
+ }
97
+
98
+ return chalk . reset ( lines . join ( '\n' ) ) ;
99
+ } ;
100
+
79
101
export const getNewFiles = async rootDir => {
80
102
const listNewFiles = await git . newFilesSinceLastRelease ( rootDir ) ;
81
103
const listPkgFiles = await npm . getFilesToBePacked ( rootDir ) ;
Original file line number Diff line number Diff line change
1
+ import test from 'ava' ;
2
+ import stripAnsi from 'strip-ansi' ;
3
+ import { groupFilesInFolders } from '../../source/util.js' ;
4
+
5
+ const testJoinList = test . macro ( ( t , { list, expected} ) => {
6
+ const output = groupFilesInFolders ( list ) ;
7
+ t . is ( stripAnsi ( output ) , expected ) ;
8
+ } ) ;
9
+
10
+ test ( 'one item' , testJoinList , {
11
+ list : [
12
+ 'scripts/a.sh' ,
13
+ ] ,
14
+ expected : '- scripts/a.sh' ,
15
+ } ) ;
16
+
17
+ test ( 'mix of collapsed and expanded folders' , testJoinList , {
18
+ list : [
19
+ 'scripts/a.sh' ,
20
+ 'scripts/b.sh' ,
21
+ 'scripts/c.sh' ,
22
+ 'test/_utils-1.js' ,
23
+ 'test/_utils-2.js' ,
24
+ 'test/_utils-3.js' ,
25
+ 'test/_utils-4.js' ,
26
+ 'test/_utils-5.js' ,
27
+ 'test/_utils-6.js' ,
28
+ ] ,
29
+ expected : `- scripts/a.sh
30
+ - scripts/b.sh
31
+ - scripts/c.sh
32
+ - test/* (6 files)` ,
33
+ } ) ;
You can’t perform that action at this time.
0 commit comments