|
3 | 3 | // Note: this *MUST NOT* globally depend on any module installed in `node_modules`, as it could be |
4 | 4 | // loaded before they're installed. |
5 | 5 |
|
| 6 | +const path = require('path') |
6 | 7 | const { p, run, exec, packageList } = require('./internal/util.js') |
7 | 8 | const { blue, green } = require('./internal/color').stdout |
8 | 9 | const deployTemplate = require('./internal/deploy-template.js') |
@@ -31,14 +32,14 @@ require('./internal/execute-tasks.js')({ |
31 | 32 | const fse = require('fs-extra') |
32 | 33 |
|
33 | 34 | for (const { target, resolved } of packageList) { |
34 | | - console.log(green('Deleting ') + blue(target)) |
35 | | - await fse.remove(resolved) |
| 35 | + console.log(green('Deleting ') + (target ? blue(target) : green('root'))) |
| 36 | + await fse.remove(path.join(resolved, 'node_modules')) |
36 | 37 | } |
37 | 38 |
|
38 | 39 | console.log(green('Preparing dependencies...')) |
39 | 40 | // We have the package and distribution bundles here in source control, and these should only |
40 | 41 | // be updated with that dependency. (Removing them causes build issues.) |
41 | | - await run('git', ['checkout', '--', 'dev-portal/node_modules']) |
| 42 | + await exec('git', ['checkout', '--', 'dev-portal/node_modules']) |
42 | 43 |
|
43 | 44 | await this.install() |
44 | 45 | }, |
@@ -89,5 +90,58 @@ require('./internal/execute-tasks.js')({ |
89 | 90 |
|
90 | 91 | async 'cfn-lint' () { |
91 | 92 | await exec('cfn-lint') |
| 93 | + }, |
| 94 | + |
| 95 | + async 'version' ({ inc: increment, type }) { |
| 96 | + if (increment == null) { |
| 97 | + throw new TypeError('Increment is required') |
| 98 | + } |
| 99 | + |
| 100 | + if (!/^(?:patch|minor|major|prepatch|preminor|premajor|prerelease)$/.test(increment)) { |
| 101 | + throw new TypeError('Increment is invalid') |
| 102 | + } |
| 103 | + |
| 104 | + // Note: this might not necessarily be installed yet, so it can't be loaded globally. |
| 105 | + const fs = require('fs-extra') |
| 106 | + const inc = require('semver/functions/inc') |
| 107 | + |
| 108 | + await this.build() |
| 109 | + |
| 110 | + console.log(green('Updating "version" field in ') + blue('package.json')) |
| 111 | + const rootPkg = JSON.parse(await fs.readFile(p('package.json'), 'utf-8')) |
| 112 | + const newVersion = inc(rootPkg.version, increment, type) |
| 113 | + |
| 114 | + async function updatePackage (resolved, target) { |
| 115 | + console.log(green('Updating "version" field in ') + blue(target)) |
| 116 | + const pkg = JSON.parse(await fs.readFile(resolved, 'utf-8')) |
| 117 | + pkg.version = newVersion |
| 118 | + fs.writeFile(resolved, JSON.stringify(pkg, null, 2) + '\n', 'utf-8') |
| 119 | + } |
| 120 | + |
| 121 | + rootPkg.version = newVersion |
| 122 | + |
| 123 | + await Promise.all([ |
| 124 | + fs.writeFile(p('package.json'), JSON.stringify(rootPkg, null, 2) + '\n', 'utf-8'), |
| 125 | + updatePackage(p('package-lock.json'), 'package-lock.json'), |
| 126 | + ...packageList |
| 127 | + .filter(p => p.target !== '') |
| 128 | + .map(async ({ target, resolved }) => Promise.all([ |
| 129 | + updatePackage(path.join(resolved, 'package.json'), path.join(target, 'package.json')), |
| 130 | + updatePackage(path.join(resolved, 'package-lock.json'), path.join(target, 'package-lock.json')) |
| 131 | + ])) |
| 132 | + ]) |
| 133 | + |
| 134 | + console.log(green('Committing updated packages')) |
| 135 | + |
| 136 | + await exec('git', [ |
| 137 | + 'commit', '--message', `v${newVersion}`, |
| 138 | + 'lambdas/static-asset-uploader/build', |
| 139 | + ...packageList.map(p => path.join(p.target, 'package.json')), |
| 140 | + ...packageList.map(p => path.join(p.target, 'package-lock.json')) |
| 141 | + ]) |
| 142 | + |
| 143 | + await exec('git', ['tag', `v${newVersion}`]) |
| 144 | + |
| 145 | + console.log(green('Release tag created: ') + blue(`v${newVersion}`)) |
92 | 146 | } |
93 | 147 | }) |
0 commit comments