Passed
Push — master ( 410804...227453 )
by Askupa
01:31
created

GruntFile.js (3 issues)

1
module.exports = function(grunt) {
2
    grunt.initConfig({
3
        pkg: grunt.file.readJSON('package.json'),
4
        banner: grunt.file.read('banner.js'),
5
        dirs: {
6
            scss: "src/scss",
7
            css: "src/css",
8
            js: "src/js",
9
            demo: "demo",
10
            build: "build"
11
        },
12
        watch: {
13
            js: {
14
                files: ['src/js/**/*.js'],
15
                tasks: ['concat:js','concat:dev','strip_code','jshint']
16
            },
17
            scss: {
18
                files: ['src/scss/**/*.scss'],
19
                tasks: ['compass','concat:css']
20
            }
21
        },
22
        concat: {
23
            css: {
24
                options: {
25
                    banner: '<%= banner %>'
26
                },
27
                files: {
28
                    '<%= dirs.build %>/mivhak.min.css': [
29
                        '<%= dirs.css %>/**/*.css'
30
                    ]
31
                }
32
            },
33
            js: {
34
                options: {
35
                    separator: "",
36
                    banner: '<%= banner %>'
37
                },
38
                files: {
39
                    '<%= dirs.build %>/mivhak.js': [
40
                        '<%= dirs.js %>/intro.js',
41
                        '<%= dirs.js %>/ace.config.js',
42
                        '<%= dirs.js %>/utility.js',
43
                        '<%= dirs.js %>/jquery.template.js',
44
                        '<%= dirs.js %>/mivhak.js',
45
                        '<%= dirs.js %>/mivhak.defaults.js',
46
                        '<%= dirs.js %>/mivhak.resources.js',
47
                        '<%= dirs.js %>/mivhak.buttons.js',
48
                        '<%= dirs.js %>/mivhak.methods.js',
49
                        '<%= dirs.js %>/mivhak.icons.js',
50
                        '<%= dirs.js %>/mivhak.component.js',
51
                        '<%= dirs.js %>/components/*.js',
52
                        '<%= dirs.js %>/jquery.mivhak.js',
53
                        '<%= dirs.js %>/outro.js'
54
                    ]
55
                }
56
            },
57
            dev: {
58
                files: {
59
                    '<%= dirs.build %>/mivhak-dev.js': ['<%= dirs.build %>/mivhak.js']
60
                }
61
            },
62
            bundle: { // Create a version that includes all dependencies
63
                files: {
64
                    '<%= dirs.build %>/mivhak.bundle.min.js': ['<%= dirs.js %>/lib/*.js','<%= dirs.build %>/mivhak.js']
65
                }
66
            }
67
        },
68
        compass: {
69
            dist: {
70
                options: {
71
                    sassDir: '<%= dirs.scss %>',
72
                    cssDir: '<%= dirs.css %>',
73
                    environment: 'production',
74
                    raw: 'preferred_syntax = :scss\n', // Use `raw` since it's not directly available
75
                    outputStyle: 'compressed'
76
                }
77
            }
78
        },
79
        jshint: {
80
            all: ['Gruntfile.js', 'build/mivhak.js']
81
        },
82
        uglify: {
83
            options: {
84
                banner: '<%= banner %>'
85
            },
86
            dist: {
87
                files: {
88
                    '<%= dirs.build %>/mivhak.min.js': ['<%= dirs.build %>/mivhak.js'],
89
                    '<%= dirs.build %>/mivhak.bundle.min.js': ['<%= dirs.build %>/mivhak.bundle.min.js']
90
                }
91
            }
92
        },
93
        strip_code: {
94
            options: {
95
                // Task-specific options go here.
96
            },
97
            your_target: {
98
                src: 'build/mivhak.js'
99
            },
100
        },
101
        components: {
102
            dist: function() {
103
                var src = '<%= dirs.js %>/components/*.js',
104
                    out = '<%= dirs.js %>/components/_compiled.js',
0 ignored issues
show
The variable out seems to be never used. Consider removing it.
Loading history...
105
                    fileList = grunt.file.expand(grunt.template.process(src)),
106
                    contents = '';
107
                
108
                fileList.forEach(function(file) {
109
                    var script = grunt.file.read(file),
110
                        template = (function() {
111
                            var src = file.replace('.js','.html');
112
                            if(grunt.file.exists(src)) return grunt.file.read(src).replace("\n"," ");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
113
                            return '';
114
                        });
115
                        
116
                    console.log(script,template);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
117
                    contents += "\n(function(template){\n" + script + "\n})(`"+template+"`);\n";
118
                });
119
                
120
//                grunt.file.write(grunt.template.process(out),contents);
121
            }
122
        }
123
    });
124
125
    // Load grunt plugins
126
    grunt.loadNpmTasks('grunt-contrib-uglify');
127
    grunt.loadNpmTasks('grunt-contrib-compass');
128
    grunt.loadNpmTasks('grunt-contrib-concat');
129
    grunt.loadNpmTasks('grunt-contrib-watch');
130
    grunt.loadNpmTasks('grunt-contrib-jshint');
131
    grunt.loadNpmTasks('grunt-strip-code');
132
    
133
    // Default task(s).
134
    grunt.registerTask('build', ['concat:js','concat:dev','concat:bundle','strip_code','uglify','compass','concat:css','jshint']);
135
    grunt.registerMultiTask("components", ["components"],function(){this.data.call();});
136
};