forked from david-loe/pauschbetrag-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
34 lines (33 loc) · 1014 Bytes
/
Copy pathutil.ts
File metadata and controls
34 lines (33 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from 'node:fs/promises'
export async function writeToDisk(
filePath: string,
data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView>
) {
// create folders
var root = ''
var folderPath = filePath
if (folderPath[0] === '/') {
root = '/'
folderPath = folderPath.slice(1)
}
const folders = folderPath.split('/').slice(0, -1) // remove last item (file)
var cfolderPath = root
for (const folder of folders) {
cfolderPath = cfolderPath + folder + '/'
try {
await fs.access(cfolderPath)
} catch {
await fs.mkdir(cfolderPath)
}
}
try {
await fs.writeFile(filePath, data)
} catch (error) {
console.error(error)
}
}
export function buildVersion(semver: string, date: string) {
const compactDate = date.replace(/-/g, '');
const [major, minor] = semver.split('.');
return `${major}.${minor}.${compactDate}`;
}