diff --git a/.gitignore b/.gitignore index 4c57006f..433f78b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,18 @@ -*.tstamp +# temporary files *~ -/google-code-prettify/ +*.swp +.DS_Store + +# package managers +/node_modules/ +/bower_components/ +npm-debug.log +.bower.json + +# generated files +#/src/prettify.js +#/src/run_prettify.js +#/loader/*.js +#/loader/*.css +#/loader/skins/*.css +#/distrib/*.zip diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 00000000..cf74969b --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,253 @@ +/** + * google-code-prettify + * https://github.com/google/code-prettify + * + * Copyright (C) 2017 Google Inc. + * Licensed under Apache 2.0 license. + */ + +module.exports = function (grunt) { + 'use strict'; + + // project configuration + grunt.initConfig({ + // metadata + pkg: grunt.file.readJSON('package.json'), + + // grunt-preprocess + preprocess: { + // https://github.com/jsoverson/preprocess#optionstype + options: { + // renders @include directives (similar to SSI server-side includes) + // where JS files are resolved relative to this directory + srcDir: 'js-modules', + type: 'js' + }, + prettify: { + src: 'js-modules/prettify.js', + dest: 'src/prettify.js' + }, + runprettify: { + options: { + context: { + // to control where defs.js is included (top level) + RUN_PRETTIFY: true + } + }, + src: 'js-modules/run_prettify.js', + dest: 'src/run_prettify.js' + } + }, + + // grunt-contrib-copy + copy: { + prettify: { + options: { + process: function (content) { + // trim trailing whitespaces in blank lines added by preprocess + return content.replace(/[ \f\t\v]+$/gm, ''); + } + }, + files: [ + {src: 'src/prettify.js', dest: 'src/prettify.js'}, + {src: 'src/run_prettify.js', dest: 'src/run_prettify.js'} + ] + }, + langs: { + options: { + process: function (content) { + // replace PR.PR_* token names with inlined strings + return content + .replace(/\bPR\.PR_ATTRIB_NAME\b/g, '"atn"') + .replace(/\bPR\.PR_ATTRIB_VALUE\b/g, '"atv"') + .replace(/\bPR\.PR_COMMENT\b/g, '"com"') + .replace(/\bPR\.PR_DECLARATION\b/g, '"dec"') + .replace(/\bPR\.PR_KEYWORD\b/g, '"kwd"') + .replace(/\bPR\.PR_LITERAL\b/g, '"lit"') + .replace(/\bPR\.PR_NOCODE\b/g, '"nocode"') + .replace(/\bPR\.PR_PLAIN\b/g, '"pln"') + .replace(/\bPR\.PR_PUNCTUATION\b/g, '"pun"') + .replace(/\bPR\.PR_SOURCE\b/g, '"src"') + .replace(/\bPR\.PR_STRING\b/g, '"str"') + .replace(/\bPR\.PR_TAG\b/g, '"tag"') + .replace(/\bPR\.PR_TYPE\b/g, '"typ"'); + } + }, + files: [{ + expand: true, + cwd: 'loader/', + src: ['lang-*.js'], + dest: 'loader/' + }] + } + }, + + // ./tasks/aliases.js + aliases: { + langs: { + src: 'loader/lang-*.js', + filter: function (src) { + // skip files that are themselves aliases created in previous runs + return grunt.file.exists(src.replace(/^loader/, 'src')); + } + } + }, + + // grunt-contrib-uglify + uglify: { + // https://github.com/mishoo/UglifyJS2#usage + options: { + report: 'gzip', + ASCIIOnly: true, + maxLineLen: 500, + screwIE8: false + }, + prettify: { + options: { + compress: { + global_defs: {'IN_GLOBAL_SCOPE': true} + }, + wrap: true + }, + src: 'src/prettify.js', + dest: 'loader/prettify.js' + }, + runprettify: { + options: { + compress: { + global_defs: {'IN_GLOBAL_SCOPE': false} + }, + wrap: true + }, + src: 'src/run_prettify.js', + dest: 'loader/run_prettify.js' + }, + langs: { + files: [{ + expand: true, + cwd: 'src/', + src: ['lang-*.js'], + dest: 'loader/', + ext: '.js' + }] + } + }, + + // google-closure-compiler + 'closure-compiler': { + // https://github.com/google/closure-compiler/wiki + options: { + // Don't specify --charset=UTF-8. If we do, then non-ascii + // codepoints that do not correspond to line terminators are + // converted to UTF-8 sequences instead of being emitted as + // ASCII. This makes the resulting JavaScript less portable. + warning_level: 'VERBOSE', + language_in: 'ECMASCRIPT5', + compilation_level: 'ADVANCED', + charset: 'US-ASCII', + }, + prettify: { + options: { + externs: 'tools/closure-compiler/amd-externs.js', + define: 'IN_GLOBAL_SCOPE=true', + output_wrapper: '!function(){%output%}()' + }, + src: '<%= uglify.prettify.src %>', + dest: '<%= uglify.prettify.dest %>' + }, + runprettify: { + options: { + externs: 'tools/closure-compiler/amd-externs.js', + define: 'IN_GLOBAL_SCOPE=false', + output_wrapper: '!function(){%output%}()' + }, + src: '<%= uglify.runprettify.src %>', + dest: '<%= uglify.runprettify.dest %>' + }, + langs: { + options: { + externs: 'js-modules/externs.js' + }, + files: '<%= uglify.langs.files %>' + } + }, + + // ./tasks/gcc.js + gcc: { + // same as 'closure-compiler:langs' + langs: { + options: { + externs: 'js-modules/externs.js' + }, + files: '<%= uglify.langs.files %>' + } + }, + + // grunt-contrib-cssmin + cssmin: { + // https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api + options: { + report: 'gzip' + }, + prettify: { + src: 'src/prettify.css', + dest: 'loader/prettify.css' + }, + skins: { + files: [{ + expand: true, + cwd: 'styles/', + src: ['*.css'], + dest: 'loader/skins/', + ext: '.css' + }] + } + }, + + // grunt-contrib-compress + compress: { + zip: { + options: { + archive: 'distrib/prettify-small.zip', + mode: 'zip', + level: 9 + }, + files: [{ + expand: true, + cwd: 'loader/', + src: ['*.js', '*.css', 'skins/*.css'], + dest: 'google-code-prettify/' + }] + } + }, + + // grunt-contrib-clean + clean: { + js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'], + css: ['loader/*.css', 'loader/skins/*.css'], + zip: ['distrib/*.zip'] + } + }); + + // load plugins that provide tasks + require('google-closure-compiler').grunt(grunt); + grunt.loadTasks('./tasks'); + grunt.loadNpmTasks('grunt-preprocess'); + grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-cssmin'); + grunt.loadNpmTasks('grunt-contrib-compress'); + grunt.loadNpmTasks('grunt-contrib-clean'); + + // register task aliases + grunt.registerTask('default', [ + //'clean', + 'preprocess', + 'copy:prettify', + 'gcc', + 'copy:langs', + 'aliases', + 'cssmin', + 'compress' + ]); +}; diff --git a/Makefile b/Makefile deleted file mode 100644 index 00ffd225..00000000 --- a/Makefile +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/make -f - -# ============================================================================ -# google-code-prettify Makefile -# ============================================================================ -# -# Requirements: -# - Make: runs this makefile -# - Shell: runs various core utils as part of the build -# (touch, mkdir, cp, rm, wc, grep, zip) -# - Perl: runs js_include.pl script which combines/generates JS source files, -# also to run some regex search-and-replace -# - Java: runs Closure Compiler and YUI Compressor -# - Node.js: runs lang-handler-aliases.js script which generates language -# aliases from loader/lang-*.js extensions -# -# ============================================================================ - -# Don't specify --charset=UTF-8. If we do, then non-ascii codepoints -# that do not correspond to line terminators are converted -# to UTF-8 sequences instead of being emitted as ASCII. -# This makes the resulting JavaScript less portable. -CLOSURE_COMPILER=java -jar tools/closure-compiler/compiler.jar \ - --warning_level VERBOSE \ - --language_in ECMASCRIPT5 \ - --compilation_level ADVANCED_OPTIMIZATIONS \ - --charset US-ASCII - -YUI_COMPRESSOR=java -jar tools/yui-compressor/yuicompressor-2.4.8.jar \ - --charset UTF-8 - -RE_TOKENS='s/\bPR\.PR_ATTRIB_NAME\b/"atn"/g; \ - s/\bPR\.PR_ATTRIB_VALUE\b/"atv"/g; \ - s/\bPR\.PR_COMMENT\b/"com"/g; \ - s/\bPR\.PR_DECLARATION\b/"dec"/g; \ - s/\bPR\.PR_KEYWORD\b/"kwd"/g; \ - s/\bPR\.PR_LITERAL\b/"lit"/g; \ - s/\bPR\.PR_PLAIN\b/"pln"/g; \ - s/\bPR\.PR_PUNCTUATION\b/"pun"/g; \ - s/\bPR\.PR_STRING\b/"str"/g; \ - s/\bPR\.PR_TAG\b/"tag"/g; \ - s/\bPR\.PR_TYPE\b/"typ"/g;' - -# targets -OUT_DIR := loader/ loader/skins/ distrib/ -JS_FILES := loader/prettify.js loader/run_prettify.js -LANG_FILES := $(subst src/, loader/, $(wildcard src/lang-*.js)) -STYLE_FILES := $(subst src/, loader/, $(wildcard src/*.css)) -SKIN_FILES := $(subst styles/, loader/skins/, $(wildcard styles/*.css)) -TARGETS := $(JS_FILES) $(LANG_FILES) $(STYLE_FILES) $(SKIN_FILES) - -.PHONY: all clean - -all: $(TARGETS) lang-aliases.tstamp distrib/prettify-small.zip - -clean: - rm -rf *.tstamp src/prettify.js src/run_prettify.js $(OUT_DIR) - -# (order-only prerequisite to make sure output directories exist) -$(TARGETS): | $(OUT_DIR) - -$(OUT_DIR): - mkdir -p $(OUT_DIR) - -# JS_FILES -src/prettify.js src/run_prettify.js: js-modules/*.js js-modules/*.pl - @perl js-modules/js_include.pl $(notdir $@) > $@ - -# JS_FILES -loader/prettify.js: src/prettify.js - @$(CLOSURE_COMPILER) --js $< \ - --externs tools/closure-compiler/amd-externs.js \ - --define IN_GLOBAL_SCOPE=true \ - --output_wrapper='!function(){%output%}()' \ - --js_output_file $@ - @wc -c $< $@ | grep -v total - -# JS_FILES -loader/run_prettify.js: src/run_prettify.js - @$(CLOSURE_COMPILER) --js $< \ - --externs tools/closure-compiler/amd-externs.js \ - --define IN_GLOBAL_SCOPE=false \ - --output_wrapper='!function(){%output%}()' \ - --js_output_file $@ - @wc -c $< $@ | grep -v total - -# LANG_FILES -loader/lang-%.js: src/lang-%.js - @$(CLOSURE_COMPILER) --js $< \ - --externs js-modules/externs.js \ - | perl -pe $(RE_TOKENS) \ - > $@ - @wc -c $< $@ | grep -v total - -# STYLE_FILES -loader/%.css: src/%.css - @$(YUI_COMPRESSOR) --type css $< > $@ - @wc -c $< $@ | grep -v total - -# SKIN_FILES -loader/skins/%.css: styles/%.css - @$(YUI_COMPRESSOR) --type css $< > $@ - @wc -c $< $@ | grep -v total - -# aliases -lang-aliases.tstamp: $(LANG_FILES) - @node tools/lang-handler-aliases.js \ - && touch lang-aliases.tstamp - -# zip file -distrib/prettify-small.zip: $(TARGETS) - @rm -f $@ \ - && cp -R loader google-code-prettify \ - && zip -q -9 -r $@ google-code-prettify \ - && rm -rf google-code-prettify - @wc -c $@ | grep -v total diff --git a/bower.json b/bower.json new file mode 100644 index 00000000..27b13817 --- /dev/null +++ b/bower.json @@ -0,0 +1,40 @@ +{ + "name": "code-prettify", + "description": "Google Code Prettify", + "authors": [ + "Google" + ], + "license": "Apache-2.0", + "homepage": "https://github.com/google/code-prettify", + "repository": { + "type": "git", + "url": "git+https://github.com/google/code-prettify.git" + }, + "keywords": [ + "syntax", + "highlight", + "highlighting", + "source", + "code", + "prettify", + "google" + ], + "main": [ + "src/prettify.js", + "src/prettify.css" + ], + "moduleType": [ + "globals", + "amd" + ], + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "distrib", + "js-modules", + "tasks", + "tests", + "tools" + ] +} diff --git a/js-modules/defs.js b/js-modules/defs.js index 487c5ee5..18f3e4aa 100644 --- a/js-modules/defs.js +++ b/js-modules/defs.js @@ -47,4 +47,9 @@ var JobT; var SourceSpansT; /** @define {boolean} */ +/* @ifndef RUN_PRETTIFY */ var IN_GLOBAL_SCOPE = true; +/* @endif */ +/* @ifdef RUN_PRETTIFY */ +var IN_GLOBAL_SCOPE = false; +/* @endif */ diff --git a/js-modules/js_include.pl b/js-modules/js_include.pl deleted file mode 100644 index 61ee4736..00000000 --- a/js-modules/js_include.pl +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/perl - -# Given a JS file looks for lines like -# include("path/to/file/to/include"); -# and replaces them with the quoted file relative to the js-modules directory. -# If the included file ends with ".pl" then it is treated as a perl file to -# execute and the stdout is used as the JS to include. - -use strict; - -# Closure Compiler @define annotations that need to be pulled out of included -# files because @defines need to be top-level vars. -my $global_defs = ""; - -# Find @defines at the top of a JS file by pulling off comments and looking for -# comments containing @define followed by a var declaration. -sub extractGlobalDefs($) { - my @headerComments; - my $s = shift; - while ($s) { - last unless $s =~ m#^\s*(?://[^\r\n]*|/\*.*?\*/[ \t]*)[\r\n]*#s; - my $comment = $&; - $s = $'; - if ($comment =~ /[\@](define|typedef)/ - && $s =~ /^\s*var\s+[^;]+;[ \t]*[\r\n]*/) { - my $global = "$&"; - $s = $'; - $global =~ s/(var\s*IN_GLOBAL_SCOPE\s*=\s*)true\b/$1false/; - $global_defs .= "$comment$global"; - } else { - push(@headerComments, $comment); - } - } - return (join "", @headerComments) . $s; -} - -# readInclude(whiteSpacePrefix, path) returns the JS content at path -# (with the ".pl" adjustment above) and prepends each line with the -# whitespace in whiteSpacePrefix to produce a chunk of JS that matches the -# indentation of the including file. -# @defines are extracted so that they can all appear globally at the top of -# the file. -sub readInclude($$) { - my $prefix = shift; - my $name = "js-modules/" . (shift); - my $in; - if ($name =~ /\.pl$/) { - open($in, "perl $name|") or die "$name: $!"; - } else { - open($in, "<$name") or die "$name: $!"; - } - my $buf = ""; - while (<$in>) { - if (m/(\s*)include\("([^"]+)"\);\s*$/) { - my $inc = extractGlobalDefs(readInclude("$prefix$1", $2)); - $buf .= $inc; - } else { - $buf .= "$prefix$_"; - } - } - close($in); - return $buf; -} - -my $target = shift; -my $inc = readInclude("", $target); -my $header = ""; -# Put descriptive top level comments above the grouped @defines. -if ($inc =~ s#^(?://[^\r\n]*|/\*.*?\*/|\s)+##s) { - $header = $&; -} -my $globals = $global_defs; -# Un-indent @defines. -$globals =~ s#^[ \t]*##gm; -$globals .= "\n" unless $globals eq ""; - -print "$header$globals$inc"; diff --git a/js-modules/prettify.js b/js-modules/prettify.js index 998b93e0..d642139b 100644 --- a/js-modules/prettify.js +++ b/js-modules/prettify.js @@ -57,9 +57,9 @@ // JSLint declarations /*global console, document, navigator, setTimeout, window, define */ -include("defs.js"); - -var HACK_TO_FIX_JS_INCLUDE_PL; +/* @ifndef RUN_PRETTIFY */ +/* @include defs.js */ +/* @endif */ /** * {@type !{ @@ -236,11 +236,11 @@ var prettyPrint; */ var PR_NOCODE = 'nocode'; - include("regexpPrecederPatterns.pl"); + /* @include regexpPrecederPatterns.js */ - include("combinePrefixPatterns.js"); + /* @include combinePrefixPatterns.js */ - include("extractSourceSpans.js"); + /* @include extractSourceSpans.js */ /** * Apply the given language handler to sourceCode and add the resulting @@ -661,9 +661,9 @@ var prettyPrint; 'regexLiterals': true }); - include("numberLines.js"); + /* @include numberLines.js */ - include("recombineTagsAndDecorations.js"); + /* @include recombineTagsAndDecorations.js */ /** Maps language-specific file extensions to handlers. */ var langHandlerRegistry = {}; diff --git a/js-modules/regexpPrecederPatterns.js b/js-modules/regexpPrecederPatterns.js new file mode 100644 index 00000000..65d3de53 --- /dev/null +++ b/js-modules/regexpPrecederPatterns.js @@ -0,0 +1,30 @@ + +// Regex pattern below is automatically generated by regexpPrecederPatterns.pl +// Do not modify, your changes will be erased. + +// CAVEAT: this does not properly handle the case where a regular +// expression immediately follows another since a regular expression may +// have flags for case-sensitivity and the like. Having regexp tokens +// adjacent is not valid in any language I'm aware of, so I'm punting. +// TODO: maybe style special characters inside a regexp as punctuation. + +/** + * A set of tokens that can precede a regular expression literal in + * javascript + * http://web.archive.org/web/20070717142515/http://www.mozilla.org/js/language/js20/rationale/syntax.html + * has the full list, but I've removed ones that might be problematic when + * seen in languages that don't support regular expression literals. + * + * Specifically, I've removed any keywords that can't precede a regexp + * literal in a syntactically legal javascript program, and I've removed the + * "in" keyword since it's not a keyword in many languages, and might be used + * as a count of inches. + * + * The link above does not accurately describe EcmaScript rules since + * it fails to distinguish between (a=++/b/i) and (a++/b/i) but it works + * very well in practice. + * + * @private + * @const + */ +var REGEXP_PRECEDER_PATTERN = '(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*'; diff --git a/js-modules/regexpPrecederPatterns.pl b/js-modules/regexpPrecederPatterns.pl index 488dbd68..0f1e1d59 100644 --- a/js-modules/regexpPrecederPatterns.pl +++ b/js-modules/regexpPrecederPatterns.pl @@ -1,6 +1,14 @@ use strict; print " +// Regex pattern below is automatically generated by regexpPrecederPatterns.pl +// Do not modify, your changes will be erased. + +// CAVEAT: this does not properly handle the case where a regular +// expression immediately follows another since a regular expression may +// have flags for case-sensitivity and the like. Having regexp tokens +// adjacent is not valid in any language I'm aware of, so I'm punting. +// TODO: maybe style special characters inside a regexp as punctuation. /** * A set of tokens that can precede a regular expression literal in @@ -9,12 +17,12 @@ * has the full list, but I've removed ones that might be problematic when * seen in languages that don't support regular expression literals. * - *

