-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (44 loc) · 1.49 KB
/
index.js
File metadata and controls
55 lines (44 loc) · 1.49 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
import { readFileSync, existsSync } from 'fs';
import { resolve, join } from 'path';
import parse from '@architect/parser';
/** @param {string} file */
function parse_arc(file) {
if (!existsSync(file)) {
throw new Error(`No ${file} found. See the documentation.`);
}
try {
const text = readFileSync(file).toString();
const arc = parse(text);
return {
static: arc.static[0][1]
};
} catch (e) {
throw new Error(`Error parsing ${file}. Please consult the documentation for correct syntax.`);
}
}
export default function () {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: '@sveltejs/adapter-begin',
async adapt(builder) {
builder.log.minor('Parsing app.arc file');
const { static: static_mount_point } = parse_arc('app.arc');
const lambda_directory = resolve(join('src', 'http', 'get-index'));
const static_directory = resolve(static_mount_point);
const server_directory = resolve(join('src', 'shared'));
builder.log.minor('Writing client application...');
builder.copy_static_files(static_directory);
builder.copy_client_files(static_directory);
builder.log.minor('Building lambda...');
const local_lambda_dir = join(__dirname, 'files');
builder.copy(local_lambda_dir, lambda_directory);
builder.log.minor('Writing server application...');
builder.copy_server_files(server_directory);
builder.log.minor('Prerendering static pages...');
await builder.prerender({
dest: static_directory
});
}
};
return adapter;
}