Skip to content

Commit c6bfd02

Browse files
committed
Write to stderr
1 parent 2a012a7 commit c6bfd02

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

bin/purge-orphaned-assets.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const assetsDirectory = argument(`assets`, () => `${dirname(manifestPath)}/asset
3030
/*
3131
* Helpers.
3232
*/
33-
34-
const write = quiet ? (() => undefined) : console.log
33+
const info = quiet ? (() => undefined) : console.log
34+
const error = quiet ? (() => undefined) : console.error
3535

3636
/*
3737
* Clean.
3838
*/
3939

4040
const main = () => {
41-
write(`Reading manifest [${manifestPath}].`)
41+
info(`Reading manifest [${manifestPath}].`)
4242

4343
const manifest = JSON.parse(readFileSync(manifestPath).toString())
4444

@@ -47,39 +47,39 @@ const main = () => {
4747
const isSsr = Array.isArray(manifest[manifestKeys[0]])
4848

4949
if (wantsSsr && ! isSsr) {
50-
write('Did not find an SSR manifest.')
50+
error('Did not expected SSR manifest.')
5151

5252
process.exit(1)
5353
}
5454

5555
isSsr
56-
? write(`SSR manifest found.`)
57-
: write(`Non-SSR manifest found.`)
56+
? info(`SSR manifest found.`)
57+
: info(`Non-SSR manifest found.`)
5858

5959
const manifestAssets = isSsr
6060
? manifestKeys.flatMap(key => manifest[key])
6161
: manifestKeys.map(key => manifest[key].file)
6262

63-
write(`Verify assets in [${assetsDirectory}].`)
63+
info(`Verify assets in [${assetsDirectory}].`)
6464

6565
const allAssets = readdirSync(assetsDirectory, { withFileTypes: true })
6666

6767
const orphanedAssets = allAssets.filter(file => file.isFile())
6868
.filter(file => manifestAssets.findIndex(asset => asset.endsWith(`/${file.name}`)) === -1)
6969

7070
if (orphanedAssets.length === 0) {
71-
write(`No ophaned assets found.`)
71+
info(`No ophaned assets found.`)
7272
} else {
7373
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.`)
7676

7777
orphanedAssets.forEach(asset => {
7878
const path = `${assetsDirectory}/${asset.name}`
7979

8080
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}].`)
8383

8484
if (! dryRun) {
8585
unlinkSync(path)

0 commit comments

Comments
 (0)