Tab layout, first commit with new third party packages
[openemr.git] / public / assets / knockout-3-4-0 / Gruntfile.js
blobca930a7f261036134455372bb07b34f82488c62d
1 /*global module:false*/
2 module.exports = function(grunt) {
3     var _ = grunt.util._;
5     // Project configuration
6     grunt.initConfig({
7         // Metadata
8         pkg: grunt.file.readJSON('package.json'),
9         fragments: './build/fragments/',
10         banner: '/*!\n' +
11                 ' * Knockout JavaScript library v<%= pkg.version %>\n' +
12                 ' * (c) Steven Sanderson - <%= pkg.homepage %>\n' +
13                 ' * License: <%= pkg.licenses[0].type %> (<%= pkg.licenses[0].url %>)\n' +
14                 ' */\n\n',
16         checktrailingspaces: {
17             main: {
18                 src: [
19                     "**/*.{js,html,css,bat,ps1,sh}",
20                     "!build/output/**",
21                     "!node_modules/**"
22                 ],
23                 filter: 'isFile'
24             }
25         },
26         build: {
27             debug: './build/output/knockout-latest.debug.js',
28             min: './build/output/knockout-latest.js'
29         },
30         dist: {
31             debug: './dist/knockout.debug.js',
32             min: './dist/knockout.js'
33         },
34         test: {
35             phantomjs: 'spec/runner.phantom.js',
36             node: 'spec/runner.node.js'
37         }
38     });
40     grunt.registerTask('clean', 'Clean up output files.', function (target) {
41         var output = grunt.config('build');
42         var files = [ output.debug, output.min ];
43         var options = { force: (target == 'force') };
44         _.forEach(files, function (file) {
45             if (grunt.file.exists(file))
46                 grunt.file.delete(file, options);
47         });
48         return !this.errorCount;
49     });
51     var trailingSpaceRegex = /[ ]$/;
52     grunt.registerMultiTask('checktrailingspaces', 'checktrailingspaces', function() {
53         var matches = [];
54         this.files[0].src.forEach(function(filepath) {
55             var content = grunt.file.read(filepath),
56                 lines = content.split(/\r*\n/);
57             lines.forEach(function(line, index) {
58                 if (trailingSpaceRegex.test(line)) {
59                     matches.push([filepath, (index+1), line].join(':'));
60                 }
61             });
62         });
63         if (matches.length) {
64             grunt.log.error("The following files have trailing spaces that need to be cleaned up:");
65             grunt.log.writeln(matches.join('\n'));
66             return false;
67         }
68     });
70     function getReferencedSources(sourceReferencesFilename) {
71         // Returns the array of filenames referenced by a file like source-references.js
72         var result;
73         global.knockoutDebugCallback = function(sources) { result = sources; };
74         eval(grunt.file.read(sourceReferencesFilename));
75         return result;
76     }
78     function getCombinedSources() {
79         var fragments = grunt.config('fragments'),
80             sourceFilenames = [
81                 fragments + 'extern-pre.js',
82                 fragments + 'amd-pre.js',
83                 getReferencedSources(fragments + 'source-references.js'),
84                 fragments + 'amd-post.js',
85                 fragments + 'extern-post.js'
86             ],
87             flattenedSourceFilenames = Array.prototype.concat.apply([], sourceFilenames),
88             combinedSources = flattenedSourceFilenames.map(function(filename) {
89                 return grunt.file.read('./' + filename);
90             }).join('');
92         return combinedSources.replace('##VERSION##', grunt.config('pkg.version'));
93     }
95     function buildDebug(output) {
96         var source = [];
97         source.push(grunt.config('banner'));
98         source.push('(function(){\n');
99         source.push('var DEBUG=true;\n');
100         source.push(getCombinedSources());
101         source.push('})();\n');
102         grunt.file.write(output, source.join('').replace(/\r\n/g, '\n'));
103     }
105     function buildMin(output, done) {
106         var cc = require('closure-compiler');
107         var options = {
108             compilation_level: 'ADVANCED_OPTIMIZATIONS',
109             output_wrapper: '(function() {%output%})();'
110         };
111         grunt.log.write('Compiling...');
112         cc.compile('/**@const*/var DEBUG=false;' + getCombinedSources(), options, function (err, stdout, stderr) {
113             if (err) {
114                 grunt.log.error(err);
115                 done(false);
116             } else {
117                 grunt.log.ok();
118                 grunt.file.write(output, (grunt.config('banner') + stdout).replace(/\r\n/g, '\n'));
119                 done(true);
120             }
121         });
122     }
124     grunt.registerMultiTask('build', 'Build', function() {
125         if (!this.errorCount) {
126             var output = this.data;
127             if (this.target === 'debug') {
128                 buildDebug(output);
129             } else if (this.target === 'min') {
130                 buildMin(output, this.async());
131             }
132         }
133         return !this.errorCount;
134     });
136     grunt.registerMultiTask('test', 'Run tests', function () {
137         var done = this.async();
138         grunt.util.spawn({ cmd: this.target, args: [this.data] },
139             function (error, result, code) {
140                 if (code === 127 /*not found*/) {
141                     grunt.verbose.error(result.stderr);
142                     // ignore this error
143                     done(true);
144                 } else {
145                     grunt.log.writeln(result.stdout);
146                     if (error)
147                         grunt.log.error(result.stderr);
148                     done(!error);
149                 }
150             }
151         );
152     });
154     grunt.registerTask('dist', function() {
155         var version = grunt.config('pkg.version'),
156             buildConfig = grunt.config('build'),
157             distConfig = grunt.config('dist');
158         grunt.file.copy(buildConfig.debug, distConfig.debug);
159         grunt.file.copy(buildConfig.min, distConfig.min);
161         console.log('To publish, run:');
162         console.log('    git add bower.json');
163         console.log('    git add -f ' + distConfig.debug);
164         console.log('    git add -f ' + distConfig.min);
165         console.log('    git checkout head');
166         console.log('    git commit -m \'Version ' + version + ' for distribution\'');
167         console.log('    git tag -a v' + version + ' -m \'Add tag v' + version + '\'');
168         console.log('    git checkout master');
169         console.log('    git push origin --tags');
170     });
172     // Default task.
173     grunt.registerTask('default', ['clean', 'checktrailingspaces', 'build', 'test']);