code-squad-cli 2.1.3 → 2.1.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.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "code-squad-cli",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "csq": "./dist/index.js"
7
7
  },
8
8
  "main": "./dist/index.js",
9
9
  "files": [
10
- "dist"
10
+ "dist",
11
+ "scripts"
11
12
  ],
12
13
  "scripts": {
13
14
  "build": "tsc && npm run bundle",
@@ -16,6 +17,7 @@
16
17
  "dev": "tsx src/index.ts",
17
18
  "type-check": "tsc --noEmit",
18
19
  "clean": "rimraf dist",
20
+ "postinstall": "node scripts/postinstall.mjs",
19
21
  "prepublishOnly": "npm run clean && npm run build"
20
22
  },
21
23
  "dependencies": {
@@ -0,0 +1,59 @@
1
+ import { existsSync, readFileSync, appendFileSync, mkdirSync, accessSync } from 'fs';
2
+ import { join, dirname, basename } from 'path';
3
+ import { homedir } from 'os';
4
+ import { execSync } from 'child_process';
5
+
6
+ // Only run for global installs - check if csq is in PATH
7
+ try {
8
+ execSync('command -v csq', { stdio: 'ignore' });
9
+ } catch {
10
+ process.exit(0);
11
+ }
12
+
13
+ const shell = basename(process.env.SHELL || '');
14
+ const home = homedir();
15
+
16
+ let rcFile;
17
+ let initLine;
18
+
19
+ switch (shell) {
20
+ case 'zsh':
21
+ rcFile = join(process.env.ZDOTDIR || home, '.zshrc');
22
+ initLine = 'eval "$(csq --init)"';
23
+ break;
24
+ case 'bash':
25
+ rcFile = existsSync(join(home, '.bashrc'))
26
+ ? join(home, '.bashrc')
27
+ : join(home, '.bash_profile');
28
+ initLine = 'eval "$(csq --init)"';
29
+ break;
30
+ case 'fish':
31
+ rcFile = join(
32
+ process.env.XDG_CONFIG_HOME || join(home, '.config'),
33
+ 'fish',
34
+ 'config.fish'
35
+ );
36
+ initLine = 'csq init | source';
37
+ break;
38
+ default:
39
+ process.exit(0);
40
+ }
41
+
42
+ // Already configured
43
+ if (existsSync(rcFile)) {
44
+ const content = readFileSync(rcFile, 'utf-8');
45
+ if (content.includes('csq --init') || content.includes('csq init')) {
46
+ process.exit(0);
47
+ }
48
+ }
49
+
50
+ try {
51
+ mkdirSync(dirname(rcFile), { recursive: true });
52
+ appendFileSync(rcFile, `\n# Code Squad CLI\n${initLine}\n`);
53
+ console.log('');
54
+ console.log(` \u2713 csq: shell integration added to ${rcFile}`);
55
+ console.log(' Restart your terminal to activate.');
56
+ console.log('');
57
+ } catch {
58
+ // Don't break install
59
+ }