Skip to content

Commit db8120c

Browse files
committed
Breakdown grunt|gulp tasks, update README.md and unit tests now run through npm directly
1 parent b188dc0 commit db8120c

File tree

11 files changed

+412
-375
lines changed

11 files changed

+412
-375
lines changed

Gruntfile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ module.exports = function(grunt) {
22

33
var config = require('./config.json');
44

5+
grunt.initConfig({});
6+
57
// Load grunt tasks to the current grunt and inject the local configuration
6-
require('./builder/patternlab_grunt')(grunt, config);
8+
require('./builder/grunt-build')(grunt, config);
9+
10+
grunt.registerTask('default', ['patternlab', 'copy:pl_main', 'copy:pl_styleguide']);
711
};

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,34 @@ Make sure you are running your terminal/command line session as administrator. T
2222

2323
### Choose Your Adventure! Now Vanilla, Grunt & Gulp
2424

25-
This repository ships with two `package.json` files, a `Gruntfile.js`, and a `gulpfile.js`. The default is grunt currently. The core builder is not dependent on either.
25+
This repository ships a `Gruntfile.js`, and a `gulpfile.js`. The default is grunt currently. The core builder and tests are not dependent on either.
2626

2727
### Getting Started - Grunt
2828

2929
To run patternlab-node using grunt, do the following in the directory you downloaded and extracted the zipped release:
3030

3131
1. Run `npm install` from the command line
32-
2. Optionally, delete `package.gulp.json`, `gulpfile.js`, and `builder/patternlab_gulp.js` files if you are certain you don't need it.
33-
* Not deleting `builder/patternlab_gulp.js` may cause a harmless error when running grunt. Delete it.
34-
3. Run `grunt` or `grunt serve` from the command line
32+
2. Optionally, delete `gulpfile.js`, `builder/gulp-core.js`, `builder/gulp-build.js` and `builder/gulp-extra.js` files if you are certain you don't need it.
33+
3. Run `grunt` or `grunt pl:serve` from the command line
3534

36-
This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `grunt serve` to have BrowserSync spin up and serve the files to you.
35+
This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `grunt pl:serve` to have BrowserSync spin up and serve the files to you.
3736

3837
### Getting Started - Gulp
3938

4039
To run patternlab-node using gulp, you need to swap out the default grunt configuration. Do the following in the directory you downloaded and extracted the zipped release:
4140

42-
1. Rename `package.json` to `package.grunt.json` or delete it if you don't intend on going back
43-
2. Rename `package.gulp.json` to `package.json`
44-
3. Run `npm install` from the command line
45-
4. Run `gulp` or `gulp serve` from the command line
41+
1. Run `npm install` from the command line
42+
2. Optionally, delete `Gruntfile.js`, `builder/grunt-core.js` and `builder/grunt-build.js` files if you are certain you don't need it.
43+
4. Run `gulp` or `gulp pl:serve` from the command line
4644

47-
This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `gulp serve` to have BrowserSync spin up and serve the files to you.
45+
This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `gulp pl:serve` to have BrowserSync spin up and serve the files to you.
4846

4947
### There and Back Again, or Switching Between Grunt and Gulp
5048

5149
It's not expected to toggle between the two build systems, but for those migrating between the two configs, here's some general guidelines:
5250

53-
* Make sure your `package.json` files are correct per the Getting Started sections.
54-
* Run `npm cache clear` before installation
55-
* Delete the contents of `./node_modules` if you want a cleaner installation.
51+
* Don't delete any files related to grunt or gulp. That's it!
52+
* The `package.json` includes all dependencies for gulp **and** grunt so you can switch between the two without doing anything.
5653
* Regarding speed, Gulp is faster. BrowserSync takes a bit longer than the old static server to spin up, but its capabilities far outweigh the startup cost.
5754

5855
### Upgrading
@@ -78,7 +75,7 @@ Get more information about patternlab-node, pattern lab in general, and where to
7875
### Further Configuration
7976

