@event-driven-io/emmett 0.20.2-alpha.4 → 0.20.2-alpha.5

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,130 @@
1
+ // src/validation/index.ts
2
+ var ValidationErrors = /* @__PURE__ */ ((ValidationErrors2) => {
3
+ ValidationErrors2["NOT_A_NONEMPTY_STRING"] = "NOT_A_NONEMPTY_STRING";
4
+ ValidationErrors2["NOT_A_POSITIVE_NUMBER"] = "NOT_A_POSITIVE_NUMBER";
5
+ ValidationErrors2["NOT_AN_UNSIGNED_BIGINT"] = "NOT_AN_UNSIGNED_BIGINT";
6
+ return ValidationErrors2;
7
+ })(ValidationErrors || {});
8
+ var isNumber = (val) => typeof val === "number" && val === val;
9
+ var isString = (val) => typeof val === "string";
10
+ var assertNotEmptyString = (value) => {
11
+ if (!isString(value) || value.length === 0) {
12
+ throw new ValidationError("NOT_A_NONEMPTY_STRING" /* NOT_A_NONEMPTY_STRING */);
13
+ }
14
+ return value;
15
+ };
16
+ var assertPositiveNumber = (value) => {
17
+ if (!isNumber(value) || value <= 0) {
18
+ throw new ValidationError("NOT_A_POSITIVE_NUMBER" /* NOT_A_POSITIVE_NUMBER */);
19
+ }
20
+ return value;
21
+ };
22
+ var assertUnsignedBigInt = (value) => {
23
+ const number = BigInt(value);
24
+ if (number < 0) {
25
+ throw new ValidationError("NOT_AN_UNSIGNED_BIGINT" /* NOT_AN_UNSIGNED_BIGINT */);
26
+ }
27
+ return number;
28
+ };
29
+
30
+ // src/errors/index.ts
31
+ var isErrorConstructor = (expect) => {
32
+ return typeof expect === "function" && expect.prototype && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
33
+ expect.prototype.constructor === expect;
34
+ };
35
+ var EmmettError = class _EmmettError extends Error {
36
+ errorCode;
37
+ constructor(options) {
38
+ const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
39
+ const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
40
+ super(message);
41
+ this.errorCode = errorCode;
42
+ Object.setPrototypeOf(this, _EmmettError.prototype);
43
+ }
44
+ };
45
+ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
46
+ constructor(current, expected, message) {
47
+ super({
48
+ errorCode: 412,
49
+ message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
50
+ });
51
+ this.current = current;
52
+ this.expected = expected;
53
+ Object.setPrototypeOf(this, _ConcurrencyError.prototype);
54
+ }
55
+ };
56
+ var ValidationError = class _ValidationError extends EmmettError {
57
+ constructor(message) {
58
+ super({
59
+ errorCode: 400,
60
+ message: message ?? `Validation Error ocurred during Emmett processing`
61
+ });
62
+ Object.setPrototypeOf(this, _ValidationError.prototype);
63
+ }
64
+ };
65
+ var IllegalStateError = class _IllegalStateError extends EmmettError {
66
+ constructor(message) {
67
+ super({
68
+ errorCode: 403,
69
+ message: message ?? `Illegal State ocurred during Emmett processing`
70
+ });
71
+ Object.setPrototypeOf(this, _IllegalStateError.prototype);
72
+ }
73
+ };
74
+ var NotFoundError = class _NotFoundError extends EmmettError {
75
+ constructor(options) {
76
+ super({
77
+ errorCode: 404,
78
+ message: options?.message ?? (options?.id ? options.type ? `${options.type} with ${options.id} was not found during Emmett processing` : `State with ${options.id} was not found during Emmett processing` : options?.type ? `${options.type} was not found during Emmett processing` : "State was not found during Emmett processing")
79
+ });
80
+ Object.setPrototypeOf(this, _NotFoundError.prototype);
81
+ }
82
+ };
83
+
84
+ // src/validation/dates.ts
85
+ var formatDateToUtcYYYYMMDD = (date) => {
86
+ const formatter = new Intl.DateTimeFormat("en-CA", {
87
+ timeZone: "UTC",
88
+ year: "numeric",
89
+ month: "2-digit",
90
+ day: "2-digit"
91
+ });
92
+ return formatter.format(date);
93
+ };
94
+ var isValidYYYYMMDD = (dateString) => {
95
+ const regex = /^\d{4}-\d{2}-\d{2}$/;
96
+ return regex.test(dateString);
97
+ };
98
+ var parseDateFromUtcYYYYMMDD = (dateString) => {
99
+ const date = /* @__PURE__ */ new Date(dateString + "T00:00:00Z");
100
+ if (!isValidYYYYMMDD(dateString)) {
101
+ throw new ValidationError("Invalid date format, must be yyyy-mm-dd");
102
+ }
103
+ if (isNaN(date.getTime())) {
104
+ throw new ValidationError("Invalid date format");
105
+ }
106
+ return date;
107
+ };
108
+
109
+ // src/config/plugins/index.ts
110
+ var isPluginConfig = (plugin) => plugin !== void 0 && (typeof plugin === "string" || "name" in plugin && plugin.name !== void 0 && typeof plugin.name === "string");
111
+
112
+ export {
113
+ formatDateToUtcYYYYMMDD,
114
+ isValidYYYYMMDD,
115
+ parseDateFromUtcYYYYMMDD,
116
+ ValidationErrors,
117
+ isNumber,
118
+ isString,
119
+ assertNotEmptyString,
120
+ assertPositiveNumber,
121
+ assertUnsignedBigInt,
122
+ isErrorConstructor,
123
+ EmmettError,
124
+ ConcurrencyError,
125
+ ValidationError,
126
+ IllegalStateError,
127
+ NotFoundError,
128
+ isPluginConfig
129
+ };
130
+ //# sourceMappingURL=chunk-AEEEXE2R.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/validation/index.ts","../src/errors/index.ts","../src/validation/dates.ts","../src/config/plugins/index.ts"],"sourcesContent":["import { ValidationError } from '../errors';\n\nexport const enum ValidationErrors {\n NOT_A_NONEMPTY_STRING = 'NOT_A_NONEMPTY_STRING',\n NOT_A_POSITIVE_NUMBER = 'NOT_A_POSITIVE_NUMBER',\n NOT_AN_UNSIGNED_BIGINT = 'NOT_AN_UNSIGNED_BIGINT',\n}\n\nexport const isNumber = (val: unknown): val is number =>\n typeof val === 'number' && val === val;\n\nexport const isString = (val: unknown): val is string =>\n typeof val === 'string';\n\nexport const assertNotEmptyString = (value: unknown): string => {\n if (!isString(value) || value.length === 0) {\n throw new ValidationError(ValidationErrors.NOT_A_NONEMPTY_STRING);\n }\n return value;\n};\n\nexport const assertPositiveNumber = (value: unknown): number => {\n if (!isNumber(value) || value <= 0) {\n throw new ValidationError(ValidationErrors.NOT_A_POSITIVE_NUMBER);\n }\n return value;\n};\n\nexport const assertUnsignedBigInt = (value: string): bigint => {\n const number = BigInt(value);\n if (number < 0) {\n throw new ValidationError(ValidationErrors.NOT_AN_UNSIGNED_BIGINT);\n }\n return number;\n};\n\nexport * from './dates';\n","import { isNumber, isString } from '../validation';\n\nexport type ErrorConstructor<ErrorType extends Error> = new (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => ErrorType;\n\nexport const isErrorConstructor = <ErrorType extends Error>(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n expect: Function,\n): expect is ErrorConstructor<ErrorType> => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n typeof expect === 'function' &&\n expect.prototype &&\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect.prototype.constructor === expect\n );\n};\n\nexport class EmmettError extends Error {\n public errorCode: number;\n\n constructor(\n options?: { errorCode: number; message?: string } | string | number,\n ) {\n const errorCode =\n options && typeof options === 'object' && 'errorCode' in options\n ? options.errorCode\n : isNumber(options)\n ? options\n : 500;\n const message =\n options && typeof options === 'object' && 'message' in options\n ? options.message\n : isString(options)\n ? options\n : `Error with status code '${errorCode}' ocurred during Emmett processing`;\n\n super(message);\n this.errorCode = errorCode;\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, EmmettError.prototype);\n }\n}\n\nexport class ConcurrencyError extends EmmettError {\n constructor(\n public current: string | undefined,\n public expected: string,\n message?: string,\n ) {\n super({\n errorCode: 412,\n message:\n message ??\n `Expected version ${expected.toString()} does not match current ${current?.toString()}`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyError.prototype);\n }\n}\n\nexport class ValidationError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 400,\n message: message ?? `Validation Error ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class IllegalStateError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 403,\n message: message ?? `Illegal State ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, IllegalStateError.prototype);\n }\n}\n\nexport class NotFoundError extends EmmettError {\n constructor(options?: { id: string; type: string; message?: string }) {\n super({\n errorCode: 404,\n message:\n options?.message ??\n (options?.id\n ? options.type\n ? `${options.type} with ${options.id} was not found during Emmett processing`\n : `State with ${options.id} was not found during Emmett processing`\n : options?.type\n ? `${options.type} was not found during Emmett processing`\n : 'State was not found during Emmett processing'),\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n","import { ValidationError } from '../errors';\n\nexport const formatDateToUtcYYYYMMDD = (date: Date) => {\n // Use the 'en-CA' locale which formats as 'yyyy-mm-dd'\n const formatter = new Intl.DateTimeFormat('en-CA', {\n timeZone: 'UTC',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n });\n\n // Format the date\n return formatter.format(date);\n};\n\n// Function to validate 'yyyy-mm-dd' format\nexport const isValidYYYYMMDD = (dateString: string) => {\n const regex = /^\\d{4}-\\d{2}-\\d{2}$/;\n return regex.test(dateString);\n};\n\nexport const parseDateFromUtcYYYYMMDD = (dateString: string) => {\n const date = new Date(dateString + 'T00:00:00Z');\n\n if (!isValidYYYYMMDD(dateString)) {\n throw new ValidationError('Invalid date format, must be yyyy-mm-dd');\n }\n\n if (isNaN(date.getTime())) {\n throw new ValidationError('Invalid date format');\n }\n\n return date;\n};\n","export type EmmettPluginConfig =\n | {\n name: string;\n register: EmmettPluginRegistration[];\n }\n | string;\n\nexport type EmmettPluginType = 'cli';\n\nexport type EmmettCliPluginRegistration = { pluginType: 'cli'; path?: string };\n\nexport type EmmettPluginRegistration = EmmettCliPluginRegistration;\n\nexport type EmmettCliCommand = {\n addCommand<CliCommand>(command: CliCommand): CliCommand;\n};\n\nexport type EmmettCliPlugin = {\n pluginType: 'cli';\n name: string;\n registerCommands: (program: EmmettCliCommand) => Promise<void> | void;\n};\n\nexport type EmmettPlugin = EmmettCliPlugin;\n\nexport const isPluginConfig = (\n plugin: Partial<EmmettPluginConfig> | string | undefined,\n): plugin is EmmettPluginConfig =>\n plugin !== undefined &&\n (typeof plugin === 'string' ||\n ('name' in plugin &&\n plugin.name !== undefined &&\n typeof plugin.name === 'string'));\n"],"mappings":"AAEO,IAAWA,OAChBA,EAAA,sBAAwB,wBACxBA,EAAA,sBAAwB,wBACxBA,EAAA,uBAAyB,yBAHTA,OAAA,IAMLC,EAAYC,GACvB,OAAOA,GAAQ,UAAYA,IAAQA,EAExBC,EAAYD,GACvB,OAAOA,GAAQ,SAEJE,EAAwBC,GAA2B,CAC9D,GAAI,CAACF,EAASE,CAAK,GAAKA,EAAM,SAAW,EACvC,MAAM,IAAIC,EAAgB,uBAAsC,EAElE,OAAOD,CACT,EAEaE,EAAwBF,GAA2B,CAC9D,GAAI,CAACJ,EAASI,CAAK,GAAKA,GAAS,EAC/B,MAAM,IAAIC,EAAgB,uBAAsC,EAElE,OAAOD,CACT,EAEaG,EAAwBH,GAA0B,CAC7D,IAAMI,EAAS,OAAOJ,CAAK,EAC3B,GAAII,EAAS,EACX,MAAM,IAAIH,EAAgB,wBAAuC,EAEnE,OAAOG,CACT,EC3BO,IAAMC,EAEXC,GAIE,OAAOA,GAAW,YAClBA,EAAO,WAEPA,EAAO,UAAU,cAAgBA,EAIxBC,EAAN,MAAMC,UAAoB,KAAM,CAC9B,UAEP,YACEC,EACA,CACA,IAAMC,EACJD,GAAW,OAAOA,GAAY,UAAY,cAAeA,EACrDA,EAAQ,UACRE,EAASF,CAAO,EACdA,EACA,IACFG,EACJH,GAAW,OAAOA,GAAY,UAAY,YAAaA,EACnDA,EAAQ,QACRI,EAASJ,CAAO,EACdA,EACA,2BAA2BC,CAAS,qCAE5C,MAAME,CAAO,EACb,KAAK,UAAYF,EAGjB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GAAI,MAAMJ,EAAK,QAAQ,CAAC,EACtB,MAAM,IAAII,EAAgB,qBAAqB,EAGjD,OAAOJ,CACT,ECRO,IAAMK,EACXC,GAEAA,IAAW,SACV,OAAOA,GAAW,UAChB,SAAUA,GACTA,EAAO,OAAS,QAChB,OAAOA,EAAO,MAAS","names":["ValidationErrors","isNumber","val","isString","assertNotEmptyString","value","ValidationError","assertPositiveNumber","assertUnsignedBigInt","number","isErrorConstructor","expect","EmmettError","_EmmettError","options","errorCode","isNumber","message","isString","ConcurrencyError","_ConcurrencyError","current","expected","ValidationError","_ValidationError","IllegalStateError","_IllegalStateError","NotFoundError","_NotFoundError","formatDateToUtcYYYYMMDD","date","isValidYYYYMMDD","dateString","parseDateFromUtcYYYYMMDD","ValidationError","isPluginConfig","plugin"]}
1
+ {"version":3,"sources":["../src/validation/index.ts","../src/errors/index.ts","../src/validation/dates.ts","../src/config/plugins/index.ts"],"sourcesContent":["import { ValidationError } from '../errors';\n\nexport const enum ValidationErrors {\n NOT_A_NONEMPTY_STRING = 'NOT_A_NONEMPTY_STRING',\n NOT_A_POSITIVE_NUMBER = 'NOT_A_POSITIVE_NUMBER',\n NOT_AN_UNSIGNED_BIGINT = 'NOT_AN_UNSIGNED_BIGINT',\n}\n\nexport const isNumber = (val: unknown): val is number =>\n typeof val === 'number' && val === val;\n\nexport const isString = (val: unknown): val is string =>\n typeof val === 'string';\n\nexport const assertNotEmptyString = (value: unknown): string => {\n if (!isString(value) || value.length === 0) {\n throw new ValidationError(ValidationErrors.NOT_A_NONEMPTY_STRING);\n }\n return value;\n};\n\nexport const assertPositiveNumber = (value: unknown): number => {\n if (!isNumber(value) || value <= 0) {\n throw new ValidationError(ValidationErrors.NOT_A_POSITIVE_NUMBER);\n }\n return value;\n};\n\nexport const assertUnsignedBigInt = (value: string): bigint => {\n const number = BigInt(value);\n if (number < 0) {\n throw new ValidationError(ValidationErrors.NOT_AN_UNSIGNED_BIGINT);\n }\n return number;\n};\n\nexport * from './dates';\n","import { isNumber, isString } from '../validation';\n\nexport type ErrorConstructor<ErrorType extends Error> = new (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => ErrorType;\n\nexport const isErrorConstructor = <ErrorType extends Error>(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n expect: Function,\n): expect is ErrorConstructor<ErrorType> => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n typeof expect === 'function' &&\n expect.prototype &&\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect.prototype.constructor === expect\n );\n};\n\nexport class EmmettError extends Error {\n public errorCode: number;\n\n constructor(\n options?: { errorCode: number; message?: string } | string | number,\n ) {\n const errorCode =\n options && typeof options === 'object' && 'errorCode' in options\n ? options.errorCode\n : isNumber(options)\n ? options\n : 500;\n const message =\n options && typeof options === 'object' && 'message' in options\n ? options.message\n : isString(options)\n ? options\n : `Error with status code '${errorCode}' ocurred during Emmett processing`;\n\n super(message);\n this.errorCode = errorCode;\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, EmmettError.prototype);\n }\n}\n\nexport class ConcurrencyError extends EmmettError {\n constructor(\n public current: string | undefined,\n public expected: string,\n message?: string,\n ) {\n super({\n errorCode: 412,\n message:\n message ??\n `Expected version ${expected.toString()} does not match current ${current?.toString()}`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ConcurrencyError.prototype);\n }\n}\n\nexport class ValidationError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 400,\n message: message ?? `Validation Error ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class IllegalStateError extends EmmettError {\n constructor(message?: string) {\n super({\n errorCode: 403,\n message: message ?? `Illegal State ocurred during Emmett processing`,\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, IllegalStateError.prototype);\n }\n}\n\nexport class NotFoundError extends EmmettError {\n constructor(options?: { id: string; type: string; message?: string }) {\n super({\n errorCode: 404,\n message:\n options?.message ??\n (options?.id\n ? options.type\n ? `${options.type} with ${options.id} was not found during Emmett processing`\n : `State with ${options.id} was not found during Emmett processing`\n : options?.type\n ? `${options.type} was not found during Emmett processing`\n : 'State was not found during Emmett processing'),\n });\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n","import { ValidationError } from '../errors';\n\nexport const formatDateToUtcYYYYMMDD = (date: Date) => {\n // Use the 'en-CA' locale which formats as 'yyyy-mm-dd'\n const formatter = new Intl.DateTimeFormat('en-CA', {\n timeZone: 'UTC',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n });\n\n // Format the date\n return formatter.format(date);\n};\n\n// Function to validate 'yyyy-mm-dd' format\nexport const isValidYYYYMMDD = (dateString: string) => {\n const regex = /^\\d{4}-\\d{2}-\\d{2}$/;\n return regex.test(dateString);\n};\n\nexport const parseDateFromUtcYYYYMMDD = (dateString: string) => {\n const date = new Date(dateString + 'T00:00:00Z');\n\n if (!isValidYYYYMMDD(dateString)) {\n throw new ValidationError('Invalid date format, must be yyyy-mm-dd');\n }\n\n if (isNaN(date.getTime())) {\n throw new ValidationError('Invalid date format');\n }\n\n return date;\n};\n","export type EmmettPluginConfig =\n | {\n name: string;\n register: EmmettPluginRegistration[];\n }\n | string;\n\nexport type EmmettPluginType = 'cli';\n\nexport type EmmettCliPluginRegistration = { pluginType: 'cli'; path?: string };\n\nexport type EmmettPluginRegistration = EmmettCliPluginRegistration;\n\nexport type EmmettCliCommand = {\n addCommand<CliCommand>(command: CliCommand): CliCommand;\n};\n\nexport type EmmettCliPlugin = {\n pluginType: 'cli';\n name: string;\n registerCommands: (program: EmmettCliCommand) => Promise<void> | void;\n};\n\nexport type EmmettPlugin = EmmettCliPlugin;\n\nexport const isPluginConfig = (\n plugin: Partial<EmmettPluginConfig> | string | undefined,\n): plugin is EmmettPluginConfig =>\n plugin !== undefined &&\n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d,SAAO,MAAM,KAAK,UAAU;AAC9B;AAEO,IAAM,2BAA2B,CAAC,eAAuB;AAC9D,QAAM,OAAO,oBAAI,KAAK,aAAa,YAAY;AAE/C,MAAI,CAAC,gBAAgB,UAAU,GAAG;AAChC,UAAM,IAAI,gBAAgB,yCAAyC;AAAA,EACrE;AAEA,MAAI,MAAM,KAAK,QAAQ,CAAC,GAAG;AACzB,UAAM,IAAI,gBAAgB,qBAAqB;AAAA,EACjD;AAEA,SAAO;AACT;;;ACRO,IAAM,iBAAiB,CAC5B,WAEA,WAAW,WACV,OAAO,WAAW,YAChB,UAAU,UACT,OAAO,SAAS,UAChB,OAAO,OAAO,SAAS;","names":["ValidationErrors"]}
package/dist/cli.js CHANGED
@@ -1,16 +1,200 @@
1
1
  #!/usr/bin/env node
2
- import{k as o,p as f}from"./chunk-3XBWME34.js";import{Command as $}from"commander";import{Command as d}from"commander";import{writeFileSync as P}from"node:fs";import{exit as c}from"process";var s=(e=["emmett-expressjs"])=>`
2
+ import {
3
+ EmmettError,
4
+ isPluginConfig
5
+ } from "./chunk-AEEEXE2R.js";
6
+
7
+ // src/cli.ts
8
+ import { Command } from "commander";
9
+
10
+ // src/commandLine/config.ts
11
+ import { Command as CliCommand } from "commander";
12
+ import { writeFileSync } from "node:fs";
13
+ import { exit } from "process";
14
+ var sampleConfig = (plugins = ["emmett-expressjs"]) => {
15
+ const pluginsNames = plugins.length > 0 ? `[
16
+ ${plugins.map((p) => `"${p}"`).join(",\n")}
17
+ ]` : "[]";
18
+ return `
3
19
  export default {
4
- plugins: ${e.length>0?`[
5
- ${e.map(t=>`"${t}"`).join(`,
6
- `)}
7
- ]`:"[]"},
8
- };
9
- `,h=(e,n)=>{try{P(e,s(n),"utf8"),console.log(`Configuration file stored at: ${e}`)}catch(t){console.error(`Error: Couldn't store config file: ${e}!`),console.error(t),process.exit(1)}},C=new d("config").description("Manage Pongo configuration");C.command("sample").description("Generate or print sample configuration").option("-plg, --plugins <name>","Specify the plugin name",(e,n)=>n.concat([e]),[]).option("-f, --file <path>","Path to configuration file with collection list").option("-g, --generate","Generate sample config file").option("-p, --print","Print sample config file").action(e=>{let n=e.plugin.length>0?e.plugin:["@event-driven-io/emmett-expressjs"];!("print"in e)&&!("generate"in e)&&(console.error(`Error: Please provide either:
10
- --print param to print sample config or
11
- --generate to generate sample config file`),c(1)),"print"in e?console.log(`${s(n)}`):"generate"in e&&(e.file||(console.error("Error: You need to provide a config file through a --file"),c(1)),h(e.file,n))});import"commander";import E from"path";var m={missingDefaultExport:`Error: Config should contain default export, e.g.
20
+ plugins: ${pluginsNames},
21
+ };
22
+ `;
23
+ };
24
+ var generateConfigFile = (configPath, collectionNames) => {
25
+ try {
26
+ writeFileSync(configPath, sampleConfig(collectionNames), "utf8");
27
+ console.log(`Configuration file stored at: ${configPath}`);
28
+ } catch (error) {
29
+ console.error(`Error: Couldn't store config file: ${configPath}!`);
30
+ console.error(error);
31
+ process.exit(1);
32
+ }
33
+ };
34
+ var configCommand = new CliCommand("config").description(
35
+ "Manage Pongo configuration"
36
+ );
37
+ configCommand.command("sample").description("Generate or print sample configuration").option(
38
+ "-plg, --plugins <name>",
39
+ "Specify the plugin name",
40
+ (value, previous) => {
41
+ return previous.concat([value]);
42
+ },
43
+ []
44
+ ).option(
45
+ "-f, --file <path>",
46
+ "Path to configuration file with collection list"
47
+ ).option("-g, --generate", "Generate sample config file").option("-p, --print", "Print sample config file").action((options) => {
48
+ const plugins = options.plugin.length > 0 ? options.plugin : ["@event-driven-io/emmett-expressjs"];
49
+ if (!("print" in options) && !("generate" in options)) {
50
+ console.error(
51
+ "Error: Please provide either:\n--print param to print sample config or\n--generate to generate sample config file"
52
+ );
53
+ exit(1);
54
+ }
55
+ if ("print" in options) {
56
+ console.log(`${sampleConfig(plugins)}`);
57
+ } else if ("generate" in options) {
58
+ if (!options.file) {
59
+ console.error(
60
+ "Error: You need to provide a config file through a --file"
61
+ );
62
+ exit(1);
63
+ }
64
+ generateConfigFile(options.file, plugins);
65
+ }
66
+ });
67
+
68
+ // src/commandLine/plugins.ts
69
+ import "commander";
70
+ import path from "path";
71
+ var PluginsConfigImportError = {
72
+ missingDefaultExport: `Error: Config should contain default export, e.g.
73
+
74
+ ${sampleConfig()}`,
75
+ missingPluginsPropertyExport: `Error: Config should contain default export with plugins array, e.g.
12
76
 
13
- ${s()}`,missingPluginsPropertyExport:`Error: Config should contain default export with plugins array, e.g.
77
+ ${sampleConfig()}`,
78
+ wrongPluginStructure: `Error: Plugin config should be either string with plugin name or object with plugin name, e.g. { name: 'emmett-expressjs' }`
79
+ };
80
+ var importPluginsConfig = async (options) => {
81
+ const configPath = path.join(
82
+ process.cwd(),
83
+ options?.configPath ?? "./dist/emmett.config.js"
84
+ );
85
+ console.log("IMPORTING" + configPath);
86
+ try {
87
+ const imported = await import(configPath);
88
+ if (!imported.default) {
89
+ return new EmmettError(PluginsConfigImportError.missingDefaultExport);
90
+ }
91
+ if (!imported.default.plugins || !Array.isArray(imported.default.plugins)) {
92
+ return new EmmettError(
93
+ PluginsConfigImportError.missingPluginsPropertyExport
94
+ );
95
+ }
96
+ if (!imported.default.plugins.every(isPluginConfig)) {
97
+ return new EmmettError(PluginsConfigImportError.wrongPluginStructure);
98
+ }
99
+ return { plugins: imported.default.plugins };
100
+ } catch (error) {
101
+ if (!options?.configPath) {
102
+ console.warn("Didn`t find config file: " + configPath, error);
103
+ return { plugins: [] };
104
+ }
105
+ return new EmmettError(
106
+ `Error: Couldn't load file:` + error.toString()
107
+ );
108
+ }
109
+ };
110
+ var loadPlugins = async (options) => {
111
+ try {
112
+ const pluginsConfig = await importPluginsConfig({
113
+ configPath: options?.configPath
114
+ });
115
+ if (pluginsConfig instanceof EmmettError) throw pluginsConfig;
116
+ if (pluginsConfig.plugins.length === 0) {
117
+ console.log(`No extensions specified in config ${options?.configPath}.`);
118
+ return [];
119
+ }
120
+ const pluginsToLoad = filterPluginsByType(
121
+ pluginsConfig.plugins,
122
+ options?.pluginType
123
+ );
124
+ const pluginsPromises = pluginsToLoad.map(async (pluginConfig) => {
125
+ const importPath = getImportPath(pluginConfig, options?.pluginType);
126
+ try {
127
+ const plugin = await import(importPath);
128
+ console.info(`Loaded plugin: ${importPath}`);
129
+ if (!plugin.default) {
130
+ throw new Error(`Plugin: ${importPath} is missing default export`);
131
+ }
132
+ return plugin.default;
133
+ } catch (error) {
134
+ console.error(`Failed to load extension "${importPath}":`, error);
135
+ return void 0;
136
+ }
137
+ });
138
+ return (await Promise.all(pluginsPromises)).filter(
139
+ (plugin) => plugin !== void 0
140
+ );
141
+ } catch (error) {
142
+ console.error(`Failed to load config ${options?.configPath}:`, error);
143
+ return [];
144
+ }
145
+ };
146
+ var registerCliPlugins = async (program2, plugins) => {
147
+ const result = [];
148
+ for (const plugin of plugins) {
149
+ const pluginName = plugin.name;
150
+ if (!("registerCommands" in plugin)) {
151
+ console.warn(`No registerCommands function found in ${pluginName}`);
152
+ }
153
+ await plugin.registerCommands(program2);
154
+ console.log(`Loaded extension: ${plugin.name}`);
155
+ result.push(plugin);
156
+ }
157
+ };
158
+ var filterPluginsByType = (plugins, pluginType) => plugins.filter(
159
+ (p) => typeof p === "string" || pluginType && (p.register === void 0 || p.register.some((r) => r.pluginType === pluginType))
160
+ );
161
+ var getImportPath = (pluginConfig, pluginType) => {
162
+ if (typeof pluginConfig === "string") {
163
+ return pluginType ? `${pluginConfig}/${pluginType}` : pluginConfig;
164
+ }
165
+ const pluginSubpath = pluginConfig.register.find((r) => pluginType && r.pluginType === pluginType)?.path ?? pluginType;
166
+ return pluginSubpath ? `${pluginConfig.name}/${pluginSubpath}` : pluginConfig.name;
167
+ };
14
168
 
