@shreyash1601/oopsify 1.0.2 → 1.0.5

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 +31 -58
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -4,7 +4,7 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const sound = require('sound-play');
6
6
  const os = require('os');
7
-
7
+ const isWindows = process.platform === 'win32';
8
8
 
9
9
  (async () => {
10
10
  // 👉 ESM imports
@@ -19,16 +19,15 @@ const os = require('os');
19
19
 
20
20
  if (command === 'setup') {
21
21
 
22
- const home = os.homedir();
23
- const isWindows = process.platform === 'win32';
22
+ const { execSync } = require('child_process');
24
23
 
25
- if (isWindows) {
26
- const profilePath = path.join(
27
- home,
28
- 'Documents',
29
- 'PowerShell',
30
- 'Microsoft.PowerShell_profile.ps1'
31
- );
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();
32
31
 
33
32
  const config = String.raw`
34
33
  # >>> oopsify setup >>>
@@ -42,27 +41,25 @@ function global:prompt {
42
41
 
43
42
  $shouldTrigger = $false
44
43
 
45
- if (-not $global:isFirstRun) {
46
-
47
- $shouldTrigger = $false
48
-
49
- if (-not $?) {
50
- $shouldTrigger = $true
51
- } elseif ($LASTEXITCODE -ne 0) {
52
- $shouldTrigger = $true
53
- } elseif ($Error.Count -gt 0) {
54
- $shouldTrigger = $true
55
- }
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
+ }
56
53
 
57
- if ($shouldTrigger) {
58
- if ($currentTime - $global:lastOopsifyTime -gt 2) {
59
- oopsify
60
- $global:lastOopsifyTime = $currentTime
54
+ if ($shouldTrigger) {
55
+ if ($currentTime - $global:lastOopsifyTime -gt 2) {
56
+ oopsify
57
+ $global:lastOopsifyTime = $currentTime
58
+ }
61
59
  }
62
- }
63
60
 
64
- $Error.Clear()
65
- }}
61
+ $Error.Clear()
62
+ }
66
63
 
67
64
  $global:isFirstRun = $false
68
65
  $global:LASTEXITCODE = 0
@@ -72,6 +69,7 @@ function global:prompt {
72
69
  # <<< oopsify setup <<<
73
70
  `;
74
71
 
72
+ // 👉 Ensure directory exists
75
73
  fs.mkdirSync(path.dirname(profilePath), { recursive: true });
76
74
 
77
75
  let existing = '';
@@ -81,42 +79,17 @@ function global:prompt {
81
79
 
82
80
  if (!existing.includes('oopsify setup')) {
83
81
  fs.appendFileSync(profilePath, config);
84
- console.log('✅ Oopsify configured successfully for PowerShell!');
82
+
83
+ console.log('✅ Oopsify auto-configured successfully!');
85
84
  console.log('👉 Restart your terminal.');
86
85
  } else {
87
86
  console.log('⚠️ Oopsify already configured.');
88
87
  }
89
88
 
90
- } else {
91
- const bashrc = path.join(home, '.bashrc');
92
-
93
- const config = `
94
- # >>> oopsify setup >>>
95
- oopsify_run() {
96
- "$@"
97
- if [ $? -ne 0 ]; then
98
- oopsify
99
- fi
100
- }
101
- alias run="oopsify_run"
102
- # <<< oopsify setup <<<
103
- `;
104
-
105
- let existing = '';
106
- if (fs.existsSync(bashrc)) {
107
- existing = fs.readFileSync(bashrc, 'utf-8');
108
- }
109
-
110
- if (!existing.includes('oopsify setup')) {
111
- fs.appendFileSync(bashrc, config);
112
- console.log('✅ Oopsify configured for bash!');
113
- console.log('👉 Run: source ~/.bashrc');
114
- } else {
115
- console.log('⚠️ Already configured.');
116
- }
89
+ } catch (err) {
90
+ console.error('❌ Failed to configure PowerShell profile');
117
91
  }
118
-
119
- return;
92
+ }
120
93
  }
121
94
  // 👉 LIST COMMAND
122
95
  if (command === 'list') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shreyash1601/oopsify",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "Play meme sounds automatically on terminal errors 🔊",
5
5
  "main": "index.js",
6
6
  "bin": {