Skip to content

Commit 80aa5b7

Browse files
author
Brian Muenzenmeyer
committed
Merge pull request #341 from pattern-lab/starterkit-manager
Basic Starterkit manager support
2 parents 591e60e + df8d175 commit 80aa5b7

File tree

2 files changed

+78
-8
lines changed

2 files changed

+78
-8
lines changed

core/lib/patternlab.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v2.0.0 - 2016
3-
*
1+
/*
2+
* patternlab-node - v2.0.0 - 2016
3+
*
44
* Brian Muenzenmeyer, Geoff Pursell, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -75,14 +75,14 @@ var patternlab_engine = function (config) {
7575
buildFrontEnd = require('./ui_builder'),
7676
he = require('html-entities').AllHtmlEntities,
7777
plutils = require('./utilities'),
78+
sm = require('./starterkit_manager'),
7879
patternlab = {};
7980

80-
patternlab.package = fs.readJSONSync('./package.json');
81+
patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json'));
8182
patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json'));
8283

8384
var paths = patternlab.config.paths;
8485

85-
8686
function getVersion() {
8787
console.log(patternlab.package.version);
8888
}
@@ -132,7 +132,15 @@ var patternlab_engine = function (config) {
132132
}
133133
}
134134

135+
function listStarterkits() {
136+
var starterkit_manager = new sm(patternlab);
137+
return starterkit_manager.list_starterkits();
138+
}
135139

140+
function loadStarterKit(starterkitName) {
141+
var starterkit_manager = new sm(patternlab);
142+
starterkit_manager.load_starterkit(starterkitName);
143+
}
136144

137145
function buildPatterns(deletePatternDir) {
138146
try {
@@ -313,6 +321,12 @@ var patternlab_engine = function (config) {
313321
build_patterns_only: function (deletePatternDir) {
314322
buildPatterns(deletePatternDir);
315323
printDebug();
324+
},
325+
list_starterkits: function () {
326+
return listStarterkits();
327+
},
328+
load_starterkit: function (starterkitName) {
329+
loadStarterKit(starterkitName);
316330
}
317331
};
318332
};

core/lib/starterkit_manager.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"use strict";
2+
3+
var starterkit_manager = function (pl) {
4+
var path = require('path'),
5+
fs = require('fs-extra'),
6+
JSON5 = require('json5'),
7+
_ = require('lodash'),
8+
paths = pl.config.paths;
9+
10+
function loadStarterKit(starterkitName) {
11+
try {
12+
var kitPath = path.resolve(
13+
path.join(process.cwd(), 'node_modules', starterkitName, pl.config.starterkitSubDir)
14+
);
15+
var kitPathDirExists = fs.statSync(kitPath).isDirectory();
16+
if (kitPathDirExists) {
17+
18+
//todo check and prompt user is paths().source is not empty
19+
20+
fs.copy(kitPath, paths.source.root, function(ex) {
21+
if (ex) {
22+
console.error(ex);
23+
}
24+
console.log('starterkit ' + starterkitName + ' loaded successfully.');
25+
});
26+
27+
}
28+
} catch (ex) {
29+
console.log(ex);
30+
console.log(starterkitName + ' not found, please use npm to install it first');
31+
}
32+
}
33+
34+
function listStarterkits() {
35+
console.log('https://github.com/search?utf8=%E2%9C%93&q=starterkit+in%3Aname%2C+user%3Apattern-lab&type=Repositories&ref=searchresults');
36+
}
37+
38+
function packStarterkit() {
39+
40+
}
41+
42+
return {
43+
load_starterkit: function (starterkitName) {
44+
loadStarterKit(starterkitName);
45+
},
46+
list_starterkits: function () {
47+
listStarterkits();
48+
},
49+
pack_starterkit: function () {
50+
packStarterkit();
51+
}
52+
};
53+
54+
};
55+
56+
module.exports = starterkit_manager;

0 commit comments

Comments
 (0)