@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.
@@ -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
  }
@@ -6,6 +6,9 @@ export class EnvApiClient {
6
6
  constructor(httpClient) {
7
7
  this.httpClient = httpClient;
8
8
  }
9
+ async fetch(url) {
10
+ return await fetch(url);
11
+ }
9
12
  async get(key) {
10
13
  try {
11
14
  return await this.httpClient.fetch(`/ci/env/${key}`);
@@ -1,9 +1,4 @@
1
- import { createWriteStream } from 'node:fs';
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 outDir = join(tmpdir(), 'envctl');
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 pipeline(Readable.fromWeb(res.body), createWriteStream(outPath, { flags: 'w' }));
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
3
  "description": "node.js CLI client for manage environments",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "engines": {