1
- import os from 'os'
2
- import path from 'path'
3
- import fs from 'fs'
1
+ import { homedir , hostname } from 'node:os'
2
+ import { join } from 'node:path'
3
+ import { readdir , stat } from 'node:fs/promises'
4
+ import { start } from 'node:repl'
4
5
5
- const host = os . hostname ( ) . toLowerCase ( )
6
+ const host = hostname ( ) . toLowerCase ( )
6
7
const rxrc = 'node_modules/@rxrc'
7
8
8
- const targetRoot = os . homedir ( )
9
+ const targetRoot = homedir ( )
9
10
10
11
const ioType = 'linux'
11
12
const pkgType = 'pacman'
@@ -194,17 +195,17 @@ const symlinks = async () => [{
194
195
pkgs : [ 'awesome' ]
195
196
} , {
196
197
src : '.config/awesome/themes/powerarrow-dark/wall.png' ,
197
- dst : await randomFile ( 'drive/wallpaper/hosts/mjolnir' ) ,
198
+ dst : await randomFile ( 'drive/wallpaper/hosts/mjolnir' ) ?? '.config/awesome/themes/powerarrow/wall.png' ,
198
199
hosts : [ 'pixelbook' , 'mjolnir' , 'gungnir' ] ,
199
200
pkgs : [ 'awesome' ]
200
201
} , {
201
202
src : '.config/awesome/themes/powerarrow-dark/wall.png' ,
202
- dst : await randomFile ( 'drive/wallpaper/hosts/freyja/vert' ) ,
203
+ dst : await randomFile ( 'drive/wallpaper/hosts/freyja/vert' ) ?? '.config/awesome/themes/powerarrow/wall.png' ,
203
204
hosts : [ 'freyja' ] ,
204
205
pkgs : [ 'awesome' ]
205
206
} , {
206
207
src : '.config/awesome/themes/powerarrow-dark/wall.png-2' ,
207
- dst : await randomFile ( 'drive/wallpaper/hosts/freyja' ) ,
208
+ dst : await randomFile ( 'drive/wallpaper/hosts/freyja' ) ?? '.config/awesome/themes/powerarrow/wall.png' ,
208
209
hosts : [ 'freyja' ] ,
209
210
pkgs : [ 'awesome' ]
210
211
} , {
@@ -231,15 +232,19 @@ export default async () => ({
231
232
} )
232
233
233
234
const randomFile = async dir => {
234
- const rootDir = path . join ( targetRoot , dir )
235
- const files = await fs . promises . readdir ( rootDir )
236
- if ( ! files . length ) throw new Error ( `No files in ${ rootDir } ` )
235
+ const rootDir = join ( targetRoot , dir )
236
+
237
+ const dirStat = await stat ( rootDir )
238
+ if ( ! dirStat . isDirectory ) return null
239
+
240
+ const files = await readdir ( rootDir )
241
+ if ( ! files . length ) return null
237
242
238
243
const checkRandom = async ( ) => {
239
244
const randomIndex = Math . floor ( Math . random ( ) * files . length )
240
245
const file = files [ randomIndex ]
241
- const stats = await fs . promises . stat ( path . join ( rootDir , file ) )
242
- if ( stats . isFile ( ) ) return path . join ( dir , file )
246
+ const stats = await stat ( join ( rootDir , file ) )
247
+ if ( stats . isFile ( ) ) return join ( dir , file )
243
248
files . splice ( randomIndex , 1 )
244
249
return checkRandom ( )
245
250
}
0 commit comments