Socket
Socket
Sign inDemoInstall

uglify-save-license

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

18

package.json
{
"name": "uglify-save-license",
"version": "0.1.0",
"version": "0.1.1",
"description": "Tiny license detector module for UglifyJS's 'comments' option",
"main": "uglify-save-license.js",
"scripts": {
"test": "node_modules/grunt-cli/bin/grunt test"
"test": "node_modules/grunt-cli/bin/grunt test",
"postinstall": "node_modules/grunt-cli/bin/grunt build"
},

@@ -22,2 +23,3 @@ "repository": {

"compression",
"minification",
"comment",

@@ -31,13 +33,13 @@ "license"

"devDependencies": {
"grunt-cli": "~0.1.11",
"grunt": "~0.4.2",
"load-grunt-tasks": "~0.2.0",
"grunt-contrib-jshint": "~0.7.2",
"load-grunt-tasks": "~0.2.1",
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-nodeunit": "~0.2.2",
"grunt-release": "~0.6.0",
"grunt-replace": "~0.5.1",
"semver": "~2.2.1",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-nodeunit": "~0.2.2",
"grunt-cli": "~0.1.11"
"semver": "~2.2.1"
}
}

@@ -7,14 +7,10 @@ # uglify-save-license

Tiny license detector module for UglifyJS's `comments` option
Tiny license detector module for the `comments` option of UglifyJS
## Concepts
Coming soon.
## Installation
Install latest stable [Node](http://nodejs.org/) and run this command in your project's root directory:
Install [Node](http://nodejs.org/) and run this command in the root of your project:
```
npm install --save-dev uglify-save-license
npm install uglify-save-license
```

@@ -24,10 +20,38 @@

First of all, load the `uglify-save-license` module.
```javascript
var saveLicense = require('uglify-save-license');
```
### Use with [UglifyJS](https://github.com/mishoo/UglifyJS2)
Coming soon.
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)
Coming soon.
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 does it works

@@ -37,8 +61,55 @@

## Example
## Examples
### CLI tool example
Coming soon.
#### 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 uncompressed file
```javascript
// example.js
// (c) John Smith | MIT License
// http://examplelibrary.com/
// anonymous function
(function(win, doc){
var string = 'Hello World! :' + doc.title;
// output greeting message
console.log(string);
}(window, document));
```
#### Command
```
node uglify-example.js [TARGET_FILE_NAME]
```
#### Output
```javascript
// example.js
// (c) John Smith | MIT License
// http://examplelibrary.com/
!function(o,l){var n="Hello World! :"+l.title;console.log(n)}(window,document);
```
### [Gruntfile](http://gruntjs.com/getting-started#the-gruntfile) example

@@ -48,3 +119,2 @@

module.exports = (grunt) ->
'use strict'

@@ -78,7 +148,3 @@ grunt.loadNpmTasks 'grunt-contrib-uglify'

grunt.registerTask 'default' [
'uglify'
'concat'
'clean'
]
grunt.registerTask 'default' ['uglify', 'concat', 'clean']
```

@@ -85,0 +151,0 @@

@@ -1,2 +0,2 @@

'use strict'
'use strict';

@@ -6,20 +6,19 @@ var path = require('path');

var files = grunt.file.expandMapping(
var files = grunt.file.expandMapping (
'{,*/}*.js',
'test/expected',
{ cwd: 'test/fixtures' }
{ cwd: 'test/actual' }
);
function exportTests(map) {
function exportTests (map) {
var basename = path.basename(map.src);
var fixture = grunt.file.read(map.src);
var actual = grunt.file.read(map.src);
var expected = grunt.file.read(map.dest);
var actual = grunt.file.read('test/actual/' + basename)
exports[basename] = function(test) {
exports[basename] = function (test) {
test.strictEqual(
actual,
expected,
basename + " is not uglified to the expected output."
basename + " is not uglified as the expected output."
);

@@ -26,0 +25,0 @@ test.done();

@@ -1,2 +0,2 @@

// uglify-save-license.js v0.1.0
// uglify-save-license.js v0.1.1
// Copyright (c) 2013 Shinnosuke Watanabe

@@ -12,7 +12,6 @@ // Licensed uder the MIT license

var prevCommentLine = 0;
// name of the file minified last
var prevFile = '';
module.exports = function saveLicense(node, comment) {
var result = false;
if(comment.file !== prevFile) {

@@ -23,11 +22,9 @@ prevCommentLine = 0;

// check if the comment contains license text
if (licenseRegexp.test(comment.value) ||
var result = licenseRegexp.test(comment.value) ||
comment.line === 1 ||
comment.line === prevCommentLine + 1) {
result = true;
}
comment.line === prevCommentLine + 1;
if (result) {
// if the comment contains license, save line number
prevCommentLine = comment.line;
prevCommentLine = comment.line;
} else {

@@ -37,6 +34,7 @@ // if the comment doesn't contain license, reset line number

}
// save current filename
prevFile = comment.file;
return result;
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc