mirror of
https://github.com/vacp2p/rfc.vac.dev.git
synced 2025-02-22 20:38:25 +00:00
chore: Fresh scraping on each sync (#4)
This commit is contained in:
parent
c51271253a
commit
6a9b7654cc
@ -36,7 +36,7 @@ export async function writeLargeFile(path, data) {
|
|||||||
|
|
||||||
export function removeDirectory(path) {
|
export function removeDirectory(path) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.rmdir(path, {recursive: true}, err => {
|
fs.rm(path, {recursive: true}, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err)
|
reject(err)
|
||||||
}
|
}
|
||||||
@ -46,6 +46,20 @@ export function removeDirectory(path) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function directoryExists(path) {
|
||||||
|
return new Promise((resolve, _) => {
|
||||||
|
const accessBitwiseOperator = fs.constants.F_OK | fs.constants.R_OK;
|
||||||
|
|
||||||
|
fs.access(path, accessBitwiseOperator, err => {
|
||||||
|
if (err) {
|
||||||
|
resolve(false)
|
||||||
|
} else {
|
||||||
|
resolve(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function createDirectory(path) {
|
export async function createDirectory(path) {
|
||||||
try {
|
try {
|
||||||
/*
|
/*
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { fetchDirectoryContents } from './fetch-content.mjs'
|
import { fetchDirectoryContents } from './fetch-content.mjs'
|
||||||
|
import path from 'path'
|
||||||
|
import { directoryExists, removeDirectory } from './file.mjs'
|
||||||
|
|
||||||
const directoriesToSync = ['codex', 'nomos', 'status', 'vac', 'waku']
|
const directoriesToSync = ['codex', 'nomos', 'status', 'vac', 'waku']
|
||||||
|
|
||||||
@ -10,6 +12,13 @@ async function main() {
|
|||||||
|
|
||||||
const baseSavePath = `./${dirName}/`
|
const baseSavePath = `./${dirName}/`
|
||||||
const prefixToRemove = dirName + '/'
|
const prefixToRemove = dirName + '/'
|
||||||
|
const directoryPath = path.join(process.cwd(), dirName);
|
||||||
|
|
||||||
|
const shouldRemoveOldContent = await directoryExists(directoryPath);
|
||||||
|
if (shouldRemoveOldContent) {
|
||||||
|
await removeDirectory(directoryPath)
|
||||||
|
console.log(`Removed old ${dirName}`)
|
||||||
|
}
|
||||||
|
|
||||||
await fetchDirectoryContents(baseUrl, baseSavePath, prefixToRemove)
|
await fetchDirectoryContents(baseUrl, baseSavePath, prefixToRemove)
|
||||||
console.log(`Synced ${dirName}`)
|
console.log(`Synced ${dirName}`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user