-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (37 loc) · 1.1 KB
/
index.js
File metadata and controls
43 lines (37 loc) · 1.1 KB
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
39
40
41
42
43
const Config = require('./config')
const Upload = require('./upload')
const logger = require('./logger')
function PacktrackerPlugin (options = {}) {
logger('instantiate plugin')
this.config = new Config(options)
}
PacktrackerPlugin.prototype.apply = function (compiler) {
if (!this.config.upload) {
logger('not uploading due to `upload` configuration')
return
}
this.upload = new Upload(this.config)
if (compiler.hooks) {
logger('using compiler.hooks')
compiler.hooks.done.tapPromise('packtracker', (stats) => {
return this.upload.process(
stats.toJson(this.config.statOptions),
getOutputPath(compiler)
)
})
} else {
logger('using after-emit plugin')
compiler.plugin('after-emit', (compilation, done) => {
this.upload.process(
compilation.getStats().toJson(this.config.statOptions),
getOutputPath(compiler)
).then(done)
})
}
}
function getOutputPath (compiler) {
return (compiler.outputFileSystem.constructor.name === 'MemoryFileSystem')
? null
: compiler.outputPath
}
module.exports = PacktrackerPlugin