@codifycli/plugin-core 1.1.0-beta6 → 1.1.0-beta9

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.
@@ -74,10 +74,11 @@ export class SequentialPty {
74
74
  process.stdout.on('resize', resizeListener);
75
75
  mPty.onExit((result) => {
76
76
  process.stdout.off('resize', resizeListener);
77
+ const raw = stripAnsi(output.join('')).replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim();
77
78
  resolve({
78
79
  status: result.exitCode === 0 ? SpawnStatus.SUCCESS : SpawnStatus.ERROR,
79
80
  exitCode: result.exitCode,
80
- data: stripAnsi(output.join('\n').trim()),
81
+ data: raw,
81
82
  });
82
83
  });
83
84
  });
@@ -20,4 +20,5 @@ export declare class FileUtils {
20
20
  static checkDirExistsOrThrowIfFile(path: string): Promise<boolean>;
21
21
  static createDirIfNotExists(path: string): Promise<void>;
22
22
  private static calculateEndingNewLines;
23
+ static createShellRcIfNotExists(): Promise<void>;
23
24
  }
@@ -19,6 +19,7 @@ export class FileUtils {
19
19
  console.log(`Finished downloading to ${destination}`);
20
20
  }
21
21
  static async addToShellRc(line) {
22
+ await FileUtils.createShellRcIfNotExists();
22
23
  const lineToInsert = addLeadingSpacer(addTrailingSpacer(line));
23
24
  await fs.appendFile(Utils.getPrimaryShellRc(), lineToInsert);
24
25
  function addLeadingSpacer(line) {
@@ -33,6 +34,7 @@ export class FileUtils {
33
34
  }
34
35
  }
35
36
  static async addAllToShellRc(lines) {
37
+ await FileUtils.createShellRcIfNotExists();
36
38
  const formattedLines = '\n' + lines.join('\n') + '\n';
37
39
  const shellRc = Utils.getPrimaryShellRc();
38
40
  console.log(`Adding to ${path.basename(shellRc)}:
@@ -46,6 +48,7 @@ ${lines.join('\n')}`);
46
48
  * @param prepend - Whether to prepend the path to the existing PATH variable.
47
49
  */
48
50
  static async addPathToShellRc(value, prepend) {
51
+ await FileUtils.createShellRcIfNotExists();
49
52
  if (await Utils.isDirectoryOnPath(value)) {
50
53
  return;
51
54
  }
@@ -183,4 +186,10 @@ ${lines.join('\n')}`);
183
186
  }
184
187
  }
185
188
  }
189
+ static async createShellRcIfNotExists() {
190
+ const shellRc = Utils.getPrimaryShellRc();
191
+ if (!await FileUtils.fileExists(shellRc)) {
192
+ await fs.writeFile(shellRc, '', 'utf8');
193
+ }
194
+ }
186
195
  }
@@ -3,7 +3,7 @@ import * as fsSync from 'node:fs';
3
3
  import * as fs from 'node:fs/promises';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
- import { SpawnStatus, getPty } from '../pty/index.js';
6
+ import { getPty, SpawnStatus } from '../pty/index.js';
7
7
  export function isDebug() {
8
8
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
9
9
  }
@@ -56,7 +56,7 @@ export const Utils = {
56
56
  return query.status === SpawnStatus.SUCCESS;
57
57
  },
58
58
  getShell() {
59
- const shell = process.env.SHELL || '';
59
+ const shell = process.env.SHELL || os.userInfo().shell || '';
60
60
  if (shell.endsWith('bash')) {
61
61
  return Shell.BASH;
62
62
  }
@@ -81,7 +81,7 @@ export const Utils = {
81
81
  return this.getShellRcFiles()[0];
82
82
  },
83
83
  getShellRcFiles() {
84
- const shell = process.env.SHELL || '';
84
+ const shell = process.env.SHELL || os.userInfo().shell || '';
85
85
  const homeDir = os.homedir();
86
86
  if (shell.endsWith('bash')) {
87
87
  // Linux typically uses .bashrc, macOS uses .bash_profile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codifycli/plugin-core",
3
- "version": "1.1.0-beta6",
3
+ "version": "1.1.0-beta9",
4
4
  "description": "TypeScript library for building Codify plugins to manage system resources (applications, CLI tools, settings) through infrastructure-as-code",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -100,10 +100,12 @@ export class SequentialPty implements IPty {
100
100
  mPty.onExit((result) => {
101
101
  process.stdout.off('resize', resizeListener);
102
102
 
103
+ const raw = stripAnsi(output.join('')).replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim();
104
+
103
105
  resolve({
104
106
  status: result.exitCode === 0 ? SpawnStatus.SUCCESS : SpawnStatus.ERROR,
105
107
  exitCode: result.exitCode,
106
- data: stripAnsi(output.join('\n').trim()),
108
+ data: raw,
107
109
  })
108
110
  })
109
111
  })
@@ -26,6 +26,8 @@ export class FileUtils {
26
26
  }
27
27
 
28
28
  static async addToShellRc(line: string): Promise<void> {
29
+ await FileUtils.createShellRcIfNotExists();
30
+
29
31
  const lineToInsert = addLeadingSpacer(
30
32
  addTrailingSpacer(line)
31
33
  );
@@ -46,6 +48,8 @@ export class FileUtils {
46
48
  }
47
49
 
48
50
  static async addAllToShellRc(lines: string[]): Promise<void> {
51
+ await FileUtils.createShellRcIfNotExists();
52
+
49
53
  const formattedLines = '\n' + lines.join('\n') + '\n';
50
54
  const shellRc = Utils.getPrimaryShellRc();
51
55
 
@@ -62,6 +66,8 @@ ${lines.join('\n')}`)
62
66
  * @param prepend - Whether to prepend the path to the existing PATH variable.
63
67
  */
64
68
  static async addPathToShellRc(value: string, prepend: boolean): Promise<void> {
69
+ await FileUtils.createShellRcIfNotExists();
70
+
65
71
  if (await Utils.isDirectoryOnPath(value)) {
66
72
  return;
67
73
  }
@@ -228,4 +234,11 @@ ${lines.join('\n')}`)
228
234
  }
229
235
  }
230
236
  }
237
+
238
+ static async createShellRcIfNotExists(): Promise<void> {
239
+ const shellRc = Utils.getPrimaryShellRc();
240
+ if (!await FileUtils.fileExists(shellRc)) {
241
+ await fs.writeFile(shellRc, '', 'utf8');
242
+ }
243
+ }
231
244
  }
@@ -4,7 +4,7 @@ import * as fs from 'node:fs/promises';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
 
7
- import { SpawnStatus, getPty } from '../pty/index.js';
7
+ import { getPty, SpawnStatus } from '../pty/index.js';
8
8
 
9
9
  export function isDebug(): boolean {
10
10
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
@@ -73,7 +73,7 @@ export const Utils = {
73
73
  },
74
74
 
75
75
  getShell(): Shell | undefined {
76
- const shell = process.env.SHELL || '';
76
+ const shell = process.env.SHELL || os.userInfo().shell || '';
77
77
 
78
78
  if (shell.endsWith('bash')) {
79
79
  return Shell.BASH
@@ -108,7 +108,7 @@ export const Utils = {
108
108
  },
109
109
 
110
110
  getShellRcFiles(): string[] {
111
- const shell = process.env.SHELL || '';
111
+ const shell = process.env.SHELL || os.userInfo().shell || '';
112
112
  const homeDir = os.homedir();
113
113
 
114
114
  if (shell.endsWith('bash')) {