Skip to content

Commit

Permalink
Fix injectGlobalMixins script (pixijs#8634)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Sep 8, 2022
1 parent c1db3d8 commit 0ec50af
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions scripts/injectGlobalMixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,19 @@ async function getPackages(result: SimplePackageJson[] = []): Promise<SimplePack
*/
async function start(): Promise<void>
{
let pixiLocation: string;
let pixiLegacyLocation: string;
let pixiGlobalMixins = '';
let pixiLegacyGlobalMixins = '';

const packages = await getPackages();
const legacyPackages = Object.keys(packages.find((pkg) => pkg.name === 'pixi.js-legacy').dependencies);
const pixiPackages = Object.keys(packages.find((pkg) => pkg.name === 'pixi.js').dependencies);
const bundles = packages.filter((p) => p.location.includes('bundles')).map((p) => p.name);
const locations = Array(bundles.length).fill('');
const mixins = Array(bundles.length).fill('');
const pkgs = bundles.map((bundle) => Object.keys(packages.find((pkg) => pkg.name === bundle).dependencies));

packages.forEach((pkg) =>
{
const basePath = path.relative(process.cwd(), pkg.location);

if (pkg.name === 'pixi.js')
{
pixiLocation = pkg.location;

return;
}
if (pkg.name === 'pixi.js-legacy')
if (bundles.includes(pkg.name))
{
pixiLegacyLocation = pkg.location;

return;
locations[bundles.indexOf(pkg.name)] = pkg.location;
}

const globalDtsPath = path.resolve(basePath, './global.d.ts');
Expand All @@ -83,25 +72,24 @@ async function start(): Promise<void>
const pixiTypeData = `/// <reference types="${pkg.name}" />\n`;
const packageTypeData = `/// <reference path="./global.d.ts" />\n`;

if (pixiPackages.includes(pkg.name))
{
pixiGlobalMixins += pixiTypeData;
}
else if (legacyPackages.includes(pkg.name))
pkgs.forEach((pixiPkgs, index) =>
{
pixiLegacyGlobalMixins += pixiTypeData;
}
if (pixiPkgs.includes(pkg.name))
{
mixins[index] += pixiTypeData;
}
});

writeToIndex(basePath, packageTypeData);
}
});

// write the total types to the main packages
let basePath = path.relative(process.cwd(), pixiLocation);
locations.forEach((location, index) =>
{
const basePath = path.relative(process.cwd(), location);

writeToIndex(basePath, pixiGlobalMixins);
basePath = path.relative(process.cwd(), pixiLegacyLocation);
writeToIndex(basePath, pixiLegacyGlobalMixins);
writeToIndex(basePath, mixins[index]);
});
}

start();

0 comments on commit 0ec50af

Please sign in to comment.