From 1e56b9431199ec2119ee2aad816ca20d7eef0375 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 5 Jun 2013 11:24:52 +0300 Subject: [PATCH] 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. --- .gitignore | 2 + htdocs/site/.jshintrc | 30 +++++++++++++++ htdocs/site/LICENSE.md | 19 ++++++++++ htdocs/site/Readme.md | 9 +++++ htdocs/site/css/all.css | 2 + htdocs/site/make.js | 80 ++++++++++++++++++++++++++++++++++++++++ htdocs/site/minify | 7 ---- htdocs/site/minify.bat | 11 ------ htdocs/site/package.json | 31 ++++++++++++++++ htdocs/site/run-tests.js | 48 ++++++++++++++++++++++++ 10 files changed, 221 insertions(+), 18 deletions(-) create mode 100644 htdocs/site/.jshintrc create mode 100644 htdocs/site/LICENSE.md create mode 100644 htdocs/site/Readme.md create mode 100644 htdocs/site/make.js delete mode 100644 htdocs/site/minify delete mode 100644 htdocs/site/minify.bat create mode 100644 htdocs/site/package.json create mode 100644 htdocs/site/run-tests.js diff --git a/.gitignore b/.gitignore index 72707e76b..e1a3494e9 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,5 @@ htmlreport/MANIFEST # kdevelop 4.x *.kdev4 + +htdocs/site/node_modules diff --git a/htdocs/site/.jshintrc b/htdocs/site/.jshintrc new file mode 100644 index 000000000..adb8cf431 --- /dev/null +++ b/htdocs/site/.jshintrc @@ -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 + } +} diff --git a/htdocs/site/LICENSE.md b/htdocs/site/LICENSE.md new file mode 100644 index 000000000..b0e7ec164 --- /dev/null +++ b/htdocs/site/LICENSE.md @@ -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. diff --git a/htdocs/site/Readme.md b/htdocs/site/Readme.md new file mode 100644 index 000000000..f09bf465b --- /dev/null +++ b/htdocs/site/Readme.md @@ -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. diff --git a/htdocs/site/css/all.css b/htdocs/site/css/all.css index 390cba037..773cfa092 100644 --- a/htdocs/site/css/all.css +++ b/htdocs/site/css/all.css @@ -1,3 +1,5 @@ +/*csslint box-sizing: false, ids: false, qualified-headings: false*/ + body { margin: 0; padding: 0; diff --git a/htdocs/site/make.js b/htdocs/site/make.js new file mode 100644 index 000000000..ac1d0fce1 --- /dev/null +++ b/htdocs/site/make.js @@ -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"); + }; + +}()); diff --git a/htdocs/site/minify b/htdocs/site/minify deleted file mode 100644 index 6aec1c141..000000000 --- a/htdocs/site/minify +++ /dev/null @@ -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 diff --git a/htdocs/site/minify.bat b/htdocs/site/minify.bat deleted file mode 100644 index fceb57ab7..000000000 --- a/htdocs/site/minify.bat +++ /dev/null @@ -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 diff --git a/htdocs/site/package.json b/htdocs/site/package.json new file mode 100644 index 000000000..be43eca2f --- /dev/null +++ b/htdocs/site/package.json @@ -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" + } +} diff --git a/htdocs/site/run-tests.js b/htdocs/site/run-tests.js new file mode 100644 index 000000000..53184f77d --- /dev/null +++ b/htdocs/site/run-tests.js @@ -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(); +}