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

Commit d7b0f15

Browse files
committed
post install that inquires user for which tab(s) to add
eslinting more code closes #1
1 parent 205de4b commit d7b0f15

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"env": {
33
"node": true,
4-
"builtin": true
4+
"builtin": true,
5+
"es6": true
56
},
67
"globals": {},
78
"rules": {

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function onPatternIterate(patternlab, pattern) {
1515
* Define what events you wish to listen to here
1616
* @param patternlab - global data store which has the handle to the event emitter
1717
*/
18-
function registerEvents(patternlab){
18+
function registerEvents(patternlab) {
1919

2020
//TODO: list all possible events
2121
patternlab.events.on('patternlab-pattern-write-end', onPatternIterate);
@@ -41,7 +41,7 @@ function getPluginFrontendConfig() {
4141
*/
4242
function pluginInit(patternlab) {
4343

44-
if(!patternlab) {
44+
if (!patternlab) {
4545
console.error('patternlab object not provided to plugin-init');
4646
process.exit(1);
4747
}
@@ -71,7 +71,7 @@ function pluginInit(patternlab) {
7171
var fileStat = fs.statSync(pluginFiles[i]);
7272
if (fileStat.isFile()) {
7373
var relativePath = path.relative(__dirname, pluginFiles[i]).replace('dist', ''); //dist is dropped
74-
var writePath = path.join(patternlab.config.paths.public.root,'patternlab-components', 'pattern-lab', pluginName, relativePath);
74+
var writePath = path.join(patternlab.config.paths.public.root, 'patternlab-components', 'pattern-lab', pluginName, relativePath);
7575
fs.copySync(pluginFiles[i], writePath);
7676
}
7777
} catch (ex) {

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
"main": "index.js",
66
"dependencies": {
77
"fs-extra": "^0.30.0",
8-
"glob": "^7.0.0"
8+
"glob": "^7.0.0",
9+
"inquirer": "^1.1.3"
910
},
1011
"repository": {
1112
"type": "git",
1213
"url": "git+https://github.com/pattern-lab/plugin-node-tab.git"
1314
},
1415
"scripts": {
15-
"test": "eslint dist/** src/**"
16+
"test": "eslint dist/** src/** index.js postinstall.js",
17+
"post_install": "node ./postinstall.js"
1618
},
1719
"author": "Brian Muenzenmeyer",
1820
"license": "MIT",

postinstall.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
const fs = require('fs-extra'),
4+
glob = require('glob'),
5+
inquirer = require('inquirer');
6+
7+
let config = require('./package.json');
8+
let fileTypes = [];
9+
10+
var questions = [
11+
{
12+
type: 'input',
13+
name: 'types',
14+
message: 'Specify filetype(s) to create a tab for. Separate multiple filetypes with a space, pipe or comma. Example: js css >>> '
15+
}
16+
];
17+
18+
inquirer
19+
.prompt(questions)
20+
.then(function (answers) {
21+
22+
fileTypes = answers.types.split(/,| /);
23+
24+
if (fileTypes.length === 1 && fileTypes[0] === '') {
25+
console.log('No filetype(s) provided. Returning unconfigured!');
26+
return;
27+
}
28+
29+
for (let i = 0; i < fileTypes.length; i++) {
30+
if (fileTypes[i].charAt(0) !== '.') {
31+
fileTypes[i] = '.' + fileTypes[i];
32+
}
33+
}
34+
35+
console.log('Adding configuration for tabs', fileTypes, 'inside package.json');
36+
config.fileTypes = fileTypes;
37+
fs.outputFileSync('./package.json', JSON.stringify(config, null, 2), 'utf-8');
38+
});
39+

0 commit comments

Comments
 (0)