[Pkg-javascript-commits] [node-uglify-save-license] 01/02: Imported Upstream version 0.4.1

Thorsten Alteholz alteholz at moszumanska.debian.org
Sat Feb 27 14:09:07 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-uglify-save-license.

commit a48a4533a99f964aa9151adbe610fe438d3c9c03
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sat Feb 27 15:08:58 2016 +0100

    Imported Upstream version 0.4.1
---
 .gitignore                                  |  20 +++
 .jshintrc                                   |   7 +
 .npmignore                                  |   4 +
 .travis.yml                                 |   8 ++
 Gruntfile.coffee                            |  86 +++++++++++++
 LICENSE                                     |  20 +++
 README.md                                   | 192 ++++++++++++++++++++++++++++
 package.json                                |  51 ++++++++
 test/expected/block-series.js               |   2 +
 test/expected/first-block.js                |   1 +
 test/expected/first-line.js                 |   1 +
 test/expected/line-after-newline.js         |   0
 test/expected/line-series.js                |   2 +
 test/expected/regexp/at_cc_on.js            |   2 +
 test/expected/regexp/at_preserve.js         |   2 +
 test/expected/regexp/copyright.js           |   2 +
 test/expected/regexp/copyright_mark.js      |   2 +
 test/expected/regexp/mit.js                 |   2 +
 test/expected/separated-block-license.js    |   2 +
 test/expected/separated-block.js            |   1 +
 test/expected/separated-line-license.js     |   2 +
 test/expected/separated-line.js             |   1 +
 test/expected/start_with_bang/block_bang.js |   2 +
 test/expected/start_with_bang/line_bang.js  |   2 +
 test/fixtures/block-series.js               |   2 +
 test/fixtures/first-block.js                |   1 +
 test/fixtures/first-line.js                 |   1 +
 test/fixtures/line-after-newline.js         |   2 +
 test/fixtures/line-series.js                |   2 +
 test/fixtures/regexp/at_cc_on.js            |   3 +
 test/fixtures/regexp/at_preserve.js         |   3 +
 test/fixtures/regexp/copyright.js           |   3 +
 test/fixtures/regexp/copyright_mark.js      |   3 +
 test/fixtures/regexp/mit.js                 |   3 +
 test/fixtures/separated-block-license.js    |   3 +
 test/fixtures/separated-block.js            |   3 +
 test/fixtures/separated-line-license.js     |   3 +
 test/fixtures/separated-line.js             |   3 +
 test/fixtures/start_with_bang/block_bang.js |   3 +
 test/fixtures/start_with_bang/line_bang.js  |   4 +
 test/test.js                                |  27 ++++
 uglify-save-license.js                      |  34 +++++
 42 files changed, 517 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6b750c2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,20 @@
