-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (42 loc) · 1.41 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
import fs from 'fs-extra';
import tomlify from 'tomlify-j0.4';
import merge from 'deepmerge';
import { writeFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
const DEFAULT_OPTIONS = {
out: 'build',
wrangler: {
type: 'webpack',
account_id: '',
workers_dev: true,
route: '',
zone_id: '',
webpack_config: './webpack.config.cjs',
site: {
bucket: './assets',
'entry-point': '.',
},
},
};
export default async function adapter(builder, options = DEFAULT_OPTIONS) {
const dir = dirname(fileURLToPath(import.meta.url));
const out = options.out || DEFAULT_OPTIONS.out;
builder.log.minor('Writing client application...');
const static_directory = join(out, 'assets');
builder.copy_client_files(static_directory);
builder.copy_static_files(static_directory);
builder.log.minor('Building server');
builder.copy_server_files(out);
builder.log.minor('Writing worker project...');
const worker_directory = join(dir, 'files');
fs.copySync(worker_directory, out);
builder.log.minor('Writing wrangler config file...');
const wrangler_file = join(out, 'wrangler.toml');
const wrangler_config = merge(DEFAULT_OPTIONS.wrangler, options.wrangler);
writeFileSync(wrangler_file, tomlify.toToml(wrangler_config));
builder.log.minor('Prerendering static pages...');
await builder.prerender({
dest: `${out}/prerendered`,
});
}