Skip to content

Commit f0c9cc3

Browse files
committed
fix
1 parent c98e22f commit f0c9cc3

File tree

1 file changed

+42
-45
lines changed

1 file changed

+42
-45
lines changed

scripts/update.packages.mjs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,58 @@
11
#!/usr/bin/env node
2-
import { confirm, select } from '@inquirer/prompts';
3-
import { execSync } from 'node:child_process';
4-
import { readdirSync, lstatSync } from 'node:fs';
5-
import { join } from 'node:path';
6-
import {rimraf} from 'rimraf';
7-
8-
const currentPath = process.cwd();
9-
const packagesDir = join(currentPath, 'packages');
2+
import { confirm, select } from '@inquirer/prompts'
3+
import { execSync } from 'node:child_process'
4+
import { readdirSync, lstatSync } from 'node:fs'
5+
import { join } from 'node:path'
6+
import { rimraf } from 'rimraf'
7+
8+
const currentPath = process.cwd()
9+
const packagesDir = join(currentPath, 'packages')
1010
const header = `
1111
==========================
1212
🤖 Package update Wizard 🧙
1313
==========================
1414
`
1515

1616
async function updatePackages(dir, target, updateFiles) {
17-
console.log(`${updateFiles ? 'Updating' : 'Checking' } packages for ${target} updates in ${dir}...`);
18-
const command = `npx npm-check-updates ${updateFiles ? '-u' : ''} --target ${target}`;
19-
execSync(command, { stdio: 'inherit', cwd: dir });
17+
console.log(`${updateFiles ? 'Updating' : 'Checking' } packages for ${target} updates in ${dir}...`)
18+
const command = `npx npm-check-updates ${updateFiles ? '-u' : ''} --target ${target}`
19+
execSync(command, { stdio: 'inherit', cwd: dir })
2020
}
2121

2222
function removeDependencies(dir) {
23-
console.log(`Removing root dependencies in ${dir}...`);
24-
const rootNodeModulesPath = join(dir, 'node_modules');
25-
rimraf.sync(rootNodeModulesPath);
23+
console.log(`Removing root dependencies in ${dir}...`)
24+
const rootNodeModulesPath = join(dir, 'node_modules')
25+
rimraf.sync(rootNodeModulesPath)
2626

27-
const packagesDir = join(dir, 'packages');
27+
const packagesDir = join(dir, 'packages')
2828

2929
readdirSync(packagesDir).forEach(packageDir => {
30-
const fullPath = join(packagesDir, packageDir);
30+
const fullPath = join(packagesDir, packageDir)
3131

3232
if (lstatSync(fullPath).isDirectory()) {
33-
console.log(`Removing dependencies in ${packageDir}...`);
34-
const nodeModulesPath = join(fullPath, 'node_modules');
35-
rimraf.sync(nodeModulesPath);
33+
console.log(`Removing dependencies in ${packageDir}...`)
34+
const nodeModulesPath = join(fullPath, 'node_modules')
35+
rimraf.sync(nodeModulesPath)
3636
}
37-
});
37+
})
3838
}
3939

40-
41-
4240
function installDependencies(dir) {
43-
console.log(`Installing dependencies in ${dir}...`);
44-
execSync('pnpm pnpm.install.workaround', { stdio: 'inherit', cwd: dir });
41+
console.log(`Installing dependencies in ${dir}...`)
42+
execSync('pnpm pnpm.install.workaround', { stdio: 'inherit', cwd: dir })
4543
}
4644

47-
4845
function isPnpmInstalled() {
4946
try {
50-
execSync('pnpm --version', { stdio: 'ignore' });
51-
return true;
47+
execSync('pnpm --version', { stdio: 'ignore' })
48+
return true
5249
} catch {
53-
return false;
50+
return false
5451
}
5552
}
5653

5754
async function main() {
58-
console.log(header);
55+
console.log(header)
5956

6057
const target = await select({
6158
message: 'Which version target would you like to update to?',
@@ -64,50 +61,50 @@ async function main() {
6461
{ name: 'Latest', value: 'latest' }
6562
],
6663
default: 'minor'
67-
});
64+
})
6865

6966
const updateFiles = await confirm({
7067
message: 'Do you want to update the package.json files?',
7168
default: true
72-
});
69+
})
7370

74-
console.log(`${updateFiles ? 'Updating' : 'Checking' } root 'package.json' for ${target} updates...`);
75-
await updatePackages(currentPath, target, updateFiles);
71+
console.log(`${updateFiles ? 'Updating' : 'Checking' } root 'package.json' for ${target} updates...`)
72+
await updatePackages(currentPath, target, updateFiles)
7673

7774
readdirSync(packagesDir).forEach(async (packageDir) => {
78-
const fullPath = join(packagesDir, packageDir);
75+
const fullPath = join(packagesDir, packageDir)
7976
if (lstatSync(fullPath).isDirectory()) {
80-
await updatePackages(fullPath, target, updateFiles);
77+
await updatePackages(fullPath, target, updateFiles)
8178
}
82-
});
79+
})
8380

8481
if (updateFiles) {
8582
const removeNodeModules = await confirm({
8683
message: 'Do you want to remove all "node_modules" and reinstall dependencies?',
8784
default: true
88-
});
85+
})
8986

9087
if (removeNodeModules) {
91-
removeDependencies(currentPath);
88+
removeDependencies(currentPath)
9289
const usePnpm = await confirm({
9390
message: 'Would you like reinstall the dependencies?',
9491
default: true
95-
});
92+
})
9693

9794
if (usePnpm) {
9895
if (isPnpmInstalled()) {
99-
installDependencies(currentPath);
96+
installDependencies(currentPath)
10097
} else {
101-
console.error('pnpm is not installed. Please install pnpm and try again.');
98+
console.error('pnpm is not installed. Please install pnpm and try again.')
10299
}
103100
}
104101
}
105102
}
106103

107-
console.log(`All packages ${updateFiles ? 'updated': 'checked'}!`);
104+
console.log(`All packages ${updateFiles ? 'updated': 'checked'}!`)
108105
}
109106

110107
main().catch((error) => {
111-
console.error('An unexpected error occurred:', error);
112-
process.exit(1);
113-
});
108+
console.error('An unexpected error occurred:', error)
109+
process.exit(1)
110+
})

0 commit comments

Comments
 (0)