|
2 | 2 |
|
3 | 3 | const pluginName = 'plugin-node-tab'; |
4 | 4 |
|
5 | | -const fs = require('fs-extra'), |
6 | | - glob = require('glob'), |
7 | | - path = require('path'), |
8 | | - EOL = require('os').EOL, |
9 | | - tab_loader = require('./src/tab-loader'); |
| 5 | +const fs = require('fs-extra'); |
| 6 | +const glob = require('glob'); |
| 7 | +const path = require('path'); |
| 8 | +const EOL = require('os').EOL; |
| 9 | +const tab_loader = require('./src/tab-loader'); |
| 10 | +const config = require('./config.json'); |
| 11 | + |
| 12 | +function writeConfigToOutput(patternlab, pluginConfig) { |
| 13 | + var pluginConfigPathName = path.resolve(patternlab.config.paths.public.root, 'patternlab-components', 'packages'); |
| 14 | + try { |
| 15 | + fs.outputFileSync(pluginConfigPathName + '/' + pluginName + '.json', JSON.stringify(pluginConfig, null, 2)); |
| 16 | + } catch (ex) { |
| 17 | + console.trace(pluginName + ': Error occurred while writing pluginFile configuration'); |
| 18 | + console.log(ex); |
| 19 | + } |
| 20 | +} |
10 | 21 |
|
11 | 22 | function onPatternIterate(patternlab, pattern) { |
12 | 23 | tab_loader(patternlab, pattern); |
@@ -49,10 +60,11 @@ function pluginInit(patternlab) { |
49 | 60 | process.exit(1); |
50 | 61 | } |
51 | 62 |
|
52 | | - let fileTypes = require('./package.json').fileTypes; |
53 | | - |
54 | 63 | //write the plugin json to public/patternlab-components |
55 | 64 | var pluginConfig = getPluginFrontendConfig(); |
| 65 | + pluginConfig.tabsToAdd = patternlab.config.plugins[pluginName].options.tabsToAdd; |
| 66 | + writeConfigToOutput(patternlab, pluginConfig); |
| 67 | + |
56 | 68 | var pluginConfigPathName = path.resolve(patternlab.config.paths.public.root, 'patternlab-components', 'packages'); |
57 | 69 | try { |
58 | 70 | fs.outputFileSync(pluginConfigPathName + '/' + pluginName + '.json', JSON.stringify(pluginConfig, null, 2)); |
@@ -90,8 +102,8 @@ function pluginInit(patternlab) { |
90 | 102 | //we are also being a bit lazy here, since we only expect one file |
91 | 103 | let tabJSFileContents = fs.readFileSync(pluginFiles[i], 'utf8'); |
92 | 104 | var snippetString = ''; |
93 | | - for (let j = 0; j < fileTypes.length; j++) { |
94 | | - let tabSnippetLocal = tab_frontend_snippet.replace(/<<type>>/g, fileTypes[j]).replace(/<<typeUC>>/g, fileTypes[j].toUpperCase()); |
| 105 | + for (let j = 0; j < pluginConfig.tabsToAdd.length; j++) { |
| 106 | + let tabSnippetLocal = tab_frontend_snippet.replace(/<<type>>/g, pluginConfig.tabsToAdd[j]).replace(/<<typeUC>>/g, pluginConfig.tabsToAdd[j].toUpperCase()); |
95 | 107 | snippetString += tabSnippetLocal + EOL; |
96 | 108 | } |
97 | 109 | tabJSFileContents = tabJSFileContents.replace('/*SNIPPETS*/', snippetString); |
|
0 commit comments