mscfetch 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/utils/envCheck.js
CHANGED
|
@@ -1,13 +1,68 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
+
import { confirm } from '@inquirer/prompts';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import ora from 'ora';
|
|
2
5
|
|
|
3
|
-
export function
|
|
6
|
+
export function isFFmpegInstalled() {
|
|
4
7
|
try {
|
|
5
8
|
execSync('ffmpeg -version', { stdio: 'ignore' });
|
|
6
9
|
return true;
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getInstallCommand() {
|
|
16
|
+
const platform = process.platform;
|
|
17
|
+
if (platform === 'win32') {
|
|
18
|
+
return 'winget install Gyan.FFmpeg --accept-package-agreements --accept-source-agreements';
|
|
19
|
+
} else if (platform === 'darwin') {
|
|
20
|
+
return 'brew install ffmpeg';
|
|
21
|
+
} else {
|
|
22
|
+
return 'sudo apt-get update && sudo apt-get install -y ffmpeg';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function checkFFmpeg() {
|
|
27
|
+
if (isFFmpegInstalled()) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log(
|
|
32
|
+
chalk.yellow('\n⚠️ FFmpeg is required for MP3 audio conversion, but was not found in your system PATH.')
|
|
33
|
+
);
|
|
34
|
+
const installCmd = getInstallCommand();
|
|
35
|
+
console.log(chalk.gray(`Detected install command for your system: ${installCmd}\n`));
|
|
36
|
+
|
|
37
|
+
let shouldInstall = false;
|
|
38
|
+
try {
|
|
39
|
+
shouldInstall = await confirm({
|
|
40
|
+
message: chalk.cyan('Would you like mscfetch to run this install command for you?'),
|
|
41
|
+
default: false, // Safe default: user has full choice to decline
|
|
42
|
+
});
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (err?.name === 'ExitPromptError') {
|
|
45
|
+
console.log(chalk.gray('\nInstallation aborted.'));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!shouldInstall) {
|
|
51
|
+
console.log(chalk.gray('\nInstallation declined. You can install FFmpeg manually at any time by running:'));
|
|
52
|
+
console.log(chalk.bold.white(` ${installCmd}`));
|
|
53
|
+
console.log(chalk.gray('Or download directly from https://ffmpeg.org/download.html\n'));
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const spinner = ora('Installing FFmpeg...').start();
|
|
58
|
+
try {
|
|
59
|
+
execSync(installCmd, { stdio: 'inherit' });
|
|
60
|
+
spinner.succeed(chalk.green('FFmpeg installation completed!'));
|
|
61
|
+
return true;
|
|
7
62
|
} catch (error) {
|
|
8
|
-
|
|
9
|
-
console.
|
|
10
|
-
console.
|
|
63
|
+
spinner.fail(chalk.red(`Automatic installation failed: ${error.message}`));
|
|
64
|
+
console.log(chalk.yellow('\nPlease run the command manually in your terminal/admin prompt:'));
|
|
65
|
+
console.log(chalk.bold.white(` ${installCmd}\n`));
|
|
11
66
|
process.exit(1);
|
|
12
67
|
}
|
|
13
68
|
}
|