15
- ${s()}`,wrongPluginStructure:"Error: Plugin config should be either string with plugin name or object with plugin name, e.g. { name: 'emmett-expressjs' }"},y=async e=>{let n=E.join(process.cwd(),e?.configPath??"./dist/emmett.config.js");console.log("IMPORTING"+n);try{let t=await import(n);return t.default?!t.default.plugins||!Array.isArray(t.default.plugins)?new o(m.missingPluginsPropertyExport):t.default.plugins.every(f)?{plugins:t.default.plugins}:new o(m.wrongPluginStructure):new o(m.missingDefaultExport)}catch(t){return e?.configPath?new o("Error: Couldn't load file:"+t.toString()):(console.warn("Didn`t find config file: "+n,t),{plugins:[]})}},p=async e=>{try{let n=await y({configPath:e?.configPath});if(n instanceof o)throw n;if(n.plugins.length===0)return console.log(`No extensions specified in config ${e?.configPath}.`),[];let i=x(n.plugins,e?.pluginType).map(async r=>{let l=w(r,e?.pluginType);try{let a=await import(l);if(console.info(`Loaded plugin: ${l}`),!a.default)throw new Error(`Plugin: ${l} is missing default export`);return a.default}catch(a){console.error(`Failed to load extension "${l}":`,a);return}});return(await Promise.all(i)).filter(r=>r!==void 0)}catch(n){return console.error(`Failed to load config ${e?.configPath}:`,n),[]}},u=async(e,n)=>{let t=[];for(let i of n){let r=i.name;"registerCommands"in i||console.warn(`No registerCommands function found in ${r}`),await i.registerCommands(e),console.log(`Loaded extension: ${i.name}`),t.push(i)}},x=(e,n)=>e.filter(t=>typeof t=="string"||n&&(t.register===void 0||t.register.some(i=>i.pluginType===n))),w=(e,n)=>{if(typeof e=="string")return n?`${e}/${n}`:e;let t=e.register.find(i=>n&&i.pluginType===n)?.path??n;return t?`${e.name}/${t}`:e.name};var g=new $;g.name("emmett").description("CLI tool for Emmett").option("--config <path>","Path to the configuration file");var v=async()=>{let e=process.argv.indexOf("--config"),n=e!==-1&&process.argv.length>e+1?process.argv[e+1]:void 0;try{let t=await p({pluginType:"cli",configPath:n});await u(g,t),g.parse(process.argv)}catch(t){console.error(`Failed to load config from ${n}:`,t)}};v().catch(e=>{console.error("CLI initialization failed:"),console.error(e)});var Y=g;export{C as configCommand,Y as default,h as generateConfigFile,y as importPluginsConfig,p as loadPlugins,u as registerCliPlugins,s as sampleConfig};
169
+ // src/cli.ts
170
+ var program = new Command();
171
+ program.name("emmett").description("CLI tool for Emmett").option("--config <path>", "Path to the configuration file");
172
+ var initCLI = async () => {
173
+ const configIndex = process.argv.indexOf("--config");
174
+ const configPath = configIndex !== -1 && process.argv.length > configIndex + 1 ? process.argv[configIndex + 1] : void 0;
175
+ try {
176
+ const plugins = await loadPlugins({
177
+ pluginType: "cli",
178
+ configPath
179
+ });
180
+ await registerCliPlugins(program, plugins);
181
+ program.parse(process.argv);
182
+ } catch (err) {
183
+ console.error(`Failed to load config from ${configPath}:`, err);
184
+ }
185
+ };
186
+ initCLI().catch((err) => {
187
+ console.error(`CLI initialization failed:`);
188
+ console.error(err);
189
+ });
190
+ var cli_default = program;
191
+ export {
192
+ configCommand,
193
+ cli_default as default,
194
+ generateConfigFile,
195
+ importPluginsConfig,
196
+ loadPlugins,
197
+ registerCliPlugins,
198
+ sampleConfig
199
+ };
16
200
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../src/commandLine/config.ts","../src/commandLine/plugins.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { loadPlugins, registerCliPlugins } from './commandLine';\n\nconst program = new Command();\n\nprogram\n .name('emmett')\n .description('CLI tool for Emmett')\n .option('--config <path>', 'Path to the configuration file');\n\n// Load extensions and parse CLI arguments\nconst initCLI = async () => {\n const configIndex = process.argv.indexOf('--config');\n\n const configPath =\n configIndex !== -1 && process.argv.length > configIndex + 1\n ? process.argv[configIndex + 1]\n : undefined;\n\n try {\n const plugins = await loadPlugins({\n pluginType: 'cli',\n configPath: configPath,\n });\n await registerCliPlugins(program, plugins);\n\n // Parse the CLI arguments\n program.parse(process.argv);\n } catch (err) {\n console.error(`Failed to load config from ${configPath}:`, err);\n }\n};\n\n//Initialize CLI and handle errors\ninitCLI().catch((err) => {\n console.error(`CLI initialization failed:`);\n console.error(err);\n});\n\nexport default program;\nexport * from './commandLine';\n","import { Command as CliCommand } from 'commander';\n// eslint-disable-next-line no-restricted-imports\nimport { writeFileSync } from 'node:fs';\nimport { exit } from 'process';\n\nexport const sampleConfig = (plugins: string[] = ['emmett-expressjs']) => {\n const pluginsNames =\n plugins.length > 0\n ? `[\\n${plugins.map((p) => `\"${p}\"`).join(',\\n')} \\n]`\n : '[]';\n\n return `\nexport default {\n plugins: ${pluginsNames},\n};\n`;\n};\n\nexport const generateConfigFile = (\n configPath: string,\n collectionNames: string[],\n): void => {\n try {\n writeFileSync(configPath, sampleConfig(collectionNames), 'utf8');\n console.log(`Configuration file stored at: ${configPath}`);\n } catch (error) {\n console.error(`Error: Couldn't store config file: ${configPath}!`);\n console.error(error);\n process.exit(1);\n }\n};\n\nexport const configCommand = new CliCommand('config').description(\n 'Manage Pongo configuration',\n);\n\ntype SampleConfigOptions =\n | {\n plugin: string[];\n print?: boolean;\n }\n | {\n plugin: string[];\n generate?: boolean;\n file?: string;\n };\n\nconfigCommand\n .command('sample')\n .description('Generate or print sample configuration')\n .option(\n '-plg, --plugins <name>',\n 'Specify the plugin name',\n (value: string, previous: string[]) => {\n // Accumulate plugins names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-f, --file <path>',\n 'Path to configuration file with collection list',\n )\n .option('-g, --generate', 'Generate sample config file')\n .option('-p, --print', 'Print sample config file')\n .action((options: SampleConfigOptions) => {\n const plugins =\n options.plugin.length > 0\n ? options.plugin\n : ['@event-driven-io/emmett-expressjs'];\n\n if (!('print' in options) && !('generate' in options)) {\n console.error(\n 'Error: Please provide either:\\n--print param to print sample config or\\n--generate to generate sample config file',\n );\n exit(1);\n }\n\n if ('print' in options) {\n console.log(`${sampleConfig(plugins)}`);\n } else if ('generate' in options) {\n if (!options.file) {\n console.error(\n 'Error: You need to provide a config file through a --file',\n );\n exit(1);\n }\n\n generateConfigFile(options.file, plugins);\n }\n });\n","import { Command as CliCommand } from 'commander';\nimport path from 'path';\nimport {\n isPluginConfig,\n type EmmettCliCommand,\n type EmmettCliPlugin,\n type EmmettPlugin,\n type EmmettPluginConfig,\n type EmmettPluginsConfig,\n type EmmettPluginType,\n} from '../config';\nimport { EmmettError } from '../errors';\nimport { sampleConfig } from './config';\n\nconst PluginsConfigImportError = {\n missingDefaultExport: `Error: Config should contain default export, e.g.\\n\\n${sampleConfig()}`,\n missingPluginsPropertyExport: `Error: Config should contain default export with plugins array, e.g.\\n\\n${sampleConfig()}`,\n wrongPluginStructure: `Error: Plugin config should be either string with plugin name or object with plugin name, e.g. { name: 'emmett-expressjs' }`,\n};\nexport const importPluginsConfig = async (options?: {\n configPath?: string | undefined;\n}): Promise<EmmettPluginsConfig | EmmettError> => {\n const configPath = path.join(\n process.cwd(),\n options?.configPath ?? './dist/emmett.config.js',\n );\n\n console.log('IMPORTING' + configPath);\n\n try {\n const imported = (await import(configPath)) as {\n default: Partial<EmmettPluginsConfig>;\n };\n\n if (!imported.default) {\n return new EmmettError(PluginsConfigImportError.missingDefaultExport);\n }\n\n if (!imported.default.plugins || !Array.isArray(imported.default.plugins)) {\n return new EmmettError(\n PluginsConfigImportError.missingPluginsPropertyExport,\n );\n }\n\n if (!imported.default.plugins.every(isPluginConfig)) {\n return new EmmettError(PluginsConfigImportError.wrongPluginStructure);\n }\n\n return { plugins: imported.default.plugins };\n } catch (error) {\n if (!options?.configPath) {\n console.warn('Didn`t find config file: ' + configPath, error);\n return { plugins: [] };\n }\n return new EmmettError(\n `Error: Couldn't load file:` + (error as Error).toString(),\n );\n }\n};\n\nexport const loadPlugins = async (options?: {\n pluginType?: EmmettPluginType;\n configPath?: string;\n}): Promise<EmmettPlugin[]> => {\n try {\n const pluginsConfig = await importPluginsConfig({\n configPath: options?.configPath,\n });\n\n if (pluginsConfig instanceof EmmettError) throw pluginsConfig;\n\n if (pluginsConfig.plugins.length === 0) {\n console.log(`No extensions specified in config ${options?.configPath}.`);\n return [];\n }\n\n const pluginsToLoad = filterPluginsByType(\n pluginsConfig.plugins,\n options?.pluginType,\n );\n\n const pluginsPromises = pluginsToLoad.map(async (pluginConfig) => {\n const importPath = getImportPath(pluginConfig, options?.pluginType);\n try {\n const plugin = (await import(importPath)) as { default: EmmettPlugin };\n\n console.info(`Loaded plugin: ${importPath}`);\n\n if (!plugin.default) {\n throw new Error(`Plugin: ${importPath} is missing default export`);\n }\n\n return plugin.default;\n } catch (error) {\n console.error(`Failed to load extension \"${importPath}\":`, error);\n return undefined;\n }\n });\n\n return (await Promise.all(pluginsPromises)).filter(\n (plugin) => plugin !== undefined,\n );\n } catch (error) {\n console.error(`Failed to load config ${options?.configPath}:`, error);\n return [];\n }\n};\n\nexport const registerCliPlugins = async (\n program: CliCommand,\n plugins: EmmettCliPlugin[],\n): Promise<void> => {\n const result: EmmettCliPlugin[] = [];\n\n for (const plugin of plugins) {\n const pluginName = plugin.name;\n\n if (!('registerCommands' in plugin)) {\n console.warn(`No registerCommands function found in ${pluginName}`);\n }\n await plugin.registerCommands(program as EmmettCliCommand);\n console.log(`Loaded extension: ${plugin.name}`);\n result.push(plugin);\n }\n};\n\nconst filterPluginsByType = (\n plugins: EmmettPluginConfig[],\n pluginType?: EmmettPluginType,\n): EmmettPluginConfig[] =>\n plugins.filter(\n (p) =>\n typeof p === 'string' ||\n (pluginType &&\n (p.register === undefined ||\n p.register.some((r) => r.pluginType === pluginType))),\n );\n\nconst getImportPath = (\n pluginConfig: EmmettPluginConfig,\n pluginType: EmmettPluginType | undefined,\n) => {\n if (typeof pluginConfig === 'string') {\n return pluginType ? `${pluginConfig}/${pluginType}` : pluginConfig;\n }\n\n const pluginSubpath =\n pluginConfig.register.find((r) => pluginType && r.pluginType === pluginType)\n ?.path ?? pluginType;\n\n return pluginSubpath\n ? `${pluginConfig.name}/${pluginSubpath}`\n : pluginConfig.name;\n};\n"],"mappings":";+CACA,OAAS,WAAAA,MAAe,YCDxB,OAAS,WAAWC,MAAkB,YAEtC,OAAS,iBAAAC,MAAqB,UAC9B,OAAS,QAAAC,MAAY,UAEd,IAAMC,EAAe,CAACC,EAAoB,CAAC,kBAAkB,IAM3D;AAAA;AAAA,aAJLA,EAAQ,OAAS,EACb;AAAA,EAAMA,EAAQ,IAAKC,G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5B,OAASQ,EAAK,CACZ,QAAQ,MAAM,8BAA8BJ,CAAU,IAAKI,CAAG,CAChE,CACF,EAGAN,EAAQ,EAAE,MAAOM,GAAQ,CACvB,QAAQ,MAAM,4BAA4B,EAC1C,QAAQ,MAAMA,CAAG,CACnB,CAAC,EAED,IAAOC,EAAQT","names":["Command","CliCommand","writeFileSync","exit","sampleConfig","plugins","p","generateConfigFile","configPath","collectionNames","error","configCommand","value","previous","options","path","PluginsConfigImportError","sampleConfig","importPluginsConfig","options","configPath","path","imported","EmmettError","isPluginConfig","error","loadPlugins","pluginsConfig","pluginsPromises","filterPluginsByType","pluginConfig","importPath","getImportPath","plugin","registerCliPlugins","program","plugins","result","pluginName","pluginType","p","r","pluginSubpath","program","Command","initCLI","configIndex","configPath","plugins","loadPlugins","registerCliPlugins","err","cli_default"]}
1
+ {"version":3,"sources":["../src/cli.ts","../src/commandLine/config.ts","../src/commandLine/plugins.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { loadPlugins, registerCliPlugins } from './commandLine';\n\nconst program = new Command();\n\nprogram\n .name('emmett')\n .description('CLI tool for Emmett')\n .option('--config <path>', 'Path to the configuration file');\n\n// Load extensions and parse CLI arguments\nconst initCLI = async () => {\n const configIndex = process.argv.indexOf('--config');\n\n const configPath =\n configIndex !== -1 && process.argv.length > configIndex + 1\n ? process.argv[configIndex + 1]\n : undefined;\n\n try {\n const plugins = await loadPlugins({\n pluginType: 'cli',\n configPath: configPath,\n });\n await registerCliPlugins(program, plugins);\n\n // Parse the CLI arguments\n program.parse(process.argv);\n } catch (err) {\n console.error(`Failed to load config from ${configPath}:`, err);\n }\n};\n\n//Initialize CLI and handle errors\ninitCLI().catch((err) => {\n console.error(`CLI initialization failed:`);\n console.error(err);\n});\n\nexport default program;\nexport * from './commandLine';\n","import { Command as CliCommand } from 'commander';\n// eslint-disable-next-line no-restricted-imports\nimport { writeFileSync } from 'node:fs';\nimport { exit } from 'process';\n\nexport const sampleConfig = (plugins: string[] = ['emmett-expressjs']) => {\n const pluginsNames =\n plugins.length > 0\n ? `[\\n${plugins.map((p) => `\"${p}\"`).join(',\\n')} \\n]`\n : '[]';\n\n return `\nexport default {\n plugins: ${pluginsNames},\n};\n`;\n};\n\nexport const generateConfigFile = (\n configPath: string,\n collectionNames: string[],\n): void => {\n try {\n writeFileSync(configPath, sampleConfig(collectionNames), 'utf8');\n console.log(`Configuration file stored at: ${configPath}`);\n } catch (error) {\n console.error(`Error: Couldn't store config file: ${configPath}!`);\n console.error(error);\n process.exit(1);\n }\n};\n\nexport const configCommand = new CliCommand('config').description(\n 'Manage Pongo configuration',\n);\n\ntype SampleConfigOptions =\n | {\n plugin: string[];\n print?: boolean;\n }\n | {\n plugin: string[];\n generate?: boolean;\n file?: string;\n };\n\nconfigCommand\n .command('sample')\n .description('Generate or print sample configuration')\n .option(\n '-plg, --plugins <name>',\n 'Specify the plugin name',\n (value: string, previous: string[]) => {\n // Accumulate plugins names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-f, --file <path>',\n 'Path to configuration file with collection list',\n )\n .option('-g, --generate', 'Generate sample config file')\n .option('-p, --print', 'Print sample config file')\n .action((options: SampleConfigOptions) => {\n const plugins =\n options.plugin.length > 0\n ? options.plugin\n : ['@event-driven-io/emmett-expressjs'];\n\n if (!('print' in options) && !('generate' in options)) {\n console.error(\n 'Error: Please provide either:\\n--print param to print sample config or\\n--generate to generate sample config file',\n );\n exit(1);\n }\n\n if ('print' in options) {\n console.log(`${sampleConfig(plugins)}`);\n } else if ('generate' in options) {\n if (!options.file) {\n console.error(\n 'Error: You need to provide a config file through a --file',\n );\n exit(1);\n }\n\n generateConfigFile(options.file, plugins);\n }\n });\n","import { Command as CliCommand } from 'commander';\nimport path from 'path';\nimport {\n isPluginConfig,\n type EmmettCliCommand,\n type EmmettCliPlugin,\n type EmmettPlugin,\n type EmmettPluginConfig,\n type EmmettPluginsConfig,\n type EmmettPluginType,\n} from '../config';\nimport { EmmettError } from '../errors';\nimport { sampleConfig } from './config';\n\nconst PluginsConfigImportError = {\n missingDefaultExport: `Error: Config should contain default export, e.g.\\n\\n${sampleConfig()}`,\n missingPluginsPropertyExport: `Error: Config should contain default export with plugins array, e.g.\\n\\n${sampleConfig()}`,\n wrongPluginStructure: `Error: Plugin config should be either string with plugin name or object with plugin name, e.g. { name: 'emmett-expressjs' }`,\n};\nexport const importPluginsConfig = async (options?: {\n configPath?: string | undefined;\n}): Promise<EmmettPluginsConfig | EmmettError> => {\n const configPath = path.join(\n process.cwd(),\n options?.configPath ?? './dist/emmett.config.js',\n );\n\n console.log('IMPORTING' + configPath);\n\n try {\n const imported = (await import(configPath)) as {\n default: Partial<EmmettPluginsConfig>;\n };\n\n if (!imported.default) {\n return new EmmettError(PluginsConfigImportError.missingDefaultExport);\n }\n\n if (!imported.default.plugins || !Array.isArray(imported.default.plugins)) {\n return new EmmettError(\n PluginsConfigImportError.missingPluginsPropertyExport,\n );\n }\n\n if (!imported.default.plugins.every(isPluginConfig)) {\n return new EmmettError(PluginsConfigImportError.wrongPluginStructure);\n }\n\n return { plugins: imported.default.plugins };\n } catch (error) {\n if (!options?.configPath) {\n console.warn('Didn`t find config file: ' + configPath, error);\n return { plugins: [] };\n }\n return new EmmettError(\n `Error: Couldn't load file:` + (error as Error).toString(),\n );\n }\n};\n\nexport const loadPlugins = async (options?: {\n pluginType?: EmmettPluginType;\n configPath?: string;\n}): Promise<EmmettPlugin[]> => {\n try {\n const pluginsConfig = await importPluginsConfig({\n configPath: options?.configPath,\n });\n\n if (pluginsConfig instanceof EmmettError) throw pluginsConfig;\n\n if (pluginsConfig.plugins.length === 0) {\n console.log(`No extensions specified in config ${options?.configPath}.`);\n return [];\n }\n\n const pluginsToLoad = filterPluginsByType(\n pluginsConfig.plugins,\n options?.pluginType,\n );\n\n const pluginsPromises = pluginsToLoad.map(async (pluginConfig) => {\n const importPath = getImportPath(pluginConfig, options?.pluginType);\n try {\n const plugin = (await import(importPath)) as { default: EmmettPlugin };\n\n console.info(`Loaded plugin: ${importPath}`);\n\n if (!plugin.default) {\n throw new Error(`Plugin: ${importPath} is missing default export`);\n }\n\n return plugin.default;\n } catch (error) {\n console.error(`Failed to load extension \"${importPath}\":`, error);\n return undefined;\n }\n });\n\n return (await Promise.all(pluginsPromises)).filter(\n (plugin) => plugin !== undefined,\n );\n } catch (error) {\n console.error(`Failed to load config ${options?.configPath}:`, error);\n return [];\n }\n};\n\nexport const registerCliPlugins = async (\n program: CliCommand,\n plugins: EmmettCliPlugin[],\n): Promise<void> => {\n const result: EmmettCliPlugin[] = [];\n\n for (const plugin of plugins) {\n const pluginName = plugin.name;\n\n if (!('registerCommands' in plugin)) {\n console.warn(`No registerCommands function found in ${pluginName}`);\n }\n await plugin.registerCommands(program as EmmettCliCommand);\n console.log(`Loaded extension: ${plugin.name}`);\n result.push(plugin);\n }\n};\n\nconst filterPluginsByType = (\n plugins: EmmettPluginConfig[],\n pluginType?: EmmettPluginType,\n): EmmettPluginConfig[] =>\n plugins.filter(\n (p) =>\n typeof p === 'string' ||\n (pluginType &&\n (p.register === undefined ||\n p.register.some((r) => r.pluginType === pluginType))),\n );\n\nconst getImportPath = (\n pluginConfig: EmmettPluginConfig,\n pluginType: EmmettPluginType | undefined,\n) => {\n if (typeof pluginConfig === 'string') {\n return pluginType ? `${pluginConfig}/${pluginType}` : pluginConfig;\n }\n\n const pluginSubpath =\n pluginConfig.register.find((r) => pluginType && r.pluginType === pluginType)\n ?.path ?? pluginType;\n\n return pluginSubpath\n ? `${pluginConfig.name}/${pluginSubpath}`\n : pluginConfig.name;\n};\n"],"mappings":";;;;;;;AACA,SAAS,eAAe;;;ACDxB,SAAS,WAAW,kBAAkB;AAEtC,SAAS,qBAAqB;AAC9B,SAAS,YAAY;AAEd,IAAM,eAAe,CAAC,UAAoB,CAAC,kBAAkB,MAAM;AACxE,QAAM,eACJ,QAAQ,SAAS,IACb;AAAA,EAAM,QAAQ,IAAI,C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