grunt-ng-annotate
Advanced tools
Comparing version 0.8.0 to 0.9.0
{ | ||
"name": "grunt-ng-annotate", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Add, remove and rebuild AngularJS dependency injection annotations.", | ||
@@ -25,3 +25,2 @@ "homepage": "https://github.com/mzgol/grunt-ng-annotate", | ||
], | ||
"main": "Gruntfile.js", | ||
"repository": { | ||
@@ -32,7 +31,3 @@ "type": "git", | ||
"bugs": "https://github.com/mzgol/grunt-ng-annotate/issues", | ||
"licenses": [ | ||
{ | ||
"type": "MIT" | ||
} | ||
], | ||
"license": "MIT", | ||
"files": [ | ||
@@ -42,3 +37,3 @@ "tasks" | ||
"dependencies": { | ||
"ng-annotate": "~0.14.0" | ||
"ng-annotate": "~0.15.1" | ||
}, | ||
@@ -49,8 +44,9 @@ "devDependencies": { | ||
"grunt-contrib-clean": "0.6.0", | ||
"grunt-eslint": "2.0.0", | ||
"grunt-eslint": "4.0.0", | ||
"grunt-jscs": "0.8.1", | ||
"grunt-mocha-test": "0.12.4", | ||
"grunt-mocha-test": "0.12.7", | ||
"jscs-trailing-comma": "0.3.0", | ||
"load-grunt-tasks": "1.0.0", | ||
"mocha": "2.0.1", | ||
"load-grunt-tasks": "2.0.0", | ||
"lodash": "2.4.1", | ||
"mocha": "2.1.0", | ||
"time-grunt": "1.0.0" | ||
@@ -57,0 +53,0 @@ }, |
@@ -5,3 +5,3 @@ # grunt-ng-annotate | ||
[![Build Status](https://travis-ci.org/mzgol/grunt-ng-annotate.svg?branch=master)](https://travis-ci.org/mzgol/grunt-ng-annotate) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/rr3i854ic8rb47i5/branch/master)](https://ci.appveyor.com/project/mzgol/grunt-ng-annotate/branch/master) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/rr3i854ic8rb47i5/branch/master?svg=true)](https://ci.appveyor.com/project/mzgol/grunt-ng-annotate/branch/master) | ||
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/) | ||
@@ -24,6 +24,5 @@ | ||
## The "ngAnnotate" task | ||
## Overview | ||
### Overview | ||
In your project's Gruntfile, add a section named `ngAnnotate` to the data object passed into `grunt.initConfig()`. | ||
This project defines the `ngAnnotate` task. In your project's Gruntfile, add a section named `ngAnnotate` to the data object passed into `grunt.initConfig()`. | ||
@@ -43,37 +42,62 @@ ```js | ||
#### Options | ||
## Options | ||
The `ngAnnotate` task accepts a couple of options: | ||
```js | ||
{ | ||
// Tells if ngAnnotate should add annotations (true by default). | ||
add: true|false, | ||
### add | ||
// Tells if ngAnnotate should remove annotations (false by default). | ||
remove: true|false, | ||
Tells if ngAnnotate should add annotations. | ||
// If provided, only strings matched by the regexp are interpreted as module | ||
// names. You can provide both a regular expression and a string representing | ||
// one. See README of ng-annotate for further details: | ||
// https://npmjs.org/package/ng-annotate | ||
regexp: regexp, | ||
Type: `boolean` | ||
// Switches the quote type for strings in the annotations array to single | ||
// ones; e.g. '$scope' instead of "$scope" (false by default). | ||
singleQuotes: true|false, | ||
Default: `true` | ||
// If ngAnnotate supports a new option that is not directly supported via | ||
// this grunt task yet, you can pass it here. These options gets merged | ||
// with the above specific to ngAnnotate. Options passed here have lower | ||
// precedence to the direct ones described above. | ||
ngAnnotateOptions: {}, | ||
} | ||
``` | ||
### remove | ||
Tells if ngAnnotate should remove annotations. | ||
Type: `boolean` | ||
Default: `false` | ||
Note that both `add` and `remove` options can be set to true; in such a case `ngAnnotate` first removes | ||
annotations and then re-adds them (it can be used to check if annotations were provided correctly). | ||
### Usage Examples | ||
### regexp | ||
If provided, only strings matched by the regexp are interpreted as module names. You can provide both a regular expression and a string representing one. See README of ng-annotate for further details: https://npmjs.org/package/ng-annotate | ||
Type: `regexp` | ||
Default: none | ||
### singleQuotes | ||
Switches the quote type for strings in the annotations array to single ones; e.g. `'$scope'` instead of `"$scope"`. | ||
Type: `boolean` | ||
Default: `false` | ||
### sourceMap | ||
Enables source map generation. | ||
Type: `boolean` or `string` | ||
Default: `false` | ||
If set to a string, the string points to a file where to save the source map. If set to `true`, an inline source map will be used. | ||
### ngAnnotateOptions | ||
If ngAnnotate supports a new option that is not directly supported via this Grunt task yet, you can pass it here. These options gets merged with the above specific to ngAnnotate. Options passed here have lower precedence to the direct ones described above. | ||
Type: `object` | ||
Default: `{}` | ||
## Usage Examples | ||
```js | ||
@@ -80,0 +104,0 @@ grunt.initConfig({ |
@@ -11,7 +11,111 @@ /** | ||
var path = require('path'); | ||
var _ = require('lodash'); | ||
var ngAnnotate = require('ng-annotate'); | ||
module.exports = function (grunt) { | ||
var fs = require('fs'), | ||
ngAnnotate = require('ng-annotate'); | ||
function getPathFromTo(fromFile, toFile) { | ||
return path.relative(path.resolve(path.dirname(fromFile)), path.resolve(toFile)); | ||
} | ||
function handleOptions(options) { | ||
var sourceMapOptions; | ||
if (!options.ngAnnotateOptions) { | ||
options.ngAnnotateOptions = {}; | ||
} | ||
if (options.add != null) { | ||
options.ngAnnotateOptions.add = options.add; | ||
delete options.add; | ||
} else { | ||
options.ngAnnotateOptions.add = true; | ||
} | ||
if (options.remove != null) { | ||
options.ngAnnotateOptions.remove = options.remove; | ||
delete options.remove; | ||
} else { | ||
options.ngAnnotateOptions.remove = false; | ||
} | ||
if (options.regexp != null) { | ||
options.ngAnnotateOptions.regexp = options.regexp; | ||
delete options.regexp; | ||
} | ||
if (options.singleQuotes != null) { | ||
options.ngAnnotateOptions.single_quotes = options.singleQuotes; | ||
delete options.singleQuotes; | ||
} | ||
if (options.sourceMap) { | ||
sourceMapOptions = options.ngAnnotateOptions.sourcemap = {}; | ||
sourceMapOptions.inline = options.sourceMap === true; | ||
} | ||
if (options.transformDest != null) { | ||
grunt.fail.fatal( | ||
[ | ||
'The `transformDest` option is no longer supported.', | ||
'The following configuration:', | ||
'', | ||
' app: {', | ||
' options: {', | ||
' transformDest: function (srcPath) {', | ||
' return doSomethingWithSrcPath(srcPath);', | ||
' },', | ||
' },', | ||
' src: [\'app/*.js\'],', | ||
' },', | ||
'', | ||
'should be replaced by:', | ||
'', | ||
' app: {', | ||
' files: [', | ||
' {', | ||
' expand: true,', | ||
' src: [\'app/*.js\'],', | ||
' rename: function (destPath, srcPath) {', | ||
' return doSomethingWithSrcPath(srcPath);', | ||
' },', | ||
' },', | ||
' ],', | ||
' },', | ||
].join('\n') | ||
); | ||
} | ||
if (options.outputFileSuffix != null) { | ||
grunt.fail.fatal( | ||
[ | ||
'The `outputFileSuffix` option is no longer supported.', | ||
'The following configuration:', | ||
'', | ||
' app: {', | ||
' options: {', | ||
' outputFileSuffix: \'-annotated\',', | ||
' },', | ||
' src: [\'app/*.js\'],', | ||
' },', | ||
'', | ||
'should be replaced by:', | ||
'', | ||
' app: {', | ||
' files: [', | ||
' {', | ||
' expand: true,', | ||
' src: [\'app/*.js\'],', | ||
' rename: function (destPath, srcPath) {', | ||
' return srcPath + \'-annotated\';', | ||
' },', | ||
' },', | ||
' ],', | ||
' },', | ||
].join('\n') | ||
); | ||
} | ||
} | ||
grunt.registerMultiTask('ngAnnotate', | ||
@@ -26,137 +130,34 @@ 'Add, remove and rebuild AngularJS dependency injection annotations', | ||
if (!options.ngAnnotateOptions) { | ||
options.ngAnnotateOptions = {}; | ||
} | ||
if (options.add != null) { | ||
options.ngAnnotateOptions.add = options.add; | ||
delete options.add; | ||
} else { | ||
options.ngAnnotateOptions.add = true; | ||
} | ||
handleOptions(options); | ||
if (options.remove != null) { | ||
options.ngAnnotateOptions.remove = options.remove; | ||
delete options.remove; | ||
} else { | ||
options.ngAnnotateOptions.remove = false; | ||
} | ||
if (options.regexp != null) { | ||
options.ngAnnotateOptions.regexp = options.regexp; | ||
delete options.regexp; | ||
} | ||
if (options.singleQuotes != null) { | ||
options.ngAnnotateOptions.single_quotes = options.singleQuotes; | ||
delete options.singleQuotes; | ||
} | ||
if (options.transformDest != null) { | ||
grunt.log.warn( | ||
[ | ||
'The `transformDest` option is deprecated and will be removed in the future.', | ||
'The following configuration:', | ||
'', | ||
' app: {', | ||
' options: {', | ||
' transformDest: function (srcPath) {', | ||
' return doSomethingWithSrcPath(srcPath);', | ||
' },', | ||
' },', | ||
' src: [\'app/*.js\'],', | ||
' },', | ||
'', | ||
'can be replaced by:', | ||
'', | ||
' app: {', | ||
' files: [', | ||
' {', | ||
' expand: true,', | ||
' src: [\'app/*.js\'],', | ||
' rename: function (destPath, srcPath) {', | ||
' return doSomethingWithSrcPath(srcPath);', | ||
' },', | ||
' },', | ||
' ],', | ||
' },', | ||
].join('\n') | ||
); | ||
} | ||
if (options.outputFileSuffix != null) { | ||
grunt.log.warn( | ||
[ | ||
'The `outputFileSuffix` option is deprecated and will be removed in the future.', | ||
'The following configuration:', | ||
'', | ||
' app: {', | ||
' options: {', | ||
' outputFileSuffix: \'-annotated\',', | ||
' },', | ||
' src: [\'app/*.js\'],', | ||
' },', | ||
'', | ||
'can be replaced by:', | ||
'', | ||
' app: {', | ||
' files: [', | ||
' {', | ||
' expand: true,', | ||
' src: [\'app/*.js\'],', | ||
' rename: function (destPath, srcPath) {', | ||
' return srcPath + \'-annotated\';', | ||
' },', | ||
' },', | ||
' ],', | ||
' },', | ||
].join('\n') | ||
); | ||
} | ||
// Iterate over all specified file groups. | ||
this.files.forEach(function (mapping) { | ||
var tmpFilePath = mapping.dest; // use the destination file as a temporary source one | ||
if (!runNgAnnotate(mapping, options)) { | ||
validRun = false; | ||
} | ||
}); | ||
if (mapping.dest) { | ||
// If destination file provided, concatenate all source files to a temporary one. | ||
// In such a case options transformDest & outputFileSuffix are ignored. | ||
function runNgAnnotate(mapping, options) { | ||
filesNum++; | ||
grunt.file.write( | ||
tmpFilePath, | ||
mapping.src.map(function (file) { | ||
return grunt.file.read(file); | ||
}).join('\n') | ||
); | ||
var ngAnnotateOptions = _.cloneDeep(options.ngAnnotateOptions); | ||
if (!runNgAnnotate(tmpFilePath, tmpFilePath, options.ngAnnotateOptions)) { | ||
validRun = false; | ||
if (ngAnnotateOptions.sourcemap) { | ||
if (mapping.src.length > 1) { | ||
grunt.fail.fatal('The ngAnnotate task doesn\'t support source maps with many-to-one mappings.'); | ||
} | ||
} else { | ||
// Otherwise each file will have its own ngAnnotate output. | ||
// Transform the destination path. | ||
if (!options.transformDest) { | ||
// By default, append options.outputFileSuffix to the file name. | ||
options.transformDest = function transformDest(path) { | ||
return path + (options.outputFileSuffix || ''); | ||
}; | ||
} | ||
mapping.src.map(function (path) { | ||
if (!runNgAnnotate(path, options.transformDest(path), options.ngAnnotateOptions)) { | ||
validRun = false; | ||
} | ||
}); | ||
ngAnnotateOptions.sourcemap.inFile = getPathFromTo(mapping.dest, mapping.src[0]); | ||
} | ||
}); | ||
function runNgAnnotate(srcPath, destPath, ngAnnotateOptions) { | ||
filesNum++; | ||
var concatenatedSource = mapping.src.map(function (file) { | ||
return grunt.file.read(file); | ||
}).join(';\n'); | ||
var ngAnnotateOutput = ngAnnotate(grunt.file.read(srcPath), ngAnnotateOptions); | ||
var ngAnnotateOutput = ngAnnotate(concatenatedSource, ngAnnotateOptions); | ||
// Write the destination file. | ||
if (ngAnnotateOutput.errors) { | ||
grunt.log.write('Generating "' + destPath + '" from "' + srcPath + '"...'); | ||
grunt.log.write('Generating "' + mapping.dest + '" from: "' + mapping.src.join('", "') + '"...'); | ||
grunt.log.error(); | ||
@@ -169,9 +170,11 @@ ngAnnotateOutput.errors.forEach(function (error) { | ||
// Remove the temporary destination file if existed. | ||
if (fs.existsSync(destPath)) { | ||
fs.unlinkSync(destPath); | ||
// Write ngAnnotate output (and a source map if requested) to the target file. | ||
if (ngAnnotateOptions.sourcemap && !ngAnnotateOptions.sourcemap.inline) { | ||
ngAnnotateOutput.src += | ||
'\n//# sourceMappingURL=' + getPathFromTo(mapping.dest, options.sourceMap); | ||
grunt.file.write(options.sourceMap, ngAnnotateOutput.map); | ||
} | ||
// Write ngAnnotate output to the target file. | ||
grunt.file.write(destPath, ngAnnotateOutput.src); | ||
grunt.file.write(mapping.dest, ngAnnotateOutput.src); | ||
@@ -178,0 +181,0 @@ return true; |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
150
0
12724
11
160
+ Addedacorn@0.11.0(transitive)
+ Addedng-annotate@0.15.4(transitive)
+ Addedordered-ast-traverse@1.1.1(transitive)
+ Addedordered-esprima-props@1.1.0(transitive)
- Removedacorn@0.9.0(transitive)
- Removedesprima@1.2.5(transitive)
- Removedng-annotate@0.14.1(transitive)
- Removedordered-ast-traverse@0.1.1(transitive)
- Removedordered-esprima-props@1.0.0(transitive)
Updatedng-annotate@~0.15.1