Skip to content

Commit

Permalink
🔧 prune unused AJ datapack exports from build
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAfroOfDoom committed Oct 23, 2024
1 parent ecac8a1 commit 4e37a5d
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions package-scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ const { rimraf } = require('rimraf');

const buildDir = './build';

const prefixPaths = (prefix, paths) => paths.map((path) => `${prefix}${path}`);
const suffixPaths = (paths, suffix) => paths.map((path) => `${path}${suffix}`);

const animatedJavaExportsToPrune = prefixPaths('omegaflowey_', [
'housefly',
'petal_pipe_circle',
'petal_pipe_middle',
'soul_0_bandaid',
'soul_0_sword',
'venus_fly_trap',
]);

const getSummitDatapackPaths = () => {
const postProcessors = [];

Expand Down Expand Up @@ -130,6 +142,47 @@ const getSummitDatapackPaths = () => {
...primaryDatapackPaths,
]);

const pruneAnimatedJavaDatapackExports = async ({ compiledPath }) => {
const prunePromises = [];
for (const dir of animatedJavaExportsToPrune) {
const pruneFunctionDir = `${compiledPath}/datapacks/animated_java/data/animated_java/function/${dir}`;
prunePromises.push(rimraf(pruneFunctionDir));
prunePromises.push(
rimraf(
`${compiledPath}/datapacks/animated_java/data/animated_java/tags/function/${dir}`,
),
);
}
await Promise.all(prunePromises);
};
postProcessors.push(pruneAnimatedJavaDatapackExports);

const pruneAnimatedJavaDatapackTags = async ({ compiledPath }) => {
for (const [tagPath, suffix] of [
[
`${compiledPath}/datapacks/animated_java/data/animated_java/tags/function/global/on_load.json`,
'/on_load',
],
[
`${compiledPath}/datapacks/animated_java/data/animated_java/tags/function/global/root/on_load.json`,
'/root/on_load',
],
[
`${compiledPath}/datapacks/animated_java/data/animated_java/tags/function/global/root/on_tick.json`,
'/root/on_tick',
],
]) {
const loadTagJson = await readJson(tagPath);
loadTagJson.values = loadTagJson.values.filter((modelTag) => {
const namespace = modelTag
.replace('animated_java:', '')
.replace(suffix, '');
return !animatedJavaExportsToPrune.includes(namespace);
});
await writeJson(tagPath, loadTagJson);
}
};
postProcessors.push(pruneAnimatedJavaDatapackTags);
return { paths: datapackPaths, postProcessors };
};

Expand All @@ -140,14 +193,6 @@ const getSummitResourcepackPaths = () => {
// Not `minecraft/sounds.json` since we just use that to disable ambient sounds
const minecraftPaths = prefixPaths('minecraft/', ['atlases', 'models']);

const animatedJavaExportsToPrune = prefixPaths('omegaflowey_', [
'housefly',
'petal_pipe_circle',
'petal_pipe_middle',
'soul_0_bandaid',
'soul_0_sword',
'venus_fly_trap',
]);
const pruneAnimatedJavaDisplayItem = async ({ compiledPath }) => {
const displayItemPath = `${compiledPath}/assets/minecraft/models/item/pink_dye.json`;
const displayItemJson = await readJson(displayItemPath);
Expand Down Expand Up @@ -392,9 +437,6 @@ const logLevel = (level, ...data) => {
}
};

const prefixPaths = (prefix, paths) => paths.map((path) => `${prefix}${path}`);
const suffixPaths = (paths, suffix) => paths.map((path) => `${path}${suffix}`);

const getCompilePaths = ({ getSummitPaths }) => {
const { variant } = args;
switch (variant) {
Expand Down

0 comments on commit 4e37a5d

Please sign in to comment.