forked from furkleindustries/inklecate-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (48 loc) · 1.14 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
const { inklecate } = require('inklecate');
const { getOptions } = require('loader-utils');
const { validate } = require('schema-utils');
const schema = {
type: 'object',
properties: {
countAllVisits: {
type: 'boolean',
},
inputFilepath: {
type: 'string',
},
verbose: {
type: 'boolean',
},
DEBUG: {
type: 'boolean',
},
},
};
module.exports = function InkWebpackLoader(content, map, meta) {
const options = getOptions(this) || {};
validate(schema, options, 'InklecateLoader');
const callback = this.async();
const inklecateOpts = {
countAllVisits: Boolean(options.countAllVisits),
inputFilepath: this.resourcePath,
verbose: Boolean(options.verbose),
DEBUG: Boolean(options.DEBUG),
};
inklecate(inklecateOpts).then(
function resolved(data) {
callback(
null,
`module.exports = ${JSON.stringify({
compilerOutput: data.compilerOutput,
storyContent: data.storyContent,
text: content.trim(),
})};\n`,
map,
meta
);
},
function rejected(err) {
return callback(typeof err === Error ? err : new Error(err));
}
);
};