8077
##### Watching Changes
81-
To have patternlab-node watch for changes to either a mustache template, data, or stylesheets, run `grunt|gulp watch` or `grunt|gulp serve`. The `Gruntfile|Gulpfile` governs what is watched. It should be easy to add scss or whatever preprocessor you fancy.
78+
To have patternlab-node watch for changes to either a mustache template, data, or stylesheets, run `grunt watch|gulp pl:connect` or `grunt|gulp pl:serve`. The `Gruntfile|Gulpfile` governs what is watched. It should be easy to add scss or whatever preprocessor you fancy.
8279

8380
##### Configurable Paths
8481
Pattern Lab Node ships with a particular source and public workflow intended to separate the code you work on with the code generated for consumption elsewhere. If you wish to change any paths, you may do so within `config.json`. The contents are here:

builder/grunt-build.js

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* patternlab-node - v1.1.0 - 2016
3+
*
4+
* Brian Muenzenmeyer, 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.
8+
*
9+
*/
10+
11+
// IMPORTANT: Remember that `./` matches the root of the grunt file that requires this one!
12+
// However, this does not apply to the `require('...')`
13+
module.exports = function(grunt, config) {
14+
var path = require('path');
15+
16+
// Load CORE tasks
17+
require('./grunt-core')(grunt, config);
18+
19+
// Load all grunt tasks
20+
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
21+
22+
// Project configuration.
23+
grunt.config.merge({
24+
pkg: grunt.file.readJSON('package.json'),
25+
concat: {
26+
options: {
27+
stripBanners: true,
28+
banner: '/* \n * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy") %> \n * \n * <%= pkg.author %>, and the web community.\n * Licensed under the <%= pkg.license %> license. \n * \n * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. \n *\n */\n\n',
29+
},
30+
pl_patternlab: {
31+
src: './builder/patternlab.js',
32+
dest: './builder/patternlab.js'
33+
},
34+
pl_object_factory: {
35+
src: './builder/object_factory.js',
36+
dest: './builder/object_factory.js'
37+
},
38+
pl_lineage: {
39+
src: './builder/lineage_hunter.js',
40+
dest: './builder/lineage_hunter.js'
41+
},
42+
pl_media_hunter: {
43+
src: './builder/media_hunter.js',
44+
dest: './builder/media_hunter.js'
45+
},
46+
pl_patternlab_grunt: {
47+
src: './builder/patternlab_grunt.js',
48+
dest: './builder/patternlab_grunt.js'
49+
},
50+
pl_patternlab_gulp: {
51+
src: './builder/patternlab_gulp.js',
52+
dest: './builder/patternlab_gulp.js'
53+
},
54+
pl_parameter_hunter: {
55+
src: './builder/parameter_hunter.js',
56+
dest: './builder/parameter_hunter.js'
57+
},
58+
pl_pattern_exporter: {
59+
src: './builder/pattern_exporter.js',
60+
dest: './builder/pattern_exporter.js'
61+
},
62+
pl_pattern_assembler: {
63+
src: './builder/pattern_assembler.js',
64+
dest: './builder/pattern_assembler.js'
65+
},
66+
pl_pseudopattern_hunter: {
67+
src: './builder/pseudopattern_hunter.js',
68+
dest: './builder/pseudopattern_hunter.js'
69+
},
70+
pl_list_item_hunter: {
71+
src: './builder/list_item_hunter.js',
72+
dest: './builder/list_item_hunter.js'
73+
},
74+
pl_style_modifier_hunter: {
75+
src: './builder/style_modifier_hunter.js',
76+
dest: './builder/style_modifier_hunter.js'
77+
}
78+
},
79+
copy: {
80+
pl_main: {
81+
files: [
82+
{
83+
expand: true,
84+
cwd: path.resolve(config.paths.source.js),
85+
src: '*.js',
86+
dest: path.resolve(config.paths.public.js)
87+
},
88+
{
89+
expand: true,
90+
cwd: path.resolve(config.paths.source.css),
91+
src: '*.css',
92+
dest: path.resolve(config.paths.public.css)
93+
},
94+
{
95+
expand: true,
96+
cwd: path.resolve(config.paths.source.images),
97+
src: ['**/*.png', '**/*.jpg', '**/*.gif', '**/*.jpeg'],
98+
dest: path.resolve(config.paths.public.images)
99+
},
100+
{
101+
expand: true,
102+
cwd: path.resolve(config.paths.source.fonts),
103+
src: '*',
104+
dest: path.resolve(config.paths.public.fonts)
105+
},
106+
{
107+
expand: true,
108+
cwd: path.resolve(config.paths.source.data),
109+
src: 'annotations.js',
110+
dest: path.resolve(config.paths.public.data)
111+
}
112+
]
113+
},
114+
pl_styleguide: {
115+
files: [
116+
{
117+
expand: true,
118+
cwd: path.resolve(config.paths.source.styleguide),
119+
src: ['*.*', '**/*.*'],
120+
dest: path.resolve(config.paths.public.styleguide)
121+
}
122+
]
123+
}
124+
},
125+
watch: {
126+
pl_all: {
127+
files: [
128+
path.resolve(config.paths.source.css + '**/*.css'),
129+
path.resolve(config.paths.source.styleguide + 'css/*.css'),
130+
path.resolve(config.paths.source.patterns + '**/*.mustache'),
131+
path.resolve(config.paths.source.patterns + '**/*.json'),
132+
path.resolve(config.paths.source.fonts + '/*'),
133+
path.resolve(config.paths.source.images + '/*'),
134+
path.resolve(config.paths.source.data + '*.json')
135+
],
136+
tasks: ['default', 'bsReload:pl_css']
137+
}
138+
},
139+
browserSync: {
140+
pl_dev: {
141+
options: {
142+
server: path.resolve(config.paths.public.root),
143+
watchTask: true,
144+
watchOptions: {
145+
ignoreInitial: true,
146+
ignored: '*.html'
147+
},
148+
plugins: [
149+
{
150+
module: 'bs-html-injector',
151+
options: {
152+
files: [path.resolve(config.paths.public.root + '/index.html'), path.resolve(config.paths.public.styleguide + '/styleguide.html')]
153+
}
154+
}
155+
]
156+
}
157+
}
158+
},
159+
bsReload: {
160+
pl_css: path.resolve(config.paths.public.root + '**/*.css')
161+
}
162+
});
163+
164+
grunt.registerTask('pl:serve', ['patternlab', 'copy:pl_main', 'copy:pl_styleguide', 'browserSync', 'watch:pl_all']);
165+
166+
grunt.registerTask('pl:build', ['concat']);
167+
};

