@expressots/shared 3.0.0 → 4.0.0-preview.1
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/README.md +31 -98
- package/lib/CHANGELOG.md +82 -65
- package/lib/README.md +31 -98
- package/lib/cjs/env/cli-options.js +2 -2
- package/lib/cjs/env/environment.js +10 -10
- package/lib/cjs/env/index.js +1 -1
- package/lib/cjs/index.js +4 -4
- package/lib/cjs/interfaces/index.js +3 -5
- package/lib/cjs/types/config/index.d.ts +1 -1
- package/lib/cjs/types/config/project-config.d.ts +5 -0
- package/lib/cjs/types/env/cli-options.d.ts +1 -1
- package/lib/cjs/types/env/env-options.d.ts +1 -1
- package/lib/cjs/types/env/environment.d.ts +1 -1
- package/lib/cjs/types/env/index.d.ts +2 -2
- package/lib/cjs/types/index.d.ts +4 -4
- package/lib/cjs/types/interfaces/application-express.interface.d.ts +9 -4
- package/lib/cjs/types/interfaces/console.interface.d.ts +6 -0
- package/lib/cjs/types/interfaces/index.d.ts +5 -5
- package/lib/cjs/types/interfaces/render/render.types.d.ts +1 -1
- package/lib/cjs/types/utils/compiler.d.ts +1 -1
- package/lib/cjs/types/utils/index.d.ts +1 -1
- package/lib/cjs/utils/index.js +2 -2
- package/lib/esm/config/index.js +1 -0
- package/lib/esm/config/project-config.js +1 -0
- package/lib/esm/env/cli-options.js +15 -0
- package/lib/esm/env/constants.js +10 -0
- package/lib/esm/env/env-options.js +19 -0
- package/lib/esm/env/environment.js +304 -0
- package/lib/esm/env/index.js +1 -0
- package/lib/esm/env/interfaces.js +1 -0
- package/lib/esm/index.mjs +4 -0
- package/lib/esm/interfaces/application-express.interface.js +1 -0
- package/lib/esm/interfaces/console.interface.js +1 -0
- package/lib/esm/interfaces/environment.interface.js +19 -0
- package/lib/esm/interfaces/index.js +1 -0
- package/lib/esm/interfaces/middleware.interface.js +1 -0
- package/lib/esm/interfaces/render/ejs.types.js +2 -0
- package/lib/esm/interfaces/render/render.types.js +20 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/types/config/index.d.ts +1 -0
- package/lib/esm/types/config/project-config.d.ts +43 -0
- package/lib/esm/types/env/cli-options.d.ts +7 -0
- package/lib/esm/types/env/constants.d.ts +10 -0
- package/lib/esm/types/env/env-options.d.ts +9 -0
- package/lib/esm/types/env/environment.d.ts +83 -0
- package/lib/esm/types/env/index.d.ts +2 -0
- package/lib/esm/types/env/interfaces.d.ts +71 -0
- package/lib/esm/types/index.d.ts +4 -0
- package/lib/esm/types/interfaces/application-express.interface.d.ts +58 -0
- package/lib/esm/types/interfaces/console.interface.d.ts +14 -0
- package/lib/esm/types/interfaces/environment.interface.d.ts +37 -0
- package/lib/esm/types/interfaces/index.d.ts +5 -0
- package/lib/esm/types/interfaces/middleware.interface.d.ts +7 -0
- package/lib/esm/types/interfaces/render/ejs.types.d.ts +169 -0
- package/lib/esm/types/interfaces/render/render.types.d.ts +71 -0
- package/lib/esm/types/utils/compiler.d.ts +17 -0
- package/lib/esm/types/utils/index.d.ts +1 -0
- package/lib/esm/types/utils/logger.d.ts +19 -0
- package/lib/esm/utils/compiler.js +69 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/logger.js +60 -0
- package/lib/package.json +154 -147
- package/package.json +154 -147
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { IConfigOptions, IConfigOutput, IEnvObject } from "./interfaces.js";
|
|
2
|
+
/**
|
|
3
|
+
* Module to parse the .env.vault file
|
|
4
|
+
* @param options - The configuration options
|
|
5
|
+
* @returns The parsed object
|
|
6
|
+
*/
|
|
7
|
+
declare function _parseVault(options: IConfigOptions): IEnvObject;
|
|
8
|
+
/**
|
|
9
|
+
* Module to verify and return the .env.vault file path
|
|
10
|
+
* @param options - The configuration options
|
|
11
|
+
* @returns The .env.vault file path
|
|
12
|
+
*/
|
|
13
|
+
declare function _vaultPath(options: any): any;
|
|
14
|
+
/**
|
|
15
|
+
* Module to verify and return the DOTENV_KEY vault key
|
|
16
|
+
* @param options - The configuration options
|
|
17
|
+
* @returns The DOTENV_KEY as a string
|
|
18
|
+
*/
|
|
19
|
+
declare function _dotenvKey(options?: IConfigOptions): string;
|
|
20
|
+
/**
|
|
21
|
+
* Module to get instructions for decrypting the .env.vault file
|
|
22
|
+
* @param result -
|
|
23
|
+
* @param dotenvKey
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
declare function _instructions(result: IConfigOutput, dotenvKey: string): {
|
|
27
|
+
ciphertext: string;
|
|
28
|
+
key: any;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Module responsible to resolve home path
|
|
32
|
+
* @param envPath - The path to resolve
|
|
33
|
+
* @returns The resolved path
|
|
34
|
+
*/
|
|
35
|
+
declare function _resolveHome(envPath: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Module to load environment variables from .env.vault file
|
|
38
|
+
* @param options - The configuration options
|
|
39
|
+
* @returns The parsed object
|
|
40
|
+
*/
|
|
41
|
+
export declare function _configVault(options: IConfigOptions): IConfigOutput;
|
|
42
|
+
/**
|
|
43
|
+
* Module to load environment variables from .env file
|
|
44
|
+
* @param options - The configuration options
|
|
45
|
+
* @returns The parsed object
|
|
46
|
+
* @public API
|
|
47
|
+
*/
|
|
48
|
+
export declare function config(options?: IConfigOptions): IConfigOutput;
|
|
49
|
+
/**
|
|
50
|
+
* Module to load environment variables from .env file
|
|
51
|
+
* @param options - The configuration options
|
|
52
|
+
* @returns The parsed object
|
|
53
|
+
* @public API
|
|
54
|
+
*/
|
|
55
|
+
export declare function configDotenv(options?: IConfigOptions): IConfigOutput;
|
|
56
|
+
/**
|
|
57
|
+
* Module to load environment variables from .env file
|
|
58
|
+
* @param envFile - The source of the .env file
|
|
59
|
+
* @returns The parsed object
|
|
60
|
+
* @public API
|
|
61
|
+
*/
|
|
62
|
+
export declare function parse(envFile: Buffer | string): Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* Decrypts a base64 encoded string
|
|
65
|
+
* @param encrypted - The base64 encoded string to decrypt
|
|
66
|
+
* @param keyStr - The key to use for decryption
|
|
67
|
+
* @returns The decrypted string
|
|
68
|
+
* @public API
|
|
69
|
+
*/
|
|
70
|
+
export declare function decrypt(encrypted: string, keyStr: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Populates the environment with the given parsed object
|
|
73
|
+
* @param envObject - The object to populate the environment with (e.g. process.env)
|
|
74
|
+
* @param parsed - The parsed object
|
|
75
|
+
* @param options - The configuration options
|
|
76
|
+
* @public API
|
|
77
|
+
*/
|
|
78
|
+
export declare function populate(envObject: IEnvObject, // Usually process.env
|
|
79
|
+
parsed: IEnvObject, options?: IConfigOptions): void;
|
|
80
|
+
/**
|
|
81
|
+
* Test swap for private functions
|
|
82
|
+
*/
|
|
83
|
+
export { _parseVault, _vaultPath, _dotenvKey, _instructions, _resolveHome };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for config options
|
|
3
|
+
* @public API
|
|
4
|
+
*/
|
|
5
|
+
export interface IConfigOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Default: `path.resolve(process.cwd(), '.env')`
|
|
8
|
+
*
|
|
9
|
+
* Specify a custom path if your file containing environment variables is located elsewhere.
|
|
10
|
+
* Can also be an array of strings, specifying multiple paths.
|
|
11
|
+
*
|
|
12
|
+
* example: `require('dotenv').config({ path: '/custom/path/to/.env' })`
|
|
13
|
+
* example: `require('dotenv').config({ path: ['/path/to/first.env', '/path/to/second.env'] })`
|
|
14
|
+
*/
|
|
15
|
+
path?: string | Array<string> | URL;
|
|
16
|
+
/**
|
|
17
|
+
* Default: `utf8`
|
|
18
|
+
*
|
|
19
|
+
* Specify the encoding of your file containing environment variables.
|
|
20
|
+
*
|
|
21
|
+
* example: `require('dotenv').config({ encoding: 'latin1' })`
|
|
22
|
+
*/
|
|
23
|
+
encoding?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Default: `false`
|
|
26
|
+
*
|
|
27
|
+
* Turn on logging to help debug why certain keys or values are not being set as you expect.
|
|
28
|
+
*
|
|
29
|
+
* example: `require('dotenv').config({ debug: process.env.DEBUG })`
|
|
30
|
+
*/
|
|
31
|
+
debug?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Default: `false`
|
|
34
|
+
*
|
|
35
|
+
* Override any environment variables that have already been set on your machine with values from your .env file.
|
|
36
|
+
*
|
|
37
|
+
* example: `require('dotenv').config({ override: true })`
|
|
38
|
+
*/
|
|
39
|
+
override?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Default: `process.env`
|
|
42
|
+
*
|
|
43
|
+
* Specify an object to write your secrets to. Defaults to process.env environment variables.
|
|
44
|
+
*
|
|
45
|
+
* example: `const processEnv = {}; require('dotenv').config({ processEnv: processEnv })`
|
|
46
|
+
*/
|
|
47
|
+
envObject?: IEnvObject;
|
|
48
|
+
/**
|
|
49
|
+
* Default: `undefined`
|
|
50
|
+
*
|
|
51
|
+
* Pass the DOTENV_KEY directly to config options. Defaults to looking for process.env.DOTENV_KEY environment variable. Note this only applies to decrypting .env.vault files. If passed as null or undefined, or not passed at all, dotenv falls back to its traditional job of parsing a .env file.
|
|
52
|
+
*
|
|
53
|
+
* example: `require('dotenv').config({ DOTENV_KEY: 'dotenv://:key_1234…@dotenvx.com/vault/.env.vault?environment=production' })`
|
|
54
|
+
*/
|
|
55
|
+
vaultEnvKey?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Interface for environment variables
|
|
59
|
+
* @public API
|
|
60
|
+
*/
|
|
61
|
+
export interface IEnvObject {
|
|
62
|
+
[name: string]: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interface for dotenv parse output
|
|
66
|
+
* @public API
|
|
67
|
+
*/
|
|
68
|
+
export interface IConfigOutput {
|
|
69
|
+
error?: Error;
|
|
70
|
+
parsed?: IEnvObject;
|
|
71
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Server as HTTPServer } from "http";
|
|
2
|
+
import { IConsoleMessage } from "./console.interface.js";
|
|
3
|
+
import { RenderEngine } from "./render/render.types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Namespace for the Server Application.
|
|
6
|
+
* @namespace Server
|
|
7
|
+
* @public API
|
|
8
|
+
*/
|
|
9
|
+
export declare namespace Server {
|
|
10
|
+
/**
|
|
11
|
+
* Interface for the WebServer application implementation.
|
|
12
|
+
*/
|
|
13
|
+
interface IWebServer {
|
|
14
|
+
listen(port: number | string, appInfo?: IConsoleMessage): Promise<IWebServerPublic>;
|
|
15
|
+
setEngine<T extends RenderEngine.EngineOptions>(engine: RenderEngine.Engine, options?: T): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Constructor type for IWebServer.
|
|
19
|
+
*/
|
|
20
|
+
interface IWebServerConstructor<T extends IWebServer> {
|
|
21
|
+
new (): T;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Interface for the WebServerBuilder.
|
|
25
|
+
* @public API
|
|
26
|
+
*/
|
|
27
|
+
interface IWebServerBuilder {
|
|
28
|
+
/**
|
|
29
|
+
* Start listening on the given port.
|
|
30
|
+
* @param port - The port number to listen on.
|
|
31
|
+
* @param consoleMessage - Optional App info message to display on startup.
|
|
32
|
+
*/
|
|
33
|
+
listen(port: number | string, consoleMessage?: IConsoleMessage): Promise<IWebServerPublic>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Public Interface for the WebServer application.
|
|
37
|
+
* @public API
|
|
38
|
+
*/
|
|
39
|
+
interface IWebServerPublic {
|
|
40
|
+
/**
|
|
41
|
+
* Get the underlying HTTP server. (default: Express.js)
|
|
42
|
+
* @returns The underlying HTTP server after initialization.
|
|
43
|
+
* @public API
|
|
44
|
+
*/
|
|
45
|
+
getHttpServer(): Promise<HTTPServer>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the port the server is listening on.
|
|
48
|
+
* Useful for dynamic port assignment (port: 0) in testing scenarios.
|
|
49
|
+
* @returns The actual port number the server is bound to.
|
|
50
|
+
* @public API
|
|
51
|
+
*/
|
|
52
|
+
getPort(): Promise<number>;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export type IWebServer = Server.IWebServer;
|
|
56
|
+
export type IWebServerConstructor<T extends IWebServer> = Server.IWebServerConstructor<T>;
|
|
57
|
+
export type IWebServerBuilder = Server.IWebServerBuilder;
|
|
58
|
+
export type IWebServerPublic = Server.IWebServerPublic;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface representing application message details for console output.
|
|
3
|
+
* @public API
|
|
4
|
+
*/
|
|
5
|
+
export interface IConsoleMessage {
|
|
6
|
+
appName: string;
|
|
7
|
+
appVersion: string;
|
|
8
|
+
apiVersions?: Array<string>;
|
|
9
|
+
/** CI environment detection info (for bootstrap logging) */
|
|
10
|
+
ciDetection?: {
|
|
11
|
+
detected: boolean;
|
|
12
|
+
platform?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Environment namespace contains all the types and interfaces related to environment configuration.
|
|
3
|
+
* @namespace Environment
|
|
4
|
+
* @public API
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace Env {
|
|
7
|
+
/**
|
|
8
|
+
* Enum representing possible server environments.
|
|
9
|
+
* @public API
|
|
10
|
+
*/
|
|
11
|
+
enum ServerEnvironment {
|
|
12
|
+
Development = "development",
|
|
13
|
+
Production = "production",
|
|
14
|
+
Remote = "remote"
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Type representing possible server environments.
|
|
18
|
+
*/
|
|
19
|
+
type TypeServerEnvironment = "development" | "production" | "remote";
|
|
20
|
+
/**
|
|
21
|
+
* Interface for environment configuration options.
|
|
22
|
+
* @public API
|
|
23
|
+
*/
|
|
24
|
+
interface IEnvironment {
|
|
25
|
+
env: {
|
|
26
|
+
development?: string;
|
|
27
|
+
production?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Type representing possible server environments.
|
|
32
|
+
* @public API
|
|
33
|
+
*/
|
|
34
|
+
type Environment = ServerEnvironment | TypeServerEnvironment | undefined;
|
|
35
|
+
}
|
|
36
|
+
export type Environment = Env.Environment;
|
|
37
|
+
export type IEnvironment = Env.IEnvironment;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { RenderEngine } from "./render/render.types.js";
|
|
2
|
+
export type { IConsoleMessage } from "./console.interface.js";
|
|
3
|
+
export type { IExpressoMiddleware } from "./middleware.interface.js";
|
|
4
|
+
export type { Environment, IEnvironment, Env } from "./environment.interface.js";
|
|
5
|
+
export { IWebServer, IWebServerBuilder, IWebServerConstructor, IWebServerPublic, Server, } from "./application-express.interface.js";
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object where {@link filename} is the final parsed path or {@link template} is the content of the included template
|
|
3
|
+
*/
|
|
4
|
+
export type IncluderResult = {
|
|
5
|
+
filename: string;
|
|
6
|
+
template?: never;
|
|
7
|
+
} | {
|
|
8
|
+
template: string;
|
|
9
|
+
filename?: never;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @param originalPath the path as it appears in the include statement
|
|
13
|
+
* @param parsedPath the previously resolved path
|
|
14
|
+
*
|
|
15
|
+
* @return An {@link IncluderResult} object containing the filename or template data.
|
|
16
|
+
*/
|
|
17
|
+
type IncluderCallback = (originalPath: string, parsedPath: string) => IncluderResult;
|
|
18
|
+
/**
|
|
19
|
+
* Escapes a string using HTML/XML escaping rules.
|
|
20
|
+
*
|
|
21
|
+
* Returns the empty string for `null` or `undefined`.
|
|
22
|
+
*
|
|
23
|
+
* @param markup Input string
|
|
24
|
+
* @return Escaped string
|
|
25
|
+
*/
|
|
26
|
+
type EscapeCallback = (markup?: any) => string;
|
|
27
|
+
export interface Options {
|
|
28
|
+
/**
|
|
29
|
+
* Log the generated JavaScript source for the EJS template to the console.
|
|
30
|
+
*
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
debug?: boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Include additional runtime debugging information in generated template
|
|
36
|
+
* functions.
|
|
37
|
+
*
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
compileDebug?: boolean | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Whether or not to use `with () {}` construct in the generated template
|
|
43
|
+
* functions. If set to `false`, data is still accessible through the object
|
|
44
|
+
* whose name is specified by `ejs.localsName` (defaults to `locals`).
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
_with?: boolean | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Whether to run in strict mode or not.
|
|
51
|
+
* Enforces `_with=false`.
|
|
52
|
+
*
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
strict?: boolean | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* An array of local variables that are always destructured from `localsName`,
|
|
58
|
+
* available even in strict mode.
|
|
59
|
+
*
|
|
60
|
+
* @default []
|
|
61
|
+
*/
|
|
62
|
+
destructuredLocals?: Array<string> | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Remove all safe-to-remove whitespace, including leading and trailing
|
|
65
|
+
* whitespace. It also enables a safer version of `-%>` line slurping for all
|
|
66
|
+
* scriptlet tags (it does not strip new lines of tags in the middle of a
|
|
67
|
+
* line).
|
|
68
|
+
*
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
rmWhitespace?: boolean | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Whether or not to compile a `ClientFunction` that can be rendered
|
|
74
|
+
* in the browser without depending on ejs.js. Otherwise, a `TemplateFunction`
|
|
75
|
+
* will be compiled.
|
|
76
|
+
*
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
client?: boolean | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The escaping function used with `<%=` construct. It is used in rendering
|
|
82
|
+
* and is `.toString()`ed in the generation of client functions.
|
|
83
|
+
*
|
|
84
|
+
* @default ejs.escapeXML
|
|
85
|
+
*/
|
|
86
|
+
escape?: EscapeCallback | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The filename of the template. Required for inclusion and caching unless
|
|
89
|
+
* you are using `renderFile`. Also used for error reporting.
|
|
90
|
+
*
|
|
91
|
+
* @default undefined
|
|
92
|
+
*/
|
|
93
|
+
filename?: string | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* The path to templates root(s). When this is set, absolute paths for includes
|
|
96
|
+
* (/filename.ejs) will be relative to the templates root(s).
|
|
97
|
+
*
|
|
98
|
+
* @default undefined
|
|
99
|
+
*/
|
|
100
|
+
root?: Array<string> | string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* The opening delimiter for all statements. This allows you to clearly delinate
|
|
103
|
+
* the difference between template code and existing delimiters. (It is recommended
|
|
104
|
+
* to synchronize this with the closeDelimiter property.)
|
|
105
|
+
*
|
|
106
|
+
* @default ejs.openDelimiter
|
|
107
|
+
*/
|
|
108
|
+
openDelimiter?: string | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* The closing delimiter for all statements. This allows to to clearly delinate
|
|
111
|
+
* the difference between template code and existing delimiters. (It is recommended
|
|
112
|
+
* to synchronize this with the openDelimiter property.)
|
|
113
|
+
*
|
|
114
|
+
* @default ejs.closeDelimiter
|
|
115
|
+
*/
|
|
116
|
+
closeDelimiter?: string | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Character to use with angle brackets for open/close
|
|
119
|
+
* @default '%'
|
|
120
|
+
*/
|
|
121
|
+
delimiter?: string | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Whether or not to enable caching of template functions. Beware that
|
|
124
|
+
* the options of compilation are not checked as being the same, so
|
|
125
|
+
* special handling is required if, for example, you want to cache client
|
|
126
|
+
* and regular functions of the same file.
|
|
127
|
+
*
|
|
128
|
+
* Requires `filename` to be set. Only works with rendering function.
|
|
129
|
+
*
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
cache?: boolean | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* The Object to which `this` is set during rendering.
|
|
135
|
+
*
|
|
136
|
+
* @default this
|
|
137
|
+
*/
|
|
138
|
+
context?: any;
|
|
139
|
+
/**
|
|
140
|
+
* Whether or not to create an async function instead of a regular function.
|
|
141
|
+
* This requires language support.
|
|
142
|
+
*
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
async?: boolean | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Make sure to set this to 'false' in order to skip UglifyJS parsing,
|
|
148
|
+
* when using ES6 features (`const`, etc) as UglifyJS doesn't understand them.
|
|
149
|
+
* @default true
|
|
150
|
+
*/
|
|
151
|
+
beautify?: boolean | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Name to use for the object storing local variables when not using `with` or destructuring.
|
|
154
|
+
*
|
|
155
|
+
* @default ejs.localsName
|
|
156
|
+
*/
|
|
157
|
+
localsName?: string | undefined;
|
|
158
|
+
/** Set to a string (e.g., 'echo' or 'print') for a function to print output inside scriptlet tags. */
|
|
159
|
+
outputFunctionName?: string | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* An array of paths to use when resolving includes with relative paths
|
|
162
|
+
*/
|
|
163
|
+
views?: Array<string> | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Custom function to handle EJS includes
|
|
166
|
+
*/
|
|
167
|
+
includer?: IncluderCallback;
|
|
168
|
+
}
|
|
169
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Options } from "./ejs.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The Render namespace contains all the types and interfaces related to rendering views.
|
|
4
|
+
* @namespace Render
|
|
5
|
+
* @public API
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace RenderEngine {
|
|
8
|
+
/**
|
|
9
|
+
* Ejs options
|
|
10
|
+
* @typedef {Object} EjsOptions
|
|
11
|
+
* @property {string | Array<string>} viewsDir - The path to the views folder
|
|
12
|
+
* @property {string} viewEngine - The view engine
|
|
13
|
+
* @property {ejs.Options} [serverOptions] - The server options
|
|
14
|
+
* @public API
|
|
15
|
+
*/
|
|
16
|
+
type EjsOptions = {
|
|
17
|
+
viewsDir?: string | Array<string>;
|
|
18
|
+
viewEngine?: string;
|
|
19
|
+
serverOptions?: Options;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Handlebars options
|
|
23
|
+
* @typedef {Object} HandlebarsOptions
|
|
24
|
+
* @property {string} viewsDir - The path to the views folder
|
|
25
|
+
* @property {string} viewEngine - The view engine to be used
|
|
26
|
+
* @property {ConfigOptions} [serverOptions] - The server options
|
|
27
|
+
* @public API
|
|
28
|
+
*/
|
|
29
|
+
type HandlebarsOptions = {
|
|
30
|
+
viewEngine?: string;
|
|
31
|
+
viewsDir?: string;
|
|
32
|
+
partialsDir?: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Pug options
|
|
36
|
+
* @typedef {Object} PugOptions
|
|
37
|
+
* @property {string} viewEngine - The view engine to be used
|
|
38
|
+
* @property {string} viewsDir - The path to the views folder
|
|
39
|
+
* @public API
|
|
40
|
+
*/
|
|
41
|
+
type PugOptions = {
|
|
42
|
+
viewEngine?: string;
|
|
43
|
+
viewsDir?: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The configuration options for the view engine.
|
|
47
|
+
* @typedef {HandlebarsOptions | EjsOptions | PugOptions} RenderOptions
|
|
48
|
+
* @public API
|
|
49
|
+
*/
|
|
50
|
+
type RenderOptions = {
|
|
51
|
+
engine: Engine;
|
|
52
|
+
options?: EngineOptions;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The supported view engines.
|
|
56
|
+
* @enum {string} Engine - The supported view engines.
|
|
57
|
+
* @readonly - This enum is read-only.
|
|
58
|
+
* @public API
|
|
59
|
+
*/
|
|
60
|
+
enum Engine {
|
|
61
|
+
HBS = "hbs",
|
|
62
|
+
EJS = "ejs",
|
|
63
|
+
PUG = "pug"
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The configuration options for the view engine.
|
|
67
|
+
* @typedef {HandlebarsOptions | EjsOptions} EngineOptions
|
|
68
|
+
* @public API
|
|
69
|
+
*/
|
|
70
|
+
type EngineOptions = HandlebarsOptions | EjsOptions | PugOptions;
|
|
71
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Service } from "ts-node";
|
|
2
|
+
import { ExpressoConfig } from "../config/index.js";
|
|
3
|
+
export declare function printError(message: string, component: string): void;
|
|
4
|
+
/**
|
|
5
|
+
* Singleton compiler class
|
|
6
|
+
*/
|
|
7
|
+
export declare class Compiler {
|
|
8
|
+
private static instance;
|
|
9
|
+
private constructor();
|
|
10
|
+
static get Instance(): Compiler;
|
|
11
|
+
getService(): Promise<Service>;
|
|
12
|
+
static interopRequireDefault(obj: any): {
|
|
13
|
+
default: any;
|
|
14
|
+
};
|
|
15
|
+
static findConfig(dir: string): Promise<string>;
|
|
16
|
+
static loadConfig(): Promise<ExpressoConfig>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Compiler } from "./compiler.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger utility for dotenv
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
Info = "info",
|
|
6
|
+
Warn = "warn",
|
|
7
|
+
Debug = "debug"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Log a message
|
|
11
|
+
* @param message - The message to log
|
|
12
|
+
* @param logLevel - The log level. Defaults to LogLevel.Info
|
|
13
|
+
*/
|
|
14
|
+
export declare function log(message: string, logLevel?: LogLevel): void;
|
|
15
|
+
export declare function printError(message: string, component: string): void;
|
|
16
|
+
export declare function printSuccess(message: string, component: string): void;
|
|
17
|
+
export declare function printWarning(message: string, component?: string): void;
|
|
18
|
+
export declare function printGenerateError(schematic: string, file: string): Promise<void>;
|
|
19
|
+
export declare function printGenerateSuccess(schematic: string, file: string): Promise<void>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
export function printError(message, component) {
|
|
6
|
+
console.error(chalk.red(`${message}:`, chalk.bold(chalk.white(`[${component}] ❌`))));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The path to the expressots.config.ts file
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
const EXPRESSOTS_CONFIG = path.join(process.cwd(), "expressots.config.ts");
|
|
13
|
+
/**
|
|
14
|
+
* The config object
|
|
15
|
+
*/
|
|
16
|
+
let globalConfigObject = null;
|
|
17
|
+
/**
|
|
18
|
+
* The ts-node register options
|
|
19
|
+
*/
|
|
20
|
+
const regOpt = {
|
|
21
|
+
compilerOptions: {
|
|
22
|
+
module: "commonjs",
|
|
23
|
+
},
|
|
24
|
+
moduleTypes: {
|
|
25
|
+
"**": "cjs",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Singleton compiler class
|
|
30
|
+
*/
|
|
31
|
+
export class Compiler {
|
|
32
|
+
static instance;
|
|
33
|
+
constructor() { }
|
|
34
|
+
static get Instance() {
|
|
35
|
+
if (!Compiler.instance) {
|
|
36
|
+
Compiler.instance = new Compiler();
|
|
37
|
+
}
|
|
38
|
+
return Compiler.instance;
|
|
39
|
+
}
|
|
40
|
+
async getService() {
|
|
41
|
+
const tsnode = await import("ts-node");
|
|
42
|
+
const compiler = tsnode.register(regOpt);
|
|
43
|
+
return compiler;
|
|
44
|
+
}
|
|
45
|
+
static interopRequireDefault(obj) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
47
|
+
const module = require(obj);
|
|
48
|
+
return module && module.__esModule ? module : { default: module };
|
|
49
|
+
}
|
|
50
|
+
static async findConfig(dir) {
|
|
51
|
+
const configPath = path.join(dir, "expressots.config.ts");
|
|
52
|
+
const exists = existsSync(configPath);
|
|
53
|
+
if (exists)
|
|
54
|
+
return configPath;
|
|
55
|
+
const parentDir = path.join(dir, "..");
|
|
56
|
+
if (parentDir === dir) {
|
|
57
|
+
printError("No config file found!", "expressots.config.ts");
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
return Compiler.findConfig(parentDir);
|
|
61
|
+
}
|
|
62
|
+
static async loadConfig() {
|
|
63
|
+
const compiler = await Compiler.Instance.getService();
|
|
64
|
+
compiler.enabled(true);
|
|
65
|
+
globalConfigObject = Compiler.interopRequireDefault(await Compiler.findConfig(process.cwd()));
|
|
66
|
+
compiler.enabled(false);
|
|
67
|
+
return globalConfigObject.default;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Compiler } from "./compiler.js";
|