@@ -30,15 +30,15 @@ const assetsDirectory = argument(`assets`, () => `${dirname(manifestPath)}/asset
30
30
/*
31
31
* Helpers.
32
32
*/
33
-
34
- const write = quiet ? ( ( ) => undefined ) : console . log
33
+ const info = quiet ? ( ( ) => undefined ) : console . log
34
+ const error = quiet ? ( ( ) => undefined ) : console . error
35
35
36
36
/*
37
37
* Clean.
38
38
*/
39
39
40
40
const main = ( ) => {
41
- write ( `Reading manifest [${ manifestPath } ].` )
41
+ info ( `Reading manifest [${ manifestPath } ].` )
42
42
43
43
const manifest = JSON . parse ( readFileSync ( manifestPath ) . toString ( ) )
44
44
@@ -47,39 +47,39 @@ const main = () => {
47
47
const isSsr = Array . isArray ( manifest [ manifestKeys [ 0 ] ] )
48
48
49
49
if ( wantsSsr && ! isSsr ) {
50
- write ( 'Did not find an SSR manifest.' )
50
+ error ( 'Did not expected SSR manifest.' )
51
51
52
52
process . exit ( 1 )
53
53
}
54
54
55
55
isSsr
56
- ? write ( `SSR manifest found.` )
57
- : write ( `Non-SSR manifest found.` )
56
+ ? info ( `SSR manifest found.` )
57
+ : info ( `Non-SSR manifest found.` )
58
58
59
59
const manifestAssets = isSsr
60
60
? manifestKeys . flatMap ( key => manifest [ key ] )
61
61
: manifestKeys . map ( key => manifest [ key ] . file )
62
62
63
- write ( `Verify assets in [${ assetsDirectory } ].` )
63
+ info ( `Verify assets in [${ assetsDirectory } ].` )
64
64
65
65
const allAssets = readdirSync ( assetsDirectory , { withFileTypes : true } )
66
66
67
67
const orphanedAssets = allAssets . filter ( file => file . isFile ( ) )
68
68
. filter ( file => manifestAssets . findIndex ( asset => asset . endsWith ( `/${ file . name } ` ) ) === - 1 )
69
69
70
70
if ( orphanedAssets . length === 0 ) {
71
- write ( `No ophaned assets found.` )
71
+ info ( `No ophaned assets found.` )
72
72
} else {
73
73
orphanedAssets . length === 1
74
- ? write ( `[${ orphanedAssets . length } ] orphaned asset found.` )
75
- : write ( `[${ orphanedAssets . length } ] orphaned assets found.` )
74
+ ? info ( `[${ orphanedAssets . length } ] orphaned asset found.` )
75
+ : info ( `[${ orphanedAssets . length } ] orphaned assets found.` )
76
76
77
77
orphanedAssets . forEach ( asset => {
78
78
const path = `${ assetsDirectory } /${ asset . name } `
79
79
80
80
dryRun
81
- ? write ( `Orphaned asset [${ path } ] would be removed.` )
82
- : write ( `Removing orphaned asset [${ path } ].` )
81
+ ? info ( `Orphaned asset [${ path } ] would be removed.` )
82
+ : info ( `Removing orphaned asset [${ path } ].` )
83
83
84
84
if ( ! dryRun ) {
85
85
unlinkSync ( path )
0 commit comments