|
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 | + |
| 5 | +// Note that yarn also has a `versions` field, but it appears to be sorting canary versions |
| 6 | +// alphabetically so we can't depend on it. Instead we use `time` which is a version to time map. |
| 7 | +const versionsProcess = spawnSync('yarn', ['info', 'material-components-web', 'time', '--json'], { |
| 8 | + shell: true |
| 9 | +}); |
| 10 | +let versions = null; |
| 11 | + |
| 12 | +try { |
| 13 | + versions = JSON.parse(versionsProcess.stdout).data; |
| 14 | +} catch (e) { |
| 15 | + console.error('Failed to retrieve latest MDC version'); |
| 16 | + throw e; |
| 17 | +} |
| 18 | + |
| 19 | +const latestCanaryVersion = Object.keys(versions) |
| 20 | + .filter(key => key.includes('-canary')) |
| 21 | + .sort((a, b) => new Date(versions[a]) - new Date(versions[b])) |
| 22 | + .pop(); |
| 23 | + |
4 | 24 | const pattern = /^material-components-web$|^@material\//;
|
5 | 25 | const params = Object.keys(packageJson.devDependencies)
|
6 | 26 | .filter(dependency => pattern.test(dependency))
|
7 |
| - .reduce((mdcDependencies, dependency) => [...mdcDependencies, `${dependency}@canary`], []); |
| 27 | + .reduce((mdcDependencies, dependency) => |
| 28 | + [...mdcDependencies, `${dependency}@${latestCanaryVersion}`], []); |
8 | 29 |
|
9 | 30 | if (!params.length) {
|
10 | 31 | throw Error(`Could not find MDC dependencies in package.json`);
|
11 | 32 | }
|
12 | 33 |
|
13 |
| -console.log('Updating all MDC dependencies to latest canary version'); |
| 34 | +console.log(`Updating all MDC dependencies to version ${latestCanaryVersion}`); |
14 | 35 | const childProcess = spawn('yarn', ['add', ...params, '-D'], {shell: true});
|
15 | 36 | childProcess.stdout.on('data', data => console.log(data + ''));
|
16 | 37 | childProcess.stderr.on('data', data => console.error(data + ''));
|
|
0 commit comments