-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
61 lines (49 loc) · 1.62 KB
/
build.mjs
File metadata and controls
61 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
import { build } from 'esbuild';
import { glob } from 'glob';
import { mkdir } from 'fs/promises';
import { dirname } from 'path';
/**
* Build script for AppSync resolver functions
* Compiles TypeScript files from backend/src/gql-functions to backend/lib/gql-functions
*/
const buildAppsyncFunctions = async () => {
console.log('Building AppSync functions...');
try {
// Find all AppSync function files
const files = await glob('backend/src/gql-functions/**/*.ts', {
ignore: ['**/*.spec.ts', '**/*.test.ts'],
});
if (files.length === 0) {
console.log('No AppSync functions found to build.');
return;
}
console.log(`Found ${files.length} AppSync function(s) to build`);
// Ensure output directory exists
await mkdir('backend/lib/gql-functions', { recursive: true });
// Build each file
for (const file of files) {
const outfile = file.replace('backend/src/gql-functions', 'backend/lib/gql-functions').replace('.ts', '.js');
// Ensure output directory exists
await mkdir(dirname(outfile), { recursive: true });
await build({
entryPoints: [file],
bundle: true,
platform: 'node',
target: 'es2020',
format: 'esm',
outfile,
external: ['@aws-appsync/utils'],
minify: false,
sourcemap: false,
});
console.log(`Built: ${file} -> ${outfile}`);
}
console.log('AppSync functions built successfully!');
} catch (error) {
console.error('Error building AppSync functions:', error);
process.exit(1);
}
};
// Run the build
buildAppsyncFunctions();