@agilecustoms/envctl 1.3.0 → 1.3.1
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/client/Cli.js +13 -0
- package/dist/client/EnvApiClient.js +3 -0
- package/dist/service/LogService.js +3 -11
- package/package.json +1 -1
package/dist/client/Cli.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import { mkdir } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { Readable } from 'node:stream';
|
|
7
|
+
import { pipeline } from 'node:stream/promises';
|
|
2
8
|
import path from 'path';
|
|
3
9
|
import * as readline from 'readline';
|
|
4
10
|
import inquirer from 'inquirer';
|
|
@@ -95,4 +101,11 @@ export class Cli {
|
|
|
95
101
|
getKind(cwd) {
|
|
96
102
|
return getDirName(cwd);
|
|
97
103
|
}
|
|
104
|
+
async writeInTmpFile(stream, fileName) {
|
|
105
|
+
const outDir = join(tmpdir(), 'envctl');
|
|
106
|
+
await mkdir(outDir, { recursive: true });
|
|
107
|
+
const outPath = join(outDir, fileName);
|
|
108
|
+
await pipeline(Readable.fromWeb(stream), createWriteStream(outPath, { flags: 'w' }));
|
|
109
|
+
return outPath;
|
|
110
|
+
}
|
|
98
111
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { mkdir } from 'node:fs/promises';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { basename, join } from 'node:path';
|
|
5
|
-
import { Readable } from 'node:stream';
|
|
6
|
-
import { pipeline } from 'node:stream/promises';
|
|
1
|
+
import { basename } from 'node:path';
|
|
7
2
|
import { TerraformAdapter } from '../client/index.js';
|
|
8
3
|
import { KnownException } from '../exceptions.js';
|
|
9
4
|
import { BaseService } from './BaseService.js';
|
|
@@ -32,15 +27,12 @@ export class LogService extends BaseService {
|
|
|
32
27
|
}).formatToParts(timestamp);
|
|
33
28
|
const get = (type) => parts.find(p => p.type === type)?.value ?? '';
|
|
34
29
|
const outName = `${get('year')}-${get('month')}-${get('day')}_${get('hour')}.${get('minute')}.${get('second')}.log`;
|
|
35
|
-
const
|
|
36
|
-
await mkdir(outDir, { recursive: true });
|
|
37
|
-
const outPath = join(outDir, outName);
|
|
38
|
-
const res = await fetch(url);
|
|
30
|
+
const res = await this.envApi.fetch(url);
|
|
39
31
|
if (!res.ok) {
|
|
40
32
|
const msg = await res.text();
|
|
41
33
|
throw new KnownException(`Failed to download logs: ${res.status} ${res.statusText}${msg ? ` - ${msg}` : ''}`);
|
|
42
34
|
}
|
|
43
|
-
await
|
|
35
|
+
const outPath = await this.cli.writeInTmpFile(res.body, outName);
|
|
44
36
|
console.log(`Logs saved to: ${outPath}`);
|
|
45
37
|
await this.cli.run('open', ['-R', outPath]);
|
|
46
38
|
}
|