@beseif-solutions/prow-core 0.0.28 → 0.0.30
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/core.d.ts +6 -9
- package/dist/core.js +4 -30
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/minified-utils/locales.d.ts +19 -7
- package/dist/minified-utils/locales.js +54 -13
- package/dist/minified-utils/properties.d.ts +2 -1
- package/dist/minified-utils/protocol.d.ts +42 -0
- package/dist/minified-utils/protocol.js +111 -0
- package/package.json +1 -2
- package/src/core.ts +10 -39
- package/src/index.ts +2 -1
- package/src/minified-utils/locales.ts +76 -16
- package/src/minified-utils/properties.ts +1 -1
- package/src/minified-utils/protocol.ts +164 -0
- package/dist/minified-utils/utils.d.ts +0 -1
- package/dist/minified-utils/utils.js +0 -26
- package/src/minified-utils/utils.ts +0 -18
package/dist/core.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
+
import Joi from "joi";
|
|
2
3
|
import _ from "lodash";
|
|
3
4
|
import moment from "moment-timezone";
|
|
4
|
-
import {
|
|
5
|
-
import { i18n } from "./minified-utils/locales";
|
|
6
|
-
import Joi from "joi";
|
|
5
|
+
import { FromCatalog, FromDirectory, T } from "./minified-utils/locales";
|
|
7
6
|
type SourceFunctions = {
|
|
8
7
|
register: <T>(source: string, data: T) => Promise<{
|
|
9
8
|
id: string;
|
|
@@ -18,17 +17,15 @@ export type Core = {
|
|
|
18
17
|
axios: typeof axios;
|
|
19
18
|
moment: typeof moment;
|
|
20
19
|
lodash: typeof _;
|
|
21
|
-
env:
|
|
22
|
-
t: ReturnType<typeof i18n>[`t`];
|
|
20
|
+
env: Record<string, any>;
|
|
23
21
|
joi: typeof Joi;
|
|
24
22
|
sources?: SourceFunctions;
|
|
23
|
+
t: T;
|
|
25
24
|
};
|
|
26
25
|
type CoreOptions = {
|
|
27
|
-
|
|
28
|
-
env?: Properties;
|
|
29
|
-
debug?: boolean;
|
|
30
|
-
locale?: string;
|
|
26
|
+
env?: Record<string, any>;
|
|
31
27
|
sources?: SourceFunctions;
|
|
28
|
+
localization: FromDirectory | FromCatalog;
|
|
32
29
|
};
|
|
33
30
|
export declare const core: (options: CoreOptions) => Core;
|
|
34
31
|
export {};
|
package/dist/core.js
CHANGED
|
@@ -5,13 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.core = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
10
|
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
10
|
-
const proxy_1 = require("./minified-utils/proxy");
|
|
11
|
-
const properties_1 = require("./minified-utils/properties");
|
|
12
11
|
const locales_1 = require("./minified-utils/locales");
|
|
13
|
-
const path_1 = __importDefault(require("path"));
|
|
14
|
-
const joi_1 = __importDefault(require("joi"));
|
|
15
12
|
const FALLBACK_SOURCES = {
|
|
16
13
|
register: async () => {
|
|
17
14
|
throw new Error(`Sources not available: valid implementation not provided`);
|
|
@@ -23,36 +20,13 @@ const FALLBACK_SOURCES = {
|
|
|
23
20
|
throw new Error(`Sources not available: valid implementation not provided`);
|
|
24
21
|
},
|
|
25
22
|
};
|
|
26
|
-
const axiosLogs = (method, debug = false) => ({
|
|
27
|
-
before: (name, [url]) => {
|
|
28
|
-
if (debug) {
|
|
29
|
-
console.log(`> [${method}]`, url);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
after: (name, response) => {
|
|
33
|
-
if (debug) {
|
|
34
|
-
console.log(`< [${method}]`, response.config.url, response.status);
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
error: (name, error) => {
|
|
38
|
-
if (debug) {
|
|
39
|
-
console.log(`< [${method}]`, error.config.url, error.status);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
23
|
const core = (options) => ({
|
|
44
|
-
axios:
|
|
45
|
-
get: (0, proxy_1.logProxy)(`axios.get`, axios_1.default.get, axiosLogs(`GET`, options.debug)),
|
|
46
|
-
post: (0, proxy_1.logProxy)(`axios.post`, axios_1.default.post, axiosLogs(`POST`, options.debug)),
|
|
47
|
-
put: (0, proxy_1.logProxy)(`axios.put`, axios_1.default.put, axiosLogs(`PUT`, options.debug)),
|
|
48
|
-
patch: (0, proxy_1.logProxy)(`axios.patch`, axios_1.default.patch, axiosLogs(`PATCH`, options.debug)),
|
|
49
|
-
delete: (0, proxy_1.logProxy)(`axios.delete`, axios_1.default.delete, axiosLogs(`DELETE`, options.debug)),
|
|
50
|
-
}),
|
|
24
|
+
axios: axios_1.default,
|
|
51
25
|
moment: moment_timezone_1.default,
|
|
52
26
|
lodash: lodash_1.default,
|
|
53
|
-
env: options.env ||
|
|
54
|
-
t: (0, locales_1.i18n)(path_1.default.join(options.root, `/locales`), { locale: options.locale }).t,
|
|
27
|
+
env: options.env || {},
|
|
55
28
|
joi: joi_1.default,
|
|
56
29
|
sources: options.sources || FALLBACK_SOURCES,
|
|
30
|
+
t: (0, locales_1.i18n)(options.localization).t,
|
|
57
31
|
});
|
|
58
32
|
exports.core = core;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export { Action, actionOutputSchema, actionSchema, Event, eventSchema, Immediate
|
|
|
6
6
|
export { Provider, providerSchema } from './entities/provider';
|
|
7
7
|
export { Source } from './entities/source';
|
|
8
8
|
export { extract, Field, fieldSchema, fieldsSchema, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
|
|
9
|
-
export { i18n, localizeFields, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
|
|
9
|
+
export { i18n, localizeFields, localizeInputs, localizeOutputs, localizeProperties, LocalizedField, LocalizedProperties } from './minified-utils/locales';
|
|
10
10
|
export { Properties } from './minified-utils/properties';
|
|
11
|
+
export { Protocol } from './minified-utils/protocol';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.getCategories = exports.core = void 0;
|
|
3
|
+
exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.getCategories = exports.core = void 0;
|
|
4
4
|
var core_1 = require("./core");
|
|
5
5
|
Object.defineProperty(exports, "core", { enumerable: true, get: function () { return core_1.core; } });
|
|
6
6
|
var category_1 = require("./entities/category");
|
|
@@ -35,3 +35,5 @@ Object.defineProperty(exports, "localizeOutputs", { enumerable: true, get: funct
|
|
|
35
35
|
Object.defineProperty(exports, "localizeProperties", { enumerable: true, get: function () { return locales_1.localizeProperties; } });
|
|
36
36
|
var properties_1 = require("./minified-utils/properties");
|
|
37
37
|
Object.defineProperty(exports, "Properties", { enumerable: true, get: function () { return properties_1.Properties; } });
|
|
38
|
+
var protocol_1 = require("./minified-utils/protocol");
|
|
39
|
+
Object.defineProperty(exports, "Protocol", { enumerable: true, get: function () { return protocol_1.Protocol; } });
|
|
@@ -3,25 +3,37 @@ import { Credentials, SessionCredentials, StaticCredentials } from '../entities/
|
|
|
3
3
|
import { Action, ConnectableEvent, Trigger } from '../entities/events';
|
|
4
4
|
import { Field } from './fields';
|
|
5
5
|
import { Provider } from '../entities/provider';
|
|
6
|
-
|
|
6
|
+
import { Source } from '../entities/source';
|
|
7
|
+
export type LocalizedField = {
|
|
7
8
|
label: string;
|
|
8
9
|
help: string;
|
|
9
10
|
};
|
|
10
|
-
type LocalizedProperties = {
|
|
11
|
+
export type LocalizedProperties = {
|
|
11
12
|
name: string;
|
|
12
13
|
description: string;
|
|
13
14
|
};
|
|
14
15
|
type TOptions = {
|
|
15
16
|
fallback?: boolean;
|
|
16
17
|
};
|
|
17
|
-
export declare const
|
|
18
|
+
export declare const validateDirectory: (directory: string) => boolean;
|
|
19
|
+
type Common = {
|
|
18
20
|
locale?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
+
};
|
|
22
|
+
export type FromCatalog = Common & {
|
|
23
|
+
catalog: Record<string, any>;
|
|
24
|
+
};
|
|
25
|
+
export type FromDirectory = Common & {
|
|
26
|
+
directory: string;
|
|
27
|
+
locale?: string;
|
|
28
|
+
write?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export type T = (code: string, opts?: TOptions) => string;
|
|
31
|
+
export declare const i18n: (options: FromCatalog | FromDirectory) => {
|
|
32
|
+
t: T;
|
|
21
33
|
i18n: I18n.I18n;
|
|
22
34
|
};
|
|
23
|
-
export declare const localizeFields: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger | StaticCredentials | SessionCredentials) => Field<LocalizedField>[];
|
|
24
|
-
export declare const localizeProperties: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger | Credentials | Provider) => LocalizedProperties;
|
|
35
|
+
export declare const localizeFields: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger | StaticCredentials | SessionCredentials | Source) => Field<LocalizedField>[];
|
|
36
|
+
export declare const localizeProperties: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger | Credentials | Provider | Source) => LocalizedProperties;
|
|
25
37
|
export declare const localizeInputs: (t: ReturnType<typeof i18n>[`t`], element: Action) => (ConnectableEvent & LocalizedProperties)[];
|
|
26
38
|
export declare const localizeOutputs: (t: ReturnType<typeof i18n>[`t`], element: Action | Trigger) => (ConnectableEvent & LocalizedProperties)[];
|
|
27
39
|
export {};
|
|
@@ -3,29 +3,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.localizeOutputs = exports.localizeInputs = exports.localizeProperties = exports.localizeFields = exports.i18n = void 0;
|
|
6
|
+
exports.localizeOutputs = exports.localizeInputs = exports.localizeProperties = exports.localizeFields = exports.i18n = exports.validateDirectory = void 0;
|
|
7
7
|
const i18n_1 = __importDefault(require("i18n"));
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
11
|
const DEFAULT_LOCALE = `en`;
|
|
13
|
-
const
|
|
12
|
+
const validateDirectory = (directory) => {
|
|
14
13
|
try {
|
|
15
|
-
if (!
|
|
16
|
-
|
|
14
|
+
if (!fs_1.default.existsSync(directory)) {
|
|
15
|
+
console.error(`Directory does not exist: ${directory}`);
|
|
16
|
+
return false;
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const files = fs_1.default.readdirSync(directory);
|
|
19
|
+
if (!files.some((file) => file.endsWith(`.json`))) {
|
|
20
|
+
console.error(`No valid localization files found in directory: ${directory}`);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error(`Error validating directory: ${error.message}`);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.validateDirectory = validateDirectory;
|
|
31
|
+
const i18n = (options) => {
|
|
32
|
+
try {
|
|
33
|
+
const common = {
|
|
24
34
|
defaultLocale: DEFAULT_LOCALE,
|
|
25
35
|
objectNotation: true,
|
|
26
36
|
autoReload: false,
|
|
27
37
|
missingKeyFn: () => ``,
|
|
28
|
-
}
|
|
38
|
+
};
|
|
39
|
+
const requestedLocale = options.locale || DEFAULT_LOCALE;
|
|
40
|
+
let i18nInstance;
|
|
41
|
+
let activeLocale;
|
|
42
|
+
if (`directory` in options) {
|
|
43
|
+
if (!(0, exports.validateDirectory)(options.directory)) {
|
|
44
|
+
throw new Error(`Invalid directory: ${options.directory}`);
|
|
45
|
+
}
|
|
46
|
+
const availableLocales = fs_1.default.readdirSync(options.directory).map((file) => path_1.default.basename(file, path_1.default.extname(file)));
|
|
47
|
+
activeLocale = availableLocales.includes(requestedLocale) ? requestedLocale : DEFAULT_LOCALE;
|
|
48
|
+
i18nInstance = new i18n_1.default.I18n({
|
|
49
|
+
...common,
|
|
50
|
+
locales: availableLocales,
|
|
51
|
+
directory: options.directory,
|
|
52
|
+
updateFiles: options.write,
|
|
53
|
+
syncFiles: true,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else if (`catalog` in options) {
|
|
57
|
+
activeLocale = requestedLocale;
|
|
58
|
+
i18nInstance = new i18n_1.default.I18n({
|
|
59
|
+
...common,
|
|
60
|
+
locales: [requestedLocale],
|
|
61
|
+
staticCatalog: {
|
|
62
|
+
[requestedLocale]: options.catalog,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`Invalid options provided for i18n function`);
|
|
68
|
+
}
|
|
29
69
|
i18nInstance.setLocale(activeLocale);
|
|
30
70
|
return {
|
|
31
71
|
t: (code, opts = {}) => {
|
|
@@ -34,7 +74,8 @@ const i18n = (directory, options = {}) => {
|
|
|
34
74
|
response = i18nInstance.__({ phrase: code, locale: DEFAULT_LOCALE });
|
|
35
75
|
}
|
|
36
76
|
return response;
|
|
37
|
-
},
|
|
77
|
+
},
|
|
78
|
+
i18n: i18nInstance,
|
|
38
79
|
};
|
|
39
80
|
}
|
|
40
81
|
catch (e) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { DotenvParseOutput } from "dotenv";
|
|
1
2
|
export declare class Properties {
|
|
2
3
|
private readonly filepath;
|
|
3
|
-
|
|
4
|
+
readonly properties: DotenvParseOutput;
|
|
4
5
|
private readonly getFile;
|
|
5
6
|
constructor(root: string, filename: string);
|
|
6
7
|
readonly read: (name: string, unknown?: boolean) => Promise<string>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Provider } from "../entities/provider";
|
|
2
|
+
export declare class Protocol {
|
|
3
|
+
private readonly provider;
|
|
4
|
+
constructor(provider: Provider);
|
|
5
|
+
evaluate: (req: Protocol.Command) => Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace Protocol {
|
|
8
|
+
type Model = `action` | `trigger` | `credentials`;
|
|
9
|
+
type Invoke = {
|
|
10
|
+
command: `invoke`;
|
|
11
|
+
model: Protocol.Model;
|
|
12
|
+
id: string;
|
|
13
|
+
params: {
|
|
14
|
+
function: string;
|
|
15
|
+
configuration: Record<string, any>;
|
|
16
|
+
};
|
|
17
|
+
context: {
|
|
18
|
+
environment: Record<string, any>;
|
|
19
|
+
localization: {
|
|
20
|
+
locale: string;
|
|
21
|
+
catalog: Record<string, any>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
type CredentialList = {
|
|
26
|
+
command: `list:credentials`;
|
|
27
|
+
};
|
|
28
|
+
type ActionList = {
|
|
29
|
+
command: `list:actions`;
|
|
30
|
+
};
|
|
31
|
+
type TriggerList = {
|
|
32
|
+
command: `list:triggers`;
|
|
33
|
+
};
|
|
34
|
+
type SourceList = {
|
|
35
|
+
command: `list:sources`;
|
|
36
|
+
};
|
|
37
|
+
type LocaleList = {
|
|
38
|
+
command: `list:locales`;
|
|
39
|
+
locale: string;
|
|
40
|
+
};
|
|
41
|
+
type Command = Invoke | CredentialList | ActionList | TriggerList | SourceList | LocaleList;
|
|
42
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Protocol = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const provider_1 = require("../entities/provider");
|
|
9
|
+
const locales_1 = require("./locales");
|
|
10
|
+
const core_1 = require("../core");
|
|
11
|
+
const joi_1 = __importDefault(require("joi"));
|
|
12
|
+
const invokeSchema = joi_1.default.object({
|
|
13
|
+
command: joi_1.default.string().valid(`invoke`).required(),
|
|
14
|
+
model: joi_1.default.string().valid(`action`, `trigger`, `credentials`).required(),
|
|
15
|
+
id: joi_1.default.string().required(),
|
|
16
|
+
params: joi_1.default.object({
|
|
17
|
+
function: joi_1.default.string().required(),
|
|
18
|
+
configuration: joi_1.default.object().required(),
|
|
19
|
+
}).required(),
|
|
20
|
+
context: joi_1.default.object({
|
|
21
|
+
environment: joi_1.default.object().required(),
|
|
22
|
+
localization: joi_1.default.object({
|
|
23
|
+
locale: joi_1.default.string().required(),
|
|
24
|
+
catalog: joi_1.default.object().required(),
|
|
25
|
+
}).required(),
|
|
26
|
+
}).required(),
|
|
27
|
+
}).required();
|
|
28
|
+
const credentialListSchema = joi_1.default.object({
|
|
29
|
+
command: joi_1.default.string().valid(`list:credentials`).required(),
|
|
30
|
+
}).required();
|
|
31
|
+
const actionListSchema = joi_1.default.object({
|
|
32
|
+
command: joi_1.default.string().valid(`list:actions`).required(),
|
|
33
|
+
}).required();
|
|
34
|
+
const triggerListSchema = joi_1.default.object({
|
|
35
|
+
command: joi_1.default.string().valid(`list:triggers`).required(),
|
|
36
|
+
}).required();
|
|
37
|
+
const sourceListSchema = joi_1.default.object({
|
|
38
|
+
command: joi_1.default.string().valid(`list:sources`).required(),
|
|
39
|
+
}).required();
|
|
40
|
+
const localeListSchema = joi_1.default.object({
|
|
41
|
+
command: joi_1.default.string().valid(`list:locales`).required(),
|
|
42
|
+
locale: joi_1.default.string().required(),
|
|
43
|
+
}).required();
|
|
44
|
+
const commandSchema = joi_1.default.alternatives(invokeSchema, credentialListSchema, actionListSchema, triggerListSchema, sourceListSchema, localeListSchema);
|
|
45
|
+
class Protocol {
|
|
46
|
+
constructor(provider) {
|
|
47
|
+
this.evaluate = async (req) => {
|
|
48
|
+
try {
|
|
49
|
+
const validation = commandSchema.validate(req);
|
|
50
|
+
if (validation.error) {
|
|
51
|
+
throw new Error(`Invalid request: ${validation.error.message}`);
|
|
52
|
+
}
|
|
53
|
+
let response;
|
|
54
|
+
switch (req.command) {
|
|
55
|
+
case `list:actions`:
|
|
56
|
+
response = Object.values(this.provider.actions || {});
|
|
57
|
+
break;
|
|
58
|
+
case `list:triggers`:
|
|
59
|
+
response = Object.values(this.provider.triggers || {});
|
|
60
|
+
break;
|
|
61
|
+
case `list:credentials`:
|
|
62
|
+
response = Object.values(this.provider.credentials || {});
|
|
63
|
+
break;
|
|
64
|
+
case `list:sources`:
|
|
65
|
+
response = Object.values(this.provider.sources || {});
|
|
66
|
+
break;
|
|
67
|
+
case `list:locales`:
|
|
68
|
+
const i18nInstance = (0, locales_1.i18n)({ directory: `node_modules/prow-hubspot-repository/locales` });
|
|
69
|
+
response = i18nInstance.i18n.getLocales().map((l) => {
|
|
70
|
+
i18nInstance.i18n.setLocale(l);
|
|
71
|
+
return {
|
|
72
|
+
code: l,
|
|
73
|
+
catalog: i18nInstance.i18n.getCatalog(),
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
case `invoke`:
|
|
78
|
+
const mEvent = lodash_1.default.get(this.provider, `${req.model}s.${req.id}`);
|
|
79
|
+
if (!mEvent) {
|
|
80
|
+
return {
|
|
81
|
+
status: 404,
|
|
82
|
+
body: JSON.stringify({ error: `Could not find ${req.model} with ID ${req.id}` }),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const f = lodash_1.default.get(mEvent, req.params.function);
|
|
86
|
+
if (!f || typeof f !== `function`) {
|
|
87
|
+
throw new Error(`Invalid function ${req.params.function}`);
|
|
88
|
+
}
|
|
89
|
+
const invokeInstance = (0, core_1.core)({
|
|
90
|
+
env: req.context.environment,
|
|
91
|
+
localization: req.context.localization,
|
|
92
|
+
});
|
|
93
|
+
response = await f(invokeInstance, req.params.configuration);
|
|
94
|
+
break;
|
|
95
|
+
default:
|
|
96
|
+
throw new Error(`Invalid command`);
|
|
97
|
+
}
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const providerValidation = (0, provider_1.providerSchema)().validate(provider);
|
|
105
|
+
if (providerValidation.error) {
|
|
106
|
+
throw new Error(`Invalid provider for protocol`);
|
|
107
|
+
}
|
|
108
|
+
this.provider = provider;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.Protocol = Protocol;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beseif-solutions/prow-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "Prow core functionalities and classes",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@types/express": "^4.17.21",
|
|
21
20
|
"axios": "^1.7.7",
|
|
22
21
|
"dotenv": "^16.4.5",
|
|
23
22
|
"handlebars": "^4.7.8",
|
package/src/core.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import axios
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import Joi from "joi";
|
|
2
3
|
import _ from "lodash";
|
|
3
4
|
import moment from "moment-timezone";
|
|
4
|
-
import {
|
|
5
|
-
import { Properties } from "./minified-utils/properties";
|
|
6
|
-
import { i18n } from "./minified-utils/locales";
|
|
7
|
-
import path from "path";
|
|
8
|
-
import Joi from "joi";
|
|
5
|
+
import { FromCatalog, FromDirectory, i18n, T } from "./minified-utils/locales";
|
|
9
6
|
|
|
10
7
|
type SourceFunctions = {
|
|
11
8
|
register: <T>(source: string, data: T) => Promise<{ id: string }>,
|
|
@@ -25,55 +22,29 @@ const FALLBACK_SOURCES: SourceFunctions = {
|
|
|
25
22
|
},
|
|
26
23
|
};
|
|
27
24
|
|
|
28
|
-
|
|
29
25
|
export type Core = {
|
|
30
26
|
axios: typeof axios,
|
|
31
27
|
moment: typeof moment,
|
|
32
28
|
lodash: typeof _,
|
|
33
|
-
env:
|
|
34
|
-
t: ReturnType<typeof i18n>[`t`],
|
|
29
|
+
env: Record<string, any>,
|
|
35
30
|
joi: typeof Joi,
|
|
36
31
|
sources?: SourceFunctions,
|
|
32
|
+
t: T,
|
|
37
33
|
};
|
|
38
34
|
|
|
39
|
-
const axiosLogs = (method: string, debug = false): ProxyLogs<
|
|
40
|
-
typeof axios[`get`]
|
|
41
|
-
| typeof axios[`post`]
|
|
42
|
-
| typeof axios[`put`]
|
|
43
|
-
| typeof axios[`patch`]
|
|
44
|
-
| typeof axios[`delete`]> => ({
|
|
45
|
-
before: (name, [url]) => {
|
|
46
|
-
if (debug) { console.log(`> [${method}]`, url); }
|
|
47
|
-
},
|
|
48
|
-
after: (name, response: AxiosResponse) => {
|
|
49
|
-
if (debug) { console.log(`< [${method}]`, response.config.url, response.status); }
|
|
50
|
-
},
|
|
51
|
-
error: (name, error: AxiosError) => {
|
|
52
|
-
if (debug) { console.log(`< [${method}]`, error.config.url, error.status); }
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
|
|
56
35
|
type CoreOptions = {
|
|
57
|
-
|
|
58
|
-
env?: Properties,
|
|
59
|
-
debug?: boolean,
|
|
60
|
-
locale?: string,
|
|
36
|
+
env?: Record<string, any>,
|
|
61
37
|
sources?: SourceFunctions,
|
|
38
|
+
localization: FromDirectory | FromCatalog,
|
|
62
39
|
};
|
|
63
40
|
|
|
64
41
|
/* eslint-disable @typescript-eslint/unbound-method */
|
|
65
42
|
export const core = (options: CoreOptions): Core => ({
|
|
66
|
-
axios:
|
|
67
|
-
get: logProxy(`axios.get`, axios.get, axiosLogs(`GET`, options.debug)),
|
|
68
|
-
post: logProxy(`axios.post`, axios.post, axiosLogs(`POST`, options.debug)),
|
|
69
|
-
put: logProxy(`axios.put`, axios.put, axiosLogs(`PUT`, options.debug)),
|
|
70
|
-
patch: logProxy(`axios.patch`, axios.patch, axiosLogs(`PATCH`, options.debug)),
|
|
71
|
-
delete: logProxy(`axios.delete`, axios.delete, axiosLogs(`DELETE`, options.debug)),
|
|
72
|
-
}),
|
|
43
|
+
axios: axios,
|
|
73
44
|
moment: moment,
|
|
74
45
|
lodash: _,
|
|
75
|
-
env: options.env ||
|
|
76
|
-
t: i18n(path.join(options.root, `/locales`), { locale: options.locale }).t,
|
|
46
|
+
env: options.env || {},
|
|
77
47
|
joi: Joi,
|
|
78
48
|
sources: options.sources || FALLBACK_SOURCES,
|
|
49
|
+
t: i18n(options.localization).t,
|
|
79
50
|
});
|
package/src/index.ts
CHANGED
|
@@ -6,5 +6,6 @@ export { Action, actionOutputSchema, actionSchema, Event, eventSchema, Immediate
|
|
|
6
6
|
export { Provider, providerSchema } from './entities/provider';
|
|
7
7
|
export { Source } from './entities/source';
|
|
8
8
|
export { extract, Field, fieldSchema, fieldsSchema, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
|
|
9
|
-
export { i18n, localizeFields, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
|
|
9
|
+
export { i18n, localizeFields, localizeInputs, localizeOutputs, localizeProperties, LocalizedField, LocalizedProperties } from './minified-utils/locales';
|
|
10
10
|
export { Properties } from './minified-utils/properties';
|
|
11
|
+
export { Protocol } from './minified-utils/protocol';
|
|
@@ -6,14 +6,14 @@ import { Credentials, SessionCredentials, StaticCredentials } from '../entities/
|
|
|
6
6
|
import { Action, ConnectableEvent, Trigger } from '../entities/events';
|
|
7
7
|
import { Field, SelectFieldChoice } from './fields';
|
|
8
8
|
import { Provider } from '../entities/provider';
|
|
9
|
-
import {
|
|
9
|
+
import { Source } from '../entities/source';
|
|
10
10
|
|
|
11
|
-
type LocalizedField = {
|
|
11
|
+
export type LocalizedField = {
|
|
12
12
|
label: string,
|
|
13
13
|
help: string,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
type LocalizedProperties = {
|
|
16
|
+
export type LocalizedProperties = {
|
|
17
17
|
name: string,
|
|
18
18
|
description: string,
|
|
19
19
|
};
|
|
@@ -22,25 +22,84 @@ type TOptions = { fallback?: boolean };
|
|
|
22
22
|
|
|
23
23
|
const DEFAULT_LOCALE = `en`;
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const validateDirectory = (directory: string): boolean => {
|
|
26
26
|
try {
|
|
27
|
-
if (!
|
|
28
|
-
|
|
27
|
+
if (!fs.existsSync(directory)) {
|
|
28
|
+
console.error(`Directory does not exist: ${directory}`);
|
|
29
|
+
return false;
|
|
29
30
|
}
|
|
31
|
+
const files = fs.readdirSync(directory);
|
|
32
|
+
if (!files.some((file) => file.endsWith(`.json`))) {
|
|
33
|
+
console.error(`No valid localization files found in directory: ${directory}`);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(`Error validating directory: ${error.message}`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
type Common = {
|
|
44
|
+
locale?: string,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type FromCatalog = Common & {
|
|
48
|
+
catalog: Record<string, any>,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type FromDirectory = Common & {
|
|
52
|
+
directory: string,
|
|
53
|
+
locale?: string,
|
|
54
|
+
write?: boolean,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type T = (code: string, opts?: TOptions) => string;
|
|
33
58
|
|
|
34
|
-
|
|
59
|
+
export const i18n = (options: FromCatalog | FromDirectory): { t: T, i18n: I18n.I18n } => {
|
|
60
|
+
try {
|
|
35
61
|
|
|
36
|
-
const
|
|
37
|
-
locales: availableLocales,
|
|
38
|
-
directory: directory,
|
|
62
|
+
const common: I18n.ConfigurationOptions = {
|
|
39
63
|
defaultLocale: DEFAULT_LOCALE,
|
|
40
64
|
objectNotation: true,
|
|
41
65
|
autoReload: false,
|
|
42
66
|
missingKeyFn: () => ``,
|
|
43
|
-
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const requestedLocale = options.locale || DEFAULT_LOCALE;
|
|
70
|
+
|
|
71
|
+
let i18nInstance: I18n.I18n;
|
|
72
|
+
let activeLocale: string;
|
|
73
|
+
if (`directory` in options) {
|
|
74
|
+
// validate directory
|
|
75
|
+
if (!validateDirectory(options.directory)) { throw new Error(`Invalid directory: ${options.directory}`); }
|
|
76
|
+
|
|
77
|
+
// get active locale
|
|
78
|
+
const availableLocales = fs.readdirSync(options.directory).map((file) => path.basename(file, path.extname(file)));
|
|
79
|
+
activeLocale = availableLocales.includes(requestedLocale) ? requestedLocale : DEFAULT_LOCALE;
|
|
80
|
+
|
|
81
|
+
// create i18n instance
|
|
82
|
+
i18nInstance = new I18n.I18n({
|
|
83
|
+
...common,
|
|
84
|
+
locales: availableLocales,
|
|
85
|
+
directory: options.directory,
|
|
86
|
+
updateFiles: options.write,
|
|
87
|
+
syncFiles: true,
|
|
88
|
+
});
|
|
89
|
+
} else if (`catalog` in options) {
|
|
90
|
+
// get active locale
|
|
91
|
+
activeLocale = requestedLocale;
|
|
92
|
+
|
|
93
|
+
// create i18n instance
|
|
94
|
+
i18nInstance = new I18n.I18n({
|
|
95
|
+
...common,
|
|
96
|
+
locales: [requestedLocale],
|
|
97
|
+
staticCatalog: {
|
|
98
|
+
[requestedLocale]: options.catalog,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
} else { throw new Error(`Invalid options provided for i18n function`); }
|
|
102
|
+
|
|
44
103
|
i18nInstance.setLocale(activeLocale);
|
|
45
104
|
|
|
46
105
|
return {
|
|
@@ -50,7 +109,8 @@ export const i18n = (directory: string, options: { locale?: string } = {}) => {
|
|
|
50
109
|
response = i18nInstance.__({ phrase: code, locale: DEFAULT_LOCALE });
|
|
51
110
|
}
|
|
52
111
|
return response;
|
|
53
|
-
},
|
|
112
|
+
},
|
|
113
|
+
i18n: i18nInstance,
|
|
54
114
|
};
|
|
55
115
|
} catch (e) { throw e; }
|
|
56
116
|
};
|
|
@@ -80,7 +140,7 @@ const localizeField = (
|
|
|
80
140
|
|
|
81
141
|
export const localizeFields = (
|
|
82
142
|
t: ReturnType<typeof i18n>[`t`],
|
|
83
|
-
element: Action | Trigger | StaticCredentials | SessionCredentials,
|
|
143
|
+
element: Action | Trigger | StaticCredentials | SessionCredentials | Source,
|
|
84
144
|
): Field<LocalizedField>[] => {
|
|
85
145
|
const response: Field<LocalizedField>[] = [];
|
|
86
146
|
if (element[`fields`] && element[`fields`].length > 0) {
|
|
@@ -91,7 +151,7 @@ export const localizeFields = (
|
|
|
91
151
|
|
|
92
152
|
export const localizeProperties = (
|
|
93
153
|
t: ReturnType<typeof i18n>[`t`],
|
|
94
|
-
element: Action | Trigger | Credentials | Provider,
|
|
154
|
+
element: Action | Trigger | Credentials | Provider | Source,
|
|
95
155
|
): LocalizedProperties => ({
|
|
96
156
|
name: t(`${element.id}.name`, { fallback: true }),
|
|
97
157
|
description: t(`${element.id}.description`),
|
|
@@ -6,7 +6,7 @@ import path from "path";
|
|
|
6
6
|
export class Properties {
|
|
7
7
|
|
|
8
8
|
private readonly filepath: string;
|
|
9
|
-
|
|
9
|
+
public readonly properties: DotenvParseOutput;
|
|
10
10
|
|
|
11
11
|
private readonly getFile = (flag: `w+` | `r`): DotenvParseOutput => {
|
|
12
12
|
try {
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { Provider, providerSchema } from "../entities/provider";
|
|
3
|
+
import { i18n } from "./locales";
|
|
4
|
+
import { core } from "../core";
|
|
5
|
+
import Joi from "joi";
|
|
6
|
+
|
|
7
|
+
const invokeSchema = Joi.object({
|
|
8
|
+
command: Joi.string().valid(`invoke`).required(),
|
|
9
|
+
model: Joi.string().valid(`action`, `trigger`, `credentials`).required(),
|
|
10
|
+
id: Joi.string().required(),
|
|
11
|
+
params: Joi.object({
|
|
12
|
+
function: Joi.string().required(),
|
|
13
|
+
configuration: Joi.object().required(),
|
|
14
|
+
}).required(),
|
|
15
|
+
context: Joi.object({
|
|
16
|
+
environment: Joi.object().required(),
|
|
17
|
+
localization: Joi.object({
|
|
18
|
+
locale: Joi.string().required(),
|
|
19
|
+
catalog: Joi.object().required(),
|
|
20
|
+
}).required(),
|
|
21
|
+
}).required(),
|
|
22
|
+
}).required();
|
|
23
|
+
|
|
24
|
+
const credentialListSchema = Joi.object({
|
|
25
|
+
command: Joi.string().valid(`list:credentials`).required(),
|
|
26
|
+
}).required();
|
|
27
|
+
|
|
28
|
+
const actionListSchema = Joi.object({
|
|
29
|
+
command: Joi.string().valid(`list:actions`).required(),
|
|
30
|
+
}).required();
|
|
31
|
+
|
|
32
|
+
const triggerListSchema = Joi.object({
|
|
33
|
+
command: Joi.string().valid(`list:triggers`).required(),
|
|
34
|
+
}).required();
|
|
35
|
+
|
|
36
|
+
const sourceListSchema = Joi.object({
|
|
37
|
+
command: Joi.string().valid(`list:sources`).required(),
|
|
38
|
+
}).required();
|
|
39
|
+
|
|
40
|
+
const localeListSchema = Joi.object({
|
|
41
|
+
command: Joi.string().valid(`list:locales`).required(),
|
|
42
|
+
locale: Joi.string().required(),
|
|
43
|
+
}).required();
|
|
44
|
+
|
|
45
|
+
const commandSchema = Joi.alternatives(
|
|
46
|
+
invokeSchema,
|
|
47
|
+
credentialListSchema,
|
|
48
|
+
actionListSchema,
|
|
49
|
+
triggerListSchema,
|
|
50
|
+
sourceListSchema,
|
|
51
|
+
localeListSchema,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export class Protocol {
|
|
55
|
+
|
|
56
|
+
private readonly provider: Provider;
|
|
57
|
+
|
|
58
|
+
constructor(provider: Provider) {
|
|
59
|
+
const providerValidation = providerSchema().validate(provider);
|
|
60
|
+
if (providerValidation.error) { throw new Error(`Invalid provider for protocol`); }
|
|
61
|
+
this.provider = provider;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public evaluate = async (req: Protocol.Command): Promise<any> => {
|
|
65
|
+
try {
|
|
66
|
+
const validation = commandSchema.validate(req);
|
|
67
|
+
if (validation.error) { throw new Error(`Invalid request: ${validation.error.message}`); }
|
|
68
|
+
|
|
69
|
+
let response: any;
|
|
70
|
+
switch (req.command) {
|
|
71
|
+
case `list:actions`:
|
|
72
|
+
response = Object.values(this.provider.actions || {});
|
|
73
|
+
break;
|
|
74
|
+
case `list:triggers`:
|
|
75
|
+
response = Object.values(this.provider.triggers || {});
|
|
76
|
+
break;
|
|
77
|
+
case `list:credentials`:
|
|
78
|
+
response = Object.values(this.provider.credentials || {});
|
|
79
|
+
break;
|
|
80
|
+
case `list:sources`:
|
|
81
|
+
response = Object.values(this.provider.sources || {});
|
|
82
|
+
break;
|
|
83
|
+
case `list:locales`:
|
|
84
|
+
const i18nInstance = i18n({ directory: `node_modules/prow-hubspot-repository/locales` });
|
|
85
|
+
response = i18nInstance.i18n.getLocales().map((l) => {
|
|
86
|
+
i18nInstance.i18n.setLocale(l);
|
|
87
|
+
return {
|
|
88
|
+
code: l,
|
|
89
|
+
catalog: i18nInstance.i18n.getCatalog(),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
break;
|
|
93
|
+
case `invoke`:
|
|
94
|
+
const mEvent = _.get(this.provider, `${req.model}s.${req.id}`);
|
|
95
|
+
if (!mEvent) {
|
|
96
|
+
return {
|
|
97
|
+
status: 404,
|
|
98
|
+
body: JSON.stringify({ error: `Could not find ${req.model} with ID ${req.id}` }),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const f = _.get(mEvent, req.params.function);
|
|
103
|
+
if (!f || typeof f !== `function`) { throw new Error(`Invalid function ${req.params.function}`); }
|
|
104
|
+
|
|
105
|
+
const invokeInstance = core({
|
|
106
|
+
env: req.context.environment,
|
|
107
|
+
localization: req.context.localization,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
response = await f(invokeInstance, req.params.configuration);
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Invalid command`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return response;
|
|
117
|
+
} catch (e) { throw e; }
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export namespace Protocol {
|
|
122
|
+
|
|
123
|
+
export type Model = `action` | `trigger` | `credentials`;
|
|
124
|
+
|
|
125
|
+
export type Invoke = {
|
|
126
|
+
command: `invoke`,
|
|
127
|
+
model: Protocol.Model,
|
|
128
|
+
id: string,
|
|
129
|
+
params: {
|
|
130
|
+
function: string,
|
|
131
|
+
configuration: Record<string, any>,
|
|
132
|
+
},
|
|
133
|
+
context: {
|
|
134
|
+
environment: Record<string, any>,
|
|
135
|
+
localization: {
|
|
136
|
+
locale: string,
|
|
137
|
+
catalog: Record<string, any>,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export type CredentialList = {
|
|
143
|
+
command: `list:credentials`,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export type ActionList = {
|
|
147
|
+
command: `list:actions`,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type TriggerList = {
|
|
151
|
+
command: `list:triggers`,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type SourceList = {
|
|
155
|
+
command: `list:sources`,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type LocaleList = {
|
|
159
|
+
command: `list:locales`,
|
|
160
|
+
locale: string,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type Command = Invoke | CredentialList | ActionList | TriggerList | SourceList | LocaleList;
|
|
164
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const validateDirectory: (directory: string) => boolean;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateDirectory = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const validateDirectory = (directory) => {
|
|
9
|
-
try {
|
|
10
|
-
if (!fs_1.default.existsSync(directory)) {
|
|
11
|
-
console.error(`Directory does not exist: ${directory}`);
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const files = fs_1.default.readdirSync(directory);
|
|
15
|
-
if (!files.some((file) => file.endsWith(`.json`))) {
|
|
16
|
-
console.error(`No valid localization files found in directory: ${directory}`);
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.error(`Error validating directory: ${error.message}`);
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
exports.validateDirectory = validateDirectory;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
export const validateDirectory = (directory: string): boolean => {
|
|
3
|
-
try {
|
|
4
|
-
if (!fs.existsSync(directory)) {
|
|
5
|
-
console.error(`Directory does not exist: ${directory}`);
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
const files = fs.readdirSync(directory);
|
|
9
|
-
if (!files.some((file) => file.endsWith(`.json`))) {
|
|
10
|
-
console.error(`No valid localization files found in directory: ${directory}`);
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
console.error(`Error validating directory: ${error.message}`);
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
};
|