hereya-cli 0.20.0 → 0.22.0

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.
@@ -5,14 +5,19 @@ import { getBackend } from '../../backend/index.js';
5
5
  import { getExecutor } from '../../executor/index.js';
6
6
  import { getConfigManager } from '../../lib/config/index.js';
7
7
  import { getEnvManager } from '../../lib/env/index.js';
8
+ import { getLogger, isDebug, setDebug } from '../../lib/log.js';
8
9
  import { getParameterManager } from '../../lib/parameter/index.js';
9
- import { delay, setDebug } from '../../lib/shell.js';
10
+ import { delay } from '../../lib/shell.js';
10
11
  export default class Undeploy extends Command {
11
12
  static description = 'Undeploy a hereya project by removing all resources.';
12
13
  static examples = ['<%= config.bin %> <%= command.id %>'];
13
14
  static flags = {
14
15
  chdir: Flags.string({
15
- description: 'directory to run command in',
16
+ description: `
17
+ Directory where the command will be executed.
18
+ If not specified, it defaults to the current working directory.
19
+ Alternatively, you can define the project root by setting the HEREYA_PROJECT_ROOT_DIR environment variable.
20
+ `,
16
21
  required: false,
17
22
  }),
18
23
  debug: Flags.boolean({
@@ -96,7 +101,10 @@ export default class Undeploy extends Command {
96
101
  skip: (ctx) => ctx.deployPackages.length === 0,
97
102
  async task(ctx, task) {
98
103
  return task.newListr(ctx.deployPackages.map((packageName) => ({
99
- async task() {
104
+ rendererOptions: {
105
+ persistentOutput: isDebug(),
106
+ },
107
+ async task(_, task) {
100
108
  const parameterManager = getParameterManager();
101
109
  const { parameters } = await parameterManager.getPackageParameters({
102
110
  package: packageName,
@@ -110,6 +118,7 @@ export default class Undeploy extends Command {
110
118
  const { executor } = executor$;
111
119
  const destroyOutput = await executor.destroy({
112
120
  isDeploying: true,
121
+ logger: getLogger(task),
113
122
  package: packageName,
114
123
  parameters,
115
124
  project: ctx.configOutput.config.project,
@@ -122,7 +131,7 @@ export default class Undeploy extends Command {
122
131
  }
123
132
  },
124
133
  title: `Destroying package ${packageName}`,
125
- })), { concurrent: false });
134
+ })), { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
126
135
  },
127
136
  title: 'Destroying deployment packages',
128
137
  },
@@ -130,7 +139,10 @@ export default class Undeploy extends Command {
130
139
  skip: (ctx) => !ctx.packages || ctx.packages.length === 0,
131
140
  async task(ctx, task) {
132
141
  return task.newListr(ctx.packages.map((packageName) => ({
133
- async task() {
142
+ rendererOptions: {
143
+ persistentOutput: isDebug(),
144
+ },
145
+ async task(_, task) {
134
146
  const parameterManager = getParameterManager();
135
147
  const { parameters } = await parameterManager.getPackageParameters({
136
148
  package: packageName,
@@ -144,6 +156,7 @@ export default class Undeploy extends Command {
144
156
  const { executor } = executor$;
145
157
  const destroyOutput = await executor.destroy({
146
158
  isDeploying: true,
159
+ logger: getLogger(task),
147
160
  package: packageName,
148
161
  parameters,
149
162
  project: ctx.configOutput.config.project,
@@ -159,7 +172,7 @@ export default class Undeploy extends Command {
159
172
  ctx.destroyed = output;
160
173
  },
161
174
  title: `Destroying ${packageName}`,
162
- })), { concurrent: true });
175
+ })), { concurrent: true, rendererOptions: { collapseSubtasks: !isDebug() } });
163
176
  },
164
177
  title: `Destroying packages`,
165
178
  },
@@ -194,7 +207,7 @@ export default class Undeploy extends Command {
194
207
  },
195
208
  title: 'Saving state',
196
209
  },
197
- ], { concurrent: false });
210
+ ], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
198
211
  },
199
212
  },
200
213
  ]);
@@ -4,14 +4,19 @@ import { getBackend } from '../../backend/index.js';
4
4
  import { getExecutor } from '../../executor/index.js';
5
5
  import { getConfigManager } from '../../lib/config/index.js';
6
6
  import { getEnvManager } from '../../lib/env/index.js';
7
+ import { getLogger, isDebug, setDebug } from '../../lib/log.js';
7
8
  import { getParameterManager } from '../../lib/parameter/index.js';
8
- import { delay, setDebug } from '../../lib/shell.js';
9
+ import { delay } from '../../lib/shell.js';
9
10
  export default class Up extends Command {
10
11
  static description = 'Provision all packages in the project.';
11
12
  static examples = ['<%= config.bin %> <%= command.id %>'];
12
13
  static flags = {
13
14
  chdir: Flags.string({
14
- description: 'directory to run command in',
15
+ description: `
16
+ Directory where the command will be executed.
17
+ If not specified, it defaults to the current working directory.
18
+ Alternatively, you can define the project root by setting the HEREYA_PROJECT_ROOT_DIR environment variable.
19
+ `,
15
20
  required: false,
16
21
  }),
17
22
  debug: Flags.boolean({
@@ -83,7 +88,10 @@ export default class Up extends Command {
83
88
  return;
84
89
  }
85
90
  return task.newListr(removedPackages.map((packageName) => ({
86
- async task() {
91
+ rendererOptions: {
92
+ persistentOutput: isDebug(),
93
+ },
94
+ async task(_, task) {
87
95
  const parameterManager = getParameterManager();
88
96
  const { parameters } = await parameterManager.getPackageParameters({
89
97
  package: packageName,
@@ -97,6 +105,7 @@ export default class Up extends Command {
97
105
  const { executor } = executor$;
98
106
  const destroyOutput = await executor.destroy({
99
107
  isDeploying: flags.deploy,
108
+ logger: getLogger(task),
100
109
  package: packageName,
101
110
  parameters,
102
111
  project: configOutput.config.project,
@@ -112,7 +121,7 @@ export default class Up extends Command {
112
121
  ctx.removed = output;
113
122
  },
114
123
  title: `Destroying ${packageName}`,
115
- })), { concurrent: true });
124
+ })), { concurrent: true, rendererOptions: { collapseSubtasks: !isDebug() } });
116
125
  },
117
126
  title: `Destroying removed packages`,
118
127
  },
@@ -123,7 +132,10 @@ export default class Up extends Command {
123
132
  return;
124
133
  }
125
134
  return task.newListr(ctx.packages.map((packageName) => ({
126
- async task() {
135
+ rendererOptions: {
136
+ persistentOutput: isDebug(),
137
+ },
138
+ async task(_, task) {
127
139
  const parameterManager = getParameterManager();
128
140
  const { parameters } = await parameterManager.getPackageParameters({
129
141
  package: packageName,
@@ -137,6 +149,7 @@ export default class Up extends Command {
137
149
  const { executor } = executor$;
138
150
  const provisionOutput = await executor.provision({
139
151
  isDeploying: flags.deploy,
152
+ logger: getLogger(task),
140
153
  package: packageName,
141
154
  parameters,
142
155
  project: ctx.configOutput.config.project,
@@ -152,7 +165,7 @@ export default class Up extends Command {
152
165
  ctx.added = output;
153
166
  },
154
167
  title: `Provisioning ${packageName}`,
155
- })), { concurrent: true });
168
+ })), { concurrent: true, rendererOptions: { collapseSubtasks: !isDebug() } });
156
169
  },
157
170
  title: `Provisioning packages`,
158
171
  },
@@ -207,7 +220,7 @@ export default class Up extends Command {
207
220
  },
208
221
  title: 'Saving state',
209
222
  },
210
- ], { concurrent: false });
223
+ ], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
211
224
  },
212
225
  title: 'Waking up the project',
213
226
  },
@@ -2,8 +2,9 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import { Listr, ListrLogger, ListrLogLevels } from 'listr2';
3
3
  import { getBackend } from '../../../backend/index.js';
4
4
  import { getExecutor } from '../../../executor/index.js';
5
+ import { getLogger, isDebug, setDebug } from '../../../lib/log.js';
5
6
  import { arrayOfStringToObject } from '../../../lib/object-utils.js';
6
- import { delay, setDebug } from '../../../lib/shell.js';
7
+ import { delay } from '../../../lib/shell.js';
7
8
  import { load } from '../../../lib/yaml-utils.js';
8
9
  export default class WorkspaceInstall extends Command {
9
10
  static args = {
@@ -73,13 +74,17 @@ export default class WorkspaceInstall extends Command {
73
74
  title: 'Resolving parameters',
74
75
  },
75
76
  {
76
- async task(ctx) {
77
+ rendererOptions: {
78
+ persistentOutput: isDebug(),
79
+ },
80
+ async task(ctx, task) {
77
81
  const executor$ = getExecutor();
78
82
  if (!executor$.success) {
79
83
  throw new Error(executor$.reason);
80
84
  }
81
85
  const { executor } = executor$;
82
86
  const provisionOutput = await executor.provision({
87
+ logger: getLogger(task),
83
88
  package: args.package,
84
89
  parameters: ctx.parameters,
85
90
  workspace: flags.workspace,
@@ -112,7 +117,7 @@ export default class WorkspaceInstall extends Command {
112
117
  },
113
118
  title: `Installing ${args.package} into workspace ${flags.workspace}`,
114
119
  },
115
- ], { concurrent: false });
120
+ ], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
116
121
  try {
117
122
  await task.run();
118
123
  myLogger.log(ListrLogLevels.COMPLETED, `Package ${args.package} installed successfully into workspace ${flags.workspace}`);
@@ -2,8 +2,9 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import { Listr, ListrLogger, ListrLogLevels } from 'listr2';
3
3
  import { getBackend } from '../../../backend/index.js';
4
4
  import { getExecutor } from '../../../executor/index.js';
5
+ import { getLogger, isDebug, setDebug } from '../../../lib/log.js';
5
6
  import { arrayOfStringToObject } from '../../../lib/object-utils.js';
6
- import { delay, setDebug } from '../../../lib/shell.js';
7
+ import { delay } from '../../../lib/shell.js';
7
8
  import { load } from '../../../lib/yaml-utils.js';
8
9
  export default class WorkspaceUninstall extends Command {
9
10
  static args = {
@@ -80,13 +81,17 @@ export default class WorkspaceUninstall extends Command {
80
81
  title: 'Resolving parameters',
81
82
  },
82
83
  {
83
- async task(ctx) {
84
+ rendererOptions: {
85
+ persistentOutput: isDebug(),
86
+ },
87
+ async task(ctx, task) {
84
88
  const executor$ = getExecutor();
85
89
  if (!executor$.success) {
86
90
  throw new Error(executor$.reason);
87
91
  }
88
92
  const { executor } = executor$;
89
93
  const destroyOutput = await executor.destroy({
94
+ logger: getLogger(task),
90
95
  package: args.package,
91
96
  parameters: ctx.parameters,
92
97
  workspace: flags.workspace,
@@ -118,7 +123,7 @@ export default class WorkspaceUninstall extends Command {
118
123
  },
119
124
  title: `Uninstalling package ${args.package} from workspace ${flags.workspace}`,
120
125
  },
121
- ]);
126
+ ], { concurrent: false, rendererOptions: { collapseSubtasks: !isDebug() } });
122
127
  try {
123
128
  await task.run();
124
129
  myLogger.log(ListrLogLevels.COMPLETED, `Package ${args.package} uninstalled successfully from workspace ${flags.workspace}`);
@@ -1,6 +1,8 @@
1
+ import { Logger } from '../lib/log.js';
1
2
  import { IPackageMetadata } from '../lib/package/index.js';
2
3
  export type ExecutorProvisionInput = {
3
4
  isDeploying?: boolean;
5
+ logger?: Logger;
4
6
  package: string;
5
7
  parameters?: {
6
8
  [key: string]: string;
@@ -12,6 +12,7 @@ export class LocalExecutor {
12
12
  return destroyPackage({
13
13
  ...input,
14
14
  env: getWorkspaceEnvOutput.env,
15
+ logger: input.logger,
15
16
  });
16
17
  }
17
18
  async provision(input) {
@@ -25,6 +26,7 @@ export class LocalExecutor {
25
26
  return provisionPackage({
26
27
  ...input,
27
28
  env: getWorkspaceEnvOutput.env,
29
+ logger: input.logger,
28
30
  });
29
31
  }
30
32
  async resolveEnvValues(input) {
package/dist/iac/cdk.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CloudFormationClient, DescribeStacksCommand } from '@aws-sdk/client-cloudformation';
2
- import { writeFileSync } from 'node:fs';
2
+ import { writeFile } from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import { runShell } from '../lib/shell.js';
5
5
  import { load } from '../lib/yaml-utils.js';
@@ -15,6 +15,7 @@ export class Cdk {
15
15
  ...remainingEnv,
16
16
  STACK_NAME: input.id
17
17
  },
18
+ logger: input.logger,
18
19
  });
19
20
  const env = await this.getEnv(input.id);
20
21
  return { env, success: true };
@@ -34,7 +35,8 @@ export class Cdk {
34
35
  env: {
35
36
  ...remainingEnv,
36
37
  STACK_NAME: input.id
37
- }
38
+ },
39
+ logger: input.logger,
38
40
  });
39
41
  return { env, success: true };
40
42
  }
@@ -58,16 +60,18 @@ export class Cdk {
58
60
  ], {
59
61
  directory: workDir,
60
62
  env: { ...input.env, ...input.parameters },
63
+ logger: input.logger,
61
64
  });
62
65
  const result = await runShell('npx', [
63
66
  'aws-cdk', 'synth',
64
67
  ], {
65
68
  directory: workDir,
66
69
  env: { ...input.env, ...input.parameters },
70
+ logger: input.logger,
67
71
  stdio: 'pipe',
68
72
  });
69
73
  const stackYamlPath = path.join(workDir, '.stack.yaml');
70
- writeFileSync(stackYamlPath, result.stdout);
74
+ await writeFile(stackYamlPath, result.stdout, { encoding: 'utf8' });
71
75
  const { data: synthedStack } = await load(stackYamlPath);
72
76
  return Object.keys(synthedStack.Parameters);
73
77
  }
@@ -1,3 +1,4 @@
1
+ import { Logger } from '../lib/log.js';
1
2
  export interface Iac {
2
3
  apply(input: ApplyInput): Promise<ApplyOutput>;
3
4
  destroy(input: DestroyInput): Promise<DestroyOutput>;
@@ -19,6 +20,7 @@ export type ApplyInput = {
19
20
  terraformStateBucketRegion?: string;
20
21
  terraformStateLockTableName: string;
21
22
  };
23
+ logger?: Logger;
22
24
  parameters?: {
23
25
  [key: string]: string;
24
26
  };
@@ -1,8 +1,9 @@
1
+ import { Logger } from '../lib/log.js';
1
2
  import { ApplyInput, ApplyOutput, DestroyInput, DestroyOutput, Iac } from './common.js';
2
3
  export declare class Terraform implements Iac {
3
4
  apply(input: ApplyInput): Promise<ApplyOutput>;
4
5
  destroy(input: DestroyInput): Promise<DestroyOutput>;
5
- downloadTerraform(): Promise<boolean>;
6
+ downloadTerraform(logger?: Logger): Promise<boolean>;
6
7
  private getEnv;
7
8
  private getTerraformBinary;
8
9
  private getWithRedirect;
@@ -26,7 +26,7 @@ export class Terraform {
26
26
  await fs.promises.writeFile(backendFile, backendConfig);
27
27
  }
28
28
  try {
29
- const terraform = await this.getTerraformBinary();
29
+ const terraform = await this.getTerraformBinary(input.logger);
30
30
  await runShell(terraform, ['init'], {
31
31
  directory: input.pkgPath,
32
32
  env: {
@@ -40,6 +40,7 @@ export class Terraform {
40
40
  typeof value === 'object' ? JSON.stringify(value) : value,
41
41
  ]),
42
42
  },
43
+ logger: input.logger,
43
44
  });
44
45
  await runShell(terraform, ['apply', '-auto-approve'], {
45
46
  directory: input.pkgPath,
@@ -54,6 +55,7 @@ export class Terraform {
54
55
  typeof value === 'object' ? JSON.stringify(value) : value,
55
56
  ]),
56
57
  },
58
+ logger: input.logger,
57
59
  });
58
60
  const env = await this.getEnv(input.pkgPath);
59
61
  return {
@@ -69,7 +71,7 @@ export class Terraform {
69
71
  }
70
72
  }
71
73
  async destroy(input) {
72
- const terraform = await this.getTerraformBinary();
74
+ const terraform = await this.getTerraformBinary(input.logger);
73
75
  try {
74
76
  await runShell(terraform, ['init'], {
75
77
  directory: input.pkgPath,
@@ -84,6 +86,7 @@ export class Terraform {
84
86
  typeof value === 'object' ? JSON.stringify(value) : value,
85
87
  ]),
86
88
  },
89
+ logger: input.logger,
87
90
  });
88
91
  const env = await this.getEnv(input.pkgPath);
89
92
  await runShell(terraform, ['destroy', '-auto-approve'], {
@@ -99,6 +102,7 @@ export class Terraform {
99
102
  typeof value === 'object' ? JSON.stringify(value) : value,
100
103
  ]),
101
104
  },
105
+ logger: input.logger,
102
106
  });
103
107
  return {
104
108
  env,
@@ -112,7 +116,11 @@ export class Terraform {
112
116
  };
113
117
  }
114
118
  }
115
- async downloadTerraform() {
119
+ async downloadTerraform(logger) {
120
+ if (process.env.HEREYA_SKIP_TERRAFORM_DOWNLOAD === 'true') {
121
+ logger?.info('Skipping terraform download');
122
+ return false;
123
+ }
116
124
  const TERRAFORM_DOWNLOAD_URLS = new Map([
117
125
  ['darwin_arm64', 'https://github.com/opentofu/opentofu/releases/download/v1.9.0/tofu_1.9.0_darwin_arm64.zip'],
118
126
  ['darwin_x64', 'https://github.com/opentofu/opentofu/releases/download/v1.9.0/tofu_1.9.0_darwin_amd64.zip'],
@@ -140,7 +148,7 @@ export class Terraform {
140
148
  await fs.promises.rm(tfPath);
141
149
  }
142
150
  }
143
- console.log('Downloading terraform...');
151
+ logger?.info('Downloading terraform...');
144
152
  const binKey = `${os.platform()}_${os.arch()}`;
145
153
  const url = TERRAFORM_DOWNLOAD_URLS.get(binKey);
146
154
  if (!url) {
@@ -168,8 +176,8 @@ export class Terraform {
168
176
  });
169
177
  return true;
170
178
  }
171
- async getEnv(pkgPath) {
172
- const terraform = await this.getTerraformBinary();
179
+ async getEnv(pkgPath, logger) {
180
+ const terraform = await this.getTerraformBinary(logger);
173
181
  const resourceOut = await runShell(terraform, ['output', '--json'], {
174
182
  directory: pkgPath,
175
183
  stdio: 'pipe',
@@ -186,8 +194,8 @@ export class Terraform {
186
194
  }
187
195
  return tfEnv;
188
196
  }
189
- async getTerraformBinary() {
190
- await this.downloadTerraform();
197
+ async getTerraformBinary(logger) {
198
+ await this.downloadTerraform(logger);
191
199
  return this.terraformBinPath();
192
200
  }
193
201
  async getWithRedirect(url, handler, reject) {
@@ -206,6 +214,9 @@ export class Terraform {
206
214
  .on('error', (error) => reject(error));
207
215
  }
208
216
  terraformBinPath() {
217
+ if (process.env.HEREYA_TERRAFORM_BIN_PATH) {
218
+ return process.env.HEREYA_TERRAFORM_BIN_PATH;
219
+ }
209
220
  return path.join(os.homedir(), '.hereya', 'iac', 'terraform', 'tofu_1', os.platform() === 'win32' ? 'tofu.exe' : 'tofu');
210
221
  }
211
222
  }
@@ -63,6 +63,7 @@ export class AwsInfrastructure {
63
63
  env: input.env ?? {},
64
64
  id: input.id,
65
65
  infraConfig,
66
+ logger: input.logger,
66
67
  parameters: input.parameters,
67
68
  pkgPath: downloadPath,
68
69
  });
@@ -97,6 +98,7 @@ export class AwsInfrastructure {
97
98
  env: input.env ?? {},
98
99
  id: input.id,
99
100
  infraConfig,
101
+ logger: input.logger,
100
102
  parameters: input.parameters,
101
103
  pkgPath: downloadPath,
102
104
  });
@@ -1,4 +1,5 @@
1
1
  import { IacType } from '../iac/common.js';
2
+ import { Logger } from '../lib/log.js';
2
3
  export declare enum InfrastructureType {
3
4
  aws = "aws",
4
5
  azure = "azure",
@@ -27,6 +28,7 @@ export type ProvisionInput = {
27
28
  };
28
29
  iacType: IacType;
29
30
  id: string;
31
+ logger?: Logger;
30
32
  parameters?: {
31
33
  [key: string]: string;
32
34
  };
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { Logger } from '../lib/log.js';
2
3
  import { PackageMetadata } from '../lib/package/index.js';
3
4
  import { AwsInfrastructure } from './aws.js';
4
5
  import { Infrastructure, InfrastructureType } from './common.js';
@@ -15,6 +16,7 @@ export type ProvisionPackageInput = {
15
16
  [key: string]: string;
16
17
  };
17
18
  isDeploying?: boolean;
19
+ logger?: Logger;
18
20
  package: string;
19
21
  parameters?: {
20
22
  [key: string]: string;
@@ -57,6 +57,7 @@ export async function destroyPackage(input) {
57
57
  env: input.env,
58
58
  iacType: metadata.iac,
59
59
  id,
60
+ logger: input.logger,
60
61
  parameters: input.parameters,
61
62
  pkgName,
62
63
  pkgUrl: packageUri,
@@ -68,6 +69,7 @@ export async function destroyPackage(input) {
68
69
  env: input.env,
69
70
  iacType: metadata.iac,
70
71
  id,
72
+ logger: input.logger,
71
73
  parameters: input.parameters,
72
74
  pkgName,
73
75
  pkgUrl: packageUri,
@@ -142,6 +144,7 @@ export async function provisionPackage(input) {
142
144
  env: { ...input.env, ...depsEnv },
143
145
  iacType: metadata.iac,
144
146
  id,
147
+ logger: input.logger,
145
148
  parameters: input.parameters,
146
149
  pkgName,
147
150
  pkgUrl: packageUri,
@@ -153,6 +156,7 @@ export async function provisionPackage(input) {
153
156
  env: input.env,
154
157
  iacType: metadata.iac,
155
158
  id,
159
+ logger: input.logger,
156
160
  parameters: input.parameters,
157
161
  pkgName,
158
162
  pkgUrl: packageUri,
@@ -27,6 +27,7 @@ export class LocalInfrastructure {
27
27
  const output = await iac.destroy({
28
28
  env: input.env ?? {},
29
29
  id: input.id,
30
+ logger: input.logger,
30
31
  parameters: input.parameters,
31
32
  pkgPath: downloadPath,
32
33
  });
@@ -49,6 +50,7 @@ export class LocalInfrastructure {
49
50
  const output = await iac.apply({
50
51
  env: input.env ?? {},
51
52
  id: input.id,
53
+ logger: input.logger,
52
54
  parameters: input.parameters,
53
55
  pkgPath: downloadPath,
54
56
  });
package/dist/lib/log.d.ts CHANGED
@@ -1,4 +1,18 @@
1
- export declare function getLogger(): {
2
- done(message: string): void;
3
- log(message: string): void;
1
+ import { ListrTaskWrapper } from 'listr2';
2
+ export declare function setDebug(value: boolean): void;
3
+ export declare function isDebug(): boolean;
4
+ export declare function getLogger(task: ListrTaskWrapper<any, any, any>): {
5
+ debug(message: string): void;
6
+ error(message: string): void;
7
+ info(message: string): void;
4
8
  };
9
+ export declare function getDefaultLogger(): {
10
+ debug(message: string): void;
11
+ error(message: string): void;
12
+ info(message: string): void;
13
+ };
14
+ export interface Logger {
15
+ debug(message: string): void;
16
+ error(message: string): void;
17
+ info(message: string): void;
18
+ }
package/dist/lib/log.js CHANGED
@@ -1,13 +1,63 @@
1
- import { ListrLogger, ListrLogLevels } from 'listr2';
2
- const myLogger = new ListrLogger({ useIcons: false });
3
- const logger = {
4
- done(message) {
5
- myLogger.log(ListrLogLevels.COMPLETED, message);
6
- },
7
- log(message) {
8
- myLogger.log(ListrLogLevels.OUTPUT, message);
9
- },
10
- };
11
- export function getLogger() {
12
- return logger;
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { stripVTControlCharacters } from 'node:util';
4
+ let debug = false;
5
+ export function setDebug(value) {
6
+ debug = value;
7
+ }
8
+ export function isDebug() {
9
+ return debug;
10
+ }
11
+ const logPath = path.resolve(process.cwd(), 'hereya-debug.log');
12
+ export function getLogger(task) {
13
+ let logFile;
14
+ if (isDebug()) {
15
+ logFile = fs.createWriteStream(logPath, { encoding: 'utf8', flags: 'a' });
16
+ }
17
+ return {
18
+ debug(message) {
19
+ if (isDebug()) {
20
+ task.output = message;
21
+ logFile.write(stripVTControlCharacters(message), 'utf8');
22
+ }
23
+ },
24
+ error(message) {
25
+ task.output = message;
26
+ if (isDebug()) {
27
+ logFile.write(stripVTControlCharacters(message), 'utf8');
28
+ }
29
+ },
30
+ info(message) {
31
+ task.output = message;
32
+ if (isDebug()) {
33
+ logFile.write(stripVTControlCharacters(message), 'utf8');
34
+ }
35
+ },
36
+ };
37
+ }
38
+ export function getDefaultLogger() {
39
+ let logFile;
40
+ if (isDebug()) {
41
+ logFile = fs.createWriteStream(logPath, { encoding: 'utf8', flags: 'a' });
42
+ }
43
+ return {
44
+ debug(message) {
45
+ if (isDebug()) {
46
+ console.debug(message);
47
+ logFile.write(stripVTControlCharacters(message), 'utf8');
48
+ }
49
+ },
50
+ error(message) {
51
+ if (isDebug()) {
52
+ console.error(message);
53
+ logFile.write(stripVTControlCharacters(message), 'utf8');
54
+ }
55
+ },
56
+ info(message) {
57
+ if (isDebug()) {
58
+ console.info(message);
59
+ logFile.write(stripVTControlCharacters(message), 'utf8');
60
+ }
61
+ },
62
+ };
13
63
  }