summaryrefslogtreecommitdiff
path: root/2/Gruntfile.js
blob: ca2182caa8af2c1f4fba4da53a57cf11ad90b634 (plain)
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
110
111
112
113
module.exports = function (grunt) {
  grunt.loadNpmTasks('grunt-recess');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-clean');

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    builddir: 'build',
    meta: {
      banner: '/**\n' +
              ' * <%= pkg.description %>\n' +
              ' * @version v<%= pkg.version %> - ' +
              '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
              ' * @link <%= pkg.homepage %>\n' +
              ' * @license <%= pkg.license %>' + ' */'
    },
    swatch: {
      amelia:{}, cerulean:{}, cosmo:{}, cyborg:{}, flatly:{}, journal:{}, readable:{},
      simplex:{}, slate:{}, spacelab:{}, spruce:{}, superhero:{}, united:{}
    },
    clean: {
      build: {
        src: ['*/build.less', '*/build-responsive.less',
              '!global/build.less', '!global/build-responsive.less']
      }
    },
    concat: {
      dist: {
        src: [],
        dest: ''
      }
    },
    recess: {
      dist: {
        options: {
          compile: true,
          compress: false
        },
        files: {}
      }
    }
  });

  grunt.registerTask('none', function() {});

  grunt.registerTask('build', 'build a regular theme', function(theme, compress) {
    var compress = compress == undefined ? true : compress;

    var concatSrc;
    var concatDest;
    var recessDest;
    var recessSrc;
    var files = {};
    var dist = {};
    concatSrc = 'global/build.less';
    concatDest = theme + '/build.less';
    recessDest = '<%=builddir%>/' + theme + '/bootstrap.css';
    recessSrc = [ theme + '/' + 'build.less' ];

    dist = {src: concatSrc, dest: concatDest};
    grunt.config('concat.dist', dist);
    files = {}; files[recessDest] = recessSrc;
    grunt.config('recess.dist.files', files);
    grunt.config('recess.dist.options.compress', false);

    grunt.task.run(['concat', 'recess:dist', 'clean:build',
      compress ? 'compress:'+recessDest+':'+'<%=builddir%>/' + theme + '/bootstrap.min.css':'none']);
  });

  grunt.registerTask('build-responsive', 'build a responsive theme', function(theme, compress) {
    var compress = compress == undefined ? true : compress;

    var concatSrc;
    var concatDest;
    var recessDest;
    var recessSrc;
    var files = {};
    var dist = {};

    concatSrc = 'global/build-responsive.less';
    concatDest = theme + '/build-responsive.less';
    recessDest = '<%=builddir%>/' + theme + '/bootstrap-responsive.css';
    recessSrc = [ theme + '/' + 'build-responsive.less' ];

    dist = {src: concatSrc, dest: concatDest};
    grunt.config('concat.dist', dist);
    files = {}; files[recessDest] = recessSrc;
    grunt.config('recess.dist.files', files);
    grunt.config('recess.dist.options.compress', false);

    grunt.task.run(['concat', 'recess:dist', 'clean:build',
      compress ? 'compress:'+recessDest+':'+'<%=builddir%>/' + theme + '/bootstrap-responsive.min.css':'none']);
  });

  grunt.registerTask('compress', 'compress a generic css', function(fileSrc, fileDst) {
    var files = {}; files[fileDst] = fileSrc;
    grunt.log.writeln('compressing file ' + fileSrc);

    grunt.config('recess.dist.files', files);
    grunt.config('recess.dist.options.compress', true);
    grunt.task.run(['recess:dist']);
  });

  grunt.registerMultiTask('swatch', 'build a theme, both not responsive and responsive', function() {
    var t = this.target;
    grunt.task.run('build:'+t, 'build-responsive:'+t);
  });

  grunt.registerTask('default', 'build a theme, both not responsive and responsive', function() {
    grunt.task.run('swatch');
  });
};