Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

Commit

Permalink
Add a new tool: jsmin.js.
Browse files Browse the repository at this point in the history
This is based on http://fmarcia.info/jsmin/test.html from Franck Marcia,
which in turn based on http://javascript.crockford.com/jsmin.html from
Douglas Crockford.
  • Loading branch information
ariya committed Sep 13, 2011
1 parent 663a5d4 commit f1513df
Show file tree
Hide file tree
Showing 9 changed files with 1,130 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -30,6 +30,7 @@ set(EIGHTPACK_PATH ${PROJECT_SOURCE_DIR}/lib)
add_subdirectory(jslint)
add_subdirectory(jshint)
add_subdirectory(jsbeautify)
add_subdirectory(jsmin)

add_subdirectory(cssbeautify)
add_subdirectory(cssmin)
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -8,8 +8,9 @@ EightPack can be [built](http://ofilabs.com/eightpack/build) on all major
desktop platforms (Windows, Mac OS X, Linux). Binaries for Windows
and Mac OS X are available for [download](http://ofilabs.com/eightpack/download).

As of now, EightPack consists of the following [tools](http://ofilabs.com/eightpack/tools): JSLint, JSHint, JS
Beautifier, CSS Beautify, and cssmin.js.
As of now, EightPack consists of the following
[tools](http://ofilabs.com/eightpack/tools): JSLint, JSHint, JS Beautifier,
JSMin, CSS Beautify, and cssmin.js.

EightPack is an open-source software, distributed and available under
[MIT License](http://ofilabs.com/eightpack/license).
Expand Down
6 changes: 6 additions & 0 deletions jsmin/CMakeLists.txt
@@ -0,0 +1,6 @@
add_executable(jsmin jsmin.cpp)
link_directories(${EIGHTPACK_PATH})
target_link_libraries(jsmin eightpack)
set_target_properties(jsmin PROPERTIES COMPILE_FLAGS ${EIGHTPACK_COMPILE_FLAGS})
set_target_properties(jsmin PROPERTIES LINK_FLAGS ${EIGHTPACK_LINK_FLAGS})
install(TARGETS jsmin DESTINATION bin)
96 changes: 96 additions & 0 deletions jsmin/CommandLine.js
@@ -0,0 +1,96 @@
/*global system: true, console: true */
var jsmin, fname, settings, level, code, result;

settings = settings || {};

function help() {
'use strict';
var opt, str;
console.log('Usage:');
console.log(' jsmin [options] filename');
console.log();
console.log('The content of filename will be minified and printed to');
console.log('standard output.');
console.log();
console.log('General options:');
console.log(' --help Show this help screen');
console.log(' --version Display version number');
console.log();
console.log('JSMin options (see http://fmarcia.info/jsmin/test.html):');
for (opt in settings) {
if (settings.hasOwnProperty(opt)) {
str = ' --' + opt;
while (str.length < 25) {
str += ' ';
}
str += settings[opt];
console.log(str);
}
}
console.log();
console.log('For more information, go to http://fmarcia.info/jsmin/test.html and');
console.log('http://www.crockford.com/javascript/jsmin.html.');
console.log();
system.exit(-1);
}

if (system.args.length < 1) {
help();
}

level = 2;

system.args.forEach(function (arg) {
'use strict';
var option, i;
if (arg.length > 2) {
if (arg.charAt(0) === '-' && arg.charAt(1) === '-') {
option = arg.substring(2, arg.length);

if (option === 'help') {
help();
}

if (option === 'version') {
console.log('jsmin.js edition 2010/01/15.');
system.exit(-1);
}

if (!settings.hasOwnProperty(option)) {
console.log('Unknown option: --' + option);
console.log('Run jsmin --help to list all possible options.');
console.log();
system.exit(-1);
}

if (option === 'aggressive') {
level = 3;
}

if (option === 'minimal') {
level = 1;
}

return;
}
}
if (typeof fname !== 'undefined') {
console.log('Please only specify one filename!');
console.log();
system.exit(-1);
}
fname = arg;
});


if (typeof fname === 'undefined') {
help();
}

try {
code = system.readFile(fname);
result = jsmin('', code, level);
console.log(result);
} catch (e) {
console.log(e);
}
5 changes: 5 additions & 0 deletions jsmin/Settings.js
@@ -0,0 +1,5 @@
var settings = {
'conversative': 'The default, removes comments and unnecessary whitespace.',
'minimal': 'Like conversative but keeps single linefeeds.',
'aggressive': 'Like conversative but removes more linefeeds (dangerous!)',
};
33 changes: 33 additions & 0 deletions jsmin/jsmin.cpp
@@ -0,0 +1,33 @@
/*
Copyright (C) 2011 Ariya Hidayat.
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.
*/


#include "jsmin_script.h"

extern void eightpack_run(int argc, char** argv, const char* cmd);

int main(int argc, char* argv[])
{
eightpack_run(argc, argv, jsmin_script);
return 0;
}

0 comments on commit f1513df

Please sign in to comment.