2020-11-28 15:45:01 +00:00
|
|
|
import path from 'path'
|
|
|
|
import fs from "fs"
|
|
|
|
|
2023-12-26 04:03:37 +00:00
|
|
|
export class Node {
|
|
|
|
|
|
|
|
static isFile = (filename) => {
|
2023-12-24 02:12:31 +00:00
|
|
|
try {
|
|
|
|
return fs.existsSync(filename)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
|
|
|
}
|
2022-04-17 13:04:58 +00:00
|
|
|
|
2023-12-26 04:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static getFullPath = (folderPath) => {
|
2023-12-24 02:12:31 +00:00
|
|
|
return fs.readdirSync(folderPath).map(fn => path.join(folderPath, fn))
|
2023-12-26 04:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static getFiles = (dir) => {
|
2023-12-24 02:12:31 +00:00
|
|
|
var results = [];
|
|
|
|
var list = fs.readdirSync(dir);
|
|
|
|
list.forEach(function(file) {
|
|
|
|
file = dir + '/' + file;
|
|
|
|
var stat = fs.statSync(file);
|
|
|
|
if (stat && stat.isDirectory()) {
|
|
|
|
/* Recurse into a subdirectory */
|
|
|
|
results = results.concat(Node.getFiles(file));
|
|
|
|
} else {
|
|
|
|
/* Is a file */
|
|
|
|
results.push(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return results.filter(f => f.endsWith(".md"))
|
2023-12-26 04:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static readFileSync = (fullPath) => {
|
2023-12-24 02:12:31 +00:00
|
|
|
return fs.readFileSync(fullPath, "utf8")
|
2023-12-26 04:03:37 +00:00
|
|
|
}
|
2020-11-30 11:29:34 +00:00
|
|
|
|
2023-12-26 04:03:37 +00:00
|
|
|
static getMarkdownFolder = () => {
|
2023-12-24 03:33:28 +00:00
|
|
|
const notesDir = path.join(process.cwd(), 'notes')
|
2023-12-26 01:50:08 +00:00
|
|
|
if (!Node.isFile(notesDir)) {
|
|
|
|
console.warn("Notes Directory does not seem to exist: ", notesDir)
|
|
|
|
}
|
2023-12-24 03:33:28 +00:00
|
|
|
return notesDir
|
2023-12-24 02:12:31 +00:00
|
|
|
}
|
|
|
|
}
|