-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade
executable file
·61 lines (52 loc) · 2.43 KB
/
upgrade
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
#!/usr/bin/env node
const chalk = require('chalk');
const {existsSync} = require('fs');
const {lstatSync} = require('fs');
const {readdirSync} = require('fs');
const path = require('path');
const {spawnSync} = require('child_process');
const scope = `@sfdx-falcon`;
const userArgs = process.argv.slice(2);
const packagesBaseDir = path.join(__dirname, 'packages');
// Define the directory search function.
const isDirectory = source => lstatSync(source).isDirectory();
const getDirectories = source => readdirSync(source).map(name => path.join(source, name)).filter(isDirectory);
const packageName = pkgDir => scope + pkgDir.substring(pkgDir.lastIndexOf(path.sep));
// Get the name of each directory inside this project's base packages directory.
const packageDirs = getDirectories(packagesBaseDir);
// Make sure that the caller provided exactly one argument.
if (userArgs.length !== 1) {
console.log(chalk`{red \nUpgrade command aborted. You must provide a package name or set the '--all' flag.\n}`);
return;
}
// Upgrade ALL dependencies of the --all flag is set.
if (userArgs[0].toLowerCase() === '--all') {
// Echo the package directories that we will work with.
console.log(chalk`{yellow \nUpgrading dependencies for the following packages...}`);
packageDirs.forEach(packageDir => {
console.log(chalk`{green ${packageName(packageDir)}}`);
});
// Upgrade the dependencies in each package.
packageDirs.forEach(packageDir => {
console.log(chalk`{yellow \nUpgrading dependencies for ${packageName(packageDir)}}\n`);
process.chdir(packageDir);
spawnSync('yarn upgrade --latest', {shell: true, stdio: 'inherit'});
});
}
else {
// Handle a single-package upgrade request.
const targetDir = path.join(packagesBaseDir, userArgs[0]);
console.log(chalk`{yellow \nUpgrading dependencies for the following package...}`);
console.log(chalk`{green ${packageName(targetDir)}}\n`);
// Make sure the specified package directory exists and process the upgrade if it does.
if (existsSync(targetDir) === true) {
process.chdir(targetDir);
spawnSync('yarn upgrade --latest', {shell: true, stdio: 'inherit'});
}
else {
console.log(chalk`{red Upgrade failed. Package directory '${targetDir}' does not exist\n}`);
return;
}
}
// Report the fact that command execution is complete.
console.log(chalk`{yellow \nPackage dependency upgrades are complete\n}`);