@jcoreio/toolchain-circle 4.6.2 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcoreio/toolchain-circle",
3
- "version": "4.6.2",
3
+ "version": "4.7.0",
4
4
  "description": "toolchain for CircleCI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,6 +17,6 @@
17
17
  "dedent-js": "^1.0.1",
18
18
  "open": "^8.4.0",
19
19
  "semver": "^7.5.3",
20
- "@jcoreio/toolchain": "4.6.2"
20
+ "@jcoreio/toolchain": "4.7.0"
21
21
  }
22
22
  }
@@ -4,7 +4,7 @@ const { scripts } = require('@jcoreio/toolchain/scripts/toolchain.cjs')
4
4
  const semver = require('semver')
5
5
 
6
6
  module.exports = [
7
- async function getConfigFiles() {
7
+ async function getConfigFiles({ fromVersion }) {
8
8
  const dockerImageVersion = '20.10.0'
9
9
  const dockerImage = `cimg/node:${dockerImageVersion}`
10
10
 
@@ -15,10 +15,16 @@ module.exports = [
15
15
  [[ $(netstat -tnlp | grep -F 'circleci-agent') ]] || pnpm run tc release
16
16
  `
17
17
 
18
+ const codecovVersion = '4.1.0'
19
+
18
20
  const defaultConfig = dedent`
19
21
  # created by ${name}
20
22
 
21
23
  version: 2.1
24
+
25
+ orbs:
26
+ codecov: codecov/codecov@${codecovVersion}
27
+
22
28
  jobs:
23
29
  build:
24
30
  docker:
@@ -42,6 +48,7 @@ module.exports = [
42
48
  name: Prepublish
43
49
  command: |
44
50
  [[ $(netstat -tnlp | grep -F 'circleci-agent') ]] || pnpm run tc prepublish
51
+ - codecov/upload
45
52
  ${
46
53
  scripts.release
47
54
  ? releaseStep.replace(/^/gm, ' '.repeat(6)).replace(/^ {6}/, '')
@@ -57,12 +64,51 @@ module.exports = [
57
64
  - github-release
58
65
  `
59
66
  return {
60
- '.circleci/config.yml': (prev) =>
61
- prev && prev.includes(name)
62
- ? prev.replace(/\bcimg\/node:([0-9.]+)/, (m, version) =>
63
- semver.lt(version, dockerImageVersion) ? dockerImage : m
67
+ '.circleci/config.yml': (config) => {
68
+ if (
69
+ !config ||
70
+ (semver.lt(fromVersion || '0.0.0', '3.0.0') && !config.includes(name))
71
+ ) {
72
+ return defaultConfig
73
+ }
74
+ config = config.replace(/\bcimg\/node:([0-9.]+)/, (m, version) =>
75
+ semver.lt(version, dockerImageVersion) ? dockerImage : m
76
+ )
77
+ if (
78
+ semver.lt(fromVersion || '0.0.0', '4.7.0') &&
79
+ !config.includes('codecov')
80
+ ) {
81
+ if (!/tc prepublish\n(\s*)- run:/m.test(config)) {
82
+ // eslint-disable-next-line no-console
83
+ console.error(
84
+ 'WARNING: failed to add codecov upload to .circleci/config.yml'
85
+ )
86
+ return config
87
+ }
88
+ if (/^orbs:/m.test(config)) {
89
+ config = config.replace(
90
+ /^orbs:/m,
91
+ `orbs:\n codecov: codecov/codecov@${codecovVersion}`
92
+ )
93
+ } else if (/^(version:.*)/m.test(config)) {
94
+ config = config.replace(
95
+ /^(version:.*)/m,
96
+ `$1\n\norbs:\n codecov: codecov/codecov@${codecovVersion}`
97
+ )
98
+ } else {
99
+ // eslint-disable-next-line no-console
100
+ console.error(
101
+ 'WARNING: failed to add codecov upload to .circleci/config.yml'
64
102
  )
65
- : defaultConfig,
103
+ return config
104
+ }
105
+ config = config.replace(
106
+ /tc prepublish\n(\s*)- run:/m,
107
+ 'tc prepublish\n$1- codecov/upload\n$1- run:'
108
+ )
109
+ }
110
+ return config
111
+ },
66
112
  }
67
113
  },
68
114
  ]