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
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
|
src/packs/__source
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/src/packs/__source" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/src/packs/__source" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
||||||
77
gulpfile.mjs
77
gulpfile.mjs
|
|
@ -1,23 +1,70 @@
|
||||||
import {dest, series, src} from 'gulp';
|
import {dest, series, src} from 'gulp';
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import replace from 'gulp-replace';
|
import replace from 'gulp-replace';
|
||||||
|
import {getRandomValues} from 'node:crypto';
|
||||||
import * as dartSass from 'sass';
|
import * as dartSass from 'sass';
|
||||||
import gulpSass from 'gulp-sass';
|
import gulpSass from 'gulp-sass';
|
||||||
import {deleteAsync} from 'del';
|
import {deleteAsync} from 'del';
|
||||||
|
import {readdirSync, readFileSync, writeFileSync, rmdirSync, existsSync, mkdirSync} from "fs";
|
||||||
import {readdirSync} from 'node:fs';
|
|
||||||
import {join} from 'node:path';
|
import {join} from 'node:path';
|
||||||
|
|
||||||
import {compilePack} from '@foundryvtt/foundryvtt-cli';
|
import {compilePack} from '@foundryvtt/foundryvtt-cli';
|
||||||
|
|
||||||
const sass = gulpSass(dartSass);
|
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() {
|
function cleanDist() {
|
||||||
return deleteAsync(['dist/**']);
|
return deleteAsync(['dist/**']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function buildStyles() {
|
function buildStyles() {
|
||||||
return src('src/style/**/*.scss')
|
return src('src/style/**/*.scss')
|
||||||
.pipe(sass().on('error', sass.logError))
|
.pipe(sass().on('error', sass.logError))
|
||||||
|
|
@ -40,6 +87,27 @@ function updateManifestFile() {
|
||||||
.pipe(dest('dist/'))
|
.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() {
|
function buildDB() {
|
||||||
// Determine which source folders to process
|
// Determine which source folders to process
|
||||||
|
|
||||||
|
|
@ -68,6 +136,7 @@ export default series(
|
||||||
copySource,
|
copySource,
|
||||||
copyAssets,
|
copyAssets,
|
||||||
buildStyles,
|
buildStyles,
|
||||||
|
prepareDB,
|
||||||
buildDB,
|
buildDB,
|
||||||
updateManifestFile
|
updateManifestFile
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue