Skip to content

Commit 0c26f9f

Browse files
Merge pull request #807 from pattern-lab/feature/refactor-help
Split out help logs into an external function
2 parents f7c70b8 + 62cd8fb commit 0c26f9f

File tree

3 files changed

+53
-84
lines changed

3 files changed

+53
-84
lines changed

packages/core/src/index.js

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const copy = require('recursive-copy');
1717
const path = require('path');
1818
const updateNotifier = require('update-notifier');
1919

20+
const help = require('./lib/help');
2021
const events = require('./lib/events');
2122
const logger = require('./lib/log');
2223
const PatternGraph = require('./lib/pattern_graph').PatternGraph;
@@ -59,89 +60,6 @@ const patternlab_module = function(config) {
5960
const patternlab = new PatternLab(config);
6061
const paths = patternlab.config.paths;
6162

62-
function help() {
63-
logger.info('');
64-
65-
logger.info('Pattern Lab Node v' + patternlab.package.version);
66-
67-
logger.info('');
68-
logger.info('Usage: patternlab.<FUNCTION_NAME>()');
69-
logger.info('');
70-
71-
logger.info(' build');
72-
logger.info(
73-
' > builds patterns, copies assets, and constructs ui into config.paths.public'
74-
);
75-
logger.info('');
76-
77-
logger.info(' patternsonly');
78-
logger.info(
79-
' > builds patterns only, leaving existing public files intact'
80-
);
81-
logger.info('');
82-
83-
logger.info(' version');
84-
logger.info(' > logs current version');
85-
logger.info('');
86-
87-
logger.info(' v');
88-
logger.info(' > return current version as a string');
89-
logger.info('');
90-
91-
logger.info(' help');
92-
logger.info(
93-
' > logs more information about patternlab-node, pattern lab in general, and where to report issues.'
94-
);
95-
logger.info('');
96-
97-
logger.info(' liststarterkits');
98-
logger.info(
99-
' > fetches starterkit repos from pattern-lab github org that contain "starterkit" in their name'
100-
);
101-
logger.info('');
102-
103-
logger.info(' loadstarterkit');
104-
logger.info(
105-
' > loads starterkit already available via `node_modules/` into config.paths.source/*'
106-
);
107-
logger.info(
108-
' > NOTE: Overwrites existing content, and only cleans out existing directory if --clean=true argument is passed.'
109-
);
110-
logger.info(
111-
' > NOTE: In most cases, `npm install starterkit-name` will precede this call.'
112-
);
113-
logger.info(' > parameters:');
114-
logger.info(' kit:string ');
115-
logger.info(' > the name of the starter kit to load');
116-
logger.info(' clean:bool ');
117-
logger.info(
118-
' > whether or not to remove all files from config.paths.source/ prior to load'
119-
);
120-
logger.info(' > example:');
121-
logger.info(
122-
' `patternlab.loadstarterkit("starterkit-mustache-demo", true)'
123-
);
124-
logger.info('');
125-
126-
// installplugin
127-
// serve
128-
// getSupportedTemplateExtensions
129-
// events
130-
// getDefaultConfig
131-
132-
logger.info('===============================');
133-
logger.info('');
134-
logger.info('Visit http://patternlab.io/ for more info about Pattern Lab');
135-
logger.info(
136-
'Visit https://github.com/pattern-lab/patternlab-node/issues to open an issue.'
137-
);
138-
logger.info(
139-
'Visit https://github.com/pattern-lab/patternlab-node/wiki to view the changelog, roadmap, and other info.'
140-
);
141-
logger.info('');
142-
logger.info('===============================');
143-
}
144-
14563
/**
14664
* If a graph was serialized and then {@code deletePatternDir == true}, there is a mismatch in the
14765
* pattern metadata and not all patterns might be recompiled.
@@ -438,7 +356,7 @@ const patternlab_module = function(config) {
438356
* @returns {void} pattern lab API usage, as console output
439357
*/
440358
help: function() {
441-
help();
359+
logger.info(help(patternlab.package.version));
442360
},
443361

444362
/**

packages/core/src/lib/help.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
/**
4+
* @function help
5+
* @desc A small helper function returning the man page string
6+
* @param {string} version - The version to include in the string literal
7+
* @return {string} - The man string
8+
*/
9+
const help = version => `
10+
Pattern Lab Node v${version}
11+
12+
Usage: patternlab.<FUNCTION>()
13+
14+
Functions:
15+
16+
build Builds patterns, copies assets, and constructs ui into config.paths.public
17+
patternsonly Builds patterns only, leaving existing public files intact
18+
liststarterkits Fetches starterkit repos from pattern-lab github org
19+
loadstarterkit Loads starterkit already available via node_modules/ into config.paths.source/*
20+
NOTE: In most cases, npm install starterkit-name will precede this call.
21+
Parameters:
22+
kit The name of the starter kit to load (string)
23+
clean Whether or not to remove all files from config.paths.source/ prior to load (bool)
24+
NOTE: Overwrites existing content. Prunes existing directory if --clean=true argument is passed.
25+
version Logs current version to stdout
26+
v Return current version as a string
27+
28+
===============================
29+
- More info about Pattern Lab: http://patternlab.io/
30+
- Open an issue: https://github.com/pattern-lab/patternlab-node/issues
31+
- View the changelog, roadmap, and other info: https://github.com/pattern-lab/patternlab-node/wiki
32+
===============================`;
33+
module.exports = help;

packages/core/test/help_tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const tap = require('tap');
4+
const help = require('../src/lib/help');
5+
6+
tap.test('help - includes passed in version number', function(
7+
test
8+
) {
9+
//arrange
10+
const version = '⚡';
11+
12+
//act
13+
const result = help(version).trim();
14+
15+
//assert
16+
test.ok(result.startsWith(`Pattern Lab Node v${version}`));
17+
test.end();
18+
});

0 commit comments

Comments
 (0)