Skip to content

Commit 007a11c

Browse files
author
Bogdan Plieshka
committed
MAGETWO-38002: Automate UI Documentation build process with Grunt.js
- Added Grunt replace plugin - Automated Grunt documentation task
1 parent 4d42108 commit 007a11c

File tree

4 files changed

+74
-25
lines changed

4 files changed

+74
-25
lines changed

Gruntfile.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,17 @@ module.exports = function (grunt) {
6868
'less:luma',
6969
'less:backend'
7070
],
71+
7172
/**
7273
* Documentation
7374
*/
7475
documentation: [
76+
'replace:documentation',
7577
'less:documentation',
7678
'styledocco:documentation',
79+
'usebanner:documentationCss',
80+
'usebanner:documentationLess',
81+
'usebanner:documentationHtml',
7782
'clean:var',
7883
'clean:pub'
7984
],
@@ -82,12 +87,6 @@ module.exports = function (grunt) {
8287
'mage-minify:legacy'
8388
],
8489

85-
'documentation-banners': [
86-
'usebanner:documentationCss',
87-
'usebanner:documentationLess',
88-
'usebanner:documentationHtml'
89-
],
90-
9190
spec: function (theme) {
9291
var runner = require('./dev/tests/js/jasmine/spec_runner');
9392

dev/tools/grunt/configs/replace.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
'use strict';
7+
8+
function findCopyright(lang) {
9+
var copyrightText = {
10+
firstLine: 'Copyright © 2015 Magento. All rights reserved.',
11+
secondLine: 'See COPYING.txt for license details.'
12+
};
13+
switch (lang) {
14+
case 'less':
15+
return new RegExp(
16+
'// /\\*\\*\r\n// \\* ' +
17+
copyrightText.firstLine +
18+
'\r\n// \\* ' +
19+
copyrightText.secondLine +
20+
'\r\n// \\*/\r\n\r\n'
21+
);
22+
break;
23+
default:
24+
return;
25+
}
26+
}
27+
28+
module.exports = {
29+
documentation: {
30+
options: {
31+
patterns: [{
32+
match: findCopyright('less'),
33+
replacement: ''
34+
}]
35+
},
36+
files: [{
37+
expand: true,
38+
flatten: true,
39+
src: [
40+
'<%= path.doc %>/source/**/*.less'
41+
],
42+
dest: '<%= path.doc %>/source/'
43+
}]
44+
}
45+
46+
};

dev/tools/grunt/configs/usebanner.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55

66
'use strict';
77

8-
var banner = {
9-
firstLine: 'Copyright © 2015 Magento. All rights reserved.',
10-
secondLine: 'See COPYING.txt for license details.',
11-
12-
css: function () {
13-
return '/**\n * ' + this.firstLine + '\n * ' + this.secondLine + '\n */\n';
14-
},
15-
16-
less: function () {
17-
return '// /**\n// * ' + this.firstLine + '\n// * ' + this.secondLine + '\n// */\n';
18-
},
19-
20-
html: function () {
21-
return '<!--\n/**\n * ' + this.firstLine + '\n * ' + this.secondLine + '\n */\n-->\n';
8+
function printCopyright(lang) {
9+
var copyrightText = {
10+
firstLine: 'Copyright © 2015 Magento. All rights reserved.',
11+
secondLine: 'See COPYING.txt for license details.'
12+
};
13+
switch (lang) {
14+
case 'css':
15+
return '/**\n * ' + copyrightText.firstLine + '\n * ' + copyrightText.secondLine + '\n */\n';
16+
break;
17+
case 'less':
18+
return '// /**\n// * ' + copyrightText.firstLine + '\n// * ' + copyrightText.secondLine + '\n// */\n';
19+
break;
20+
case 'html':
21+
return '<!--\n/**\n * ' + copyrightText.firstLine + '\n * ' + copyrightText.secondLine + '\n */\n-->\n';
22+
break;
23+
default:
24+
return;
2225
}
23-
};
26+
}
2427

2528
module.exports = {
2629
options: {
@@ -29,31 +32,31 @@ module.exports = {
2932
},
3033
setup: {
3134
options: {
32-
banner: banner.css()
35+
banner: printCopyright('css')
3336
},
3437
files: {
3538
src: '<%= path.css.setup %>/*.css'
3639
}
3740
},
3841
documentationCss: {
3942
options: {
40-
banner: banner.css()
43+
banner: printCopyright('css')
4144
},
4245
files: {
4346
src: '<%= path.doc %>/**/*.css'
4447
}
4548
},
4649
documentationLess: {
4750
options: {
48-
banner: banner.less()
51+
banner: printCopyright('less')
4952
},
5053
files: {
5154
src: '<%= path.doc %>/**/*.less'
5255
}
5356
},
5457
documentationHtml: {
5558
options: {
56-
banner: banner.html()
59+
banner: printCopyright('html')
5760
},
5861
files: {
5962
src: '<%= path.doc %>/**/*.html'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"grunt-contrib-less": "^0.12.0",
2121
"grunt-contrib-watch": "^0.6.1",
2222
"grunt-exec": "^0.4.6",
23+
"grunt-replace": "^0.9.2",
2324
"grunt-styledocco": "^0.1.4",
2425
"grunt-template-jasmine-requirejs": "^0.2.3",
2526
"grunt-text-replace": "^0.4.0",

0 commit comments

Comments
 (0)