-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild.js
executable file
·35 lines (27 loc) · 1.08 KB
/
rebuild.js
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
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const cliName = Object.keys(packageJson.bin)[0];
console.log('Starting rebuild process...');
try {
console.log('Unlinking global package...');
execSync(`npm unlink -g ${packageJson.name}`, { stdio: 'inherit' });
} catch (error) {
console.log('Package was not linked globally. Continuing...');
}
console.log('Removing node_modules and package-lock.json...');
try {
fs.rmSync('node_modules', { recursive: true, force: true });
fs.unlinkSync('package-lock.json');
} catch (error) {
console.log('Error removing files:', error.message);
}
console.log('Installing dependencies...');
execSync('npm install', { stdio: 'inherit' });
console.log('Building project...');
execSync('npm run build', { stdio: 'inherit' });
console.log('Linking package globally...');
execSync('npm link', { stdio: 'inherit' });
console.log('Rebuild complete!');
console.log(`You can now run your CLI tool using the '${cliName}' command.`);