-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
109 lines (93 loc) · 3.58 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
// colors for terminal
require('colors');
// utility, lodash
const _ = require( 'lodash' );
_.mixin( require( 'underscore.string' ).exports() );
module.exports = grunt => {
// Hide 'Running task' text from grunt output
grunt.log.header = () => {};
// Initial config
const config = {
// Read JSON files
pkg: grunt.file.readJSON( 'package.json' ),
backgrounds: grunt.file.readJSON( 'backgrounds.json' )
};
const humanized = config.pkg.humanized;
// General purpose functions.
const share = (key, data) => {
// tasks can share anything into grunt.config:
grunt.registerTask( '__taskshare', '', () => grunt.config( key, data ) );
grunt.task.run( '__taskshare' );
},
header = (msg, before) => {
!before || grunt.log.write( '\n' + before.bold );
const d = _('-').repeat( 77 );
grunt.log.subhead( d + '\n' + msg.grey + '\n' + d );
},
generating = msg => grunt.log.subhead( 'Generating ' + msg + '...' ),
defaultOr = (name, base, ext) =>
(name === 'default' ? base : base + ' - ' + _.capitalize( name )) + (ext || '');
// Tasks options
var tasks = {
bump: {
options: {
files: ['package.json'],
updateConfigs: ['pkg'],
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json'],
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: true,
pushTo: 'origin',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false
}
},
clean: ['*.tmTheme'],
copy: { colorschemes: { files: [{
expand: true,
flatten: true,
cwd: 'templates',
src: ['template.hidden-tmTheme'],
rename: () => grunt.config( 'renamer' )( '.tmTheme' )
}]}},
replace: { colorschemes: {
overwrite: true,
replacements: [
{ from: '{{name}}', to: '<%= renamer() %>' },
{ from: '{{bg_rgb}}', to: '<%= bg.rgb %>' },
{ from: '{{bg_hex}}', to: '<%= bg.hex %>' }
]
}},
verbosity: { hidden: { tasks: ['copy', 'clean'] } }
};
// Merge tasks options with config
_.merge( config, tasks );
require( 'load-grunt-tasks' )( grunt );
// Define grunt tasks:
grunt.registerTask( 'default', [] );
// Build task:
// ColorSchemes task:
grunt.registerTask( 'build', 'Build custom themes', () => {
header( 'Current version: ' + grunt.config( 'pkg.version' ) + '\n' +
'Github repository: https://github.com/centril/' + grunt.config( 'pkg.name' ),
humanized + ' Builder' );
grunt.task.run( ['verbosity', 'clean'] );
header( 'Building theme files' );
grunt.config( 'backgrounds').forEach( bg => {
generating( bg.name + ' variation' );
const renamer = _.partial( defaultOr, bg.name, humanized );
share( 'renamer', renamer );
share( 'bg', bg );
share( 'replace.colorschemes.src', [renamer( '.tmTheme' )] );
grunt.task.run( ['copy:colorschemes', 'replace:colorschemes'] );
});
});
// Load grunt config
grunt.initConfig( config );
// Load all npm tasks at once
require( 'matchdep' ).filterDev( 'grunt-*' ).forEach( grunt.loadNpmTasks );
};