@@ -33,73 +33,6 @@ function isUnpackedDir(dirPath: string, pattern: string, unpackDirs: string[]) {
3333 }
3434}
3535
36- export type FileProperties = {
37- filepath : string ;
38- properties : {
39- unpack ?: boolean ;
40- } ;
41- } ;
42-
43- async function getFileOrdering (
44- options : CreateOptions ,
45- src : string ,
46- filenames : string [ ] ,
47- ) : Promise < FileProperties [ ] > {
48- if ( ! options . ordering ) {
49- return filenames . map < FileProperties > ( ( filepath ) => ( { filepath, properties : { } } ) ) ;
50- }
51- const orderingMap : FileProperties [ ] = ( await fs . readFile ( options . ordering ) )
52- . toString ( )
53- . split ( '\n' )
54- . map < FileProperties > ( ( line ) => {
55- line = line . trim ( ) ;
56- const config : FileProperties = { filepath : line , properties : { } } ;
57- const colonIndex = line . indexOf ( ':' ) ;
58- if ( colonIndex > - 1 ) {
59- config . filepath = line . substring ( 0 , colonIndex ) ; // file path
60- const props = line . substring ( colonIndex + 1 ) ; // props on other side of the `:`
61- config . properties = props . length > 2 ? JSON . parse ( props ) : { } ; // file properties
62- }
63- if ( config . filepath . startsWith ( '/' ) ) {
64- config . filepath = config . filepath . slice ( 1 ) ;
65- }
66- return config ;
67- } ) ;
68-
69- const ordering : FileProperties [ ] = [ ] ;
70- for ( const config of orderingMap ) {
71- const pathComponents = config . filepath . split ( path . sep ) ;
72- let str = src ;
73- for ( const pathComponent of pathComponents ) {
74- str = path . join ( str , pathComponent ) ;
75- ordering . push ( { filepath : str , properties : config . properties } ) ;
76- }
77- }
78-
79- let missing = 0 ;
80- const total = filenames . length ;
81-
82- const fileOrderingSorted : FileProperties [ ] = [ ] ;
83- const isAlreadySorted = ( file : string ) =>
84- fileOrderingSorted . findIndex ( ( config ) => file === config . filepath ) > - 1 ;
85-
86- for ( const config of ordering ) {
87- if ( ! isAlreadySorted ( config . filepath ) && filenames . includes ( config . filepath ) ) {
88- fileOrderingSorted . push ( config ) ;
89- }
90- }
91-
92- for ( const file of filenames ) {
93- if ( ! isAlreadySorted ( file ) ) {
94- fileOrderingSorted . push ( { filepath : file , properties : { } } ) ;
95- missing += 1 ;
96- }
97- }
98-
99- console . log ( `Ordering file has ${ ( ( total - missing ) / total ) * 100 } % coverage.` ) ;
100- return fileOrderingSorted ;
101- }
102-
10336export async function createPackage ( src : string , dest : string ) {
10437 return createPackageWithOptions ( src , dest , { } ) ;
10538}
@@ -151,10 +84,54 @@ export async function createPackageFromFiles(
15184 const links : disk . BasicFilesArray = [ ] ;
15285 const unpackDirs : string [ ] = [ ] ;
15386
154- const filenamesSorted : FileProperties [ ] = await getFileOrdering ( options , src , filenames ) ;
87+ let filenamesSorted : string [ ] = [ ] ;
88+ if ( options . ordering ) {
89+ const orderingFiles = ( await fs . readFile ( options . ordering ) )
90+ . toString ( )
91+ . split ( '\n' )
92+ . map ( ( line ) => {
93+ if ( line . includes ( ':' ) ) {
94+ line = line . split ( ':' ) . pop ( ) ! ;
95+ }
96+ line = line . trim ( ) ;
97+ if ( line . startsWith ( '/' ) ) {
98+ line = line . slice ( 1 ) ;
99+ }
100+ return line ;
101+ } ) ;
102+
103+ const ordering : string [ ] = [ ] ;
104+ for ( const file of orderingFiles ) {
105+ const pathComponents = file . split ( path . sep ) ;
106+ let str = src ;
107+ for ( const pathComponent of pathComponents ) {
108+ str = path . join ( str , pathComponent ) ;
109+ ordering . push ( str ) ;
110+ }
111+ }
112+
113+ let missing = 0 ;
114+ const total = filenames . length ;
115+
116+ for ( const file of ordering ) {
117+ if ( ! filenamesSorted . includes ( file ) && filenames . includes ( file ) ) {
118+ filenamesSorted . push ( file ) ;
119+ }
120+ }
121+
122+ for ( const file of filenames ) {
123+ if ( ! filenamesSorted . includes ( file ) ) {
124+ filenamesSorted . push ( file ) ;
125+ missing += 1 ;
126+ }
127+ }
155128
156- const handleFile = async function ( config : FileProperties ) {
157- const filename = config . filepath ;
129+ console . log ( `Ordering file has ${ ( ( total - missing ) / total ) * 100 } % coverage.` ) ;
130+ } else {
131+ filenamesSorted = filenames ;
132+ }
133+
134+ const handleFile = async function ( filename : string ) {
158135 if ( ! metadata [ filename ] ) {
159136 const fileType = await determineFileType ( filename ) ;
160137 if ( ! fileType ) {
@@ -169,9 +146,6 @@ export async function createPackageFromFiles(
169146 unpack : string | undefined ,
170147 unpackDir : string | undefined ,
171148 ) {
172- if ( config . properties . unpack != null ) {
173- return config . properties . unpack ;
174- }
175149 let shouldUnpack = false ;
176150 if ( unpack ) {
177151 shouldUnpack = minimatch ( filename , unpack , { matchBase : true } ) ;
@@ -216,12 +190,12 @@ export async function createPackageFromFiles(
216190
217191 const names = filenamesSorted . slice ( ) ;
218192
219- const next = async function ( config ?: FileProperties ) {
220- if ( ! config ) {
193+ const next = async function ( name ?: string ) {
194+ if ( ! name ) {
221195 return insertsDone ( ) ;
222196 }
223197
224- await handleFile ( config ) ;
198+ await handleFile ( name ) ;
225199 return next ( names . shift ( ) ) ;
226200 } ;
227201
0 commit comments