codify-plugin-lib 1.0.182-beta17 → 1.0.182-beta19

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.
@@ -86,7 +86,7 @@ export class BackgroundPty {
86
86
  resolve(null);
87
87
  }
88
88
  });
89
- console.log(`Running command ${cmd}${options?.cwd ? ` (cwd: ${options.cwd})` : ''}`);
89
+ console.log(`Running command: ${cmd}${options?.cwd ? ` (cwd: ${options.cwd})` : ''}`);
90
90
  this.basePty.write(`${command}\r`);
91
91
  }));
92
92
  }).finally(async () => {
@@ -1,8 +1,8 @@
1
1
  export declare class FileUtils {
2
2
  static downloadFile(url: string, destination: string): Promise<void>;
3
- static addToStartupFile(line: string): Promise<void>;
4
- static addAllToStartupFile(lines: string[]): Promise<void>;
5
- static addPathToPrimaryShellRc(value: string, prepend: boolean): Promise<void>;
3
+ static addToShellRc(line: string): Promise<void>;
4
+ static addAllToShellRc(lines: string[]): Promise<void>;
5
+ static addPathToShellRc(value: string, prepend: boolean): Promise<void>;
6
6
  static dirExists(path: string): Promise<boolean>;
7
7
  static fileExists(path: string): Promise<boolean>;
8
8
  static exists(path: string): Promise<boolean>;
@@ -18,7 +18,7 @@ export class FileUtils {
18
18
  await finished(Readable.fromWeb(body).pipe(ws));
19
19
  console.log(`Finished downloading to ${destination}`);
20
20
  }
21
- static async addToStartupFile(line) {
21
+ static async addToShellRc(line) {
22
22
  const lineToInsert = addLeadingSpacer(addTrailingSpacer(line));
23
23
  await fs.appendFile(Utils.getPrimaryShellRc(), lineToInsert);
24
24
  function addLeadingSpacer(line) {
@@ -32,14 +32,17 @@ export class FileUtils {
32
32
  : line + '\n';
33
33
  }
34
34
  }
35
- static async addAllToStartupFile(lines) {
35
+ static async addAllToShellRc(lines) {
36
36
  const formattedLines = '\n' + lines.join('\n') + '\n';
37
37
  const shellRc = Utils.getPrimaryShellRc();
38
38
  console.log(`Adding to ${path.basename(shellRc)}:
39
39
  ${lines.join('\n')}`);
40
40
  await fs.appendFile(shellRc, formattedLines);
41
41
  }
42
- static async addPathToPrimaryShellRc(value, prepend) {
42
+ static async addPathToShellRc(value, prepend) {
43
+ if (!(await Utils.isDirectoryOnPath(value))) {
44
+ return;
45
+ }
43
46
  const shellRc = Utils.getPrimaryShellRc();
44
47
  console.log(`Saving path: ${value} to ${shellRc}`);
45
48
  if (prepend) {
@@ -23,4 +23,5 @@ export declare const Utils: {
23
23
  getShell(): Shell | undefined;
24
24
  getPrimaryShellRc(): string;
25
25
  getShellRcFiles(): string[];
26
+ isDirectoryOnPath(directory: string): Promise<boolean>;
26
27
  };
@@ -1,5 +1,6 @@
1
1
  import os from 'node:os';
2
2
  import path from 'node:path';
3
+ import { getPty } from '../pty/index.js';
3
4
  export function isDebug() {
4
5
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
5
6
  }
@@ -108,4 +109,10 @@ export const Utils = {
108
109
  path.join(homeDir, '.profile'),
109
110
  ];
110
111
  },
112
+ async isDirectoryOnPath(directory) {
113
+ const $ = getPty();
114
+ const { data: pathQuery } = await $.spawn('echo $PATH', { interactive: true });
115
+ const lines = pathQuery.split(':');
116
+ return lines.includes(directory);
117
+ },
111
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.182-beta17",
3
+ "version": "1.0.182-beta19",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -104,7 +104,7 @@ export class BackgroundPty implements IPty {
104
104
  }
105
105
  });
106
106
 
107
- console.log(`Running command ${cmd}${options?.cwd ? ` (cwd: ${options.cwd})` : ''}`)
107
+ console.log(`Running command: ${cmd}${options?.cwd ? ` (cwd: ${options.cwd})` : ''}`)
108
108
  this.basePty.write(`${command}\r`);
109
109
 
110
110
  }));
@@ -25,7 +25,7 @@ export class FileUtils {
25
25
  console.log(`Finished downloading to ${destination}`);
26
26
  }
27
27
 
28
- static async addToStartupFile(line: string): Promise<void> {
28
+ static async addToShellRc(line: string): Promise<void> {
29
29
  const lineToInsert = addLeadingSpacer(
30
30
  addTrailingSpacer(line)
31
31
  );
@@ -45,7 +45,7 @@ export class FileUtils {
45
45
  }
46
46
  }
47
47
 
48
- static async addAllToStartupFile(lines: string[]): Promise<void> {
48
+ static async addAllToShellRc(lines: string[]): Promise<void> {
49
49
  const formattedLines = '\n' + lines.join('\n') + '\n';
50
50
  const shellRc = Utils.getPrimaryShellRc();
51
51
 
@@ -55,7 +55,11 @@ ${lines.join('\n')}`)
55
55
  await fs.appendFile(shellRc, formattedLines)
56
56
  }
57
57
 
58
- static async addPathToPrimaryShellRc(value: string, prepend: boolean): Promise<void> {
58
+ static async addPathToShellRc(value: string, prepend: boolean): Promise<void> {
59
+ if (!(await Utils.isDirectoryOnPath(value))) {
60
+ return;
61
+ }
62
+
59
63
  const shellRc = Utils.getPrimaryShellRc();
60
64
  console.log(`Saving path: ${value} to ${shellRc}`);
61
65
 
@@ -124,7 +128,6 @@ ${lines.join('\n')}`)
124
128
  await fs.writeFile(filePath, newContents, 'utf8');
125
129
  }
126
130
 
127
-
128
131
  static async removeLineFromFile(filePath: string, search: RegExp | string): Promise<void> {
129
132
  const file = await fs.readFile(filePath, 'utf8')
130
133
  const lines = file.split('\n');
@@ -1,6 +1,7 @@
1
1
  import { OS } from 'codify-schemas';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
+ import { getPty } from '../pty/index.js';
4
5
 
5
6
  export function isDebug(): boolean {
6
7
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
@@ -138,6 +139,13 @@ export const Utils = {
138
139
  path.join(homeDir, '.profile'),
139
140
  ];
140
141
  },
142
+
143
+ async isDirectoryOnPath(directory: string): Promise<boolean> {
144
+ const $ = getPty();
145
+ const { data: pathQuery } = await $.spawn('echo $PATH', { interactive: true });
146
+ const lines = pathQuery.split(':');
147
+ return lines.includes(directory);
148
+ },
141
149
  };
142
150
 
143
151