@nattyjs/common 0.0.1-beta.2 → 0.0.1-beta.21
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.cjs +121 -10
- package/dist/index.d.ts +72 -4
- package/dist/index.mjs +118 -11
- package/package.json +8 -4
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,8 @@ const fs = require('fs');
|
|
|
4
4
|
const dotenv = require('dotenv');
|
|
5
5
|
const dotenvExpand = require('dotenv-expand');
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const child_process = require('child_process');
|
|
8
|
+
const getPortPlease = require('get-port-please');
|
|
7
9
|
|
|
8
10
|
function _interopNamespaceCompat(e) {
|
|
9
11
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
@@ -25,6 +27,17 @@ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
|
25
27
|
const commonContainer = new class {
|
|
26
28
|
constructor() {
|
|
27
29
|
this.metadataConfig = { services: /* @__PURE__ */ new Map() };
|
|
30
|
+
this.types = {};
|
|
31
|
+
}
|
|
32
|
+
registerType(type) {
|
|
33
|
+
if (type) {
|
|
34
|
+
if (typeof type === "string")
|
|
35
|
+
type = JSON.parse(type);
|
|
36
|
+
this.types[type.name] = type;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
setupCliConfig(config) {
|
|
40
|
+
this.nattyCliConfig = config;
|
|
28
41
|
}
|
|
29
42
|
setupConfig(config) {
|
|
30
43
|
const modelBinding = {
|
|
@@ -35,7 +48,7 @@ const commonContainer = new class {
|
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
};
|
|
38
|
-
this.nattyConfig = { ...{ api: { rootPath: "api" }, modelBinding, globalConfig: {} }, ...config };
|
|
51
|
+
this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {} }, ...config };
|
|
39
52
|
}
|
|
40
53
|
setupBuildOptions(options) {
|
|
41
54
|
this.buildOptions = options;
|
|
@@ -225,20 +238,29 @@ function getPath(pathCollection, isIncludeRoot = true, isCreateFolder = false) {
|
|
|
225
238
|
return currentPath;
|
|
226
239
|
}
|
|
227
240
|
|
|
241
|
+
function resolvePath(path$1) {
|
|
242
|
+
return path.resolve(commonContainer.buildOptions.rootDir, path$1);
|
|
243
|
+
}
|
|
244
|
+
|
|
228
245
|
async function readEnv() {
|
|
229
|
-
|
|
246
|
+
const envConfig = commonContainer.nattyCliConfig.env;
|
|
247
|
+
let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
|
|
248
|
+
if (envConfig && envConfig.path)
|
|
249
|
+
filePath = resolvePath(envConfig.path);
|
|
230
250
|
let parsedEnvTsDefinition = {};
|
|
231
|
-
|
|
251
|
+
let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
|
|
252
|
+
if (!parsedEnv && filePath && fs.existsSync(filePath)) {
|
|
232
253
|
const { parsed, error } = dotenv__namespace.config({
|
|
233
254
|
debug: !!process.env.DEBUG || void 0,
|
|
234
255
|
path: filePath
|
|
235
256
|
});
|
|
236
|
-
|
|
237
|
-
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
238
|
-
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
239
|
-
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
240
|
-
dotenvExpand__namespace.expand({ parsed });
|
|
257
|
+
parsedEnv = parsed;
|
|
241
258
|
}
|
|
259
|
+
const info = getEnvTsDefinition(parsedEnv);
|
|
260
|
+
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
261
|
+
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
262
|
+
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
263
|
+
dotenvExpand__namespace.expand({ parsed: parsedEnv });
|
|
242
264
|
return parsedEnvTsDefinition;
|
|
243
265
|
}
|
|
244
266
|
|
|
@@ -286,10 +308,10 @@ function readEnvKey(key) {
|
|
|
286
308
|
}
|
|
287
309
|
|
|
288
310
|
class UserIdentity {
|
|
289
|
-
constructor(isAuthenticate, id,
|
|
311
|
+
constructor(isAuthenticate, id, claims) {
|
|
290
312
|
this.isAuthenticate = isAuthenticate;
|
|
291
313
|
this.id = id;
|
|
292
|
-
this.
|
|
314
|
+
this.claims = claims;
|
|
293
315
|
}
|
|
294
316
|
}
|
|
295
317
|
|
|
@@ -566,18 +588,105 @@ class List {
|
|
|
566
588
|
}
|
|
567
589
|
}
|
|
568
590
|
|
|
591
|
+
var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
|
|
592
|
+
FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
|
|
593
|
+
FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
|
|
594
|
+
FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
|
|
595
|
+
FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
|
|
596
|
+
FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
|
|
597
|
+
return FrameworkType2;
|
|
598
|
+
})(FrameworkType || {});
|
|
599
|
+
|
|
600
|
+
function registerType(type) {
|
|
601
|
+
commonContainer.registerType(type);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
class AbstractRunner {
|
|
605
|
+
async exec(command, args, cwd = process.cwd()) {
|
|
606
|
+
const options = {
|
|
607
|
+
cwd,
|
|
608
|
+
stdio: "pipe",
|
|
609
|
+
shell: true
|
|
610
|
+
};
|
|
611
|
+
return new Promise((resolve, reject) => {
|
|
612
|
+
const child = child_process.spawn(
|
|
613
|
+
`${command}`,
|
|
614
|
+
[...args],
|
|
615
|
+
options
|
|
616
|
+
);
|
|
617
|
+
child.stdout.on(
|
|
618
|
+
"data",
|
|
619
|
+
(data) => {
|
|
620
|
+
const writeData = data.toString().replace(/\r\n|\n/, "");
|
|
621
|
+
if (writeData.indexOf("[NATTYJS]") > -1 || writeData.indexOf("[NATTYJS:LOGGER]") > -1) {
|
|
622
|
+
console.log(writeData);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
);
|
|
626
|
+
child.on("close", (code) => {
|
|
627
|
+
if (code === 0) {
|
|
628
|
+
resolve(null);
|
|
629
|
+
} else {
|
|
630
|
+
console.error(
|
|
631
|
+
`${command} ${args}`
|
|
632
|
+
);
|
|
633
|
+
reject();
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
async function getPort() {
|
|
641
|
+
const portNumber = commonContainer.nattyConfig?.port || 3200;
|
|
642
|
+
if (portNumber)
|
|
643
|
+
return portNumber;
|
|
644
|
+
const port = await getPortPlease.getPort({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
|
|
645
|
+
commonContainer.nattyConfig.port = port;
|
|
646
|
+
return port;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const reset = "\x1B[0m";
|
|
650
|
+
const NATTY_LOGGER = `[NATTYJS:LOGGER] `;
|
|
651
|
+
const log = {
|
|
652
|
+
green: (text) => console.log("\x1B[32m" + NATTY_LOGGER + text + reset),
|
|
653
|
+
red: (text) => console.log("\x1B[31m" + NATTY_LOGGER + text + reset),
|
|
654
|
+
blue: (text) => console.log("\x1B[34m" + NATTY_LOGGER + text + reset),
|
|
655
|
+
yellow: (text) => console.log("\x1B[33m" + NATTY_LOGGER + text + reset)
|
|
656
|
+
};
|
|
657
|
+
class AbstractConsoleLogger {
|
|
658
|
+
log(message) {
|
|
659
|
+
log.yellow(message);
|
|
660
|
+
}
|
|
661
|
+
info(message) {
|
|
662
|
+
log.blue(message);
|
|
663
|
+
}
|
|
664
|
+
warn(message) {
|
|
665
|
+
log.yellow(message);
|
|
666
|
+
}
|
|
667
|
+
error(message) {
|
|
668
|
+
log.red(message);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
class ConsoleLogger extends AbstractConsoleLogger {
|
|
673
|
+
}
|
|
674
|
+
|
|
569
675
|
exports.ALLOW_METHODS = ALLOW_METHODS;
|
|
676
|
+
exports.AbstractRunner = AbstractRunner;
|
|
570
677
|
exports.ActionFilter = ActionFilter;
|
|
571
678
|
exports.AuthenticationFilter = AuthenticationFilter;
|
|
572
679
|
exports.AuthorizationFilter = AuthorizationFilter;
|
|
573
680
|
exports.BACK_SLASH_REGEX = BACK_SLASH_REGEX;
|
|
574
681
|
exports.BLANK = BLANK;
|
|
575
682
|
exports.CONTROLLER = CONTROLLER;
|
|
683
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
576
684
|
exports.DEFAULT_ACTIONS = DEFAULT_ACTIONS;
|
|
577
685
|
exports.DEFAULT_CHILD_PATH = DEFAULT_CHILD_PATH;
|
|
578
686
|
exports.DELETE = DELETE;
|
|
579
687
|
exports.ENVIRONMENTS = ENVIRONMENTS;
|
|
580
688
|
exports.ExceptionFilter = ExceptionFilter;
|
|
689
|
+
exports.FrameworkType = FrameworkType;
|
|
581
690
|
exports.GET = GET;
|
|
582
691
|
exports.HTTP_METHOD_ROUTES = HTTP_METHOD_ROUTES;
|
|
583
692
|
exports.IGNORE_METHODS = IGNORE_METHODS;
|
|
@@ -596,10 +705,12 @@ exports.commonContainer = commonContainer;
|
|
|
596
705
|
exports.createPath = createPath;
|
|
597
706
|
exports.createTestServer = createTestServer;
|
|
598
707
|
exports.getPath = getPath;
|
|
708
|
+
exports.getPort = getPort;
|
|
599
709
|
exports.isConstructor = isConstructor;
|
|
600
710
|
exports.isEqual = isEqual;
|
|
601
711
|
exports.isFunction = isFunction;
|
|
602
712
|
exports.isObject = isObject;
|
|
603
713
|
exports.readEnv = readEnv;
|
|
604
714
|
exports.readEnvKey = readEnvKey;
|
|
715
|
+
exports.registerType = registerType;
|
|
605
716
|
exports.typeContainer = typeContainer;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestRouteInfo, IHttpResult, IModelBindingContext, ProblemDetail, IExceptionContext, HttpResponseInit, NattyTestModule, ModelBinding, BuildOptions, ClassTypeInfo } from '@nattyjs/types';
|
|
1
|
+
import { RequestRouteInfo, IHttpResult, IModelBindingContext, ProblemDetail, IExceptionContext, HttpResponseInit, NattyTestModule, ModelBinding, BuildOptions, TypesInfo, ClassTypeInfo } from '@nattyjs/types';
|
|
2
2
|
|
|
3
3
|
interface ClassType<T> extends Function {
|
|
4
4
|
new (...args: any[]): T;
|
|
@@ -7,8 +7,8 @@ interface ClassType<T> extends Function {
|
|
|
7
7
|
declare class UserIdentity<T> {
|
|
8
8
|
isAuthenticate: boolean;
|
|
9
9
|
id?: any;
|
|
10
|
-
|
|
11
|
-
constructor(isAuthenticate: boolean, id?: any,
|
|
10
|
+
claims?: T;
|
|
11
|
+
constructor(isAuthenticate: boolean, id?: any, claims?: T);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface IExecutionContext {
|
|
@@ -53,6 +53,14 @@ interface GlobalConfig {
|
|
|
53
53
|
onException?: ClassType<ExceptionFilter>;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
interface CorsConfig {
|
|
57
|
+
origin: string[];
|
|
58
|
+
methods: string;
|
|
59
|
+
preflightContinue: boolean;
|
|
60
|
+
optionsSuccessStatus: number;
|
|
61
|
+
credentials: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
interface NattyConfig {
|
|
57
65
|
app: any;
|
|
58
66
|
testModule?: NattyTestModule;
|
|
@@ -61,12 +69,44 @@ interface NattyConfig {
|
|
|
61
69
|
};
|
|
62
70
|
modelBinding?: ModelBinding;
|
|
63
71
|
global?: GlobalConfig;
|
|
72
|
+
autoGeneratePort?: boolean;
|
|
73
|
+
port?: number;
|
|
74
|
+
cors?: CorsConfig;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare abstract class AbstractRunner {
|
|
78
|
+
abstract run(): void;
|
|
79
|
+
protected exec(command: string, args: any[], cwd?: string): Promise<null | string>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface EnvConfig {
|
|
83
|
+
path: string;
|
|
84
|
+
dictionary: {
|
|
85
|
+
[key: string]: any;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface PackageJsonConfig {
|
|
90
|
+
addExports: string[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface LibraryConfig {
|
|
94
|
+
packageJson: PackageJsonConfig;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface NattyCliConfig {
|
|
98
|
+
library?: Partial<LibraryConfig>;
|
|
99
|
+
env?: Partial<EnvConfig>;
|
|
100
|
+
runner?: ClassType<AbstractRunner>;
|
|
101
|
+
port?: number;
|
|
64
102
|
}
|
|
65
103
|
|
|
66
104
|
declare const commonContainer: {
|
|
67
105
|
setupConfig(config?: NattyConfig): void;
|
|
106
|
+
setupCliConfig(config: NattyCliConfig): void;
|
|
68
107
|
setupBuildOptions(options: BuildOptions): any;
|
|
69
108
|
get nattyConfig(): NattyConfig;
|
|
109
|
+
get nattyCliConfig(): NattyCliConfig;
|
|
70
110
|
get buildOptions(): BuildOptions;
|
|
71
111
|
get envTsDefinition(): {
|
|
72
112
|
[key: string]: string;
|
|
@@ -83,6 +123,8 @@ declare const commonContainer: {
|
|
|
83
123
|
setMetadata(key: string, value: any, propName: string): void;
|
|
84
124
|
getMetadataValue(key: string, propName: string): any;
|
|
85
125
|
get globalConfig(): GlobalConfig;
|
|
126
|
+
registerType(type: TypesInfo): void;
|
|
127
|
+
types: TypesInfo;
|
|
86
128
|
};
|
|
87
129
|
|
|
88
130
|
declare const typeContainer: {
|
|
@@ -206,4 +248,30 @@ declare class List<T> {
|
|
|
206
248
|
declare function isObject(value: any): boolean;
|
|
207
249
|
declare function isEqual(first: any, second: any): boolean;
|
|
208
250
|
|
|
209
|
-
|
|
251
|
+
declare enum FrameworkType {
|
|
252
|
+
Express = 0,
|
|
253
|
+
Fastify = 1,
|
|
254
|
+
AzureFunction = 2,
|
|
255
|
+
Firebase = 3,
|
|
256
|
+
Lambda = 4
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
interface NattyAppConfig extends NattyConfig {
|
|
260
|
+
framework: FrameworkType;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
declare function registerType(type: TypesInfo): void;
|
|
264
|
+
|
|
265
|
+
declare function getPort(): Promise<number>;
|
|
266
|
+
|
|
267
|
+
declare abstract class AbstractConsoleLogger {
|
|
268
|
+
log(message: any): void;
|
|
269
|
+
info(message: any): void;
|
|
270
|
+
warn(message: any): void;
|
|
271
|
+
error(message: any): void;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare class ConsoleLogger extends AbstractConsoleLogger {
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export { ALLOW_METHODS, AbstractRunner, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, Claim, ClassType, ConsoleLogger, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, GlobalConfig, HTTP_METHOD_ROUTES, IActionExecutedContext, IActionExecutingContext, IExecutionContext, IGNORE_METHODS, List, MetaConfigProps, Middleware, NattyAppConfig, NattyCliConfig, NattyConfig, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, getPort, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer };
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,24 @@ import { existsSync } from 'fs';
|
|
|
3
3
|
import * as dotenv from 'dotenv';
|
|
4
4
|
import * as dotenvExpand from 'dotenv-expand';
|
|
5
5
|
import * as path from 'path';
|
|
6
|
+
import { resolve } from 'path';
|
|
7
|
+
import { spawn } from 'child_process';
|
|
8
|
+
import { getPort as getPort$1 } from 'get-port-please';
|
|
6
9
|
|
|
7
10
|
const commonContainer = new class {
|
|
8
11
|
constructor() {
|
|
9
12
|
this.metadataConfig = { services: /* @__PURE__ */ new Map() };
|
|
13
|
+
this.types = {};
|
|
14
|
+
}
|
|
15
|
+
registerType(type) {
|
|
16
|
+
if (type) {
|
|
17
|
+
if (typeof type === "string")
|
|
18
|
+
type = JSON.parse(type);
|
|
19
|
+
this.types[type.name] = type;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
setupCliConfig(config) {
|
|
23
|
+
this.nattyCliConfig = config;
|
|
10
24
|
}
|
|
11
25
|
setupConfig(config) {
|
|
12
26
|
const modelBinding = {
|
|
@@ -17,7 +31,7 @@ const commonContainer = new class {
|
|
|
17
31
|
}
|
|
18
32
|
}
|
|
19
33
|
};
|
|
20
|
-
this.nattyConfig = { ...{ api: { rootPath: "api" }, modelBinding, globalConfig: {} }, ...config };
|
|
34
|
+
this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {} }, ...config };
|
|
21
35
|
}
|
|
22
36
|
setupBuildOptions(options) {
|
|
23
37
|
this.buildOptions = options;
|
|
@@ -207,20 +221,29 @@ function getPath(pathCollection, isIncludeRoot = true, isCreateFolder = false) {
|
|
|
207
221
|
return currentPath;
|
|
208
222
|
}
|
|
209
223
|
|
|
224
|
+
function resolvePath(path) {
|
|
225
|
+
return resolve(commonContainer.buildOptions.rootDir, path);
|
|
226
|
+
}
|
|
227
|
+
|
|
210
228
|
async function readEnv() {
|
|
211
|
-
|
|
229
|
+
const envConfig = commonContainer.nattyCliConfig.env;
|
|
230
|
+
let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
|
|
231
|
+
if (envConfig && envConfig.path)
|
|
232
|
+
filePath = resolvePath(envConfig.path);
|
|
212
233
|
let parsedEnvTsDefinition = {};
|
|
213
|
-
|
|
234
|
+
let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
|
|
235
|
+
if (!parsedEnv && filePath && existsSync(filePath)) {
|
|
214
236
|
const { parsed, error } = dotenv.config({
|
|
215
237
|
debug: !!process.env.DEBUG || void 0,
|
|
216
238
|
path: filePath
|
|
217
239
|
});
|
|
218
|
-
|
|
219
|
-
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
220
|
-
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
221
|
-
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
222
|
-
dotenvExpand.expand({ parsed });
|
|
240
|
+
parsedEnv = parsed;
|
|
223
241
|
}
|
|
242
|
+
const info = getEnvTsDefinition(parsedEnv);
|
|
243
|
+
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
244
|
+
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
245
|
+
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
246
|
+
dotenvExpand.expand({ parsed: parsedEnv });
|
|
224
247
|
return parsedEnvTsDefinition;
|
|
225
248
|
}
|
|
226
249
|
|
|
@@ -268,10 +291,10 @@ function readEnvKey(key) {
|
|
|
268
291
|
}
|
|
269
292
|
|
|
270
293
|
class UserIdentity {
|
|
271
|
-
constructor(isAuthenticate, id,
|
|
294
|
+
constructor(isAuthenticate, id, claims) {
|
|
272
295
|
this.isAuthenticate = isAuthenticate;
|
|
273
296
|
this.id = id;
|
|
274
|
-
this.
|
|
297
|
+
this.claims = claims;
|
|
275
298
|
}
|
|
276
299
|
}
|
|
277
300
|
|
|
@@ -548,4 +571,88 @@ class List {
|
|
|
548
571
|
}
|
|
549
572
|
}
|
|
550
573
|
|
|
551
|
-
|
|
574
|
+
var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
|
|
575
|
+
FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
|
|
576
|
+
FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
|
|
577
|
+
FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
|
|
578
|
+
FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
|
|
579
|
+
FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
|
|
580
|
+
return FrameworkType2;
|
|
581
|
+
})(FrameworkType || {});
|
|
582
|
+
|
|
583
|
+
function registerType(type) {
|
|
584
|
+
commonContainer.registerType(type);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
class AbstractRunner {
|
|
588
|
+
async exec(command, args, cwd = process.cwd()) {
|
|
589
|
+
const options = {
|
|
590
|
+
cwd,
|
|
591
|
+
stdio: "pipe",
|
|
592
|
+
shell: true
|
|
593
|
+
};
|
|
594
|
+
return new Promise((resolve, reject) => {
|
|
595
|
+
const child = spawn(
|
|
596
|
+
`${command}`,
|
|
597
|
+
[...args],
|
|
598
|
+
options
|
|
599
|
+
);
|
|
600
|
+
child.stdout.on(
|
|
601
|
+
"data",
|
|
602
|
+
(data) => {
|
|
603
|
+
const writeData = data.toString().replace(/\r\n|\n/, "");
|
|
604
|
+
if (writeData.indexOf("[NATTYJS]") > -1 || writeData.indexOf("[NATTYJS:LOGGER]") > -1) {
|
|
605
|
+
console.log(writeData);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
child.on("close", (code) => {
|
|
610
|
+
if (code === 0) {
|
|
611
|
+
resolve(null);
|
|
612
|
+
} else {
|
|
613
|
+
console.error(
|
|
614
|
+
`${command} ${args}`
|
|
615
|
+
);
|
|
616
|
+
reject();
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
async function getPort() {
|
|
624
|
+
const portNumber = commonContainer.nattyConfig?.port || 3200;
|
|
625
|
+
if (portNumber)
|
|
626
|
+
return portNumber;
|
|
627
|
+
const port = await getPort$1({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
|
|
628
|
+
commonContainer.nattyConfig.port = port;
|
|
629
|
+
return port;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const reset = "\x1B[0m";
|
|
633
|
+
const NATTY_LOGGER = `[NATTYJS:LOGGER] `;
|
|
634
|
+
const log = {
|
|
635
|
+
green: (text) => console.log("\x1B[32m" + NATTY_LOGGER + text + reset),
|
|
636
|
+
red: (text) => console.log("\x1B[31m" + NATTY_LOGGER + text + reset),
|
|
637
|
+
blue: (text) => console.log("\x1B[34m" + NATTY_LOGGER + text + reset),
|
|
638
|
+
yellow: (text) => console.log("\x1B[33m" + NATTY_LOGGER + text + reset)
|
|
639
|
+
};
|
|
640
|
+
class AbstractConsoleLogger {
|
|
641
|
+
log(message) {
|
|
642
|
+
log.yellow(message);
|
|
643
|
+
}
|
|
644
|
+
info(message) {
|
|
645
|
+
log.blue(message);
|
|
646
|
+
}
|
|
647
|
+
warn(message) {
|
|
648
|
+
log.yellow(message);
|
|
649
|
+
}
|
|
650
|
+
error(message) {
|
|
651
|
+
log.red(message);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
class ConsoleLogger extends AbstractConsoleLogger {
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export { ALLOW_METHODS, AbstractRunner, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, ConsoleLogger, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, HTTP_METHOD_ROUTES, IGNORE_METHODS, List, MetaConfigProps, Middleware, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, getPort, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nattyjs/common",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.21",
|
|
4
4
|
"description": "Now I’m the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin’ letters to relatives / Embellishin’ my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "ajayojha <ojhaajay@outlook.com>",
|
|
@@ -14,10 +14,14 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "unbuild"
|
|
16
16
|
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"dotenv": "16.3.1",
|
|
19
|
+
"dotenv-expand": "10.0.0",
|
|
20
|
+
"get-port-please": "3.1.1"
|
|
21
|
+
},
|
|
17
22
|
"devDependencies": {
|
|
18
23
|
"@types/node": "20.3.1",
|
|
19
|
-
"@nattyjs/types": "0.0.1-beta.
|
|
20
|
-
"unbuild": "1.2.1"
|
|
21
|
-
"dotenv-expand": "10.0.0"
|
|
24
|
+
"@nattyjs/types": "0.0.1-beta.21",
|
|
25
|
+
"unbuild": "1.2.1"
|
|
22
26
|
}
|
|
23
27
|
}
|