-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess-custom-blocks.js
41 lines (37 loc) · 1.1 KB
/
process-custom-blocks.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
const { getVueJestConfig, getCustomTransformer } = require('./utils');
const vueOptionsNamespace = require('./constants').vueOptionsNamespace;
function applyTransformer(
transformer,
blocks,
vueOptionsNamespace,
filename,
config,
) {
return transformer.process({ blocks, vueOptionsNamespace, filename, config });
}
function groupByType(acc, block) {
acc[block.type] = acc[block.type] || [];
acc[block.type].push(block);
return acc;
}
module.exports = function (allBlocks, filename, config) {
const blocksByType = allBlocks.reduce(groupByType, {});
const code = [];
for (const [type, blocks] of Object.entries(blocksByType)) {
const transformer = getCustomTransformer(
getVueJestConfig(config).transform,
type,
);
if (transformer) {
const codeStr = applyTransformer(
transformer,
blocks,
vueOptionsNamespace,
filename,
config,
);
code.push(codeStr);
}
}
return code.length ? code.join('\n') : '';
};