Skip to content

Commit

Permalink
Added sync API for building backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinbrown authored and rich-exogee committed Mar 7, 2023
1 parent ac44131 commit 7522470
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 25 deletions.
52 changes: 28 additions & 24 deletions graphweaver.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@
"name": "✨ root",
"path": "."
},
{
"name": "➡️ Example: Complex",
"path": "src/examples/example-complex"
},
{
"name": "➡️ Example: Complex with Migrations",
"path": "src/examples/example-complex-migrations"
},
{
"name": "➡️ Example: Xero",
"path": "src/examples/example-xero"
},
{
"name": "📦 @exogee/create-graphweaver",
"path": "src/packages/create-graphweaver"
},
{
"name": "📦 @exogee/graphweaver",
"path": "src/packages/core"
},
{
"name": "📦 @exogee/graphweaver-admin-ui",
"path": "src/packages/admin-ui"
Expand All @@ -36,10 +16,26 @@
"name": "📦 @exogee/graphweaver-apollo",
"path": "src/packages/apollo"
},
{
"name": "📦 @exogee/graphweaver-builder",
"path": "src/packages/builder"
},
{
"name": "📦 @exogee/graphweaver-cli",
"path": "src/packages/cli"
},
{
"name": "📦 @exogee/graphweaver",
"path": "src/packages/core"
},
{
"name": "📦 @exogee/create-graphweaver",
"path": "src/packages/create-graphweaver"
},
{
"name": "📦 @exogee/logger",
"path": "src/packages/logger"
},
{
"name": "📦 @exogee/graphweaver-mikroorm",
"path": "src/packages/mikroorm"
Expand All @@ -56,17 +52,25 @@
"name": "📦 @exogee/graphweaver-scalars",
"path": "src/packages/scalars"
},
{
"name": "📦 vite-plugin-graphweaver",
"path": "src/packages/vite-plugin-graphweaver"
},
{
"name": "📦 @exogee/graphweaver-xero",
"path": "src/packages/xero"
},
{
"name": "📦 @exogee/logger",
"path": "src/packages/logger"
"name": "➡️ Example: Complex",
"path": "src/examples/example-complex"
},
{
"name": "📦 vite-plugin-graphweaver",
"path": "src/packages/vite-plugin-graphweaver"
"name": "➡️ Example: Complex with Migrations",
"path": "src/examples/example-complex-migrations"
},
{
"name": "➡️ Example: Xero",
"path": "src/examples/example-xero"
}
],
"settings": {}
Expand Down
41 changes: 40 additions & 1 deletion src/packages/builder/src/build/backend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { build } from 'esbuild';
import { build, buildSync } from 'esbuild';
import rimrafCallback from 'rimraf';
import { promisify } from 'util';
import {
Expand Down Expand Up @@ -68,3 +68,42 @@ export const buildBackend = async (_: BackendBuildOptions) => {
//
// We'll kill it with a process.exit(0) out in the main file when we know we're done.
};

export const buildBackendSync = (_: BackendBuildOptions) => {
// Clear the folder
rimrafCallback.sync(path.join('.graphweaver', 'backend'));

// Are there any custom additional functions we need to build?
// If so, merge them in.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { backend } = require(path.join(process.cwd(), 'graphweaver-config'));

const functions: AdditionalFunctionConfig[] = [
{
handlerPath: './src/backend/index',
},
...backend.additionalFunctions,
];

if (Array.isArray(backend.additionalFunctions)) {
for (const backendFunction of functions) {
// TODO: Better validation
if (backendFunction.handlerPath) {
buildSync({
...baseEsbuildConfig,

plugins: [makeOptionalMikroOrmPackagesExternalPlugin()],

entryPoints: [inputPathFor(backendFunction.handlerPath)],
outfile: `${buildOutputPathFor(backendFunction.handlerPath)}.js`,
});
}
}
}

// Note, this will leave the ESBuild service process around:
// https://github.com/evanw/esbuild/issues/985
// console.log('Handles: ', (process as any)._getActiveHandles());
//
// We'll kill it with a process.exit(0) out in the main file when we know we're done.
};

0 comments on commit 7522470

Please sign in to comment.