@shreyash1601/oopsify 1.0.1 → 1.0.3

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.
Files changed (2) hide show
  1. package/bin/index.js +39 -67
  2. package/package.json +3 -3
package/bin/index.js CHANGED
@@ -2,13 +2,12 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
- const player = require('node-wav-player');
5
+ const sound = require('sound-play');
6
6
  const os = require('os');
7
7
 
8
8
 
9
9
  (async () => {
10
10
  // 👉 ESM imports
11
- const inquirer = (await import('inquirer')).default;
12
11
  const chalkImport = await import('chalk');
13
12
  const chalk = new chalkImport.Chalk({ level: 3 });
14
13
 
@@ -20,16 +19,15 @@ const os = require('os');
20
19
 
21
20
  if (command === 'setup') {
22
21
 
23
- const home = os.homedir();
24
- const isWindows = process.platform === 'win32';
22
+ const { execSync } = require('child_process');
25
23
 
26
- if (isWindows) {
27
- const profilePath = path.join(
28
- home,
29
- 'Documents',
30
- 'PowerShell',
31
- 'Microsoft.PowerShell_profile.ps1'
32
- );
24
+ if (isWindows) {
25
+ try {
26
+ // 👉 Get actual PowerShell profile path
27
+ const profilePath = execSync(
28
+ 'powershell -NoProfile -Command "$PROFILE"',
29
+ { encoding: 'utf-8' }
30
+ ).trim();
33
31
 
34
32
  const config = String.raw`
35
33
  # >>> oopsify setup >>>
@@ -43,27 +41,25 @@ function global:prompt {
43
41
 
44
42
  $shouldTrigger = $false
45
43
 
46
- if (-not $global:isFirstRun) {
47
-
48
- $shouldTrigger = $false
49
-
50
- if (-not $?) {
51
- $shouldTrigger = $true
52
- } elseif ($LASTEXITCODE -ne 0) {
53
- $shouldTrigger = $true
54
- } elseif ($Error.Count -gt 0) {
55
- $shouldTrigger = $true
56
- }
44
+ if (-not $?) {
45
+ $shouldTrigger = $true
46
+ }
47
+ elseif ($LASTEXITCODE -ne 0) {
48
+ $shouldTrigger = $true
49
+ }
50
+ elseif ($Error.Count -gt 0) {
51
+ $shouldTrigger = $true
52
+ }
57
53
 
58
- if ($shouldTrigger) {
59
- if ($currentTime - $global:lastOopsifyTime -gt 2) {
60
- oopsify
61
- $global:lastOopsifyTime = $currentTime
54
+ if ($shouldTrigger) {
55
+ if ($currentTime - $global:lastOopsifyTime -gt 2) {
56
+ oopsify
57
+ $global:lastOopsifyTime = $currentTime
58
+ }
62
59
  }
63
- }
64
60
 
65
- $Error.Clear()
66
- }}
61
+ $Error.Clear()
62
+ }
67
63
 
68
64
  $global:isFirstRun = $false
69
65
  $global:LASTEXITCODE = 0
@@ -73,6 +69,7 @@ function global:prompt {
73
69
  # <<< oopsify setup <<<
74
70
  `;
75
71
 
72
+ // 👉 Ensure directory exists
76
73
  fs.mkdirSync(path.dirname(profilePath), { recursive: true });
77
74
 
78
75
  let existing = '';
@@ -82,42 +79,17 @@ function global:prompt {
82
79
 
83
80
  if (!existing.includes('oopsify setup')) {
84
81
  fs.appendFileSync(profilePath, config);
85
- console.log('✅ Oopsify configured successfully for PowerShell!');
82
+
83
+ console.log('✅ Oopsify auto-configured successfully!');
86
84
  console.log('👉 Restart your terminal.');
87
85
  } else {
88
86
  console.log('⚠️ Oopsify already configured.');
89
87
  }
90
88
 
91
- } else {
92
- const bashrc = path.join(home, '.bashrc');
93
-
94
- const config = `
95
- # >>> oopsify setup >>>
96
- oopsify_run() {
97
- "$@"
98
- if [ $? -ne 0 ]; then
99
- oopsify
100
- fi
101
- }
102
- alias run="oopsify_run"
103
- # <<< oopsify setup <<<
104
- `;
105
-
106
- let existing = '';
107
- if (fs.existsSync(bashrc)) {
108
- existing = fs.readFileSync(bashrc, 'utf-8');
109
- }
110
-
111
- if (!existing.includes('oopsify setup')) {
112
- fs.appendFileSync(bashrc, config);
113
- console.log('✅ Oopsify configured for bash!');
114
- console.log('👉 Run: source ~/.bashrc');
115
- } else {
116
- console.log('⚠️ Already configured.');
117
- }
89
+ } catch (err) {
90
+ console.error('❌ Failed to configure PowerShell profile');
118
91
  }
119
-
120
- return;
92
+ }
121
93
  }
122
94
  // 👉 LIST COMMAND
123
95
  if (command === 'list') {
@@ -186,13 +158,13 @@ alias run="oopsify_run"
186
158
 
187
159
  const soundPath = path.join(soundsDir, `${soundName}.wav`);
188
160
 
189
- player.play({
190
- path: soundPath,
191
- }).then(async () => {
192
-
193
- console.log('\x1b[103m\x1b[31m\x1b[1m 😵 Oops! That didn’t go as planned \x1b[0m\r\n\n');
194
- }).catch(() => {
195
- console.error(`❌ Sound "${soundName}" not found`);
196
- });
161
+ sound.play(soundPath)
162
+ .then(() => {
163
+ process.stdout.write('\n');
164
+ process.stdout.write('\x1b[103m\x1b[31m\x1b[1m 😵 Oops! That didn’t go as planned \x1b[0m\n\n');
165
+ })
166
+ .catch(() => {
167
+ console.error('⚠️ Unable to play sound on this system');
168
+ });
197
169
 
198
170
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shreyash1601/oopsify",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Play meme sounds automatically on terminal errors 🔊",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -19,10 +19,10 @@
19
19
  "dependencies": {
20
20
  "chalk": "^5.0.0",
21
21
  "enquirer": "^2.4.1",
22
- "node-wav-player": "^1.0.0"
22
+ "sound-play": "^1.1.0"
23
23
  },
24
24
  "files": [
25
25
  "bin",
26
26
  "sounds"
27
27
  ]
28
- }
28
+ }