Skip to content

Commit

Permalink
add --debug option for additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
julianbenegas committed Oct 16, 2024
1 parent a57e2b9 commit 5981118
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 44 deletions.
6 changes: 6 additions & 0 deletions packages/basehub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# basehub

## 7.5.11

### Patch Changes

- add --debug option with additional logging

## 7.5.10

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/basehub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "basehub",
"description": "A very fast Headless CMS.",
"author": "JB <[email protected]>",
"version": "7.5.10",
"version": "7.5.11",
"license": "MIT",
"repository": "basehub-ai/basehub",
"bugs": "https://github.com/basehub-ai/basehub/issues",
Expand Down
1 change: 1 addition & 0 deletions packages/basehub/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const args = arg(
"--help": Boolean,
"--watch": Boolean,
"--api-version": String,
"--debug": Boolean,
// aliases
"-o": "--output",
"-t": "--token",
Expand Down
154 changes: 113 additions & 41 deletions packages/basehub/src/bin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const main = async (
gitBranchDeploymentURL,
resolvedRef,
newResolvedRefPromise,
token,
} = await getStuffFromEnv({ ...options, previousResolvedRef });

const basehubModulePath = resolvePkg("basehub");
Expand Down Expand Up @@ -104,6 +105,10 @@ export const main = async (
: null,
// `🔑 Git Commit SHA: ${gitCommitSHA}`,
]);

if (args["--debug"]) {
console.log(`[basehub] using token: ${token}`);
}
}

// cleanup the output directory if input hash changes
Expand Down Expand Up @@ -153,7 +158,7 @@ export const main = async (
"Content-Type": "application/json",
},
output: path.join(basehubOutputPath),
verbose: false,
verbose: silent ? false : args["--debug"],
sortProperties: true,
silent,
previousSchemaHash,
Expand All @@ -168,6 +173,10 @@ export const main = async (
};
}

if (args["--debug"]) {
console.log(`[basehub] generated in: ${basehubOutputPath}`);
}

const generatedMainExportPath = path.join(basehubOutputPath, "index.ts");

// We'll patch some things from the generated code.
Expand Down Expand Up @@ -290,46 +299,65 @@ R extends Omit<MutationGenqlSelection, "transaction" | "transactionAwaitable"> &
logIfNotSilent(silent, "📦 Compiling to JavaScript...");
const reactPumpOutDir = path.join(basehubOutputPath, "react-pump");
const nextToolbarOutDir = path.join(basehubOutputPath, "next-toolbar");
await Promise.all([
esbuild.build({
entryPoints: [generatedMainExportPath],
bundle: true,
outdir: basehubOutputPath,
minify: false,
treeShaking: true,
splitting: true,
format: "esm",
external: peerDependencies,
}),
esbuild.build({
entryPoints: [
path.join(basehubModulePath, "src", "react", "pump", "index.ts"),
],
bundle: true,
outdir: reactPumpOutDir,
minify: false,
treeShaking: true,
splitting: true,
format: "esm",
target: ["es2020", "node18"],
external: peerDependencies,
plugins: [useClientPlugin],
}),
esbuild.build({
entryPoints: [
path.join(basehubModulePath, "src", "next", "toolbar", "index.ts"),
],
bundle: true,
outdir: nextToolbarOutDir,
minify: false,
treeShaking: true,
splitting: true,
format: "esm",
target: ["es2020", "node18"],
external: peerDependencies,
plugins: [ScssModulesPlugin(), useClientPlugin],
}),
]);

await esbuild.build({
entryPoints: [generatedMainExportPath],
bundle: true,
outdir: basehubOutputPath,
minify: false,
treeShaking: true,
splitting: true,
format: "esm",
external: peerDependencies,
});

if (args["--debug"]) {
console.log(
`[basehub] compiled main export with esbuild in: ${generatedMainExportPath}`
);
}

await esbuild.build({
entryPoints: [
path.join(basehubModulePath, "src", "react", "pump", "index.ts"),
],
bundle: true,
outdir: reactPumpOutDir,
minify: false,
treeShaking: true,
splitting: true,
format: "esm",
target: ["es2020", "node18"],
external: peerDependencies,
plugins: [useClientPlugin],
});

if (args["--debug"]) {
console.log(
`[basehub] compiled react pump with esbuild in: ${reactPumpOutDir}`
);
}

await esbuild.build({
entryPoints: [
path.join(basehubModulePath, "src", "next", "toolbar", "index.ts"),
],
bundle: true,
outdir: nextToolbarOutDir,
minify: false,
treeShaking: true,
splitting: true,
format: "esm",
target: ["es2020", "node18"],
external: peerDependencies,
plugins: [ScssModulesPlugin(), useClientPlugin],
});

if (args["--debug"]) {
console.log(
`[basehub] compiled next toolbar with esbuild in: ${nextToolbarOutDir}`
);
}

/**
* DTS stuff.
Expand All @@ -343,6 +371,13 @@ R extends Omit<MutationGenqlSelection, "transaction" | "transactionAwaitable"> &
nextToolbarOutDir
);

if (args["--debug"]) {
console.log(`[basehub] copied dts for react pump to: ${reactPumpOutDir}`);
console.log(
`[basehub] copied dts for next toolbar to: ${nextToolbarOutDir}`
);
}

appendGeneratedCodeBanner(basehubOutputPath, args["--banner"]);

if (output !== "node_modules") {
Expand Down Expand Up @@ -445,6 +480,18 @@ R extends Omit<MutationGenqlSelection, "transaction" | "transactionAwaitable"> &
path.join(nextToolbarOutDir, "index.d.ts")
)}";`
);

if (args["--debug"]) {
console.log(
`[basehub] aliased index.js and index.d.ts to: ${basehubOutputPath}`
);
console.log(
`[basehub] aliased react pump index.js and index.d.ts to: ${reactPumpOutDir}`
);
console.log(
`[basehub] aliased next toolbar index.js and index.d.ts to: ${nextToolbarOutDir}`
);
}
}

if (shouldAppendToGitIgnore) {
Expand Down Expand Up @@ -497,12 +544,37 @@ R extends Omit<MutationGenqlSelection, "transaction" | "transactionAwaitable"> &
2
)
);

if (args["--debug"]) {
console.log(`[basehub] wrote build manifest to: ${buildManifestPath}`);
}
}

logIfNotSilent(
silent,
`🪄 Generated \`basehub\` client in ${Date.now() - now}ms`
);

if (args["--debug"]) {
console.log(`[basehub] finished in ${Date.now() - now}ms`);
console.log(
`[basehub] checking if the generated client exists after 1 second`
);

await new Promise((resolve) => {
setTimeout(() => {
resolve(null);
console.log(
`[basehub] generated client exists? ${
fs.existsSync(path.join(basehubOutputPath, "index.js"))
? "YES"
: "NO"
}`
);
}, 1000);
});
}

return {
preventedClientGeneration,
schemaHash,
Expand Down
7 changes: 7 additions & 0 deletions playground/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# playground

## 0.0.153

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.152

### Patch Changes
Expand Down
5 changes: 3 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "playground",
"private": true,
"version": "0.0.152",
"version": "0.0.153",
"scripts": {
"dev": "basehub dev & next dev --port 3003",
"build": "basehub && next build",
"build:analyze": "cross-env ANALYZE=true pnpm build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"generate": "basehub"
},
"dependencies": {
"basehub": "workspace:*",
Expand Down

0 comments on commit 5981118

Please sign in to comment.