fixes asynchronous error with a pinky promise
parent
df4fd6061d
commit
ec4c9768dd
91
gulpfile.mjs
91
gulpfile.mjs
|
|
@ -12,7 +12,7 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,28 +22,28 @@ const sass = gulpSass(dartSass);
|
||||||
* @returns {string} A string containing random letters (A-Z, a-z) and numbers (0-9).
|
* @returns {string} A string containing random letters (A-Z, a-z) and numbers (0-9).
|
||||||
*/
|
*/
|
||||||
function randomID(reference = "", length = 16) {
|
function randomID(reference = "", length = 16) {
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder()
|
||||||
const data = encoder.encode(reference);
|
const data = encoder.encode(reference)
|
||||||
return subtle.digest('SHA-256', data).then(hashBuffer => {
|
return subtle.digest('SHA-256', data).then(hashBuffer => {
|
||||||
// Step 2: Convert the hash to a Base62 string
|
// Step 2: Convert the hash to a Base62 string
|
||||||
const base62Chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
const base62Chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||||
const hashArray = new Uint8Array(hashBuffer);
|
const hashArray = new Uint8Array(hashBuffer)
|
||||||
let num = BigInt(0);
|
let num = BigInt(0)
|
||||||
|
|
||||||
// Convert hash buffer to a BigInt
|
// Convert hash buffer to a BigInt
|
||||||
for (let byte of hashArray) {
|
for (let byte of hashArray) {
|
||||||
num = (num << BigInt(8)) | BigInt(byte);
|
num = (num << BigInt(8)) | BigInt(byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
let base62Id = '';
|
let base62Id = '';
|
||||||
while (num > 0) {
|
while (num > 0) {
|
||||||
const remainder = num % BigInt(62);
|
const remainder = num % BigInt(62)
|
||||||
base62Id = base62Chars[Number(remainder)] + base62Id;
|
base62Id = base62Chars[Number(remainder)] + base62Id
|
||||||
num = num / BigInt(62);
|
num = num / BigInt(62)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Return the first 16 characters
|
// Step 3: Return the first 16 characters
|
||||||
return base62Id.slice(-length);
|
return base62Id.slice(-length)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,13 +63,13 @@ const convert = function (from, to, ofType, overwrite = true) {
|
||||||
let promises = []
|
let promises = []
|
||||||
|
|
||||||
const filewalker = async (source) => {
|
const filewalker = async (source) => {
|
||||||
console.debug("entering directory", source);
|
console.debug("entering directory", source)
|
||||||
for (let file of readdirSync(source)) {
|
for (let file of readdirSync(source)) {
|
||||||
if (statSync(join(source, file)).isDirectory()) {
|
if (statSync(join(source, file)).isDirectory()) {
|
||||||
await filewalker(join(source, file));
|
await filewalker(join(source, file))
|
||||||
} else {
|
} else {
|
||||||
console.debug("processing file", join(source, file))
|
console.debug("processing file", join(source, file))
|
||||||
let originalSource = JSON.parse(readFileSync(join(source, file), {encoding: "utf8"}));
|
let originalSource = JSON.parse(readFileSync(join(source, file), {encoding: "utf8"}))
|
||||||
promises.push(new Promise((resolve2) => {
|
promises.push(new Promise((resolve2) => {
|
||||||
randomID("DSA_4-1" + TYPE + originalSource.name.trim()).then(id => {
|
randomID("DSA_4-1" + TYPE + originalSource.name.trim()).then(id => {
|
||||||
let targetSource = {
|
let targetSource = {
|
||||||
|
|
@ -81,9 +81,12 @@ const convert = function (from, to, ofType, overwrite = true) {
|
||||||
system: {...originalSource},
|
system: {...originalSource},
|
||||||
}
|
}
|
||||||
delete targetSource.system.image;
|
delete targetSource.system.image;
|
||||||
let target = JSON.stringify(targetSource, null, 2);
|
let target = JSON.stringify(targetSource, null, 2)
|
||||||
let newFileName = "./" + join(DEST, id + ".json");
|
let newFileName = "./" + join(DEST, id + ".json")
|
||||||
writeFileSync(newFileName, target, {encoding: "utf8"});
|
if (!existsSync(join("./", DEST))) {
|
||||||
|
mkdirSync(join("./", DEST))
|
||||||
|
}
|
||||||
|
writeFileSync(newFileName, target, {encoding: "utf8"})
|
||||||
resolve2()
|
resolve2()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -98,7 +101,7 @@ const convert = function (from, to, ofType, overwrite = true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanDist() {
|
function cleanDist() {
|
||||||
return deleteAsync(['dist/**']);
|
return deleteAsync(['dist/**'])
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildStyles() {
|
function buildStyles() {
|
||||||
|
|
@ -141,32 +144,32 @@ gulp.task('prepareDB', async function (done) {
|
||||||
mkdirSync("./src/packs/__source");
|
mkdirSync("./src/packs/__source");
|
||||||
}
|
}
|
||||||
|
|
||||||
await convert("./src/packs/_source/talente", "./src/packs/__source/talente", "Skill");
|
await convert("./src/packs/_source/talente", "./src/packs/__source/talente", "Skill")
|
||||||
await convert("./src/packs/_source/zauber", "./src/packs/__source/zauber", "Spell");
|
await convert("./src/packs/_source/zauber", "./src/packs/__source/zauber", "Spell")
|
||||||
await convert("./src/packs/_source/vorteile", "./src/packs/__source/vorteile", "Advantage");
|
await convert("./src/packs/_source/vorteile", "./src/packs/__source/vorteile", "Advantage")
|
||||||
await convert("./src/packs/_source/nachteile", "./src/packs/__source/vorteile", "Advantage", false);
|
await convert("./src/packs/_source/nachteile", "./src/packs/__source/vorteile", "Advantage", false)
|
||||||
await convert("./src/packs/_source/sonderfertigkeiten", "./src/packs/__source/sonderfertigkeiten", "SpecialAbility");
|
await convert("./src/packs/_source/sonderfertigkeiten", "./src/packs/__source/sonderfertigkeiten", "SpecialAbility")
|
||||||
await convert("./src/packs/_source/waehrungen", "./src/packs/__source/waehrungen", "Equipment");
|
await convert("./src/packs/_source/waehrungen", "./src/packs/__source/waehrungen", "Equipment")
|
||||||
await convert("./src/packs/_source/Gegenstaende/Waffen", "./src/packs/__source/Waffen", "Equipment");
|
await convert("./src/packs/_source/Gegenstaende/Waffen", "./src/packs/__source/Waffen", "Equipment")
|
||||||
await convert("./src/packs/_source/Gegenstaende/Munition", "./src/packs/__source/Munition", "Equipment");
|
await convert("./src/packs/_source/Gegenstaende/Munition", "./src/packs/__source/Munition", "Equipment")
|
||||||
await convert("./src/packs/_source/Gegenstaende/Ruestzeug", "./src/packs/__source/Ruestzeug", "Equipment");
|
await convert("./src/packs/_source/Gegenstaende/Ruestzeug", "./src/packs/__source/Ruestzeug", "Equipment")
|
||||||
await convert("./src/packs/_source/Gegenstaende/Behaelter", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Behaelter", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/Gegenstaende/Bekleidung", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Bekleidung", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/Gegenstaende/Beleuchtung", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Beleuchtung", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/Gegenstaende/Buecher", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Buecher", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/Gegenstaende/Essutensilien", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Essutensilien", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/Gegenstaende/Sonstiges", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Sonstiges", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/Gegenstaende/Werkzeug", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Werkzeug", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/Gegenstaende/Seile", "./src/packs/__source/Gegenstaende", "Equipment", false);
|
await convert("./src/packs/_source/Gegenstaende/Seile", "./src/packs/__source/Gegenstaende", "Equipment", false)
|
||||||
await convert("./src/packs/_source/liturgien-und-segnungen", "./src/packs/__source/liturgien", "Liturgy");
|
await convert("./src/packs/_source/liturgien-und-segnungen", "./src/packs/__source/liturgien", "Liturgy")
|
||||||
await convert("./src/packs/_source/wunden", "./src/packs/__source/wunden", "ActiveEffect");
|
await convert("./src/packs/_source/wunden", "./src/packs/__source/wunden", "ActiveEffect")
|
||||||
|
|
||||||
await convert("./src/packs/_source/kulturen", "./src/packs/__source/kulturen", "Culture");
|
await convert("./src/packs/_source/kulturen", "./src/packs/__source/kulturen", "Culture")
|
||||||
await convert("./src/packs/_source/spezien", "./src/packs/__source/spezien", "Species");
|
await convert("./src/packs/_source/spezien", "./src/packs/__source/spezien", "Species")
|
||||||
await convert("./src/packs/_source/professionen", "./src/packs/__source/professionen", "Profession");
|
await convert("./src/packs/_source/professionen", "./src/packs/__source/professionen", "Profession")
|
||||||
done()
|
done()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -183,10 +186,10 @@ function buildDB() {
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const folder of folders) {
|
for (const folder of folders) {
|
||||||
const src = join(PACK_SRC, folder.name);
|
const src = join(PACK_SRC, folder.name)
|
||||||
const dest = join(PACK_DEST, folder.name);
|
const dest = join(PACK_DEST, folder.name)
|
||||||
console.info(`Compiling pack ${folder.name}`);
|
console.info(`Compiling pack ${folder.name}`)
|
||||||
await compilePack(src, dest, {recursive: true, nedb: false});
|
await compilePack(src, dest, {recursive: true, nedb: false})
|
||||||
|
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue