convert node to static class
This commit is contained in:
parent
84c657cffa
commit
fd45def1bf
26
lib/node.js
26
lib/node.js
@ -1,8 +1,9 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
|
|
||||||
export const Node = {
|
export class Node {
|
||||||
isFile: function(filename) {
|
|
||||||
|
static isFile = (filename) => {
|
||||||
try {
|
try {
|
||||||
return fs.existsSync(filename)
|
return fs.existsSync(filename)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -10,11 +11,13 @@ export const Node = {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
}
|
||||||
getFullPath: function(folderPath) {
|
|
||||||
|
static getFullPath = (folderPath) => {
|
||||||
return fs.readdirSync(folderPath).map(fn => path.join(folderPath, fn))
|
return fs.readdirSync(folderPath).map(fn => path.join(folderPath, fn))
|
||||||
},
|
}
|
||||||
getFiles: function(dir) {
|
|
||||||
|
static getFiles = (dir) => {
|
||||||
var results = [];
|
var results = [];
|
||||||
var list = fs.readdirSync(dir);
|
var list = fs.readdirSync(dir);
|
||||||
list.forEach(function(file) {
|
list.forEach(function(file) {
|
||||||
@ -29,12 +32,13 @@ export const Node = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return results.filter(f => f.endsWith(".md"))
|
return results.filter(f => f.endsWith(".md"))
|
||||||
},
|
}
|
||||||
readFileSync: function(fullPath) {
|
|
||||||
return fs.readFileSync(fullPath, "utf8")
|
|
||||||
},
|
|
||||||
|
|
||||||
getMarkdownFolder: function() {
|
static readFileSync = (fullPath) => {
|
||||||
|
return fs.readFileSync(fullPath, "utf8")
|
||||||
|
}
|
||||||
|
|
||||||
|
static getMarkdownFolder = () => {
|
||||||
const notesDir = path.join(process.cwd(), 'notes')
|
const notesDir = path.join(process.cwd(), 'notes')
|
||||||
if (!Node.isFile(notesDir)) {
|
if (!Node.isFile(notesDir)) {
|
||||||
console.warn("Notes Directory does not seem to exist: ", notesDir)
|
console.warn("Notes Directory does not seem to exist: ", notesDir)
|
||||||
|
Loading…
Reference in New Issue
Block a user