-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathvox.js
33 lines (28 loc) · 876 Bytes
/
vox.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
import path from 'path';
import fs from 'fs';
import {fillTemplate, createRelativeFromAbsolutePath, parseIdHash} from '../util.js';
const dirname = path.dirname(import.meta.url.replace(/^[a-z]+:\/\//, ''));
const templateString = fs.readFileSync(path.join(dirname, '..', 'type_templates', 'vox.js'), 'utf8');
// const cwd = process.cwd();
export default {
load(id) {
id = createRelativeFromAbsolutePath(id);
const {
contentId,
name,
description,
components,
} = parseIdHash(id);
const code = fillTemplate(templateString, {
srcUrl: JSON.stringify(id),
contentId: JSON.stringify(contentId),
name: JSON.stringify(name),
description: JSON.stringify(description),
components: JSON.stringify(components),
});
return {
code,
map: null,
};
},
};