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.
- package/dist/pty/background-pty.js +1 -1
- package/dist/utils/file-utils.d.ts +3 -3
- package/dist/utils/file-utils.js +6 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +7 -0
- package/package.json +1 -1
- package/src/pty/background-pty.ts +1 -1
- package/src/utils/file-utils.ts +7 -4
- package/src/utils/index.ts +8 -0
|
@@ -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
|
|
4
|
-
static
|
|
5
|
-
static
|
|
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>;
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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) {
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -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
|
@@ -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
|
}));
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -25,7 +25,7 @@ export class FileUtils {
|
|
|
25
25
|
console.log(`Finished downloading to ${destination}`);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
static async
|
|
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
|
|
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
|
|
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');
|
package/src/utils/index.ts
CHANGED
|
@@ -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
|
|