htdocs: add a node.js method for minifying the files.

Run `node make` or `node make minify`.

Additionally, you can use `npm run check` or `npm run lint` to check our js and css files for errors with JSHint and csslint.
This commit is contained in:
XhmikosR 2013-06-05 11:24:52 +03:00 committed by Daniel Marjamki
parent 2204bd89b2
commit 1e56b94311
10 changed files with 221 additions and 18 deletions

2
.gitignore vendored
View File

@ -69,3 +69,5 @@ htmlreport/MANIFEST
# kdevelop 4.x
*.kdev4
htdocs/site/node_modules

30
htdocs/site/.jshintrc Normal file
View File

@ -0,0 +1,30 @@
{
"node" : true,
"browser" : false,
"bitwise": true,
"boss": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"indent": 4,
"latedef": true,
"multistr": true,
"noarg": true,
"noempty": true,
"plusplus": false,
"regexp": true,
"strict": false,
"trailing": true,
"unused": true,
"globals": {
"cd": true,
"cp": true,
"target": true,
"echo": true,
"cat": true,
"exec": true,
"require": true,
"__dirname": true
}
}

19
htdocs/site/LICENSE.md Normal file
View File

@ -0,0 +1,19 @@
Copyright (C) 2013 MPC-HC Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

9
htdocs/site/Readme.md Normal file
View File

@ -0,0 +1,9 @@
Getting started
---------------
* Install [node.js](http://nodejs.org/download/)
* Install the node.js dependencies: `npm install`
* Run `node make` or `node make minify`
You can run `npm run check` or `npm run lint` to run [JSHint](https://github.com/jshint/jshint)
and [csslint](https://github.com/stubbornella/csslint) for our files.

View File

@ -1,3 +1,5 @@
/*csslint box-sizing: false, ids: false, qualified-headings: false*/
body {
margin: 0;
padding: 0;

80
htdocs/site/make.js Normal file
View File

@ -0,0 +1,80 @@
/**!
* make.js, script to build the website for cppcheck
* Released under the terms of MIT license.
*
* https://github.com/danmar/cppcheck
*
* Copyright (C) 2013 XhmikosR and Cppcheck team.
*/
(function () {
'use strict';
require('shelljs/make');
var fs = require('fs'),
cleanCSS = require('clean-css'),
UglifyJS = require('uglify-js'),
ROOT_DIR = __dirname + '/'; // absolute path to project's root
//
// make minify
//
target.minify = function () {
cd(ROOT_DIR);
echo();
echo("### Minifying css files...");
// pack.css
var inCss = cat(['css/all.css',
'css/demo.css',
'css/normalize.css'
]);
var packCss = cleanCSS.process(inCss, {
removeEmpty: true,
keepSpecialComments: 0
});
fs.writeFileSync('css/pack.css', packCss, 'utf8');
echo();
echo('### Finished' + ' ' + 'css/pack.css' + '.');
echo();
echo("### Minifying js files...");
var inJs = cat(['js/github.js',
'js/picnet.table.filter.min.js']);
var minifiedJs = UglifyJS.minify(inJs, {
compress: true,
fromString: true, // this is needed to pass JS source code instead of filenames
mangle: true,
warnings: false
});
fs.writeFileSync('js/pack.js', minifiedJs.code, 'utf8');
echo();
echo('### Finished' + ' ' + 'js/pack.js' + '.');
};
//
// make all
//
target.all = function () {
target.minify();
};
//
// make help
//
target.help = function () {
echo("Available targets:");
echo(" minify Creates the minified CSS and JS");
echo(" help shows this help message");
};
}());

View File

@ -1,7 +0,0 @@
#!/bin/bash
# install node.js and then run:
# npm install -g clean-css
# npm install -g uglify-js
cat css/all.css css/demo.css css/normalize.css | cleancss --s0 -o css/pack.css
uglifyjs js/github.js js/picnet.table.filter.min.js -o js/pack.js --compress --mangle

View File

@ -1,11 +0,0 @@
@echo off
rem install node.js and then run:
rem npm install -g clean-css
rem npm install -g uglify-js
pushd %~dp0
type css\all.css css\demo.css css\normalize.css | cleancss --s0 -o css\pack.css
cmd /c uglifyjs js/github.js js/picnet.table.filter.min.js -o js/pack.js --compress --mangle
popd

31
htdocs/site/package.json Normal file
View File

@ -0,0 +1,31 @@
{
"name": "cppcheck-web",
"version": "0.1.0",
"author": "XhmikosR (https://github.com/XhmikosR)",
"description": "The dependencies to build cppcheck's website",
"homepage": "https://github.com/danmar/cppcheck",
"repository": {
"type": "git",
"url": "https://github.com/danmar/cppcheck.git"
},
"bugs": {
"url": "http://sourceforge.net/apps/trac/cppcheck/wiki"
},
"license": "MIT",
"main": "make.js",
"readmeFilename": "Readme.md",
"scripts": {
"check": "node run-tests",
"lint": "node run-tests"
},
"dependencies": {
"clean-css": "~1.0.6",
"csslint": "~0.9.10",
"jshint": "~2.1.3",
"shelljs": "~0.1.4",
"uglify-js": "~2.3.6"
},
"engines": {
"node": "~0.8.0"
}
}

48
htdocs/site/run-tests.js Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env node
/**!
* run-tests.js, script to run csslint and JSHint for our files
* Released under the terms of MIT license.
*
* https://github.com/danmar/cppcheck
*
* Copyright (C) 2013 XhmikosR and Cppcheck team.
*/
require('shelljs/global');
cd(__dirname);
//
// JSHint
//
JSHINT_BIN = './node_modules/jshint/bin/jshint';
if (!test('-f', JSHINT_BIN)) {
echo('JSHint not found. Run `npm install` in the root dir first.');
exit(1);
}
if (exec('node' +' ' + JSHINT_BIN +' ' + 'make.js run-tests.js').code !== 0) {
echo('*** JSHint failed! (return code != 0)');
echo();
} else {
echo('JSHint completed successfully');
echo();
}
//
// csslint
//
CSSLINT_BIN = './node_modules/csslint/cli.js';
if (!test('-f', CSSLINT_BIN)) {
echo('csslint not found. Run `npm install` in the root dir first.');
exit(1);
}
if (exec('node' +' ' + CSSLINT_BIN +' ' + 'css/all.css').code !== 0) {
echo('*** csslint failed! (return code != 0)');
echo();
}