Specifically, I've removed any keywords that can't precede a regexp + * Specifically, I've removed any keywords that can't precede a regexp * literal in a syntactically legal javascript program, and I've removed the * \"in\" keyword since it's not a keyword in many languages, and might be used * as a count of inches. * - *

The link above does not accurately describe EcmaScript rules since + * The link above does not accurately describe EcmaScript rules since * it fails to distinguish between (a=++/b/i) and (a++/b/i) but it works * very well in practice. * @@ -34,7 +42,7 @@ "->", "\\/=?", # "/", "/=", "::?", # ":", "::", - "<>?>?=?", # ">", ">=", ">>", ">>=", ">>>", ">>>=", ",", ";", # ";" @@ -58,11 +66,3 @@ $pattern .= ")\\\\s*'"; # matches at end, and matches empty string print "$pattern;\n"; - -print " -// CAVEAT: this does not properly handle the case where a regular -// expression immediately follows another since a regular expression may -// have flags for case-sensitivity and the like. Having regexp tokens -// adjacent is not valid in any language I'm aware of, so I'm punting. -// TODO: maybe style special characters inside a regexp as punctuation. -"; diff --git a/js-modules/run_prettify.js b/js-modules/run_prettify.js index 04546b3d..5fec41ad 100644 --- a/js-modules/run_prettify.js +++ b/js-modules/run_prettify.js @@ -61,6 +61,10 @@ * */ +/* @ifdef RUN_PRETTIFY */ +/* @include defs.js */ +/* @endif */ + (function () { "use strict"; @@ -226,7 +230,7 @@ loadStylesheetsFallingBack(skinUrls); var prettyPrint = (function () { - include("prettify.js"); + /* @include prettify.js */ return prettyPrint; })(); diff --git a/package.json b/package.json new file mode 100644 index 00000000..61493b1e --- /dev/null +++ b/package.json @@ -0,0 +1,57 @@ +{ + "name": "code-prettify", + "version": "1.0.0", + "description": "Google Code Prettify", + "license": "Apache-2.0", + "homepage": "https://github.com/google/code-prettify", + "repository": { + "type": "git", + "url": "git+https://github.com/google/code-prettify.git" + }, + "bugs": { + "url": "https://github.com/google/code-prettify/issues" + }, + "keywords": [ + "syntax", + "highlight", + "highlighting", + "source", + "code", + "prettify", + "google" + ], + "author": "Google", + "maintainers": [ + "Mike Samuel " + ], + "contributors": [ + "Amro " + ], + "main": "src/prettify.js", + "directories": { + "lib": "src", + "doc": "docs", + "example": "examples", + "test": "tests" + }, + "files": [ + "loader/", + "src/", + "styles/*.css", + "COPYING" + ], + "scripts": { + "grunt": "grunt", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "devDependencies": { + "google-closure-compiler": "^20161201.0.0", + "grunt": "^1.0.1", + "grunt-contrib-clean": "^1.0.0", + "grunt-contrib-compress": "^1.3.0", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-cssmin": "^1.0.2", + "grunt-contrib-uglify": "^2.0.0", + "grunt-preprocess": "^5.1.0" + } +} diff --git a/tasks/aliases.js b/tasks/aliases.js new file mode 100644 index 00000000..e67aadf9 --- /dev/null +++ b/tasks/aliases.js @@ -0,0 +1,72 @@ +/** + * google-code-prettify + * https://github.com/google/code-prettify + * + * @author Amro + * @license Apache-2.0 + */ + +module.exports = function (grunt) { + 'use strict'; + + var fs = require('fs'); + var runLanguageHandler = require('./lib/lang-aliases'); + + /** + * Copy timestamp from source to destination file. + * @param {string} src + * @param {string} dest + * @param {boolean} timestamp + */ + function syncTimestamp(src, dest, timestamp) { + if (timestamp) { + var stat = fs.lstatSync(src); + var fd = fs.openSync(dest, process.platform === 'win32' ? 'r+' : 'r'); + fs.futimesSync(fd, stat.atime, stat.mtime); + fs.closeSync(fd); + } + } + + /** + * Copy file mode from source to destination. + * @param {string} src + * @param {string} dest + * @param {boolean|number} mode + */ + function syncMod(src, dest, mode) { + if (mode !== false) { + fs.chmodSync(dest, (mode === true) ? fs.lstatSync(src).mode : mode); + } + } + + // Create copies of language handler files under all registered aliases + grunt.registerMultiTask('aliases', 'Create language aliases', function () { + var opts = this.options({ + timestamp: false, + mode: false + }); + + var count = 0; + this.filesSrc.forEach(function (src) { + // run language handler in sandbox + grunt.verbose.subhead('Running ' + src.cyan + ' in sandbox...'); + var exts = runLanguageHandler(src); + grunt.verbose.ok(); + + // go over collected extensions + exts.forEach(function (ext) { + // copy file + var dest = src.replace(/\blang-\w+\b/, 'lang-' + ext); + grunt.verbose.writeln('Copying ' + src.cyan + ' -> ' + dest.cyan); + grunt.file.copy(src, dest); + + // sync timestamp and file mode + syncTimestamp(src, dest, opts.timestamp); + syncMod(src, dest, opts.mode); + count++; + }); + }); + grunt.log.ok('Copied ' + count.toString().cyan + + grunt.util.pluralize(count, ' file/ files')); + }); +}; diff --git a/tasks/gcc.js b/tasks/gcc.js new file mode 100644 index 00000000..cd64d29f --- /dev/null +++ b/tasks/gcc.js @@ -0,0 +1,49 @@ +/** + * google-code-prettify + * https://github.com/google/code-prettify + * + * @author Amro + * @license Apache-2.0 + */ + +module.exports = function (grunt) { + 'use strict'; + + /* + * HACK: Custom task to override "closure-compiler:langs" since all lang-* + * files are compiled in parallel, launching too many Java processes at once + * which easily runs out of memory! This task programmatically creates + * separate targets (one file per target) so that lang files are compiled + * sequentially (sync) instead of in parallel (async). + */ + grunt.registerMultiTask('gcc', 'Override closure-compiler', function () { + // closure-compiler:langs + var task = 'closure-compiler'; + var target = this.target; + if (!grunt.task.exists(task)) { + grunt.fail.warn(grunt.util.error('Require task "' + task + '".')); + } + + // create new targets for each file (one file per target) + var count = 0; + var opts = this.options(); + this.files.forEach(function (file, idx) { + // simple target config with only: src, dest, and options + delete file.orig; + file.options = opts; + + // configure new target + grunt.config.set([task, target + idx], file); + grunt.verbose.writeln('New target ' + (task + ':' + target + idx).cyan); + count++; + }); + grunt.log.ok('Configured ' + count.toString().cyan + ' lang targets'); + + // remove original multi-file target + grunt.config.set([task, target], {}); + + // enqueue modified task to run + //console.log(grunt.config.get(task)); + grunt.task.run(task); + }); +}; diff --git a/tasks/lib/lang-aliases.js b/tasks/lib/lang-aliases.js new file mode 100644 index 00000000..7272e829 --- /dev/null +++ b/tasks/lib/lang-aliases.js @@ -0,0 +1,92 @@ +/** + * google-code-prettify + * https://github.com/google/code-prettify + * + * @author Amro + * @license Apache-2.0 + */ + +var fs = require('fs'); +var path = require('path'); +var vm = require('vm'); + +/** + * Returns a mock object PR of the prettify API. This is used to collect + * registered language file extensions. + * + * @return {Object} PR object with an additional `extensions` property. + */ +function createSandbox() { + // collect registered language extensions + var sandbox = {}; + sandbox.extensions = []; + // mock prettify.js API + sandbox.window = {}; + sandbox.window.PR = sandbox.PR = { + registerLangHandler: function (handler, exts) { + sandbox.extensions = sandbox.extensions.concat(exts); + }, + createSimpleLexer: function (sPatterns, fPatterns) { + return function (job) {}; + }, + sourceDecorator: function (options) { + return function (job) {}; + }, + prettyPrintOne: function (src, lang, ln) { + return src; + }, + prettyPrint: function (done, root) {}, + PR_ATTRIB_NAME: 'atn', + PR_ATTRIB_VALUE: 'atv', + PR_COMMENT: 'com', + PR_DECLARATION: 'dec', + PR_KEYWORD: 'kwd', + PR_LITERAL: 'lit', + PR_NOCODE: 'nocode', + PR_PLAIN: 'pln', + PR_PUNCTUATION: 'pun', + PR_SOURCE: 'src', + PR_STRING: 'str', + PR_TAG: 'tag', + PR_TYPE: 'typ' + }; + return sandbox; +} + +/** + * Runs a language handler file under VM to collect extensions. + * + * Given a lang-*.js file, runs the language handler in a fake context where + * PR.registerLangHandler collects handler names without doing anything else. + * This is later used to makes copies of the JS extension under all its + * registered language names lang-.js + * + * @param {string} src path to lang-xxx.js language handler + * @return {Array} registered file extensions + */ +function runLanguageHandler(src) { + // execute source code in an isolated sandbox with a mock PR object + var sandbox = createSandbox(); + vm.runInNewContext(fs.readFileSync(src), sandbox, { + filename: src + }); + + // language name + var lang = path.basename(src, path.extname(src)).replace(/^lang-/, ''); + + // collect and filter extensions + var exts = sandbox.extensions.map(function (ext) { + // case-insensitive names + return ext.toLowerCase(); + }).filter(function (ext) { + // skip self, and internal names like foo-bar-baz or lang.foo + return ext !== lang && !/\W/.test(ext); + }); + exts = exts.filter(function (ext, pos) { + // remove duplicates + return exts.indexOf(ext) === pos; + }); + return exts; +} + +module.exports = runLanguageHandler; diff --git a/tools/closure-compiler/COPYING b/tools/closure-compiler/COPYING deleted file mode 100644 index d6456956..00000000 --- a/tools/closure-compiler/COPYING +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/tools/closure-compiler/README.md b/tools/closure-compiler/README.md deleted file mode 100644 index cbb22775..00000000 --- a/tools/closure-compiler/README.md +++ /dev/null @@ -1,503 +0,0 @@ -# [Google Closure Compiler](https://developers.google.com/closure/compiler/) - -[![Build Status](https://travis-ci.org/google/closure-compiler.svg?branch=master)](https://travis-ci.org/google/closure-compiler) - -The [Closure Compiler](https://developers.google.com/closure/compiler/) is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. - -## Getting Started - * [Download the latest version](http://dl.google.com/closure-compiler/compiler-latest.zip) ([Release details here](https://github.com/google/closure-compiler/wiki/Releases)) - * [Download a specific version](https://github.com/google/closure-compiler/wiki/Binary-Downloads). Also available via: - - [Maven](https://github.com/google/closure-compiler/wiki/Maven) - - [NPM](https://www.npmjs.com/package/google-closure-compiler) - * See the [Google Developers Site](https://developers.google.com/closure/compiler/docs/gettingstarted_app) for documentation including instructions for running the compiler from the command line. - -## Options for Getting Help -1. Post in the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss) -2. Ask a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/google-closure-compiler) -3. Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ) - -## Building it Yourself - -Note: The Closure Compiler requires [Java 7 or higher](http://www.java.com/). - -### Using [Maven](http://maven.apache.org/) - -1. Download [Maven](http://maven.apache.org/download.cgi). - -2. Run `mvn -DskipTests` (omit the `-DskipTests` if you want to run all the -unit tests too). - - This will produce a jar file called `target/closure-compiler-1.0-SNAPSHOT.jar`. - -### Using [Eclipse](http://www.eclipse.org/) - -1. Download and open the [Eclipse IDE](http://www.eclipse.org/). -2. Navigate to ```File > New > Project ...``` and create a Java Project. Give - the project a name. -3. Select ```Create project from existing source``` and choose the root of the - checked-out source tree as the existing directory. -3. Navigate to the ```build.xml``` file. You will see all the build rules in - the Outline pane. Run the ```jar``` rule to build the compiler in - ```build/compiler.jar```. - -## Running - -On the command line, at the root of this project, type - -``` -java -jar build/compiler.jar -``` - -This starts the compiler in interactive mode. Type - -```javascript -var x = 17 + 25; -``` - -then hit "Enter", then hit "Ctrl-Z" (on Windows) or "Ctrl-D" (on Mac or Linux) -and "Enter" again. The Compiler will respond: - -```javascript -var x=42; -``` - -The Closure Compiler has many options for reading input from a file, writing -output to a file, checking your code, and running optimizations. To learn more, -type - -``` -java -jar compiler.jar --help -``` - -More detailed information about running the Closure Compiler is available in the -[documentation](http://code.google.com/closure/compiler/docs/gettingstarted_app.html). - -## Compiling Multiple Scripts - -If you have multiple scripts, you should compile them all together with one -compile command. - -```bash -java -jar compiler.jar --js_output_file=out.js in1.js in2.js in3.js ... -``` - -You can also use minimatch-style globs. - -```bash -# Recursively include all js files in subdirs -java -jar compiler.jar --js_output_file=out.js 'src/**.js' - -# Recursively include all js files in subdirs, exclusing test files. -# Use single-quotes, so that bash doesn't try to expand the '!' -java -jar compiler.jar --js_output_file=out.js 'src/**.js' '!**_test.js' -``` - -The Closure Compiler will concatenate the files in the order they're passed at -the command line. - -If you're using globs or many files, you may start to run into -problems with managing dependencies between scripts. In this case, you should -use the [Closure Library](https://developers.google.com/closure/library/). It -contains functions for enforcing dependencies between scripts, and Closure Compiler -will re-order the inputs automatically. - -## How to Contribute -### Reporting a bug -1. First make sure that it is really a bug and not simply the way that Closure Compiler works (especially true for ADVANCED_OPTIMIZATIONS). - * Check the [official documentation](https://developers.google.com/closure/compiler/) - * Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ) - * Search on [Stack Overflow](http://stackoverflow.com/questions/tagged/google-closure-compiler) and in the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss) -2. If you still think you have found a bug, make sure someone hasn't already reported it. See the list of [known issues](https://github.com/google/closure-compiler/issues). -3. If it hasn't been reported yet, post a new issue. Make sure to add enough detail so that the bug can be recreated. The smaller the reproduction code, the better. - -### Suggesting a Feature -1. Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ) to make sure that the behaviour you would like isn't specifically excluded (such as string inlining). -2. Make sure someone hasn't requested the same thing. See the list of [known issues](https://github.com/google/closure-compiler/issues). -3. Read up on [what type of feature requests are accepted](https://github.com/google/closure-compiler/wiki/FAQ#how-do-i-submit-a-feature-request-for-a-new-type-of-optimization). -4. Submit your reqest as an issue. - -### Submitting patches -1. All contributors must sign a contributor license agreement (CLA). - A CLA basically says that you own the rights to any code you contribute, - and that you give us permission to use that code in Closure Compiler. - You maintain the copyright on that code. - If you own all the rights to your code, you can fill out an - [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). - If your employer has any rights to your code, then they also need to fill out - a [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). - If you don't know if your employer has any rights to your code, you should - ask before signing anything. - By default, anyone with an @google.com email address already has a CLA - signed for them. -2. To make sure your changes are of the type that will be accepted, ask about your patch on the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss) -3. Fork the repository. -4. Make your changes. -5. Submit a pull request for your changes. A project developer will review your work and then merge your request into the project. - -## Closure Compiler License - -Copyright 2009 The Closure Compiler Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -## Dependency Licenses - -### Rhino - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Path - src/com/google/javascript/rhino, test/com/google/javascript/rhino -
URLhttp://www.mozilla.org/rhino
Version1.5R3, with heavy modifications
LicenseNetscape Public License and MPL / GPL dual license
DescriptionA partial copy of Mozilla Rhino. Mozilla Rhino is an -implementation of JavaScript for the JVM. The JavaScript -parse tree data structures were extracted and modified -significantly for use by Google's JavaScript compiler.
Local ModificationsThe packages have been renamespaced. All code not -relevant to the parse tree has been removed. A JsDoc parser and static typing -system have been added.
- -### Args4j - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathlib/args4j.jar
URLhttps://args4j.dev.java.net/
Version2.0.26
LicenseMIT
Descriptionargs4j is a small Java class library that makes it easy to parse command line -options/arguments in your CUI application.
Local ModificationsNone
- -### Guava Libraries - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathlib/guava.jar
URLhttps://github.com/google/guava
Version18.0
LicenseApache License 2.0
DescriptionGoogle's core Java libraries.
Local ModificationsNone
- -### JSR 305 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathlib/jsr305.jar
URLhttp://code.google.com/p/jsr-305/
Versionsvn revision 47
LicenseBSD License
DescriptionAnnotations for software defect detection.
Local ModificationsNone
- -### JUnit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathlib/junit.jar
URLhttp://sourceforge.net/projects/junit/
Version4.11
LicenseCommon Public License 1.0
DescriptionA framework for writing and running automated tests in Java.
Local ModificationsNone
- -### Protocol Buffers - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathlib/protobuf-java.jar
URLhttps://github.com/google/protobuf
Version2.5.0
LicenseNew BSD License
DescriptionSupporting libraries for protocol buffers, -an encoding of structured data.
Local ModificationsNone
- -### Truth - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathlib/truth.jar
URLhttps://github.com/google/truth
Version0.24
LicenseApache License 2.0
DescriptionAssertion/Proposition framework for Java unit tests
Local ModificationsNone
- -### Ant - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Path - lib/ant.jar, lib/ant-launcher.jar -
URLhttp://ant.apache.org/bindownload.cgi
Version1.8.1
LicenseApache License 2.0
DescriptionAnt is a Java based build tool. In theory it is kind of like "make" -without make's wrinkles and with the full portability of pure java code.
Local ModificationsNone
- -### GSON - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathlib/gson.jar
URLhttps://github.com/google/gson
Version2.2.4
LicenseApache license 2.0
DescriptionA Java library to convert JSON to Java objects and vice-versa
Local ModificationsNone
- -### Node.js Closure Compiler Externs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code Pathcontrib/nodejs
URLhttps://github.com/dcodeIO/node.js-closure-compiler-externs
Versione891b4fbcf5f466cc4307b0fa842a7d8163a073a
LicenseApache 2.0 license
DescriptionType contracts for NodeJS APIs
Local ModificationsSubstantial changes to make them compatible with NpmCommandLineRunner.
diff --git a/tools/closure-compiler/compiler.jar b/tools/closure-compiler/compiler.jar deleted file mode 100644 index 9cae6957..00000000 Binary files a/tools/closure-compiler/compiler.jar and /dev/null differ diff --git a/tools/lang-handler-aliases.js b/tools/lang-handler-aliases.js deleted file mode 100644 index e1b8abfc..00000000 --- a/tools/lang-handler-aliases.js +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env node - -/** - * For each lang-*.js file, runs the language handler in a fake context where - * PR.registerLangHandler collects handler names without doing anything else, - * and then makes copies of the JS extension under all registered language - * names lang-.js - * - * As verbose output, it also prints lines of the form: - * lang-foo.js => foo,bar,baz - */ - -var fs = require('fs'); -var path = require('path'); -var vm = require('vm'); - -function getSandbox() { - // collect registered language extensions - var sandbox = {}; - sandbox.langExtensions = []; - // mock prettify.js API - sandbox.window = {}; - sandbox.window.PR = sandbox.PR = { - registerLangHandler: function (_, exts) { - exts.forEach(function (ext) { - // take case-insensitive names, - // and skip internal stuff like: foo-bar-baz - var handler = String(ext).toLowerCase(); - if (/^\w+$/.test(handler)) { - sandbox.langExtensions.push(handler); - } - }); - }, - createSimpleLexer: function () {}, - sourceDecorator: function () {}, - PR_ATTRIB_NAME: 'atn', - PR_ATTRIB_VALUE: 'atv', - PR_COMMENT: 'com', - PR_DECLARATION: 'dec', - PR_KEYWORD: 'kwd', - PR_LITERAL: 'lit', - PR_PLAIN: 'pln', - PR_PUNCTUATION: 'pun', - PR_STRING: 'str', - PR_TAG: 'tag', - PR_TYPE: 'typ' - }; - return sandbox; -} - -// loop over lang-*.js files, and run each in an isolated sandbox -var srcDir = path.join(__dirname, '..', 'loader'); -fs.readdirSync(srcDir).filter(function (f) { - return path.extname(f) == '.js' && /^lang-/.test(f); -}).forEach(function (f) { - // read source code - var sourceFile = path.join(srcDir, f); - var code = fs.readFileSync(sourceFile); - - // execute code in a seperate VM with a fake PR in context - var sandbox = getSandbox(); - vm.runInNewContext(code, sandbox, { - filename: sourceFile - }); - - // collect extensions list - var langExtensions = sandbox.langExtensions.sort(); - console.log(f + ' => ' + langExtensions); - - // for each unique alias, copy file if not already exist - langExtensions.filter(function (ext, pos) { - return langExtensions.indexOf(ext) == pos; - }).forEach(function (ext) { - var targetFile = path.join(srcDir, 'lang-' + ext + '.js'); - if (!fs.existsSync(targetFile)) { - fs.writeFileSync(targetFile, code); - } - }); -}); diff --git a/tools/yui-compressor/LICENSE.TXT b/tools/yui-compressor/LICENSE.TXT deleted file mode 100644 index fc34134a..00000000 --- a/tools/yui-compressor/LICENSE.TXT +++ /dev/null @@ -1,54 +0,0 @@ -YUI Compressor Copyright License Agreement (BSD License) - -Copyright (c) 2009, Yahoo! Inc. -All rights reserved. - -Redistribution and use of this software in source and binary forms, -with or without modification, are permitted provided that the following -conditions are met: - -* Redistributions of source code must retain the above - copyright notice, this list of conditions and the - following disclaimer. - -* Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - -* Neither the name of Yahoo! Inc. nor the names of its - contributors may be used to endorse or promote products - derived from this software without specific prior - written permission of Yahoo! Inc. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software also requires access to software from the following sources: - -The Jarg Library v 1.0 ( http://jargs.sourceforge.net/ ) is available -under a BSD License – Copyright (c) 2001-2003 Steve Purcell, -Copyright (c) 2002 Vidar Holen, Copyright (c) 2002 Michal Ceresna and -Copyright (c) 2005 Ewan Mellor. - -The Rhino Library ( http://www.mozilla.org/rhino/ ) is dually available -under an MPL 1.1/GPL 2.0 license, with portions subject to a BSD license. - -Additionally, this software contains modified versions of the following -component files from the Rhino Library: - -[org/mozilla/javascript/Decompiler.java] -[org/mozilla/javascript/Parser.java] -[org/mozilla/javascript/Token.java] -[org/mozilla/javascript/TokenStream.java] - -The modified versions of these files are distributed under the MPL v 1.1 -( http://www.mozilla.org/MPL/MPL-1.1.html ) diff --git a/tools/yui-compressor/README b/tools/yui-compressor/README deleted file mode 100644 index c2b5751c..00000000 --- a/tools/yui-compressor/README +++ /dev/null @@ -1,145 +0,0 @@ -============================================================================== -YUI Compressor -============================================================================== - -NAME - - YUI Compressor - The Yahoo! JavaScript and CSS Compressor - -SYNOPSIS - - Usage: java -jar yuicompressor-x.y.z.jar [options] [input file] - - Global Options - -h, --help Displays this information - --type Specifies the type of the input file - --charset Read the input file using - --line-break Insert a line break after the specified column number - -v, --verbose Display informational messages and warnings - -o Place the output into or a file pattern. - Defaults to stdout. - - JavaScript Options - --nomunge Minify only, do not obfuscate - --preserve-semi Preserve all semicolons - --disable-optimizations Disable all micro optimizations - -DESCRIPTION - - The YUI Compressor is a JavaScript compressor which, in addition to removing - comments and white-spaces, obfuscates local variables using the smallest - possible variable name. This obfuscation is safe, even when using constructs - such as 'eval' or 'with' (although the compression is not optimal is those - cases) Compared to jsmin, the average savings is around 20%. - - The YUI Compressor is also able to safely compress CSS files. The decision - on which compressor is being used is made on the file extension (js or css) - -GLOBAL OPTIONS - - -h, --help - Prints help on how to use the YUI Compressor - - --line-break - Some source control tools don't like files containing lines longer than, - say 8000 characters. The linebreak option is used in that case to split - long lines after a specific column. It can also be used to make the code - more readable, easier to debug (especially with the MS Script Debugger) - Specify 0 to get a line break after each semi-colon in JavaScript, and - after each rule in CSS. - - --type js|css - The type of compressor (JavaScript or CSS) is chosen based on the - extension of the input file name (.js or .css) This option is required - if no input file has been specified. Otherwise, this option is only - required if the input file extension is neither 'js' nor 'css'. - - --charset character-set - If a supported character set is specified, the YUI Compressor will use it - to read the input file. Otherwise, it will assume that the platform's - default character set is being used. The output file is encoded using - the same character set. - - -o outfile - - Place output in file outfile. If not specified, the YUI Compressor will - default to the standard output, which you can redirect to a file. - Supports a filter syntax for expressing the output pattern when there are - multiple input files. ex: - java -jar yuicompressor.jar -o '.css$:-min.css' *.css - ... will minify all .css files and save them as -min.css - - -v, --verbose - Display informational messages and warnings. - -JAVASCRIPT ONLY OPTIONS - - --nomunge - Minify only. Do not obfuscate local symbols. - - --preserve-semi - Preserve unnecessary semicolons (such as right before a '}') This option - is useful when compressed code has to be run through JSLint (which is the - case of YUI for example) - - --disable-optimizations - Disable all the built-in micro optimizations. - -NOTES - - + If no input file is specified, it defaults to stdin. - - + Supports wildcards for specifying multiple input files. - - + The YUI Compressor requires Java version >= 1.4. - - + It is possible to prevent a local variable, nested function or function - argument from being obfuscated by using "hints". A hint is a string that - is located at the very beginning of a function body like so: - - function fn (arg1, arg2, arg3) { - "arg2:nomunge, localVar:nomunge, nestedFn:nomunge"; - - ... - var localVar; - ... - - function nestedFn () { - .... - } - - ... - } - - The hint itself disappears from the compressed file. - - + C-style comments starting with /*! are preserved. This is useful with - comments containing copyright/license information. For example: - - /*! - * TERMS OF USE - EASING EQUATIONS - * Open source under the BSD License. - * Copyright 2001 Robert Penner All rights reserved. - */ - - becomes: - - /* - * TERMS OF USE - EASING EQUATIONS - * Open source under the BSD License. - * Copyright 2001 Robert Penner All rights reserved. - */ - -MODIFIED RHINO FILES - - YUI Compressor uses a modified version of the Rhino library - (http://www.mozilla.org/rhino/) The changes were made to support - JScript conditional comments, preserved comments, unescaped slash - characters in regular expressions, and to allow for the optimization - of escaped quotes in string literals. - -COPYRIGHT AND LICENSE - - Copyright (c) 2010 Yahoo! Inc. All rights reserved. - The copyrights embodied in the content of this file are licensed - by Yahoo! Inc. under the BSD (revised) open source license. diff --git a/tools/yui-compressor/yuicompressor-2.4.8.jar b/tools/yui-compressor/yuicompressor-2.4.8.jar deleted file mode 100644 index a1cf0a09..00000000 Binary files a/tools/yui-compressor/yuicompressor-2.4.8.jar and /dev/null differ