Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 6c1342f

Browse files
Merge pull request #18 from pattern-lab/dev
2.0.2
2 parents 2e0d5a9 + ecd289e commit 6c1342f

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

.eslintrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"builtin": true,
55
"es6": true
66
},
7+
"parserOptions": {
8+
"ecmaVersion": 6,
9+
"sourceType": "module"
10+
},
711
"globals": {},
812
"rules": {
913
"block-scoped-var": 0,
@@ -61,14 +65,14 @@
6165
"no-undef": 2,
6266
"no-underscore-dangle": 0,
6367
"no-unreachable": 1,
64-
"no-unused-vars": 0,
68+
"no-unused-vars": 1,
6569
"no-use-before-define": 1,
6670
"no-useless-call": 2,
6771
"no-useless-concat": 2,
6872
"no-with": 2,
6973
"quotes": [0, "single"],
7074
"radix": 2,
71-
"semi": [0, "never"],
75+
"semi": [1, "always"],
7276
"strict": 0,
7377
"space-before-blocks": 1,
7478
"space-before-function-paren": [1, {

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Or add it directly to your project's `package.json` file and run `npm install`
1818

1919
During installation, the plugin is added as a key to the `plugins` object in your main Pattern Lab project's `patternlab-config.json` file
2020

21+
> If you don't see this object, try running `npm run postinstall` within the root of your project.
22+
2123
## Configuration
2224

2325
Post-installation, you will see the following in your `patternlab-config.json`:

dist/js/plugin-node-tab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var PluginTab = {
22

33
/**
4-
* The function defined as the onready callback within the plugin configuration.
4+
* The function defined as the onready callback within the plugin configuration.
55
*/
66
init: function () {
77

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const glob = require('glob');
77
const path = require('path');
88
const EOL = require('os').EOL;
99
const tab_loader = require('./src/tab-loader');
10-
const config = require('./config.json');
1110

1211
function writeConfigToOutput(patternlab, pluginConfig) {
1312
var pluginConfigPathName = path.resolve(patternlab.config.paths.public.root, 'patternlab-components', 'packages');
@@ -46,7 +45,7 @@ function getPluginFrontendConfig() {
4645
'javascripts':['patternlab-components\/pattern-lab\/' + pluginName + '\/js\/' + pluginName + '.js'],
4746
'onready':'PluginTab.init()',
4847
'callback':''
49-
}
48+
};
5049
}
5150

5251
/**
@@ -102,12 +101,14 @@ function pluginInit(patternlab) {
102101
//we are also being a bit lazy here, since we only expect one file
103102
let tabJSFileContents = fs.readFileSync(pluginFiles[i], 'utf8');
104103
var snippetString = '';
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());
107-
snippetString += tabSnippetLocal + EOL;
104+
if (pluginConfig.tabsToAdd && pluginConfig.tabsToAdd.length > 0) {
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());
107+
snippetString += tabSnippetLocal + EOL;
108+
}
109+
tabJSFileContents = tabJSFileContents.replace('/*SNIPPETS*/', snippetString);
110+
fs.outputFileSync(writePath, tabJSFileContents);
108111
}
109-
tabJSFileContents = tabJSFileContents.replace('/*SNIPPETS*/', snippetString);
110-
fs.outputFileSync(writePath, tabJSFileContents);
111112
}
112113
} catch (ex) {
113114
console.trace('plugin-node-tab: Error occurred while copying pluginFile', pluginFiles[i]);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plugin-node-tab",
3-
"version": "2.0.0",
3+
"version": "2.0.2",
44
"description": "",
55
"main": "index.js",
66
"dependencies": {
@@ -12,7 +12,7 @@
1212
"url": "git+https://github.com/pattern-lab/plugin-node-tab.git"
1313
},
1414
"scripts": {
15-
"test": "eslint dist/** src/** index.js postinstall.js",
15+
"test": "eslint src/** index.js postinstall.js",
1616
"postinstall": "node ./postinstall.js"
1717
},
1818
"author": "Brian Muenzenmeyer",

postinstall.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
console.log('Pattern Lab Node Plugin - "plugin-node-tab" installed. ');
2+
console.log('You may have to run `npm run postinstall` from your console as well.');
23
console.log('Configure or disable this plugin inside your patternlab-config.json file.');
34
console.log('Add tabs to the Pattern Lab UI by adding file extensions to the "tabsToAdd" array on the plugins.plugin-node-tab.options object.');

src/tab-loader.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"use strict";
22

3-
const fs = require('fs-extra'),
4-
path = require('path'),
5-
fileTypes = require('./../package.json').fileTypes;
3+
const fs = require('fs-extra');
4+
const path = require('path');
65

76
/**
87
* The backend method that is called during the patternlab-pattern-write-end event.
@@ -12,6 +11,9 @@ const fs = require('fs-extra'),
1211
*/
1312
function findTab(patternlab, pattern) {
1413

14+
//read the filetypes from the configuration
15+
const fileTypes = patternlab.config.plugins['plugin-node-tab'].options.tabsToAdd;
16+
1517
//exit if either of these two parameters are missing
1618
if (!patternlab) {
1719
console.error('plugin-node-tab: patternlab object not provided to findTab');
@@ -28,9 +30,10 @@ function findTab(patternlab, pattern) {
2830

2931
//loop through all configured types
3032
for (let i = 0; i < fileTypes.length; i++) {
33+
const fileType = fileTypes[i].toLowerCase();
3134

32-
customFileTypePath = customFileTypePath.substr(0, customFileTypePath.lastIndexOf(".")) + '.' + fileTypes[i];
33-
var customFileTypeOutputPath = patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'custom', '.' + fileTypes[i]);
35+
customFileTypePath = customFileTypePath.substr(0, customFileTypePath.lastIndexOf(".")) + '.' + fileType;
36+
var customFileTypeOutputPath = patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'custom', '.' + fileType);
3437

3538
//look for a custom filetype for this template
3639
try {

0 commit comments

Comments
 (0)