-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
38 lines (32 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict"
const anymatch = require("anymatch")
const ngAnnotate = require("ng-annotate")
module.exports = class ngAnnotateCompiler {
constructor(config) {
this.config = defaults(config && config.plugins && config.plugins.ngAnnotate, {
add: true,
remove: true,
map: false,
})
this.pattern = this.config.pattern || /\.js$/
this.isIgnored = anymatch(this.config.ignore || /^(bower_components|vendor)/)
}
compile(file) {
if (this.isIgnored(file.path)) return Promise.resolve(file)
const options = withInFile(this.config, file.path)
const annotated = ngAnnotate(file.data, options)
if (annotated.errors) return Promise.reject(annotated.errors)
return Promise.resolve(Object.assign({}, file, {data: annotated.src, map: annotated.map || file.map}))
}
get brunchPlugin() { return true }
get type() { return "javascript" }
}
function defaults(options, defaults) {
return Object.assign({}, defaults, options)
}
function withInFile(options, inFile) {
if (!options.map) return options
return Object.assign({}, options, {
map: Object.assign({}, options.map, {inFile})
})
}