mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
Added confirmation before overwriting your LDB with the tool command (#482)
This commit is contained in:
parent
bb9036ee7a
commit
243630878b
3 changed files with 51 additions and 20 deletions
|
|
@ -1,31 +1,55 @@
|
|||
import { compilePack } from '@foundryvtt/foundryvtt-cli';
|
||||
import readline from 'node:readline/promises';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
const MODULE_ID = process.cwd();
|
||||
const yaml = false;
|
||||
|
||||
const packs = await deepGetDirectories('./packs');
|
||||
console.log(packs);
|
||||
for (const pack of packs) {
|
||||
if (pack === '.gitattributes') continue;
|
||||
console.log('Packing ' + pack);
|
||||
await compilePack(`${MODULE_ID}/src/${pack}`, `${MODULE_ID}/${pack}`, { yaml });
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
const answer = await rl.question(
|
||||
'You are about to overwrite your current database with the saved packs/json. Write "Overwrite" if you are sure. ',
|
||||
function (answer) {
|
||||
rl.close();
|
||||
return answer;
|
||||
}
|
||||
);
|
||||
|
||||
if (answer.toLowerCase() === 'overwrite') {
|
||||
await pullToLDB();
|
||||
} else {
|
||||
console.log('Canceled');
|
||||
}
|
||||
|
||||
async function deepGetDirectories(distPath) {
|
||||
const dirr = await fs.readdir('src/' + distPath);
|
||||
const dirrsWithSub = [];
|
||||
for (let file of dirr) {
|
||||
const stat = await fs.stat('src/' + distPath + '/' + file);
|
||||
if (stat.isDirectory()) {
|
||||
const deeper = await deepGetDirectories(distPath + '/' + file);
|
||||
if (deeper.length > 0) {
|
||||
dirrsWithSub.push(...deeper);
|
||||
} else {
|
||||
dirrsWithSub.push(distPath + '/' + file);
|
||||
}
|
||||
}
|
||||
process.exit();
|
||||
|
||||
async function pullToLDB() {
|
||||
const packs = await deepGetDirectories('./packs');
|
||||
console.log(packs);
|
||||
for (const pack of packs) {
|
||||
if (pack === '.gitattributes') continue;
|
||||
console.log('Packing ' + pack);
|
||||
await compilePack(`${MODULE_ID}/src/${pack}`, `${MODULE_ID}/${pack}`, { yaml });
|
||||
}
|
||||
|
||||
return dirrsWithSub;
|
||||
async function deepGetDirectories(distPath) {
|
||||
const dirr = await fs.readdir('src/' + distPath);
|
||||
const dirrsWithSub = [];
|
||||
for (let file of dirr) {
|
||||
const stat = await fs.stat('src/' + distPath + '/' + file);
|
||||
if (stat.isDirectory()) {
|
||||
const deeper = await deepGetDirectories(distPath + '/' + file);
|
||||
if (deeper.length > 0) {
|
||||
dirrsWithSub.push(...deeper);
|
||||
} else {
|
||||
dirrsWithSub.push(distPath + '/' + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dirrsWithSub;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue