@pcg/cli-tools 1.0.0-alpha.2 → 1.0.0-alpha.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/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/package.json +14 -2
- package/.turbo/turbo-build.log +0 -16
- package/.turbo/turbo-lint.log +0 -4
- package/CHANGELOG.md +0 -7
- package/eslint.config.cjs +0 -14
- package/eslint.config.js +0 -5
- package/src/command.ts +0 -10
- package/src/config.ts +0 -47
- package/src/database.ts +0 -24
- package/src/env.ts +0 -6
- package/src/index.ts +0 -5
- package/src/logger.ts +0 -54
- package/tsconfig.json +0 -9
- package/tsconfig.lib.json +0 -9
- package/tsdown.config.ts +0 -11
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ const createCommandWithEnv = (name) => createCommand(name).option("--env <env>",
|
|
|
25
25
|
let cliConfig;
|
|
26
26
|
const getConfig = async () => {
|
|
27
27
|
if (cliConfig) return cliConfig;
|
|
28
|
-
const localConfigFile = join(process.cwd(), "/config.yml");
|
|
28
|
+
const localConfigFile = join(process.cwd(), "/cli.config.yml");
|
|
29
29
|
let configFile = "";
|
|
30
30
|
try {
|
|
31
31
|
await stat(localConfigFile);
|
|
@@ -64,9 +64,10 @@ const colorScheme = {
|
|
|
64
64
|
const useLogger = (opts) => {
|
|
65
65
|
const { name } = opts;
|
|
66
66
|
const plainText = format.printf(({ level, message, timestamp }) => {
|
|
67
|
-
const color = colorScheme[level]
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const color = colorScheme[level] ?? ((text) => text);
|
|
68
|
+
let msg = typeof message === "string" ? message : "";
|
|
69
|
+
if (isObject(message)) msg = JSON.stringify(message, null, 2);
|
|
70
|
+
return `${typeof timestamp === "string" ? timestamp : ""} ${color(level.toUpperCase().padEnd(5))} ${clc.yellow(`[${name}]`)} ${color(msg)}`;
|
|
70
71
|
});
|
|
71
72
|
return createLogger({
|
|
72
73
|
level: "debug",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["cliConfig: CliConfig","colorScheme: Record<string,
|
|
1
|
+
{"version":3,"file":"index.js","names":["cliConfig: CliConfig | undefined","colorScheme: Record<string, ColorFn>","color: ColorFn","msg: string"],"sources":["../src/env.ts","../src/command.ts","../src/config.ts","../src/database.ts","../src/logger.ts"],"sourcesContent":["export enum Env {\n LOCAL = 'local',\n DEV = 'dev',\n STAGE = 'stage',\n PROD = 'prod',\n}\n","import { createCommand } from 'commander';\n\nimport { Env } from './env.js';\n\nexport interface CommandArgsWithEnv {\n env: Env;\n}\n\nexport const createCommandWithEnv = (name: string) => createCommand(name)\n .option('--env <env>', 'Environment where commands will be executed', Env.LOCAL);\n","import { readFile, stat } from 'fs/promises';\nimport { join } from 'path';\nimport { parse } from 'yaml';\n\nexport interface DatabaseConfig {\n host: string;\n port: number;\n user: string;\n pass: string;\n db: string;\n}\n\nexport interface WithEnv<T> {\n local: T;\n dev: T;\n stage: T;\n prod: T;\n}\n\nexport interface CliConfig {\n database: WithEnv<DatabaseConfig>;\n}\n\nlet cliConfig: CliConfig | undefined;\nexport const getConfig = async <T extends CliConfig>(): Promise<T> => {\n if (cliConfig) {\n return cliConfig as T;\n }\n\n const localConfigFile = join(process.cwd(), '/cli.config.yml');\n\n let configFile = '';\n try {\n await stat(localConfigFile);\n configFile = localConfigFile;\n } catch {\n throw new Error('Can`t find config.yml file in project root directory');\n }\n\n cliConfig = parse(\n await readFile(configFile, {\n encoding: 'utf-8',\n }),\n ) as CliConfig;\n\n return cliConfig as T;\n};\n","import { default as knex } from 'knex';\n\nimport { getConfig } from './config.js';\nimport { type Env } from './env.js';\n\ninterface KnexClientOptions {\n env: Env;\n}\n\nexport const createKnexClient = async (opts: KnexClientOptions) => {\n const appConfig = await getConfig();\n const dbConfig = appConfig.database[opts.env];\n\n return knex({\n client: 'pg',\n connection: {\n host: dbConfig.host,\n port: dbConfig.port,\n user: dbConfig.user,\n password: dbConfig.pass,\n database: dbConfig.db,\n },\n });\n};\n","import { isObject } from '@pcg/predicates';\nimport clc from 'cli-color';\nimport {\n createLogger, format,\n type Logger, transports,\n} from 'winston';\n\ntype ColorFn = (text: string) => string;\n\nconst colorScheme: Record<string, ColorFn> = {\n info: clc.greenBright as ColorFn,\n error: clc.red as ColorFn,\n warn: clc.yellow as ColorFn,\n debug: clc.magentaBright as ColorFn,\n};\n\nexport interface UseCliLoggerOpts {\n name: string;\n}\n\nexport const useLogger = (opts: UseCliLoggerOpts): Logger => {\n const { name } = opts;\n\n const plainText = format.printf(({\n level,\n message,\n timestamp,\n }) => {\n const color: ColorFn = colorScheme[level] ?? ((text: string): string => text);\n\n let msg: string = typeof message === 'string' ? message : '';\n if (isObject(message)) {\n msg = JSON.stringify(message, null, 2);\n }\n\n const sTimestamp = typeof timestamp === 'string' ? timestamp : '';\n const sLevel = color(level.toUpperCase().padEnd(5));\n const sName = (clc.yellow as ColorFn)(`[${name}]`);\n const sMessage = color(msg);\n\n return `${sTimestamp} ${sLevel} ${sName} ${sMessage}`;\n });\n\n return createLogger({\n level: 'debug',\n transports: [\n new transports.Console(),\n ],\n format: format.combine(\n format.timestamp(),\n plainText,\n ),\n });\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAY,sCAAL;AACL;AACA;AACA;AACA;;;;;;ACIF,MAAa,wBAAwB,SAAiB,cAAc,KAAK,CACtE,OAAO,eAAe,+CAA+C,IAAI,MAAM;;;;ACclF,IAAIA;AACJ,MAAa,YAAY,YAA6C;AACpE,KAAI,UACF,QAAO;CAGT,MAAM,kBAAkB,KAAK,QAAQ,KAAK,EAAE,kBAAkB;CAE9D,IAAI,aAAa;AACjB,KAAI;AACF,QAAM,KAAK,gBAAgB;AAC3B,eAAa;SACP;AACN,QAAM,IAAI,MAAM,uDAAuD;;AAGzE,aAAY,MACV,MAAM,SAAS,YAAY,EACzB,UAAU,SACX,CAAC,CACH;AAED,QAAO;;;;;ACpCT,MAAa,mBAAmB,OAAO,SAA4B;CAEjE,MAAM,YADY,MAAM,WAAW,EACR,SAAS,KAAK;AAEzC,QAAO,KAAK;EACV,QAAQ;EACR,YAAY;GACV,MAAM,SAAS;GACf,MAAM,SAAS;GACf,MAAM,SAAS;GACf,UAAU,SAAS;GACnB,UAAU,SAAS;GACpB;EACF,CAAC;;;;;ACbJ,MAAMC,cAAuC;CAC3C,MAAM,IAAI;CACV,OAAO,IAAI;CACX,MAAM,IAAI;CACV,OAAO,IAAI;CACZ;AAMD,MAAa,aAAa,SAAmC;CAC3D,MAAM,EAAE,SAAS;CAEjB,MAAM,YAAY,OAAO,QAAQ,EAC/B,OACA,SACA,gBACI;EACJ,MAAMC,QAAiB,YAAY,YAAY,SAAyB;EAExE,IAAIC,MAAc,OAAO,YAAY,WAAW,UAAU;AAC1D,MAAI,SAAS,QAAQ,CACnB,OAAM,KAAK,UAAU,SAAS,MAAM,EAAE;AAQxC,SAAO,GALY,OAAO,cAAc,WAAW,YAAY,GAK1C,GAJN,MAAM,MAAM,aAAa,CAAC,OAAO,EAAE,CAAC,CAIpB,GAHhB,IAAI,OAAmB,IAAI,KAAK,GAAG,CAGV,GAFvB,MAAM,IAAI;GAG3B;AAEF,QAAO,aAAa;EAClB,OAAO;EACP,YAAY,CACV,IAAI,WAAW,SAAS,CACzB;EACD,QAAQ,OAAO,QACb,OAAO,WAAW,EAClB,UACD;EACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pcg/cli-tools",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "CLI utilities for database, logging and configuration",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"email": "code@deepvision.team",
|
|
8
|
+
"name": "DeepVision Code"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Vitaliy Angolenko <v.angolenko@deepvision.software>",
|
|
12
|
+
"Sergii Sadovyi <s.sadovyi@deepvision.software>"
|
|
13
|
+
],
|
|
5
14
|
"type": "module",
|
|
6
15
|
"main": "dist/index.js",
|
|
7
16
|
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
8
20
|
"dependencies": {
|
|
9
21
|
"cli-color": "^2.0.4",
|
|
10
22
|
"winston": "^3.19.0",
|
|
11
23
|
"yaml": "^2.8.0",
|
|
12
|
-
"@pcg/predicates": "1.0.0-alpha.
|
|
24
|
+
"@pcg/predicates": "1.0.0-alpha.2"
|
|
13
25
|
},
|
|
14
26
|
"devDependencies": {
|
|
15
27
|
"@types/cli-color": "^2.0.6",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @pcg/cli-tools@1.0.0-alpha.1 build /Users/vangolenko/node/pcg/packages/cli-tools
|
|
4
|
-
> tsdown
|
|
5
|
-
|
|
6
|
-
[34mℹ[39m tsdown [2mv0.15.12[22m powered by rolldown [2mv1.0.0-beta.45[22m
|
|
7
|
-
[34mℹ[39m Using tsdown config: [4m/Users/vangolenko/node/pcg/packages/cli-tools/tsdown.config.ts[24m
|
|
8
|
-
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
9
|
-
[34mℹ[39m tsconfig: [34mtsconfig.lib.json[39m
|
|
10
|
-
[34mℹ[39m Build start
|
|
11
|
-
[34mℹ[39m Cleaning 3 files
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m4.84 kB[22m [2m│ gzip: 1.91 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22mindex.js.map [2m9.84 kB[22m [2m│ gzip: 3.44 kB[22m
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m1.96 kB[22m [2m│ gzip: 0.76 kB[22m
|
|
15
|
-
[34mℹ[39m 3 files, total: 16.64 kB
|
|
16
|
-
[32m✔[39m Build complete in [32m1200ms[39m
|
package/.turbo/turbo-lint.log
DELETED
package/CHANGELOG.md
DELETED
package/eslint.config.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// @pkg 📦 DeepVision ESLint Config [NestJS]
|
|
3
|
-
// @version 📍 1.0.0
|
|
4
|
-
// @author 🐳 DeepVision Team <code@deepvision.team>
|
|
5
|
-
//
|
|
6
|
-
// Documentation reference: https://eslint.org/docs/user-guide/configuring/
|
|
7
|
-
// ESLint versions: https://eslint.org/blog/
|
|
8
|
-
//
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, node/no-unpublished-require
|
|
10
|
-
const deep = require('@deepvision/eslint-plugin');
|
|
11
|
-
|
|
12
|
-
module.exports = [
|
|
13
|
-
...deep.default.configs.node,
|
|
14
|
-
];
|
package/eslint.config.js
DELETED
package/src/command.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createCommand } from 'commander';
|
|
2
|
-
|
|
3
|
-
import { Env } from './env.js';
|
|
4
|
-
|
|
5
|
-
export interface CommandArgsWithEnv {
|
|
6
|
-
env: Env;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const createCommandWithEnv = (name: string) => createCommand(name)
|
|
10
|
-
.option('--env <env>', 'Environment where commands will be executed', Env.LOCAL);
|
package/src/config.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { readFile, stat } from 'fs/promises';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { parse } from 'yaml';
|
|
4
|
-
|
|
5
|
-
export interface DatabaseConfig {
|
|
6
|
-
host: string;
|
|
7
|
-
port: number;
|
|
8
|
-
user: string;
|
|
9
|
-
pass: string;
|
|
10
|
-
db: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface WithEnv<T> {
|
|
14
|
-
local: T;
|
|
15
|
-
dev: T;
|
|
16
|
-
stage: T;
|
|
17
|
-
prod: T;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface CliConfig {
|
|
21
|
-
database: WithEnv<DatabaseConfig>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let cliConfig: CliConfig | undefined;
|
|
25
|
-
export const getConfig = async <T extends CliConfig>(): Promise<T> => {
|
|
26
|
-
if (cliConfig) {
|
|
27
|
-
return cliConfig as T;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const localConfigFile = join(process.cwd(), '/config.yml');
|
|
31
|
-
|
|
32
|
-
let configFile = '';
|
|
33
|
-
try {
|
|
34
|
-
await stat(localConfigFile);
|
|
35
|
-
configFile = localConfigFile;
|
|
36
|
-
} catch {
|
|
37
|
-
throw new Error('Can`t find config.yml file in project root directory');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
cliConfig = parse(
|
|
41
|
-
await readFile(configFile, {
|
|
42
|
-
encoding: 'utf-8',
|
|
43
|
-
}),
|
|
44
|
-
) as CliConfig;
|
|
45
|
-
|
|
46
|
-
return cliConfig as T;
|
|
47
|
-
};
|
package/src/database.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { default as knex } from 'knex';
|
|
2
|
-
|
|
3
|
-
import { getConfig } from './config.js';
|
|
4
|
-
import { type Env } from './env.js';
|
|
5
|
-
|
|
6
|
-
interface KnexClientOptions {
|
|
7
|
-
env: Env;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const createKnexClient = async (opts: KnexClientOptions) => {
|
|
11
|
-
const appConfig = await getConfig();
|
|
12
|
-
const dbConfig = appConfig.database[opts.env];
|
|
13
|
-
|
|
14
|
-
return knex({
|
|
15
|
-
client: 'pg',
|
|
16
|
-
connection: {
|
|
17
|
-
host: dbConfig.host,
|
|
18
|
-
port: dbConfig.port,
|
|
19
|
-
user: dbConfig.user,
|
|
20
|
-
password: dbConfig.pass,
|
|
21
|
-
database: dbConfig.db,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
};
|
package/src/env.ts
DELETED
package/src/index.ts
DELETED
package/src/logger.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { isObject } from '@pcg/predicates';
|
|
2
|
-
import clc from 'cli-color';
|
|
3
|
-
import {
|
|
4
|
-
createLogger, format,
|
|
5
|
-
type Logger, transports,
|
|
6
|
-
} from 'winston';
|
|
7
|
-
|
|
8
|
-
type ColorFn = (text: string) => string;
|
|
9
|
-
|
|
10
|
-
const colorScheme: Record<string, ColorFn> = {
|
|
11
|
-
info: clc.greenBright as ColorFn,
|
|
12
|
-
error: clc.red as ColorFn,
|
|
13
|
-
warn: clc.yellow as ColorFn,
|
|
14
|
-
debug: clc.magentaBright as ColorFn,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export interface UseCliLoggerOpts {
|
|
18
|
-
name: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const useLogger = (opts: UseCliLoggerOpts): Logger => {
|
|
22
|
-
const { name } = opts;
|
|
23
|
-
|
|
24
|
-
const plainText = format.printf(({
|
|
25
|
-
level,
|
|
26
|
-
message,
|
|
27
|
-
timestamp,
|
|
28
|
-
}) => {
|
|
29
|
-
const color: ColorFn = colorScheme[level] ?? ((text: string): string => text);
|
|
30
|
-
|
|
31
|
-
let msg: string = typeof message === 'string' ? message : '';
|
|
32
|
-
if (isObject(message)) {
|
|
33
|
-
msg = JSON.stringify(message, null, 2);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const sTimestamp = typeof timestamp === 'string' ? timestamp : '';
|
|
37
|
-
const sLevel = color(level.toUpperCase().padEnd(5));
|
|
38
|
-
const sName = (clc.yellow as ColorFn)(`[${name}]`);
|
|
39
|
-
const sMessage = color(msg);
|
|
40
|
-
|
|
41
|
-
return `${sTimestamp} ${sLevel} ${sName} ${sMessage}`;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return createLogger({
|
|
45
|
-
level: 'debug',
|
|
46
|
-
transports: [
|
|
47
|
-
new transports.Console(),
|
|
48
|
-
],
|
|
49
|
-
format: format.combine(
|
|
50
|
-
format.timestamp(),
|
|
51
|
-
plainText,
|
|
52
|
-
),
|
|
53
|
-
});
|
|
54
|
-
};
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED