-
Notifications
You must be signed in to change notification settings - Fork 4
/
report.js
66 lines (58 loc) · 1.8 KB
/
report.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const util = require('util')
const fs = require('fs')
const webpack = require('webpack')
const PacktrackerPlugin = require('@packtracker/webpack-plugin')
let config = {}
if (fs.existsSync(process.env.WEBPACK_CONFIG_PATH)) {
customConfig = require(process.env.WEBPACK_CONFIG_PATH)
console.log(`packtracker: webpack config file loaded (${process.env.WEBPACK_CONFIG_PATH})`)
// Check for CRA config factory
if (isFunction(customConfig)) {
config = customConfig('production', { mode: 'production' })
} else {
config = customConfig
}
} else {
console.log(`packtracker: webpack config file not found`)
}
config.plugins = config.plugins || []
if (process.env.GITHUB_EVENT_PATH) {
console.log(`packtracker: loading github config`)
config.plugins.push(new PacktrackerPlugin(githubConfig()))
} else if (process.env.CIRCLECI) {
console.log(`packtracker: loading circle config`)
config.plugins.push(new PacktrackerPlugin(circleConfig()))
}
webpack(config, (err) => {
if (err) {
console.log(`packtracker: webpack build failed`)
process.exit(1)
} else {
console.log(`packtracker: webpack build succeeded`)
process.exit(0)
}
})
function githubConfig () {
const event = require(process.env.GITHUB_EVENT_PATH)
return {
upload: true,
fail_build: true,
branch: event.ref.replace('refs/heads/', ''),
author: event.head_commit.author.email,
message: event.head_commit.message,
commit: process.env.GITHUB_SHA,
committed_at: parseInt(+new Date(event.head_commit.timestamp) / 1000),
prior_commit: event.before,
}
}
function circleConfig () {
return {
upload: true,
fail_build: true,
branch: process.env.CIRCLE_BRANCH,
commit: process.env.CIRCLE_SHA1,
}
}
function isFunction(value) {
return value && {}.toString.call(value) === '[object Function]'
}