|
1 | 1 | const {join} = require('path');
|
2 |
| -const {spawn} = require('child_process'); |
| 2 | +const {spawn, spawnSync} = require('child_process'); |
3 | 3 | const packageJson = require(join(__dirname, '../../package.json'));
|
| 4 | +const versionsProcess = spawnSync('yarn', [ |
| 5 | + 'info', 'material-components-web', 'dist-tags.canary', '--json' |
| 6 | +], {shell: true}); |
| 7 | +let latestCanaryVersion = null; |
| 8 | + |
| 9 | +try { |
| 10 | + latestCanaryVersion = JSON.parse(versionsProcess.stdout.toString()).data; |
| 11 | +} catch (e) { |
| 12 | + console.error('Failed to retrieve latest MDC version'); |
| 13 | + throw e; |
| 14 | +} |
| 15 | + |
4 | 16 | const pattern = /^material-components-web$|^@material\//;
|
5 | 17 | const params = Object.keys(packageJson.devDependencies)
|
6 | 18 | .filter(dependency => pattern.test(dependency))
|
7 |
| - .reduce((mdcDependencies, dependency) => [...mdcDependencies, `${dependency}@canary`], []); |
| 19 | + .reduce((mdcDependencies, dependency) => |
| 20 | + [...mdcDependencies, `${dependency}@${latestCanaryVersion}`], []); |
8 | 21 |
|
9 | 22 | if (!params.length) {
|
10 | 23 | throw Error(`Could not find MDC dependencies in package.json`);
|
11 | 24 | }
|
12 | 25 |
|
13 |
| -console.log('Updating all MDC dependencies to latest canary version'); |
| 26 | +console.log(`Updating all MDC dependencies to version ${latestCanaryVersion}`); |
14 | 27 | const childProcess = spawn('yarn', ['add', ...params, '-D'], {shell: true});
|
15 | 28 | childProcess.stdout.on('data', data => console.log(data + ''));
|
16 | 29 | childProcess.stderr.on('data', data => console.error(data + ''));
|
|
0 commit comments