UNPKG

1.06 kBJavaScriptView Raw
1const SETTINGS_SCHEMA_PATH = '../config/settings_schema.json';
2const THEME_INFO_PANEL = 'theme_info';
3
4function FileListPlugin(version) {
5 this.version = version;
6}
7
8FileListPlugin.prototype.apply = function(compiler) {
9 compiler.hooks.emit.tap('Slate Tag Plugin', (compilation) => {
10 const asset = compilation.assets[SETTINGS_SCHEMA_PATH].source();
11 const schema = JSON.parse(asset);
12
13 const themeInfo = findThemeInfoPanel(schema);
14
15 if (themeInfo) {
16 /* eslint-disable-next-line camelcase */
17 themeInfo.theme_packaged_with = `@shopify/slate-tools@${this.version}`;
18 }
19
20 const jsonString = JSON.stringify(schema);
21
22 compilation.assets[SETTINGS_SCHEMA_PATH] = {
23 source() {
24 return jsonString;
25 },
26 size() {
27 return jsonString.length;
28 },
29 };
30 });
31};
32
33function findThemeInfoPanel(schema) {
34 if (!Array.isArray(schema)) {
35 return null;
36 }
37
38 return schema.find((panel) => {
39 return typeof panel === 'object' && panel.name === THEME_INFO_PANEL;
40 });
41}
42
43module.exports = FileListPlugin;