diff --git a/package-lock.json b/package-lock.json index 864d027c..35dab92f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "autocompleter": "^9.3.2", "gulp": "^5.0.0", "gulp-less": "^5.0.0", + "readline": "^1.3.0", "rollup": "^4.40.0" }, "devDependencies": { @@ -4263,6 +4264,11 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/readline": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", + "integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==" + }, "node_modules/rechoir": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz", diff --git a/package.json b/package.json index a7dd69b9..af5adfd6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "build": "npm run rollup && npm run gulp", "rollup": "rollup -c", "gulp": "gulp less", + "readline": "^1.3.0", "pushLDBtoYML": "node ./tools/pushLDBtoYML.mjs", "pullYMLtoLDB": "node ./tools/pullYMLtoLDB.mjs", "createSymlink": "node ./tools/create-symlink.mjs" diff --git a/tools/pullYMLtoLDB.mjs b/tools/pullYMLtoLDB.mjs index 6c2b8c79..52b0f0da 100644 --- a/tools/pullYMLtoLDB.mjs +++ b/tools/pullYMLtoLDB.mjs @@ -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; + } }