+actual/
+
+# Node
+# https://github.com/github/gitignore/blob/master/Node.gitignore
+
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+npm-debug.log
+node_modules
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..5287fc8
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,7 @@
+{
+  "camelcase": true,
+  "indent": 2,
+  "quotmark": "single",
+  "browser": false,
+  "node": true
+}
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..0b3cf3f
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,4 @@
+.travis.yml
+.jshintrc
+Gruntfile.coffee
+test/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..607bd79
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,8 @@
+language: node_js
+node_js:
+  - "0.10"
+  - "0.11"
+before_script:
+  - npm install -g grunt-cli
+notifications:
+  email: false
\ No newline at end of file
diff --git a/Gruntfile.coffee b/Gruntfile.coffee
new file mode 100644
index 0000000..a6110e7
--- /dev/null
+++ b/Gruntfile.coffee
@@ -0,0 +1,86 @@
+module.exports = (grunt) ->
+  'use strict'
+
+  require('load-grunt-tasks') grunt
+  semver = require 'semver'
+  
+  pkg = grunt.file.readJSON 'package.json'
+  
+  getNextVersion = ->
+    currentVer = pkg.version
+    semver.inc currentVer, 'patch'
+      
+  grunt.initConfig
+    jshint:
+      options:
+        jshintrc: '.jshintrc'
+      main:
+        files:
+          src: ['uglify-save-license.js']
+      test:
+        files:
+          src: '<%= nodeunit.all %>'
+    
+    clean:
+      test:
+        src: ['test/actual/*.js']
+    
+    replace:
+      version:
+        options:
+          prefix: ' v'
+          preservePrefix: true
+          patterns: [
+            match: pkg.version
+            replacement: getNextVersion()
+          ]
+        files:
+          'uglify-save-license.js': ['uglify-save-license.js']
+      year:
+        options:
+          prefix: '2013 - '
+          preservePrefix: true
+          patterns: [
+            match: "#{ new Date().getFullYear() - 1 }"
+            replacement: "#{ new Date().getFullYear() }"
+          ]
+        files:
+          'uglify-save-license.js': ['uglify-save-license.js']
+    
+    uglify:
+      options:
+        preserveComments: ->
+          args = grunt.util.toArray arguments
+          require('./uglify-save-license.js') args...
+      fixture:
+        files: [
+          expand: true
+          cwd: 'test/fixtures'
+          src: '{,*/}*.js'
+          dest: 'test/actual'
+        ]
+    
+    nodeunit:
+      options:
+        reporter: 'default'
+      all: ['test/test.js']
+
+    watch:
+      main:
+        files: ['uglify-save-license.js']
+        tasks: ['build']
+    
+    release: {}
+
+  grunt.registerTask 'test', [
+    'jshint'
+    'clean'
+    'uglify'
+    'nodeunit'
+  ]
+
+  grunt.registerTask 'build', ['replace', 'test']
+  
+  grunt.registerTask 'default', ['build', 'watch']
+
+  grunt.registerTask 'publish', ['build', 'release:patch']
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..cfb8c53
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 - 2014 Shinnosuke Watanabe
+
+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/README.md b/README.md
new file mode 100644
index 0000000..9627218
--- /dev/null
+++ b/README.md
@@ -0,0 +1,192 @@
+# uglify-save-license
+
+[![NPM version](https://badge.fury.io/js/uglify-save-license.svg)](http://badge.fury.io/js/uglify-save-license)
+[![Build Status](https://travis-ci.org/shinnn/uglify-save-license.svg)](https://travis-ci.org/shinnn/uglify-save-license)
+[![devDependency Status](https://david-dm.org/shinnn/uglify-save-license/dev-status.svg)](https://david-dm.org/shinnn/uglify-save-license#info=devDependencies)
+
+A support module for [UglifyJS](http://lisperator.net/uglifyjs/) to detect and preserve license comments
+
+```javascript
+//     Backbone.js 1.1.2
+
+//     (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+//     Backbone may be freely distributed under the MIT license.
+//     For all details and documentation:
+//     http://backbonejs.org
+
+(function(root, factory) {
+
+  // Set up Backbone appropriately for the environment. Start with AMD.
+  if (typeof define === 'function' && define.amd) {
+    define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
+//...
+```
+
+↓
+
+```javascript
+//     Backbone.js 1.1.2
+//     (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+//     Backbone may be freely distributed under the MIT license.
+//     For all details and documentation:
+//     http://backbonejs.org
+!function(a,b){if("function"==typeof define&&define.amd)define(["underscore","jquery","exports"],function(c,d,e){a.Backbone=b(a,e,c,d)});else if("undefined"!=typeof exports){...
+```
+
+## Overview
+
+This module enables us to preserve license comments when using UglifyJS.
+
+Even if the license statement is in multiple line comments, or the comment has no directive such as `@license` and `/*!`, this module keeps them readable.
+
+## Installation
+
+Install with [npm](https://npmjs.org/). (Make sure you have installed [Node](http://nodejs.org/download/).)
+
+```
+npm install --save-dev uglify-save-license
+```
+
+## Usage
+
+First of all, load `uglify-save-license` module.
+
+```javascript
+var saveLicense = require('uglify-save-license');
+```
+
+### Use with [UglifyJS](https://github.com/mishoo/UglifyJS2)
+
+Pass this module to the [`comments` option](https://github.com/mishoo/UglifyJS2#keeping-comments-in-the-output).
+
+```javascript
+var result = UglifyJS.minify('file1.js', {
+  output: {
+    comments: saveLicense
+  }
+});
+```
+
+### Use with [grunt-contrib-uglify](https://github.com/gruntjs/grunt-contrib-uglify)
+
+Pass this module to the [`preserveComments` option](https://github.com/gruntjs/grunt-contrib-uglify#preservecomments).
+
+```javascript
+grunt.initConfig({
+  uglify: {
+    my_target: {
+      options: {
+        preserveComments: saveLicense
+      },    
+      src: ['src/app.js'],
+      dest: 'dest/app.min.js' 
+    }
+  }
+});
+```
+
+## How it works
+
+*uglify-save-license* checks each [comment token](http://lisperator.net/uglifyjs/ast#tokens) of a JavaScript file.
+The comment will be regarded as a license statement and preserved after compression, if it meets at least one of the following requirements:
+
+1. The comment is in the *first* line of a file.
+2. [The regexp for license statement](./uglify-save-license.js#L7) matches the string of the comment. It matches, for example, `MIT` and `Copyright`.
+3. There is a comment at the *previous* line, and it matches 1. 2. or 3.
+
+## Examples
+
+### CLI tool example
+
+#### Main script (`uglify-example.js`)
+
+```javascript
+#!/usr/bin/env node
+
+var UglifyJS    = require('uglify-js'),
+    saveLicense = require('uglify-save-license');
+
+var minified = UglifyJS.minify(process.argv[2], {
+  output: {
+    comments: saveLicense
+  }
+}).code;
+
+console.log(minified);
+```
+
+#### Target file
+
+```javascript
+// First line
+
+// (c) 2014 John  <- contains '(c)'
+// The previous line is preserved
+
+// This line won't be preserved.
+(function(win, doc) {
+  var str = 'Hello World! :' + doc.title;
+
+  // This line will not, too.
+  console.log(str);
+}(window, document));
+```
+
+#### Command
+
+```
+node uglify-example.js <target filename>
+```
+
+#### Output
+
+```javascript
+// First line
+// (c) 2014 John  <- contains '(c)'
+// The previous line is preserved
+!function(o,l){var n="Hello World! :"+l.title;console.log(n)}(window,document);
+```
+
+### [Gruntfile.coffee](http://gruntjs.com/getting-started#the-gruntfile) example
+
+```coffeescript
+module.exports = (grunt) ->
+
+  grunt.loadNpmTasks 'grunt-contrib-uglify'
+  grunt.loadNpmTasks 'grunt-contrib-concat'
+  grunt.loadNpmTasks 'grunt-contrib-clean'
+  
+  grunt.initConfig
+    uglify:
+      target:
+        options:
+          preserveComments: require 'uglify-save-license'
+        files: [
+          expand: true
+          flatten: true
+          cwd: 'path/to/src'
+          src: ['**/*.js']
+          dest: 'tmp/'
+        ]
+
+    concat:
+      js:
+        src: ['tmp/*.js']
+        dest: 'path/to/build/app.js'
+
+    clean:
+      tmpdir: ['tmp']
+
+  grunt.registerTask 'default' ['uglify', 'concat', 'clean']
+```
+
+## Acknowledgements
+
+*uglify-save-license* is inspired by [grunt-license-saver](https://github.com/kyo-ago/grunt-license-saver) and I used it as reference.
+Thanks, [kyo-ago](https://github.com/kyo-ago).
+
+## License
+
+Copyright (c) 2013 - 2014 [Shinnosuke Watanabe](https://github.com/shinnn)
+
+Licensed under [the MIT license](./LICENSE).
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..8d27d9d
--- /dev/null
+++ b/package.json
@@ -0,0 +1,51 @@
+{
+  "name": "uglify-save-license",
+  "version": "0.4.1",
+  "description": "License detector for UglifyJS",
+  "main": "./uglify-save-license.js",
+  "scripts": {
+    "test": "grunt build"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/shinnn/uglify-save-license.git"
+  },
+  "author": {
+    "name": "Shinnosuke Watanabe",
+    "url": "https://github.com/shinnn"
+  },
+  "readmeFilename": "README.md",
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "https://github.com/shinnn/uglify-save-license/blob/master/LICENSE"
+    }
+  ],
+  "keywords": [
+    "uglify",
+    "compression",
+    "minification",
+    "comment",
+    "license",
+    "copyright",
+    "detection",
+    "preservation",
+    "banner"
+  ],
+  "bugs": {
+    "url": "https://github.com/shinnn/uglify-save-license/issues"
+  },
+  "homepage": "https://github.com/shinnn/uglify-save-license",
+  "devDependencies": {
+    "grunt": "^0.4.4",
+    "load-grunt-tasks": "^0.4.0",
+    "grunt-contrib-jshint": "^0.10.0",
+    "grunt-contrib-watch": "^0.6.1",
+    "grunt-contrib-uglify": "^0.4.0",
+    "grunt-contrib-clean": "^0.5.0",
+    "grunt-contrib-nodeunit": "^0.3.3",
+    "grunt-release": "^0.7.0",
+    "grunt-replace": "^0.7.7",
+    "semver": "^2.2.1"
+  }
+}
diff --git a/test/expected/block-series.js b/test/expected/block-series.js
new file mode 100644
index 0000000..adef163
--- /dev/null
+++ b/test/expected/block-series.js
@@ -0,0 +1,2 @@
+/* First block */
+/* Second block */
diff --git a/test/expected/first-block.js b/test/expected/first-block.js
new file mode 100644
index 0000000..7e7099b
--- /dev/null
+++ b/test/expected/first-block.js
@@ -0,0 +1 @@
+/* First block */
diff --git a/test/expected/first-line.js b/test/expected/first-line.js
new file mode 100644
index 0000000..bfdee39
--- /dev/null
+++ b/test/expected/first-line.js
@@ -0,0 +1 @@
+// First line
diff --git a/test/expected/line-after-newline.js b/test/expected/line-after-newline.js
new file mode 100644
index 0000000..e69de29
diff --git a/test/expected/line-series.js b/test/expected/line-series.js
new file mode 100644
index 0000000..64c7f4b
--- /dev/null
+++ b/test/expected/line-series.js
@@ -0,0 +1,2 @@
+// First line
+// Second line
diff --git a/test/expected/regexp/at_cc_on.js b/test/expected/regexp/at_cc_on.js
new file mode 100644
index 0000000..46d3193
--- /dev/null
+++ b/test/expected/regexp/at_cc_on.js
@@ -0,0 +1,2 @@
+// @cc_on directive
+// @cc_on This line should be preserved.
diff --git a/test/expected/regexp/at_preserve.js b/test/expected/regexp/at_preserve.js
new file mode 100644
index 0000000..9ca33fb
--- /dev/null
+++ b/test/expected/regexp/at_preserve.js
@@ -0,0 +1,2 @@
+// @preserve directive
+// @preserve This line should be preserved.
diff --git a/test/expected/regexp/copyright.js b/test/expected/regexp/copyright.js
new file mode 100644
index 0000000..f9809cf
--- /dev/null
+++ b/test/expected/regexp/copyright.js
@@ -0,0 +1,2 @@
+// Copyright string
+// Copyright <year> This line should be preserved.
diff --git a/test/expected/regexp/copyright_mark.js b/test/expected/regexp/copyright_mark.js
new file mode 100644
index 0000000..b2d1b00
--- /dev/null
+++ b/test/expected/regexp/copyright_mark.js
@@ -0,0 +1,2 @@
+// Copyright mark
+// (c) This line should be preserved.
diff --git a/test/expected/regexp/mit.js b/test/expected/regexp/mit.js
new file mode 100644
index 0000000..5ed19cf
--- /dev/null
+++ b/test/expected/regexp/mit.js
@@ -0,0 +1,2 @@
+// MIT license
+// (MIT) This line should be preserved.
diff --git a/test/expected/separated-block-license.js b/test/expected/separated-block-license.js
new file mode 100644
index 0000000..fe153ef
--- /dev/null
+++ b/test/expected/separated-block-license.js
@@ -0,0 +1,2 @@
+/* First block */
+/* Second block (MIT) */
diff --git a/test/expected/separated-block.js b/test/expected/separated-block.js
new file mode 100644
index 0000000..7e7099b
--- /dev/null
+++ b/test/expected/separated-block.js
@@ -0,0 +1 @@
+/* First block */
diff --git a/test/expected/separated-line-license.js b/test/expected/separated-line-license.js
new file mode 100644
index 0000000..bb142f9
--- /dev/null
+++ b/test/expected/separated-line-license.js
@@ -0,0 +1,2 @@
+// First line
+// (c) Second line
diff --git a/test/expected/separated-line.js b/test/expected/separated-line.js
new file mode 100644
index 0000000..bfdee39
--- /dev/null
+++ b/test/expected/separated-line.js
@@ -0,0 +1 @@
+// First line
diff --git a/test/expected/start_with_bang/block_bang.js b/test/expected/start_with_bang/block_bang.js
new file mode 100644
index 0000000..8f72570
--- /dev/null
+++ b/test/expected/start_with_bang/block_bang.js
@@ -0,0 +1,2 @@
+// Start with bang (block comment)
+/*! This line should be preserved. */
diff --git a/test/expected/start_with_bang/line_bang.js b/test/expected/start_with_bang/line_bang.js
new file mode 100644
index 0000000..00f6c08
--- /dev/null
+++ b/test/expected/start_with_bang/line_bang.js
@@ -0,0 +1,2 @@
+// Start with bang (line comment)
+// Any comments should not exist below.  
diff --git a/test/fixtures/block-series.js b/test/fixtures/block-series.js
new file mode 100644
index 0000000..adef163
--- /dev/null
+++ b/test/fixtures/block-series.js
@@ -0,0 +1,2 @@
+/* First block */
+/* Second block */
diff --git a/test/fixtures/first-block.js b/test/fixtures/first-block.js
new file mode 100644
index 0000000..7e7099b
--- /dev/null
+++ b/test/fixtures/first-block.js
@@ -0,0 +1 @@
+/* First block */
diff --git a/test/fixtures/first-line.js b/test/fixtures/first-line.js
new file mode 100644
index 0000000..bfdee39
--- /dev/null
+++ b/test/fixtures/first-line.js
@@ -0,0 +1 @@
+// First line
diff --git a/test/fixtures/line-after-newline.js b/test/fixtures/line-after-newline.js
new file mode 100644
index 0000000..a72fa2f
--- /dev/null
+++ b/test/fixtures/line-after-newline.js
@@ -0,0 +1,2 @@
+
+// First line after a line break
diff --git a/test/fixtures/line-series.js b/test/fixtures/line-series.js
new file mode 100644
index 0000000..64c7f4b
--- /dev/null
+++ b/test/fixtures/line-series.js
@@ -0,0 +1,2 @@
+// First line
+// Second line
diff --git a/test/fixtures/regexp/at_cc_on.js b/test/fixtures/regexp/at_cc_on.js
new file mode 100644
index 0000000..417eba4
--- /dev/null
+++ b/test/fixtures/regexp/at_cc_on.js
@@ -0,0 +1,3 @@
+// @cc_on directive
+
+// @cc_on This line should be preserved.
\ No newline at end of file
diff --git a/test/fixtures/regexp/at_preserve.js b/test/fixtures/regexp/at_preserve.js
new file mode 100644
index 0000000..63cf55d
--- /dev/null
+++ b/test/fixtures/regexp/at_preserve.js
@@ -0,0 +1,3 @@
+// @preserve directive
+
+// @preserve This line should be preserved.
\ No newline at end of file
diff --git a/test/fixtures/regexp/copyright.js b/test/fixtures/regexp/copyright.js
new file mode 100644
index 0000000..2d35096
--- /dev/null
+++ b/test/fixtures/regexp/copyright.js
@@ -0,0 +1,3 @@
+// Copyright string
+
+// Copyright <year> This line should be preserved.
diff --git a/test/fixtures/regexp/copyright_mark.js b/test/fixtures/regexp/copyright_mark.js
new file mode 100644
index 0000000..131e91a
--- /dev/null
+++ b/test/fixtures/regexp/copyright_mark.js
@@ -0,0 +1,3 @@
+// Copyright mark
+
+// (c) This line should be preserved.
diff --git a/test/fixtures/regexp/mit.js b/test/fixtures/regexp/mit.js
new file mode 100644
index 0000000..e80f56f
--- /dev/null
+++ b/test/fixtures/regexp/mit.js
@@ -0,0 +1,3 @@
+// MIT license
+
+// (MIT) This line should be preserved.
diff --git a/test/fixtures/separated-block-license.js b/test/fixtures/separated-block-license.js
new file mode 100644
index 0000000..86b06ed
--- /dev/null
+++ b/test/fixtures/separated-block-license.js
@@ -0,0 +1,3 @@
+/* First block */
+
+/* Second block (MIT) */
diff --git a/test/fixtures/separated-block.js b/test/fixtures/separated-block.js
new file mode 100644
index 0000000..c4f1a21
--- /dev/null
+++ b/test/fixtures/separated-block.js
@@ -0,0 +1,3 @@
+/* First block */
+
+/* This block should not be saved */
diff --git a/test/fixtures/separated-line-license.js b/test/fixtures/separated-line-license.js
new file mode 100644
index 0000000..29affc5
--- /dev/null
+++ b/test/fixtures/separated-line-license.js
@@ -0,0 +1,3 @@
+// First line
+
+// (c) Second line
diff --git a/test/fixtures/separated-line.js b/test/fixtures/separated-line.js
new file mode 100644
index 0000000..c462183
--- /dev/null
+++ b/test/fixtures/separated-line.js
@@ -0,0 +1,3 @@
+// First line
+
+// This line should not be saved.
diff --git a/test/fixtures/start_with_bang/block_bang.js b/test/fixtures/start_with_bang/block_bang.js
new file mode 100644
index 0000000..eae09ca
--- /dev/null
+++ b/test/fixtures/start_with_bang/block_bang.js
@@ -0,0 +1,3 @@
+// Start with bang (block comment)
+
+/*! This line should be preserved. */
diff --git a/test/fixtures/start_with_bang/line_bang.js b/test/fixtures/start_with_bang/line_bang.js
new file mode 100644
index 0000000..a0a74db
--- /dev/null
+++ b/test/fixtures/start_with_bang/line_bang.js
@@ -0,0 +1,4 @@
+// Start with bang (line comment)
+// Any comments should not exist below.  
+
+//! This line should not be preserved.
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..673af8d
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,27 @@
+'use strict';
+
+var path = require('path');
+var grunt = require('grunt');
+
+var files = grunt.file.expandMapping (
+  '{,*/,*/*/}*.js',
+  'test/expected',
+  { cwd: 'test/actual' }
+);
+
+function exportTests (map) {
+  var basename = path.basename(map.src);
+  
+  exports[basename] = function (test) {
+    var actual = grunt.file.read(map.src);
+    var expected = grunt.file.read(map.dest);
+    
+    test.strictEqual(
+      actual,
+      expected
+    );
+    test.done();
+  };
+}
+
+files.forEach(exportTests);
diff --git a/uglify-save-license.js b/uglify-save-license.js
new file mode 100644
index 0000000..2ac9769
--- /dev/null
+++ b/uglify-save-license.js
@@ -0,0 +1,34 @@
+// uglify-save-license.js v0.4.1
+// Copyright (c) 2013 - 2014 Shinnosuke Watanabe
+// Licensed uder the MIT license
+
+'use strict';
+
+var licenseRegexp = /@preserve|@cc_on|\bMIT\b|\bMPL\b|\bGPL\b|\bBSD\b|\bISCL\b|\(c\)|License|Copyright/mi;
+
+// number of line where license comment appeared last
+var prevCommentLine = 0;
+// name of the file minified last
+var prevFile = '';
+
+module.exports = function saveLicense(node, comment) {
+  if (comment.file !== prevFile) {
+    prevCommentLine = 0;
+  }
+
+  var isLicense = licenseRegexp.test(comment.value) ||
+                  (comment.type === 'comment2' &&
+                  comment.value.charAt(0) === '!') ||
+                  comment.line === 1 ||
+                  comment.line === prevCommentLine + 1;
+  
+  if (isLicense) {
+    prevCommentLine = comment.line;
+  } else {
+    prevCommentLine = 0;
+  }
+  
+  prevFile = comment.file;
+  
+  return isLicense;
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-uglify-save-license.git



More information about the Pkg-javascript-commits mailing list