|
|
|
@ -1,5 +1,12 @@
|
|
|
|
|
class Model {
|
|
|
|
|
constructor() {}
|
|
|
|
|
constructor() {
|
|
|
|
|
// Initialize isomorphic-git with a file system
|
|
|
|
|
window.fs = new LightningFS("fs");
|
|
|
|
|
// I prefer using the Promisified version honestly
|
|
|
|
|
window.pfs = window.fs.promises;
|
|
|
|
|
|
|
|
|
|
window.dir = "/test-clone";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async dirList(dir = "/") {
|
|
|
|
|
let list = await pfs.readdir(dir);
|
|
|
|
@ -8,19 +15,18 @@ class Model {
|
|
|
|
|
let re = /^\..*$/;
|
|
|
|
|
|
|
|
|
|
if (re.test(list[u])) {
|
|
|
|
|
list.splice(u, 1)
|
|
|
|
|
u--
|
|
|
|
|
list.splice(u, 1);
|
|
|
|
|
u--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dirtree = [dir];
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
|
|
dirtree[i + 1] = list[i];
|
|
|
|
|
let itemStat = await pfs.stat(dirtree[0] + dirtree[i+1]);
|
|
|
|
|
let itemStat = await pfs.stat(dirtree[0] + dirtree[i + 1]);
|
|
|
|
|
if (itemStat.isDirectory()) {
|
|
|
|
|
dirtree[i+1] = await this.dirList(dirtree[0] + dirtree[i+1] + "/");
|
|
|
|
|
dirtree[i + 1] = await this.dirList(dirtree[0] + dirtree[i + 1] + "/");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -30,7 +36,12 @@ class Model {
|
|
|
|
|
async dirTree(dir = "/") {
|
|
|
|
|
var tree = await this.dirList(dir);
|
|
|
|
|
|
|
|
|
|
console.log(tree);
|
|
|
|
|
//console.log(tree);
|
|
|
|
|
return tree;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
purgeFS() {
|
|
|
|
|
delete window.fs;
|
|
|
|
|
window.fs = new LightningFS("fs", { wipe: true });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|