adding pack tools.

This commit is contained in:
rwanoux
2024-11-18 09:27:33 +01:00
parent e721c706eb
commit ca816eec2d
5 changed files with 129 additions and 7 deletions
+52
View File
@@ -0,0 +1,52 @@
name: Release Creation
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# get part of the tag after the `v`
- name: Extract tag version number
id: get_version
uses: battila7/get-version-action@v2
# Substitute the Manifest and Download URLs in the module.json
- name: Substitute Manifest and Download Links For Versioned Ones
id: sub_manifest_link_version
uses: microsoft/variable-substitution@v1
with:
files: "system.json"
env:
version: ${{steps.get_version.outputs.version-without-v}}
url: https://github.com/${{github.repository}}
manifest: https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/system.json
download: https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/system.zip
- name: Install Dependencies
run: npm ci
# Pull YAML to LDB packs
- name: Build Packs
run: npm run pullYAMLtoLDB
# Create a zip file with all files required by the module to add to the release
- run: zip -r ./system.zip system.json template.json asset/ css/ lang/ module/ templates/ packs/
# Create a release for this specific version
- name: Update Release with Files
id: create_version_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true # Set this to false if you want to prevent updating existing releases
name: ${{ github.event.release.name }}
draft: ${{ github.event.release.unpublished }}
prerelease: ${{ github.event.release.prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "./system.json, ./system.zip"
tag: ${{ github.event.release.tag_name }}
body: ${{ github.event.release.body }}
+4 -4
View File
@@ -1,15 +1,15 @@
# IDE
.idea/
.vs/
.vsode
# Node Modules
node_modules/
node_modules
npm-debug.log
# les bdd de packs
packs/
packs
# Foundry
*.lock
jsconfig.json
foundry
foundry
+5 -3
View File
@@ -5,14 +5,16 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"launch window Foundry11": "cd C:/Program Files/Foundry Virtual Tabletop_V11/resources/app && node main.js",
"launch Foundry12": "cd C:/Program Files/Foundry Virtual Tabletop_V12/resources/app && node main.js",
"watch": "gulp watch",
"buildStyle": "gulp buildStyles"
"buildStyle": "gulp buildStyles",
"pushLDBtoYAML": "node ./tools/pushLDBtoYAML.mjs",
"pullYAMLtoLDB": "node ./tools/pullYAMLtoLDB.mjs"
},
"author": "",
"author": "Rwan",
"devDependencies": {
"@typhonjs-fvtt/eslint-config-foundry.js": "^0.8.0",
"@foundryvtt/foundryvtt-cli": "^1.0.2",
"browser-sync": "^2.27.11",
"gulp": "^4.0.2",
"gulp-sass": "^5.1.0",
+16
View File
@@ -0,0 +1,16 @@
import { compilePack } from '@foundryvtt/foundryvtt-cli';
import { promises as fs } from 'fs';
const MODULE_ID = process.cwd();
const yaml = true;
const packs = await fs.readdir('./src/packs');
for (const pack of packs) {
if (pack === '.gitattributes') continue;
console.log('Packing ' + pack);
await compilePack(
`${MODULE_ID}/src/packs/${pack}`,
`${MODULE_ID}/packs/${pack}`,
{ yaml }
);
}
+52
View File
@@ -0,0 +1,52 @@
import { extractPack } from "@foundryvtt/foundryvtt-cli";
import { promises as fs } from "fs";
import path from "path";
const MODULE_ID = process.cwd();
const yaml = true;
const log = true;
const packs = await fs.readdir("./packs");
for (const pack of packs) {
if (pack === ".gitattributes") continue;
const packPath = path.join("./packs", pack);
const stats = await fs.lstat(packPath); // Utilisation de lstat pour vérifier si c'est un fichier ou un répertoire
if (!stats.isDirectory()) {
console.log(`${pack} est un fichier, il est ignoré.`);
continue; // Si ce n'est pas un répertoire, passer à l'élément suivant
}
console.log("Unpacking " + pack);
const directory = `./src/packs/${pack}`;
try {
console.log(directory);
for (const file of await fs.readdir(directory)) {
await fs.unlink(path.join(directory, file));
}
} catch (error) {
if (error.code === "ENOENT") console.log("No files inside of " + pack);
else console.log(error);
}
await extractPack(
`${MODULE_ID}/packs/${pack}`,
`${MODULE_ID}/src/packs/${pack}`,
{
yaml,
transformName,
log
}
);
}
/**
* Prefaces the document with its type
* @param {object} doc - The document data
*/
function transformName(doc) {
const safeFileName = doc.name.replace(/[^a-zA-Z0-9А-я]/g, "_");
const type = doc._key.split("!")[1];
const prefix = ["actors", "items"].includes(type) ? doc.type : type;
return `${doc.name ? `${prefix}_${safeFileName}_${doc._id}` : doc._id}.${yaml ? "yml" : "json"
}`;
}