@benshawmean/envedit 1.2.1 → 1.2.3

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/.gitlab-ci.yml CHANGED
@@ -1,13 +1,11 @@
1
1
  stages:
2
2
  - test
3
- - deploy
3
+ - publish
4
4
 
5
5
  workflow:
6
6
  rules:
7
7
  - if: $CI_COMMIT_BRANCH
8
8
  - if: $CI_COMMIT_TAG
9
- - if: $CI_COMMIT_DESCRIPTION =~ /(no|skip)\s+(ci|pipeline)/mi
10
- when: never
11
9
 
12
10
  default:
13
11
  image: oven/bun:debian
@@ -21,25 +19,27 @@ default:
21
19
  variables:
22
20
  GLAB_NPM_REG: ${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/
23
21
  VERSION_REGEX: /^v\d+\.\d+\.\d+(-\S*)?$/
24
- NO_CI_REGEX: /(no|skip)\s+(ci|pipeline)/mi
25
22
 
26
23
  test:
27
24
  stage: test
25
+
28
26
  rules:
29
27
  - if: $CI_COMMIT_TAG || $CI_COMMIT_MESSAGE =~ $VERSION_REGEX
30
28
  when: never
31
- - if: $CI_COMMIT_DESCRIPTION =~ $NO_CI_REGEX
32
- when: never
33
29
  - if: $CI_COMMIT_BRANCH
34
30
  when: always
31
+
35
32
  allow_failure: false
33
+
36
34
  script:
37
35
  - bun test
38
36
  - sed 's/amp;//' coverage/junit.xml > coverage/junit.xml.tmp # remove amp; from junit report to prevent gitlab parsing issues
39
37
  - mv coverage/junit.xml.tmp coverage/junit.xml # make the change permanent
40
38
  - cargo install -q lcov2xml # used to convert lcov output to cobertura-xml for gitlab code coverage parsing
41
39
  - lcov2xml coverage/lcov.info -o coverage/cobertura-coverage.xml
40
+
42
41
  coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
42
+
43
43
  artifacts:
44
44
  reports:
45
45
  junit: ./coverage/junit.xml
@@ -47,18 +47,19 @@ test:
47
47
  coverage_format: cobertura
48
48
  path: ./coverage/cobertura-coverage.xml
49
49
 
50
- deploy:
51
- stage: deploy
50
+ publish:
51
+ stage: publish
52
+
52
53
  id_tokens:
53
54
  SIGSTORE_ID_TOKEN:
54
55
  aud: sigstore
55
56
  NPM_ID_TOKEN:
56
57
  aud: "npm:registry.npmjs.org"
58
+
57
59
  rules:
58
60
  - if: $CI_COMMIT_REF_PROTECTED && $CI_COMMIT_TAG && $CI_COMMIT_TAG =~ $VERSION_REGEX
59
61
  when: always
60
- - if: $CI_COMMIT_DESCRIPTION =~ $NO_CI_REGEX
61
- when: never
62
+
62
63
  script:
63
64
  - | # Setup environment variables for deployment
64
65
  export PACKAGE_NAME=$(jq -r '.name' package.json)
@@ -71,13 +72,11 @@ deploy:
71
72
  exit 9001
72
73
  fi
73
74
 
74
- - | # Publish to npm and GitLab registries
75
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" > .npmrc
76
- bun pm pack --filename package.tgz
77
- bunx npm publish -q package.tgz
78
-
79
- bun publish --silent --registry https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/ package.tgz
80
- rm package.tgz .npmrc
75
+ - bun pm pack --filename package.tgz
76
+ - bunx npm publish -q package.tgz
77
+ - sh ci/npm.sh
78
+ - bun publish --silent package.tgz
79
+ - rm package.tgz .npmrc
81
80
 
82
81
  allow_failure:
83
82
  exit_codes:
@@ -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
package/ci/npm.sh ADDED
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env bash
2
+
3
+ echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" > .npmrc
4
+ echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/" >> .npmrc
@@ -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) => {
13
+ handler: async (argv) => {
15
14
  const config = new Configuration().loadConfigurationFile();
15
+ const logger = new Logger(argv.level);
16
16
 
17
17
  const name = await input({
18
18
  message: "Enter the environment name:",
@@ -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) => {
13
+ handler: async (argv) => {
15
14
  const config = new Configuration().loadConfigurationFile();
15
+ const logger = new Logger(argv.level);
16
16
 
17
17
  const name = await select({
18
18
  message: "Select the environment to edit:",
@@ -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) => {
8
+ handler: async (argv) => {
11
9
  const config = new Configuration().loadConfigurationFile();
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) => {
13
+ handler: async (argv) => {
15
14
  const config = new Configuration().loadConfigurationFile();
15
+ const logger = new Logger(argv.level);
16
16
 
17
17
  const name = await select({
18
18
  message: "Select the environment to remove:",
@@ -28,8 +28,7 @@ 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)
@@ -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
  }
@@ -1,21 +1,10 @@
1
- import type { CommandModule } from "yargs";
1
+ import Commands from "./environment";
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;
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,17 +1,18 @@
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) => {
13
+ handler: async (argv) => {
14
+ const logger = new Logger(argv.level);
15
+
15
16
  new Configuration().loadConfigurationFile();
16
17
 
17
18
  if (fs.existsSync('.git')) {
@@ -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,18 +1,19 @@
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) => {
14
+ handler: async (argv) => {
15
+ const logger = new Logger(argv.level);
16
+
16
17
  const config = new Configuration().loadConfigurationFile();
17
18
 
18
19
  const name = await select({
@@ -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;
@@ -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) => {
11
+ handler: async (argv) => {
13
12
  const config = new Configuration().loadConfigurationFile();
13
+ const logger = new Logger(argv.level);
14
14
 
15
15
  const name = await input({
16
16
  message: "Enter the variable name:",
@@ -33,8 +33,7 @@ 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 })
@@ -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) => {
11
+ handler: async (argv) => {
13
12
  const config = new Configuration().loadConfigurationFile();
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
85
  .saveConfigurationFile();
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]
@@ -1,15 +1,14 @@
1
- import type { CommandModule } from "yargs";
2
-
3
1
  import { Configuration, EnvironmentFile, VariableType } from "#lib/config";
4
2
  import { NotFoundError } from "#lib/error";
5
- import { logger } from "#lib/logger";
3
+ import { Logger } from "#lib/logger";
6
4
 
7
5
  export default {
8
6
  command: 'list',
9
7
  describe: 'List all environment variables',
10
8
  builder: (yargs) => yargs,
11
- handler: async (_args) => {
9
+ handler: async (argv) => {
12
10
  const config = new Configuration().loadConfigurationFile();
11
+ const logger = new Logger(argv.level);
13
12
 
14
13
  const activeEnv = config.getActiveEnvironment();
15
14
 
@@ -19,25 +18,18 @@ export default {
19
18
 
20
19
  const envFile = new EnvironmentFile(activeEnv.file).load();
21
20
 
22
- const mappedVariables: Array<{ name: string; value: string; type: VariableType }> = [];
23
-
24
21
  for (const [key, value] of Object.entries(envFile.content)) {
25
22
  const variableConfiguration = config.getVariable(key);
26
23
  if (variableConfiguration) {
27
- logger.debug(`Mapping variable "${key}" with value "${value}" and type "${variableConfiguration.type}"`);
24
+ const type = Configuration.getTypeDetails(variableConfiguration.type);
28
25
 
29
- const data = {
30
- name: key,
31
- value: variableConfiguration.type === VariableType.Private ? value.replaceAll(/./gm, '*') : value,
32
- type: variableConfiguration.type,
33
- };
26
+ const maskedValue = type.value === VariableType.Private ? value.replaceAll(/./gm, '*') : value;
34
27
 
35
- mappedVariables.push(data);
28
+ logger
29
+ .info(`Name: ${key}`)
30
+ .info(`Value: ${maskedValue}`)
31
+ .info(`Type: ${type.name} (${type.value})`);
36
32
  }
37
33
  }
38
-
39
- console.log(
40
- JSON.stringify(mappedVariables, null, 2)
41
- )
42
34
  }
43
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) => {
11
+ handler: async (argv) => {
13
12
  const config = new Configuration().loadConfigurationFile();
13
+ const logger = new Logger(argv.level);
14
14
 
15
15
  const name = await select({
16
16
  message: "Select the variable to remove:",
@@ -24,8 +24,7 @@ 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)
@@ -35,8 +34,7 @@ export default {
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/cmd/variable.ts CHANGED
@@ -1,21 +1,10 @@
1
- import type { CommandModule } from "yargs";
1
+ import Commands from "./variable";
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;
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,
@@ -52,8 +55,8 @@ export class Configuration {
52
55
 
53
56
  public loadConfigurationFile() {
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
 
@@ -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.1",
5
+ "version": "1.2.3",
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",