builder/grunt-core.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* patternlab-node - v1.1.0 - 2016
3+
*
4+
* Brian Muenzenmeyer, 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.
8+
*
9+
*/
10+
11+
// IMPORTANT: Remember that `./` matches the root of the grunt file that requires this one!
12+
// However, this does not apply to the `require('...')`
13+
module.exports = function(grunt, config) {
14+
var patternlab = require('./patternlab.js')(config);
15+
16+
grunt.registerTask('patternlab', 'create design systems with atomic design', function(arg) {
17+
if(arguments.length === 0){
18+
patternlab.build(true);
19+
}
20+
21+
if(arg && arg === 'v'){
22+
patternlab.version();
23+
}
24+
25+
if(arg && arg === "only_patterns"){
26+
patternlab.build_patterns_only(true);
27+
}
28+
29+
if(arg && arg === "help"){
30+
patternlab.help();
31+
}
32+
33+
if(arg && (arg !== "v" && arg !=="only_patterns" && arg !=="help")){
34+
patternlab.help();
35+
}
36+
});
37+
};

builder/gulp-build.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* patternlab-node - v1.1.0 - 2016
3+
*
4+
* Brian Muenzenmeyer, 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.
8+
*
9+
*/
10+
11+
// IMPORTANT: Remember that `./` matches the root of the gulp file that requires this one!
12+
// However, this does not apply to the `require('...')`
13+
module.exports = function(gulp, config) {
14+
var path = require('path'),
15+
browserSync = require('browser-sync').create();
16+
17+
// Load CORE tasks
18+
require('./gulp-core')(gulp, config);
19+
20+
// COPY TASKS
21+
22+
// JS copy
23+
gulp.task('pl:cp:js', function(){
24+
return gulp.src('**/*.js', {cwd: path.resolve(config.paths.source.js)} )
25+
.pipe(gulp.dest(path.resolve(config.paths.public.js)));
26+
});
27+
28+
// Images copy
29+
gulp.task('pl:cp:img', function(){
30+
return gulp.src(
31+
[ '**/*.gif', '**/*.png', '**/*.jpg', '**/*.jpeg' ],
32+
{cwd: path.resolve(config.paths.source.images)} )
33+
.pipe(gulp.dest(path.resolve(config.paths.public.images)));
34+
});
35+
36+
// Fonts copy
37+
gulp.task('pl:cp:font', function(){
38+
return gulp.src('*', {cwd: path.resolve(config.paths.source.fonts)})
39+
.pipe(gulp.dest(path.resolve(config.paths.public.images)));
40+
});
41+
42+
// Data copy
43+
gulp.task('pl:cp:data', function(){
44+
return gulp.src('annotations.js', {cwd: path.resolve(config.paths.source.data)})
45+
.pipe(gulp.dest(path.resolve(config.paths.public.data)));
46+
});
47+
48+
// CSS Copy
49+
gulp.task('pl:cp:css', function(){
50+
return gulp.src(path.resolve(config.paths.source.css, 'style.css'))
51+
.pipe(gulp.dest(path.resolve(config.paths.public.css)))
52+
.pipe(browserSync.stream());
53+
});
54+
55+
// Styleguide Copy
56+
gulp.task('pl:cp:styleguide', function(){
57+
return gulp.src(
58+
[ '**/*'],
59+
{cwd: path.resolve(config.paths.source.styleguide)} )
60+
.pipe(gulp.dest(path.resolve(config.paths.public.styleguide)))
61+
.pipe(browserSync.stream());
62+
});
63+
64+
//server and watch tasks
65+
gulp.task('pl:connect', ['pl:lab'], function(){
66+
browserSync.init({
67+
server: {
68+
baseDir: path.resolve(config.paths.public.root)
69+
}
70+
});
71+
gulp.watch(path.resolve(config.paths.source.css, '**/*.css'), ['pl:cp:css']);
72+
73+
gulp.watch(path.resolve(config.paths.source.styleguide, '**/*.*'), ['pl:cp:styleguide']);
74+
75+
gulp.watch(
76+
[
77+
path.resolve(config.paths.source.patterns, '**/*.mustache'),
78+
path.resolve(config.paths.source.patterns, '**/*.json'),
79+
path.resolve(config.paths.source.data, '*.json'),
80+
path.resolve(config.paths.source.fonts + '/*'),
81+
path.resolve(config.paths.source.images + '/*'),
82+
path.resolve(config.paths.source.data + '*.json')
83+
],
84+
['pl:lab-pipe'],
85+
function () { browserSync.reload(); }
86+
);
87+
88+
});
89+
90+
gulp.task('pl:lab-pipe', ['pl:lab'], function(cb){
91+
cb();
92+
browserSync.reload();
93+
});
94+
95+
gulp.task('pl:assets', ['pl:cp:js', 'pl:cp:img', 'pl:cp:font', 'pl:cp:data', 'pl:cp:css', 'pl:cp:styleguide' ]);
96+
gulp.task('pl:prelab', ['pl:clean', 'pl:assets']);
97+
gulp.task('pl:lab', ['pl:prelab', 'patternlab'], function(cb){cb();});
98+
gulp.task('pl:patterns', ['patternlab:only_patterns']);
99+
gulp.task('pl:serve', ['pl:lab', 'pl:connect']);
100+
};

0 commit comments

Comments
 (0)