adds preparing the database as a mandatory step and also adds the directory of prepped database jsons to the ignore list
parent
7e2ebb7e75
commit
bc04bcdaec
|
|
@ -1,2 +1,3 @@
|
|||
dist
|
||||
node_modules
|
||||
src/packs/__source
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/src/packs/__source" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/src/packs/__source" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
|
|
|||
77
gulpfile.mjs
77
gulpfile.mjs
|
|
@ -1,23 +1,70 @@
|
|||
import {dest, series, src} from 'gulp';
|
||||
import process from 'node:process';
|
||||
import replace from 'gulp-replace';
|
||||
|
||||
import {getRandomValues} from 'node:crypto';
|
||||
import * as dartSass from 'sass';
|
||||
import gulpSass from 'gulp-sass';
|
||||
import {deleteAsync} from 'del';
|
||||
|
||||
import {readdirSync} from 'node:fs';
|
||||
import {readdirSync, readFileSync, writeFileSync, rmdirSync, existsSync, mkdirSync} from "fs";
|
||||
import {join} from 'node:path';
|
||||
|
||||
import {compilePack} from '@foundryvtt/foundryvtt-cli';
|
||||
|
||||
const sass = gulpSass(dartSass);
|
||||
|
||||
|
||||
/**
|
||||
* Generate a random alphanumeric string ID of a given requested length using `crypto.getRandomValues()`.
|
||||
* @param {number} length The length of the random string to generate, which must be at most 16384.
|
||||
* @returns {string} A string containing random letters (A-Z, a-z) and numbers (0-9).
|
||||
*/
|
||||
function randomID(length = 16) {
|
||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const cutoff = 0x100000000 - (0x100000000 % chars.length);
|
||||
const random = new Uint32Array(length);
|
||||
do {
|
||||
getRandomValues(random);
|
||||
} while (random.some(x => x >= cutoff));
|
||||
let id = "";
|
||||
for (let i = 0; i < length; i++) id += chars[random[i] % chars.length];
|
||||
return id;
|
||||
}
|
||||
|
||||
const convert = function (from, to, ofType) {
|
||||
|
||||
const SOURCE = from;
|
||||
const DEST = to;
|
||||
const TYPE = ofType;
|
||||
|
||||
try {
|
||||
rmdirSync(DEST, {force: true, recursive: true})
|
||||
} catch (e) {
|
||||
}
|
||||
mkdirSync(DEST)
|
||||
|
||||
readdirSync(SOURCE).forEach(file => {
|
||||
let originalSource = JSON.parse(readFileSync(join(SOURCE, file), {encoding: "utf8"}));
|
||||
let id = randomID();
|
||||
let targetSource = {
|
||||
_id: id,
|
||||
_key: "!items!" + id,
|
||||
type: TYPE,
|
||||
img: originalSource.image,
|
||||
name: originalSource.name.trim(),
|
||||
system: {...originalSource}
|
||||
}
|
||||
delete targetSource.system.image;
|
||||
let target = JSON.stringify(targetSource, null, 2);
|
||||
let newFileName = "./" + join(DEST, id + ".json");
|
||||
writeFileSync(newFileName, target, {encoding: "utf8"});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function cleanDist() {
|
||||
return deleteAsync(['dist/**']);
|
||||
}
|
||||
|
||||
|
||||
function buildStyles() {
|
||||
return src('src/style/**/*.scss')
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
|
|
@ -40,6 +87,27 @@ function updateManifestFile() {
|
|||
.pipe(dest('dist/'))
|
||||
}
|
||||
|
||||
async function prepareDB() {
|
||||
|
||||
try {
|
||||
if (!existsSync("./src/packs/__source")) {
|
||||
mkdirSync("./src/packs/__source");
|
||||
}
|
||||
|
||||
convert("./src/packs/_source/talente", "./src/packs/__source/talente", "Skill");
|
||||
convert("./src/packs/_source/zauber", "./src/packs/__source/zauber", "Spell");
|
||||
convert("./src/packs/_source/vorteile", "./src/packs/__source/vorteile", "Advantage");
|
||||
convert("./src/packs/_source/waffen", "./src/packs/__source/waffen", "Equipment");
|
||||
convert("./src/packs/_source/munition", "./src/packs/__source/munition", "Equipment");
|
||||
convert("./src/packs/_source/ruestzeug", "./src/packs/__source/ruestzeug", "Equipment");
|
||||
convert("./src/packs/_source/liturgien-und-segnungen", "./src/packs/__source/liturgien", "Liturgy");
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function buildDB() {
|
||||
// Determine which source folders to process
|
||||
|
||||
|
|
@ -68,6 +136,7 @@ export default series(
|
|||
copySource,
|
||||
copyAssets,
|
||||
buildStyles,
|
||||
prepareDB,
|
||||
buildDB,
|
||||
updateManifestFile
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue