Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
scripts: update types publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Feb 8, 2024
1 parent 8e8bdb0 commit 9007080
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"serve": "tsx scripts/build.ts --serve",
"watch": "tsx scripts/build.ts --watch",
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --ignore-pattern src/*",
"prepublishOnly": "if [ -d lib ]; then rm -r lib; fi && tsc && cp package.json lib && cp LICENSE lib && cp README.md lib"
"prepublishOnly": "tsx scripts/prepare.ts"
},
"repository": {
"type": "git",
Expand Down
26 changes: 0 additions & 26 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,6 @@ try {
});
}
},
{
name: "typeMapper",
setup: async build => {
let defContent = "";

build.onLoad({ filter: /\.[jt]sx?/ }, async args => {
const filePath = path.relative(rootDirname, args.path);
if (filePath?.startsWith("src/core")) {
let aliased = "@pyoncord/" + filePath.slice(9, -path.extname(filePath).length);
if (aliased.endsWith("/index")) aliased = aliased.slice(0, -6);

defContent += [
`declare module "${aliased}" {`,
`\texport * from "./${filePath.slice(4, -path.extname(filePath).length)}";`,
"}"
].join("\n") + "\n";
}

return null;
});

build.onEnd(async () => {
// await writeFile("./lib/defs.d.ts", defContent);
});
}
},
{
name: "swc",
setup(build) {
Expand Down
18 changes: 5 additions & 13 deletions scripts/publish.ts → scripts/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// WARNING! ENTER AT YOUR OWN PERIL
// do not read the code
import esbuild from "esbuild";
import { existsSync } from "fs";
import { appendFile, cp, mkdir, rm } from "fs/promises";
Expand Down Expand Up @@ -28,24 +30,15 @@ for (const file of [
);
}

const setup = async build => {
// const pathMap = [] as Array<{
// alias: string,
// path: string;
// }>;

// oh no, this is very bad
const pluginSetup = async build => {
build.onLoad({ filter: /\.[jt]sx?/ }, async args => {
const filePath = path.relative(rootDirname, args.path);

if (filePath?.startsWith("../src/core")) {
let trimmedPath = filePath.slice(12, -path.extname(filePath).length);
if (trimmedPath.endsWith("/index")) trimmedPath = trimmedPath.slice(0, -6);

// pathMap.push({
// alias: "@pyoncord/" + trimmedPath,
// path: "core" + trimmedPath
// });

const declarationContents = [
`declare module "${"@pyoncord/" + trimmedPath}" {`,
` export * from "./${"core/" + trimmedPath}";`,
Expand All @@ -63,15 +56,14 @@ const setup = async build => {
});
};


await esbuild.build({
entryPoints: ["src/entry.js"],
write: false,
bundle: true,
external: ["~*", "*.png"],
plugins: [{
name: "typeMapper",
setup
setup: pluginSetup
}]
});

Expand Down

0 comments on commit 9007080

Please sign in to comment.