@fullstackunicorn/filesystem 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/fsa.js +38 -1
- package/modules/fss.js +37 -0
- package/package.json +1 -1
package/modules/fsa.js
CHANGED
|
@@ -42,5 +42,42 @@ export const fsa = {
|
|
|
42
42
|
else if (file?.buffer instanceof ArrayBuffer) buffer = Buffer.from(file.buffer)
|
|
43
43
|
else throw new Error('buffer-error')
|
|
44
44
|
await fsAsync.writeFile(filePath, buffer)
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
isJunk: name => {
|
|
47
|
+
if (!name) return true
|
|
48
|
+
const lower = name.toLowerCase()
|
|
49
|
+
if (lower.endsWith('~') || lower.endsWith('.tmp') || lower.endsWith('.temp')) return true
|
|
50
|
+
return [
|
|
51
|
+
'.ds_store', '._', '.spotlight-v100', '.trashes', '.fseventsd', '.temporaryitems', '.apdisk', '.volumeicon.icns',
|
|
52
|
+
'thumbs.db', 'ehthumbs.db', 'desktop.ini', '$recycle.bin', 'system volume information',
|
|
53
|
+
'lost+found', '__macosx', '.swp', '.swo', '.#', '.cache'
|
|
54
|
+
].some(bad => lower === bad || lower.startsWith(bad))
|
|
55
|
+
},
|
|
56
|
+
copyFile: fsAsync.copyFile,
|
|
57
|
+
copyDir: async (src, dest) => {
|
|
58
|
+
await fsa.ensureDir(dest)
|
|
59
|
+
const entries = await fsa.readDir(src)
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
const srcPath = `${src}/${entry}`
|
|
62
|
+
const destPath = `${dest}/${entry}`
|
|
63
|
+
const stat = await fsa.stat(srcPath)
|
|
64
|
+
if (stat.isDirectory()) await fsa.copyDir(srcPath, destPath)
|
|
65
|
+
else await fsAsync.copyFile(srcPath, destPath)
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
getDirPaths: async (basePath) => {
|
|
69
|
+
const files = []
|
|
70
|
+
const scan = async dir => {
|
|
71
|
+
const entries = await fsa.readDir(dir)
|
|
72
|
+
for (const entry of entries) {
|
|
73
|
+
if (fsa.isJunk(entry)) continue
|
|
74
|
+
const fullPath = path.join(dir, entry)
|
|
75
|
+
const stat = await fsa.stat(fullPath)
|
|
76
|
+
if (stat.isDirectory()) await scan(fullPath)
|
|
77
|
+
else files.push(path.relative(basePath, fullPath))
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
await scan(basePath)
|
|
81
|
+
return files
|
|
82
|
+
},
|
|
46
83
|
}
|
package/modules/fss.js
CHANGED
|
@@ -39,5 +39,42 @@ export const fss = {
|
|
|
39
39
|
else if (file?.buffer instanceof ArrayBuffer) buffer = Buffer.from(file.buffer)
|
|
40
40
|
else throw new Error('buffer-error')
|
|
41
41
|
fsSync.writeFileSync(filePath, buffer)
|
|
42
|
+
},
|
|
43
|
+
isJunk: name => {
|
|
44
|
+
if (!name) return true
|
|
45
|
+
const lower = name.toLowerCase()
|
|
46
|
+
if (lower.endsWith('~') || lower.endsWith('.tmp') || lower.endsWith('.temp')) return true
|
|
47
|
+
return [
|
|
48
|
+
'.ds_store', '._', '.spotlight-v100', '.trashes', '.fseventsd', '.temporaryitems', '.apdisk', '.volumeicon.icns',
|
|
49
|
+
'thumbs.db', 'ehthumbs.db', 'desktop.ini', '$recycle.bin', 'system volume information',
|
|
50
|
+
'lost+found', '__macosx', '.swp', '.swo', '.#', '.cache'
|
|
51
|
+
].some(bad => lower === bad || lower.startsWith(bad))
|
|
52
|
+
},
|
|
53
|
+
copyFile: fsSync.copyFileSync,
|
|
54
|
+
copyDir: (src, dest) => {
|
|
55
|
+
fss.ensureDir(dest)
|
|
56
|
+
const entries = fss.readDir(src)
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
const srcPath = `${src}/${entry}`
|
|
59
|
+
const destPath = `${dest}/${entry}`
|
|
60
|
+
const stat = fss.stat(srcPath)
|
|
61
|
+
if (stat.isDirectory()) fss.copyDir(srcPath, destPath)
|
|
62
|
+
else fsSync.copyFileSync(srcPath, destPath)
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
getDirPaths: (basePath) => {
|
|
66
|
+
const files = []
|
|
67
|
+
const scan = dir => {
|
|
68
|
+
const entries = fss.readDir(dir)
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
if (fss.isJunk(entry)) continue
|
|
71
|
+
const fullPath = path.join(dir, entry)
|
|
72
|
+
const stat = fss.stat(fullPath)
|
|
73
|
+
if (stat.isDirectory()) scan(fullPath)
|
|
74
|
+
else files.push(path.relative(basePath, fullPath))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
scan(basePath)
|
|
78
|
+
return files
|
|
42
79
|
}
|
|
43
80
|
}
|
package/package.json
CHANGED