forked from architect/sveltekit-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (55 loc) · 1.99 KB
/
index.js
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
62
63
64
65
66
67
68
import { readFileSync, existsSync, writeFileSync } from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import esbuild from 'esbuild'
const { resolve, join } = path
const __dirname = path.dirname(new URL(import.meta.url).pathname)
/**
* @typedef {import('esbuild').BuildOptions} BuildOptions
*/
/**
* @param {{
* esbuild?: (defaultOptions: BuildOptions) => Promise<BuildOptions> | BuildOptions;
* }} [options]
**/
export default function (options) {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: '@architect/sveltekit-adapter',
async adapt({ utils }) {
const files = fileURLToPath(new URL('./files', import.meta.url))
utils.log.minor('verifying app.arc manifest exists')
if (!existsSync('app.arc')) {
utils.log.minor('adding architect manifest app.arc')
utils.copy(join(files, 'app.arc'), 'app.arc')
}
utils.log.minor('bundling server for lambda...')
utils.copy(join(files, 'entry.js'), '.svelte-kit/begin/entry.js')
/** @type {BuildOptions} */
const defaultOptions = {
entryPoints: ['.svelte-kit/begin/entry.js'],
outfile: join('.svelte-kit', 'begin', 'sveltekit-render', 'index.js'),
bundle: true,
external: ['aws-sdk'],
inject: [join(files, 'shims.js')],
platform: 'node'
}
const buildOptions =
options && options.esbuild ? await options.esbuild(defaultOptions) : defaultOptions
await esbuild.build(buildOptions)
const static_directory = resolve('.svelte-kit', 'begin', 'public')
utils.log.minor('Writing client application...')
utils.copy_static_files(static_directory)
utils.copy_client_files(static_directory)
writeFileSync(
join('.svelte-kit', 'begin', 'sveltekit-render', 'package.json'),
'{"module":"commonjs"}'
)
utils.log.minor('Prerendering static pages...')
await utils.prerender({
dest: static_directory
})
}
}
return adapter
}