Created
October 4, 2022 14:00
-
-
Save argahsuknesib/fcecae15c71653f3dd725073dfc44ad5 to your computer and use it in GitHub Desktop.
Providing the data folder, the script will start a community solid server with names of the data files as of the solid pod.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Logger } from "tslog" | |
const fs = require('fs') | |
const generator = require('generate-password') | |
const jsonFile = require('jsonfile') | |
const directory: string = './data' | |
const { exec } = require('node:child_process') | |
const logging: Logger = new Logger(); | |
const cmdCreatePods: string = 'community-solid-server -c @css:config/file.json --seededPodConfigJson multiSolidPod.json'; | |
const cmdLDESServer: string = 'npx @solid/community-server -c @css:config/file-no-setup.json -p 3000 -f ./data --seededPodConfigJson multiSolidPod.json' | |
const cmdLDESUnsafe: string = 'npx @solid/community-server -c config/unsafe.json -p 3000 -f ./data --seededPodConfigJson multiSolidPod.json' | |
const mailDomain: string = '@protego.com' | |
type multipod = { | |
podName: string, | |
email: string, | |
password: string | |
} | |
type myType = { | |
solidpod: multipod[]; | |
} | |
const fileObject: myType = { | |
solidpod: [], | |
}; | |
export class prepareSolidPod { | |
async listFile(path: string) { | |
const dir = await fs.promises.opendir(path) | |
for await (const value of dir) { | |
let fileName: string = value.name.slice(0, -3) | |
let solidObject = { | |
podName: fileName, | |
email: fileName + mailDomain, | |
password: generator.generate({ | |
length: 6, | |
numbers: false, | |
excludeSimilarCharacters: true | |
}) | |
} | |
fileObject.solidpod.push(solidObject); | |
} | |
} | |
async writeJSONFile(object: multipod[]) { | |
for await (const { } of object) { | |
const podContent: string = JSON.stringify(fileObject.solidpod) | |
jsonFile.writeFile('multiSolidPod.json', JSON.parse(podContent), function (error:any) { | |
if (error) { | |
throw new Error("The error is" + error); | |
} | |
logging.info('JSON file is created.') | |
}) | |
} | |
} | |
async createSolidPods() { | |
await exec(cmdLDESUnsafe, (error: any, output: any) => { | |
if (error) { | |
logging.error(error) | |
return | |
} | |
logging.info('solid pods are created.') | |
}) | |
} | |
async pushDataToPodLDES(path:string) { | |
const dir = await fs.promises.opendir(path) | |
for await (const value of dir){ | |
let fileName: string = value.name.slice(0, -3) | |
exec('ls', (error: any, output:any) => { | |
if (error) { | |
logging.error(error) | |
return | |
} | |
logging.info('testing this out.') | |
}) | |
} | |
} | |
async splitN3IntoChunks(filePath: string){ | |
console.log('hello, the file being processed is: ' + filePath); | |
const stream = fs.createReadStream(filePath); | |
} | |
} | |
let protegoPods = new prepareSolidPod(); | |
protegoPods.listFile(directory).then(() => { | |
protegoPods.writeJSONFile(fileObject.solidpod) | |
.then(async (res) => { | |
await protegoPods.createSolidPods() | |
}) | |
.then(async (res) => { | |
await protegoPods.pushDataToPodLDES(directory) | |
}); | |
}).catch(error => { | |
console.log(error); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment