@benshawmean/envedit 1.2.2 → 1.3.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.
@@ -0,0 +1,10 @@
1
+ import type { CommandModule as YargModule } from 'yargs';
2
+ import type { Logger } from '#lib/logger';
3
+
4
+ type Argv = {
5
+ level: string;
6
+ }
7
+
8
+ declare global {
9
+ export type CommandModule = YargModule<Argv, Argv>;
10
+ }
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # envedit
1
+ # ![EnvEdit Icon](https://cdn.benshawmean.com/icons/envedit-icon.png){width=32} envedit
2
2
 
3
3
  `envedit` is a simple CLI application used to manage environments.
4
4
  It allows you to create, edit, and delete custom environments, as well as
@@ -1,21 +1,10 @@
1
- import type { CommandModule } from "yargs";
1
+ import Commands from "./environmentCmd";
2
2
 
3
- import Add from "./environment/add";
4
- import Edit from "./environment/edit";
5
- import List from "./environment/list";
6
- import Remove from "./environment/remove";
7
-
8
- const data = {
3
+ export default {
9
4
  command: 'environment',
10
5
  describe: 'Manage environments',
11
6
  builder: (yargs) => yargs
12
7
  .usage('Usage: envedit environment <command> [options]')
13
- .command([Add, Edit, List, Remove])
8
+ .command(Commands)
14
9
  .demandCommand(),
15
- handler: async (_args) => {}
16
- } satisfies CommandModule;
17
-
18
- export const command = data.command;
19
- export const describe = data.describe;
20
- export const builder = data.builder;
21
- export const handler = data.handler;
10
+ } as CommandModule;
@@ -1,18 +1,18 @@
1
1
  import fs from "node:fs";
2
2
 
3
3
  import { confirm, input, password, select } from "@inquirer/prompts";
4
- import type { CommandModule } from "yargs";
5
4
 
6
5
  import { Configuration, EnvironmentFile, VariableType } from "#lib/config";
7
6
  import { NotFoundError } from "#lib/error";
8
- import { logger } from "#lib/logger";
7
+ import { Logger } from "#lib/logger";
9
8
 
10
9
  export default {
11
10
  command: 'add',
12
11
  describe: 'Add a new environment',
13
12
  builder: (yargs) => yargs,
14
- handler: async (_args) => {
15
- const config = new Configuration().loadConfigurationFile();
13
+ handler: async (argv) => {
14
+ const config = new Configuration().load();
15
+ const logger = new Logger(argv.level);
16
16
 
17
17
  const name = await input({
18
18
  message: "Enter the environment name:",
@@ -45,7 +45,7 @@ export default {
45
45
 
46
46
  config
47
47
  .addEnvironment({ name, prefix, file, isActive })
48
- .saveConfigurationFile();
48
+ .save();
49
49
 
50
50
  const envFile = new EnvironmentFile(file).load();
51
51
 
@@ -1,18 +1,18 @@
1
1
  import fs from "node:fs";
2
2
 
3
3
  import { confirm, input, select, checkbox } from "@inquirer/prompts";
4
- import type { CommandModule } from "yargs";
5
4
 
6
5
  import { Configuration } from "#lib/config";
7
6
  import { NotFoundError } from "#lib/error";
8
- import { logger } from "#lib/logger";
7
+ import { Logger } from "#lib/logger";
9
8
 
10
9
  export default {
11
10
  command: 'edit',
12
11
  describe: 'Edit an environment',
13
12
  builder: (yargs) => yargs,
14
- handler: async (_args) => {
15
- const config = new Configuration().loadConfigurationFile();
13
+ handler: async (argv) => {
14
+ const config = new Configuration().load();
15
+ const logger = new Logger(argv.level);
16
16
 
17
17
  const name = await select({
18
18
  message: "Select the environment to edit:",
@@ -65,7 +65,7 @@ export default {
65
65
 
66
66
  config
67
67
  .editEnvironment(name, updatedEnv)
68
- .saveConfigurationFile();
68
+ .save();
69
69
 
70
70
  if (itemsToEdit.includes("file") && fs.existsSync(selectedEnv.file)) {
71
71
  logger.debug(`Old environment file found: ${selectedEnv.file}`);
@@ -0,0 +1,6 @@
1
+ import Add from "./add";
2
+ import Edit from "./edit";
3
+ import List from "./list";
4
+ import Remove from "./remove";
5
+
6
+ export default [Add, Edit, List, Remove]
@@ -1,14 +1,13 @@
1
- import type { CommandModule } from "yargs";
2
-
3
1
  import { Configuration } from "#lib/config";
4
- import { logger } from "#lib/logger";
2
+ import { Logger } from "#lib/logger";
5
3
 
6
4
  export default {
7
5
  command: 'list',
8
6
  describe: 'List all environments',
9
7
  builder: (yargs) => yargs,
10
- handler: async (_args) => {
11
- const config = new Configuration().loadConfigurationFile();
8
+ handler: async (argv) => {
9
+ const config = new Configuration().load();
10
+ const logger = new Logger(argv.level);
12
11
 
13
12
  logger.debug(`Listing all environments`);
14
13
 
@@ -1,18 +1,18 @@
1
1
  import fs from "node:fs";
2
2
 
3
3
  import { confirm, select } from "@inquirer/prompts";
4
- import type { CommandModule } from "yargs";
5
4
 
6
5
  import { Configuration } from "#lib/config";
7
6
  import { NotFoundError } from "#lib/error";
8
- import { logger } from "#lib/logger";
7
+ import { Logger } from "#lib/logger";
9
8
 
10
9
  export default {
11
10
  command: 'remove',
12
11
  describe: 'Remove an environment',
13
12
  builder: (yargs) => yargs,
14
- handler: async (_args) => {
15
- const config = new Configuration().loadConfigurationFile();
13
+ handler: async (argv) => {
14
+ const config = new Configuration().load();
15
+ const logger = new Logger(argv.level);
16
16
 
17
17
  const name = await select({
18
18
  message: "Select the environment to remove:",
@@ -28,12 +28,11 @@ export default {
28
28
  throw new NotFoundError(`Environment not found: ${name}`);
29
29
  }
30
30
 
31
- logger
32
- .debug(`Removing environment "${name}" with file: "${selectedEnv.file}"`);
31
+ logger.debug(`Removing environment "${name}" with file: "${selectedEnv.file}"`);
33
32
 
34
33
  config
35
34
  .removeEnvironment(name)
36
- .saveConfigurationFile();
35
+ .save();
37
36
 
38
37
  if (fs.existsSync(selectedEnv.file)) {
39
38
  const toDelete = await confirm({
@@ -41,8 +40,7 @@ export default {
41
40
  });
42
41
 
43
42
  if (toDelete) {
44
- logger
45
- .debug(`Deleting environment file: ${selectedEnv.file}`);
43
+ logger.debug(`Deleting environment file: ${selectedEnv.file}`);
46
44
  fs.unlinkSync(selectedEnv.file);
47
45
  }
48
46
  }
package/cmd/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import Environment from './environment';
2
+ import Variable from './variable';
3
+ import Use from './use';
4
+ import Setup from './setup';
5
+
6
+ export default [Environment, Variable, Use, Setup];
package/cmd/setup.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  import fs from "node:fs";
2
2
 
3
3
  import { confirm } from "@inquirer/prompts";
4
- import type { CommandModule } from "yargs";
5
4
 
6
5
  import { Configuration } from "#lib/config";
7
- import { logger } from "#lib/logger";
6
+ import { Logger } from "#lib/logger";
8
7
 
9
- const data = {
8
+ export default {
10
9
  command: 'setup',
11
10
  describe: 'Setup the project for use with envedit',
12
11
  builder: (yargs) => yargs
13
12
  .usage('Usage: envedit setup'),
14
- handler: async (_args) => {
15
- new Configuration().loadConfigurationFile();
13
+ handler: async (argv) => {
14
+ const logger = new Logger(argv.level);
15
+
16
+ new Configuration().load();
16
17
 
17
18
  if (fs.existsSync('.git')) {
18
19
  logger.debug(`Git repository found. Checking for git ignore file.`);
@@ -56,9 +57,4 @@ const data = {
56
57
  }
57
58
  }
58
59
  }
59
- } satisfies CommandModule;
60
-
61
- export const command = data.command;
62
- export const describe = data.describe;
63
- export const builder = data.builder;
64
- export const handler = data.handler;
60
+ } as CommandModule;
package/cmd/use.ts CHANGED
@@ -1,19 +1,20 @@
1
1
  import fs from "node:fs";
2
2
 
3
3
  import { select } from "@inquirer/prompts";
4
- import type { CommandModule } from "yargs";
5
4
 
6
5
  import { Configuration } from "#lib/config";
7
6
  import { NotFoundError } from "#lib/error";
8
- import { logger } from "#lib/logger";
7
+ import { Logger } from "#lib/logger";
9
8
 
10
- const data = {
9
+ export default {
11
10
  command: 'use',
12
11
  describe: 'Set the current environment to use',
13
12
  builder: (yargs) => yargs
14
13
  .usage('Usage: envedit use'),
15
- handler: async (_args) => {
16
- const config = new Configuration().loadConfigurationFile();
14
+ handler: async (argv) => {
15
+ const logger = new Logger(argv.level);
16
+
17
+ const config = new Configuration().load();
17
18
 
18
19
  const name = await select({
19
20
  message: "Select the environment to use",
@@ -39,7 +40,7 @@ const data = {
39
40
  env.isActive = env.name === name;
40
41
  }
41
42
 
42
- config.saveConfigurationFile();
43
+ config.save();
43
44
  }
44
45
 
45
46
  logger.debug(`Creating symlink to environment file: ${selectedEnv.file}`);
@@ -54,9 +55,4 @@ const data = {
54
55
 
55
56
  fs.symlinkSync(envFilePath, '.env', 'file');
56
57
  }
57
- } satisfies CommandModule;
58
-
59
- export const command = data.command;
60
- export const describe = data.describe;
61
- export const builder = data.builder;
62
- export const handler = data.handler;
58
+ } as CommandModule;
package/cmd/variable.ts CHANGED
@@ -1,21 +1,10 @@
1
- import type { CommandModule } from "yargs";
1
+ import Commands from "./variableCmd";
2
2
 
3
- import Add from "./variable/add";
4
- import Edit from "./variable/edit";
5
- import List from "./variable/list";
6
- import Remove from "./variable/remove";
7
-
8
- const data = {
3
+ export default {
9
4
  command: 'variable',
10
5
  describe: 'Manage environment variables',
11
6
  builder: (yargs) => yargs
12
7
  .usage('Usage: envedit variable <command> [options]')
13
- .command([Add, Edit, List, Remove])
8
+ .command(Commands)
14
9
  .demandCommand(),
15
- handler: async (_args) => {}
16
- } satisfies CommandModule;
17
-
18
- export const command = data.command;
19
- export const describe = data.describe;
20
- export const builder = data.builder;
21
- export const handler = data.handler;
10
+ } as CommandModule;
@@ -1,16 +1,16 @@
1
1
  import { confirm, input, password, select } from "@inquirer/prompts";
2
- import type { CommandModule } from "yargs";
3
2
 
4
3
  import { Configuration, EnvironmentFile, VariableType } from "#lib/config";
5
4
  import { NotFoundError } from "#lib/error";
6
- import { logger } from "#lib/logger";
5
+ import { Logger } from "#lib/logger";
7
6
 
8
7
  export default {
9
8
  command: 'add',
10
9
  describe: 'Add a new environment variable',
11
10
  builder: (yargs) => yargs,
12
- handler: async (_args) => {
13
- const config = new Configuration().loadConfigurationFile();
11
+ handler: async (argv) => {
12
+ const config = new Configuration().load();
13
+ const logger = new Logger(argv.level);
14
14
 
15
15
  const name = await input({
16
16
  message: "Enter the variable name:",
@@ -33,12 +33,11 @@ export default {
33
33
  ],
34
34
  });
35
35
 
36
- logger
37
- .debug(`Adding new variable "${name}" with type "${type}"`);
36
+ logger.debug(`Adding new variable "${name}" with type "${type}"`);
38
37
 
39
38
  config
40
39
  .addVariable({ name, type })
41
- .saveConfigurationFile();
40
+ .save();
42
41
 
43
42
  const shouldGloballySet = await confirm({
44
43
  message: "Do you want to set this variable with a global value for all environments?",
@@ -59,8 +58,7 @@ export default {
59
58
  ? await password(request)
60
59
  : await input(request);
61
60
 
62
- logger
63
- .debug(`Setting variable "${name}" with global value "${globalValue}" for all environments`);
61
+ logger.debug(`Setting variable "${name}" with global value "${globalValue}" for all environments`);
64
62
 
65
63
  valuesToSet.forEach((envValue) => { envValue.value = globalValue });
66
64
  } else {
@@ -74,15 +72,13 @@ export default {
74
72
  ? await password(request)
75
73
  : await input(request);
76
74
 
77
- logger
78
- .debug(`Setting variable "${name}" with value "${envValue.value}" for environment "${envValue.envName}"`);
75
+ logger.debug(`Setting variable "${name}" with value "${envValue.value}" for environment "${envValue.envName}"`);
79
76
  }
80
77
  }
81
78
 
82
79
  for (const envValue of valuesToSet) {
83
80
  const env = config.getEnvironment(envValue.envName);
84
- logger
85
- .debug(`Retrieving environment: ${envValue.envName}`);
81
+ logger.debug(`Retrieving environment: ${envValue.envName}`);
86
82
 
87
83
  if (!env) {
88
84
  throw new NotFoundError(`Environment not found: ${envValue.envName}`);
@@ -1,16 +1,16 @@
1
1
  import { confirm, input, password, select, checkbox } from "@inquirer/prompts";
2
- import type { CommandModule } from "yargs";
3
2
 
4
3
  import { Configuration, EnvironmentFile, VariableType } from "#lib/config";
5
4
  import { NotFoundError } from "#lib/error";
6
- import { logger } from "#lib/logger";
5
+ import { Logger } from "#lib/logger";
7
6
 
8
7
  export default {
9
8
  command: 'edit',
10
9
  describe: 'Edit an environment variable',
11
10
  builder: (yargs) => yargs,
12
- handler: async (_args) => {
13
- const config = new Configuration().loadConfigurationFile();
11
+ handler: async (argv) => {
12
+ const config = new Configuration().load();
13
+ const logger = new Logger(argv.level);
14
14
 
15
15
  const name = await select({
16
16
  message: "Select the variable to edit:",
@@ -35,8 +35,7 @@ export default {
35
35
  });
36
36
 
37
37
  if (isEditingConfig) {
38
- logger
39
- .debug(`Editing variable configuration for: ${name}`);
38
+ logger.debug(`Editing variable configuration for: ${name}`);
40
39
 
41
40
  const itemsToEdit = await checkbox({
42
41
  message: "Select the items to edit:",
@@ -57,8 +56,7 @@ export default {
57
56
  for (const env of config.configuration.environments) {
58
57
  const envFile = new EnvironmentFile(env.file).load();
59
58
 
60
- logger
61
- .debug(`Editing variable "${name}" in environment file: ${env.file}`);
59
+ logger.debug(`Editing variable "${name}" in environment file: ${env.file}`);
62
60
 
63
61
  if (envFile.content[name] !== undefined) {
64
62
  const value = envFile.content[name];
@@ -79,16 +77,14 @@ export default {
79
77
  default: variableConfiguration.type,
80
78
  });
81
79
 
82
- logger
83
- .debug(`Editing variable type for "${name}" to "${updatedVariable.type}"`);
80
+ logger.debug(`Editing variable type for "${name}" to "${updatedVariable.type}"`);
84
81
  }
85
82
 
86
83
  config
87
84
  .editVariable(name, updatedVariable)
88
- .saveConfigurationFile();
85
+ .save();
89
86
  } else {
90
- logger
91
- .debug(`Adding editing variable value for: ${name}`);
87
+ logger.debug(`Adding editing variable value for: ${name}`);
92
88
 
93
89
  let valuesToSet = config.configuration.environments.map(env => ({
94
90
  envName: env.name,
@@ -109,8 +105,7 @@ export default {
109
105
  ? await password(request)
110
106
  : await input(request);
111
107
 
112
- logger
113
- .debug(`Setting variable "${variableConfiguration.name}" with global value "${globalValue}" for all environments`);
108
+ logger.debug(`Setting variable "${variableConfiguration.name}" with global value "${globalValue}" for all environments`);
114
109
 
115
110
  valuesToSet.forEach((envValue) => { envValue.value = globalValue });
116
111
  } else {
@@ -122,8 +117,7 @@ export default {
122
117
  })),
123
118
  });
124
119
 
125
- logger
126
- .debug(`Selected environments for editing: ${envsToEdit.join(", ")}`);
120
+ logger.debug(`Selected environments for editing: ${envsToEdit.join(", ")}`);
127
121
 
128
122
  valuesToSet = valuesToSet.filter(envValue => envsToEdit.includes(envValue.envName));
129
123
 
@@ -151,8 +145,7 @@ export default {
151
145
  throw new NotFoundError(`Environment not found: ${envValue.envName}`);
152
146
  }
153
147
 
154
- logger
155
- .debug(`Setting variable "${variableConfiguration.name}" with value "${envValue.value}" in environment file: ${env.file}`);
148
+ logger.debug(`Setting variable "${variableConfiguration.name}" with value "${envValue.value}" in environment file: ${env.file}`);
156
149
 
157
150
  EnvironmentFile.quickUpdate(env.file, variableConfiguration.name, envValue.value);
158
151
  }
@@ -0,0 +1,6 @@
1
+ import Add from "./add";
2
+ import Edit from "./edit";
3
+ import List from "./list";
4
+ import Remove from "./remove";
5
+
6
+ export default [Add, Edit, List, Remove]
@@ -0,0 +1,35 @@
1
+ import { Configuration, EnvironmentFile, VariableType } from "#lib/config";
2
+ import { NotFoundError } from "#lib/error";
3
+ import { Logger } from "#lib/logger";
4
+
5
+ export default {
6
+ command: 'list',
7
+ describe: 'List all environment variables',
8
+ builder: (yargs) => yargs,
9
+ handler: async (argv) => {
10
+ const config = new Configuration().load();
11
+ const logger = new Logger(argv.level);
12
+
13
+ const activeEnv = config.getActiveEnvironment();
14
+
15
+ if (!activeEnv) {
16
+ throw new NotFoundError(`No active environment found. Please set an active environment using the "use" command.`);
17
+ }
18
+
19
+ const envFile = new EnvironmentFile(activeEnv.file).load();
20
+
21
+ for (const [key, value] of Object.entries(envFile.content)) {
22
+ const variableConfiguration = config.getVariable(key);
23
+ if (variableConfiguration) {
24
+ const type = Configuration.getTypeDetails(variableConfiguration.type);
25
+
26
+ const maskedValue = type.value === VariableType.Private ? value.replaceAll(/./gm, '*') : value;
27
+
28
+ logger
29
+ .info(`Name: ${key}`)
30
+ .info(`Value: ${maskedValue}`)
31
+ .info(`Type: ${type.name} (${type.value})`);
32
+ }
33
+ }
34
+ }
35
+ } satisfies CommandModule;
@@ -1,16 +1,16 @@
1
1
  import { select } from "@inquirer/prompts";
2
- import type { CommandModule } from "yargs";
3
2
 
4
3
  import { Configuration, EnvironmentFile } from "#lib/config";
5
4
  import { NotFoundError } from "#lib/error";
6
- import { logger } from "#lib/logger";
5
+ import { Logger } from "#lib/logger";
7
6
 
8
7
  export default {
9
8
  command: 'remove',
10
9
  describe: 'Remove an environment variable',
11
10
  builder: (yargs) => yargs,
12
- handler: async (_args) => {
13
- const config = new Configuration().loadConfigurationFile();
11
+ handler: async (argv) => {
12
+ const config = new Configuration().load();
13
+ const logger = new Logger(argv.level);
14
14
 
15
15
  const name = await select({
16
16
  message: "Select the variable to remove:",
@@ -24,19 +24,17 @@ export default {
24
24
  throw new NotFoundError(`Variable not found: ${name}`);
25
25
  }
26
26
 
27
- logger
28
- .debug(`Removing variable "${name}" from configuration and all environment files`);
27
+ logger.debug(`Removing variable "${name}" from configuration and all environment files`);
29
28
 
30
29
  config
31
30
  .removeVariable(name)
32
- .saveConfigurationFile();
31
+ .save();
33
32
 
34
33
  for (const env of config.configuration.environments) {
35
34
  const envFile = new EnvironmentFile(env.file).load();
36
35
 
37
36
  if (envFile.content[name] !== undefined) {
38
- logger
39
- .debug(`Removing variable "${name}" from environment file: ${env.file}`);
37
+ logger.debug(`Removing variable "${name}" from environment file: ${env.file}`);
40
38
  envFile.removeVariable(name).save();
41
39
  }
42
40
  }
package/index.ts CHANGED
@@ -2,24 +2,20 @@
2
2
  import yargs from "yargs";
3
3
  import { hideBin } from "yargs/helpers";
4
4
 
5
- import { logger } from "#lib/logger";
5
+ import Commands from "./cmd";
6
6
 
7
7
  await yargs(hideBin(process.argv))
8
+ .option("level", {
9
+ alias: "l",
10
+ type: "string",
11
+ description: "Set the log level",
12
+ choices: ['debug', 'info', 'warn', 'error', 'fatal'],
13
+ default: process.env.LOG_LEVEL || "info",
14
+ })
15
+ .env('ENVEDIT')
8
16
  .scriptName("envedit")
9
17
  .usage("Usage: $0 <command>")
10
- .commandDir(
11
- `${import.meta.dir}/cmd`,
12
- {
13
- extensions: ['ts'],
14
- visit: (commandObject, commandPath, filename) => {
15
- logger.debug(`Loading command: ${commandPath}`);
16
-
17
- logger.debug(`Command Name: ${commandObject.command}`);
18
- logger.debug(`Command Description: ${commandObject.describe}`);
19
-
20
- return commandObject;
21
- }
22
- },
23
- )
18
+ .command(Commands)
24
19
  .demandCommand()
20
+ .strict()
25
21
  .parseAsync();
package/lib/config.ts CHANGED
@@ -3,6 +3,9 @@ import fs from 'fs';
3
3
  import { parse } from 'dotenv';
4
4
 
5
5
  import { NotFoundError } from '#lib/error';
6
+ import { Logger } from '#lib/logger';
7
+
8
+ const logger = new Logger(process.env.LOG_LEVEL || 'info');
6
9
 
7
10
  export enum VariableType {
8
11
  Public,
@@ -50,10 +53,10 @@ export class Configuration {
50
53
  };
51
54
  }
52
55
 
53
- public loadConfigurationFile() {
56
+ public load() {
54
57
  if (!fs.existsSync(this.configFilePath)) {
55
- console.log(`Configuration file not found: ${this.configFilePath}`);
56
- console.log(`Creating a new configuration file`);
58
+ logger.info(`Configuration file not found: ${this.configFilePath}`);
59
+ logger.info(`Creating a new configuration file`);
57
60
 
58
61
  const config = new Configuration();
59
62
 
@@ -61,7 +64,7 @@ export class Configuration {
61
64
  config.importFromEnv(fs.readFileSync('.env', "utf-8"));
62
65
  }
63
66
 
64
- this.saveConfigurationFile();
67
+ this.save();
65
68
  }
66
69
 
67
70
  const configContent = Bun.YAML.parse(fs.readFileSync(this.configFilePath, "utf-8")) as GeneralConfiguration;
@@ -72,7 +75,7 @@ export class Configuration {
72
75
  return this;
73
76
  }
74
77
 
75
- public saveConfigurationFile() {
78
+ public save() {
76
79
  fs.writeFileSync(
77
80
  this.configFilePath,
78
81
  Bun.YAML.stringify(this.configuration, null, 2),
@@ -181,6 +184,20 @@ export class Configuration {
181
184
 
182
185
  return config;
183
186
  }
187
+
188
+ public static getTypeDetails(type: VariableType): { name: keyof typeof VariableType, value: VariableType } {
189
+ const VariableTypeMap = Object.entries(VariableType).reduce((acc, [key, value]) => {
190
+ if (typeof value === "number") {
191
+ acc[value] = key as keyof typeof VariableType;
192
+ }
193
+ return acc;
194
+ }, {} as Record<number, keyof typeof VariableType>);
195
+
196
+ return {
197
+ name: VariableTypeMap[type]!,
198
+ value: type
199
+ };
200
+ }
184
201
  }
185
202
 
186
203
  export class EnvironmentFile {
package/lib/logger.ts CHANGED
@@ -1,15 +1,40 @@
1
1
  import pino from 'pino';
2
+ import type { LevelWithSilentOrString, Logger as PinoLogger } from 'pino';
2
3
 
3
- const level = process.env.LOG_LEVEL || 'info';
4
+ export class Logger {
5
+ private readonly logger: PinoLogger<never, boolean>;
6
+ constructor(public readonly level: LevelWithSilentOrString) {
7
+ this.logger = pino({
8
+ level,
9
+ transport: {
10
+ target: 'pino-pretty',
11
+ options: {
12
+ colorize: true,
13
+ translateTime: 'SYS:standard',
14
+ ignore: 'pid,hostname',
15
+ },
16
+ },
17
+ });
18
+ }
4
19
 
5
- export const logger = pino({
6
- level,
7
- transport: {
8
- target: 'pino-pretty',
9
- options: {
10
- colorize: true,
11
- translateTime: 'SYS:standard',
12
- ignore: 'pid,hostname',
13
- },
14
- },
15
- });
20
+ public readonly debug = (msg: string) => {
21
+ this.logger.debug(msg);
22
+ return this;
23
+ }
24
+ public readonly info = (msg: string) => {
25
+ this.logger.info(msg);
26
+ return this;
27
+ }
28
+ public readonly warn = (msg: string) => {
29
+ this.logger.warn(msg);
30
+ return this;
31
+ }
32
+ public readonly error = (msg: string) => {
33
+ this.logger.error(msg);
34
+ return this;
35
+ }
36
+ public readonly fatal = (msg: string) => {
37
+ this.logger.fatal(msg);
38
+ return this;
39
+ }
40
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@benshawmean/envedit",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "1.2.2",
5
+ "version": "1.3.0",
6
6
  "license": "GPL-3.0-only",
7
7
  "bin": {
8
8
  "envedit": "index.ts"
package/tsconfig.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "moduleDetection": "force",
8
8
  "jsx": "react-jsx",
9
9
  "allowJs": true,
10
- "types": ["bun"],
10
+ "types": ["bun", "./@types/custom.d.ts"],
11
11
 
12
12
  // Bundler mode
13
13
  "moduleResolution": "bundler",
@@ -1,43 +0,0 @@
1
- import type { CommandModule } from "yargs";
2
-
3
- import { Configuration, EnvironmentFile, VariableType } from "#lib/config";
4
- import { NotFoundError } from "#lib/error";
5
- import { logger } from "#lib/logger";
6
-
7
- export default {
8
- command: 'list',
9
- describe: 'List all environment variables',
10
- builder: (yargs) => yargs,
11
- handler: async (_args) => {
12
- const config = new Configuration().loadConfigurationFile();
13
-
14
- const activeEnv = config.getActiveEnvironment();
15
-
16
- if (!activeEnv) {
17
- throw new NotFoundError(`No active environment found. Please set an active environment using the "use" command.`);
18
- }
19
-
20
- const envFile = new EnvironmentFile(activeEnv.file).load();
21
-
22
- const mappedVariables: Array<{ name: string; value: string; type: VariableType }> = [];
23
-
24
- for (const [key, value] of Object.entries(envFile.content)) {
25
- const variableConfiguration = config.getVariable(key);
26
- if (variableConfiguration) {
27
- logger.debug(`Mapping variable "${key}" with value "${value}" and type "${variableConfiguration.type}"`);
28
-
29
- const data = {
30
- name: key,
31
- value: variableConfiguration.type === VariableType.Private ? value.replaceAll(/./gm, '*') : value,
32
- type: variableConfiguration.type,
33
- };
34
-
35
- mappedVariables.push(data);
36
- }
37
- }
38
-
39
- console.log(
40
- JSON.stringify(mappedVariables, null, 2)
41
- )
42
- }
43
- } satisfies CommandModule;