@hubspot/local-dev-lib 0.0.7 → 0.0.9
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/api/customObjects.js +3 -3
- package/api/fileMapper.d.ts +2 -0
- package/api/fileMapper.js +3 -2
- package/api/functions.js +1 -1
- package/api/hubdb.js +4 -4
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +2 -2
- package/api/localDevAuth.d.ts +5 -1
- package/api/localDevAuth.js +1 -1
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +2 -2
- package/api/projects.js +2 -2
- package/api/sandboxHubs.js +1 -1
- package/api/sandboxSync.js +1 -1
- package/api/secrets.js +2 -2
- package/api/validateHubl.js +1 -1
- package/config/CLIConfiguration.js +20 -18
- package/config/configFile.js +1 -2
- package/config/configUtils.js +2 -1
- package/config/config_DEPRECATED.js +27 -24
- package/config/environment.js +4 -3
- package/constants/ports.d.ts +3 -0
- package/constants/ports.js +6 -0
- package/errors/apiErrors.d.ts +1 -1
- package/errors/apiErrors.js +13 -13
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/fileSystemErrors.js +1 -1
- package/errors/standardErrors.d.ts +4 -3
- package/errors/standardErrors.js +2 -2
- package/http/index.js +8 -4
- package/lang/en.json +383 -0
- package/lang/lang/en.json +383 -0
- package/lib/archive.js +10 -9
- package/lib/cms/functions.js +13 -13
- package/lib/cms/handleFieldsJS.js +8 -6
- package/lib/cms/modules.js +5 -4
- package/lib/cms/processFieldsJs.js +6 -8
- package/lib/cms/templates.js +10 -5
- package/lib/cms/uploadFolder.js +11 -7
- package/lib/cms/watch.js +33 -21
- package/lib/customObjects.d.ts +4 -4
- package/lib/customObjects.js +21 -4
- package/lib/fileMapper.js +28 -21
- package/lib/github.js +15 -11
- package/lib/gitignore.js +2 -1
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +5 -4
- package/lib/logging/git.js +1 -1
- package/lib/logging/logs.js +5 -1
- package/lib/oauth.js +5 -4
- package/lib/personalAccessKey.d.ts +1 -1
- package/lib/personalAccessKey.js +6 -5
- package/lib/portManager.d.ts +13 -0
- package/lib/portManager.js +45 -0
- package/lib/sandboxes.js +7 -7
- package/lib/trackUsage.js +3 -3
- package/models/HubSpotAuthError.d.ts +1 -1
- package/models/HubSpotAuthError.js +2 -2
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +5 -5
- package/package.json +7 -2
- package/types/Error.d.ts +3 -3
- package/types/Http.d.ts +8 -11
- package/types/Hubdb.d.ts +27 -17
- package/types/Lang.d.ts +7 -0
- package/types/Lang.js +2 -0
- package/types/PortManager.d.ts +4 -0
- package/types/PortManager.js +2 -0
- package/types/Schemas.d.ts +18 -33
- package/types/Utils.d.ts +5 -0
- package/utils/PortManagerServer.d.ts +29 -0
- package/utils/PortManagerServer.js +158 -0
- package/utils/cms/modules.js +2 -1
- package/utils/detectPort.d.ts +1 -0
- package/utils/detectPort.js +102 -0
- package/utils/lang.d.ts +2 -4
- package/utils/lang.js +12 -14
- package/utils/logger.d.ts +4 -3
- package/utils/logger.js +4 -3
- package/utils/notify.js +2 -1
- package/lang/en.lyaml +0 -247
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Express, Request, Response } from 'express';
|
|
3
|
+
import { Server } from 'http';
|
|
4
|
+
import { RequestPortsData } from '../types/PortManager';
|
|
5
|
+
type ServerPortMap = {
|
|
6
|
+
[instanceId: string]: number;
|
|
7
|
+
};
|
|
8
|
+
declare class PortManagerServer {
|
|
9
|
+
app?: Express;
|
|
10
|
+
server?: Server;
|
|
11
|
+
serverPortMap: ServerPortMap;
|
|
12
|
+
constructor();
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
reset(): void;
|
|
15
|
+
listen(): Promise<Server>;
|
|
16
|
+
setupRoutes(): void;
|
|
17
|
+
setPort(instanceId: string, port: number): void;
|
|
18
|
+
deletePort(instanceId: string): void;
|
|
19
|
+
send404(res: Response, instanceId: string): void;
|
|
20
|
+
getServers: (req: Request, res: Response) => Promise<void>;
|
|
21
|
+
getServerPortByInstanceId: (req: Request, res: Response) => void;
|
|
22
|
+
assignPortsToServers: (req: Request<never, never, {
|
|
23
|
+
portData: Array<RequestPortsData>;
|
|
24
|
+
}>, res: Response) => Promise<void>;
|
|
25
|
+
deleteServerInstance: (req: Request, res: Response) => void;
|
|
26
|
+
closeServer: (req: Request, res: Response) => void;
|
|
27
|
+
}
|
|
28
|
+
declare const _default: PortManagerServer;
|
|
29
|
+
export default _default;
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
const express_1 = __importDefault(require("express"));
|
|
7
|
+
const cors_1 = __importDefault(require("cors"));
|
|
8
|
+
const detectPort_1 = require("./detectPort");
|
|
9
|
+
const ports_1 = require("../constants/ports");
|
|
10
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
11
|
+
const logger_1 = require("./logger");
|
|
12
|
+
const lang_1 = require("./lang");
|
|
13
|
+
const i18nKey = 'utils.PortManagerServer';
|
|
14
|
+
class PortManagerServer {
|
|
15
|
+
app;
|
|
16
|
+
server;
|
|
17
|
+
serverPortMap;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.serverPortMap = {};
|
|
20
|
+
}
|
|
21
|
+
async init() {
|
|
22
|
+
if (this.app) {
|
|
23
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.duplicateInstance`);
|
|
24
|
+
}
|
|
25
|
+
this.app = (0, express_1.default)();
|
|
26
|
+
this.app.use(express_1.default.json());
|
|
27
|
+
this.app.use((0, cors_1.default)());
|
|
28
|
+
this.setupRoutes();
|
|
29
|
+
try {
|
|
30
|
+
this.server = await this.listen();
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
const error = e;
|
|
34
|
+
if (error.code === 'EADDRINUSE') {
|
|
35
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.portInUse`, {
|
|
36
|
+
port: ports_1.PORT_MANAGER_SERVER_PORT,
|
|
37
|
+
}, error);
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
reset() {
|
|
43
|
+
this.app = undefined;
|
|
44
|
+
this.server = undefined;
|
|
45
|
+
this.serverPortMap = {};
|
|
46
|
+
}
|
|
47
|
+
listen() {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const server = this.app.listen(ports_1.PORT_MANAGER_SERVER_PORT, () => {
|
|
50
|
+
(0, logger_1.debug)(`${i18nKey}.started`, {
|
|
51
|
+
port: ports_1.PORT_MANAGER_SERVER_PORT,
|
|
52
|
+
});
|
|
53
|
+
resolve(server);
|
|
54
|
+
}).on('error', (err) => {
|
|
55
|
+
reject(err);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
setupRoutes() {
|
|
60
|
+
if (!this.app) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.app.get('/servers', this.getServers);
|
|
64
|
+
this.app.get('/servers/:instanceId', this.getServerPortByInstanceId);
|
|
65
|
+
this.app.post('/servers', this.assignPortsToServers);
|
|
66
|
+
this.app.delete('/servers/:instanceId', this.deleteServerInstance);
|
|
67
|
+
this.app.post('/close', this.closeServer);
|
|
68
|
+
}
|
|
69
|
+
setPort(instanceId, port) {
|
|
70
|
+
(0, logger_1.debug)(`${i18nKey}.setPort`, { instanceId, port });
|
|
71
|
+
this.serverPortMap[instanceId] = port;
|
|
72
|
+
}
|
|
73
|
+
deletePort(instanceId) {
|
|
74
|
+
(0, logger_1.debug)(`${i18nKey}.deletedPort`, {
|
|
75
|
+
instanceId,
|
|
76
|
+
port: this.serverPortMap[instanceId],
|
|
77
|
+
});
|
|
78
|
+
delete this.serverPortMap[instanceId];
|
|
79
|
+
}
|
|
80
|
+
send404(res, instanceId) {
|
|
81
|
+
res
|
|
82
|
+
.status(404)
|
|
83
|
+
.send((0, lang_1.i18n)(`${i18nKey}.errors.404`, { instanceId: instanceId }));
|
|
84
|
+
}
|
|
85
|
+
getServers = async (req, res) => {
|
|
86
|
+
res.send({
|
|
87
|
+
servers: this.serverPortMap,
|
|
88
|
+
count: Object.keys(this.serverPortMap).length,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
getServerPortByInstanceId = (req, res) => {
|
|
92
|
+
const { instanceId } = req.params;
|
|
93
|
+
const port = this.serverPortMap[instanceId];
|
|
94
|
+
if (port) {
|
|
95
|
+
res.send({ port });
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.send404(res, instanceId);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
assignPortsToServers = async (req, res) => {
|
|
102
|
+
const { portData } = req.body;
|
|
103
|
+
const portPromises = [];
|
|
104
|
+
for (let i = 0; i < portData.length; i++) {
|
|
105
|
+
const { port, instanceId } = portData[i];
|
|
106
|
+
if (this.serverPortMap[instanceId]) {
|
|
107
|
+
res.status(409).send((0, lang_1.i18n)(`${i18nKey}.errors.409`, {
|
|
108
|
+
instanceId,
|
|
109
|
+
port: this.serverPortMap[instanceId],
|
|
110
|
+
}));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
else if (port && (port < ports_1.MIN_PORT_NUMBER || port > ports_1.MAX_PORT_NUMBER)) {
|
|
114
|
+
res.status(400).send((0, lang_1.i18n)(`${i18nKey}.errors.400`, {
|
|
115
|
+
minPort: ports_1.MIN_PORT_NUMBER,
|
|
116
|
+
maxPort: ports_1.MAX_PORT_NUMBER,
|
|
117
|
+
}));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const promise = new Promise(resolve => {
|
|
122
|
+
(0, detectPort_1.detectPort)(port, Object.values(this.serverPortMap)).then(resolvedPort => {
|
|
123
|
+
resolve({
|
|
124
|
+
[instanceId]: resolvedPort,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
portPromises.push(promise);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const portList = await Promise.all(portPromises);
|
|
132
|
+
const ports = portList.reduce((a, c) => Object.assign(a, c));
|
|
133
|
+
for (const instanceId in ports) {
|
|
134
|
+
this.setPort(instanceId, ports[instanceId]);
|
|
135
|
+
}
|
|
136
|
+
res.send({ ports });
|
|
137
|
+
};
|
|
138
|
+
deleteServerInstance = (req, res) => {
|
|
139
|
+
const { instanceId } = req.params;
|
|
140
|
+
const port = this.serverPortMap[instanceId];
|
|
141
|
+
if (port) {
|
|
142
|
+
this.deletePort(instanceId);
|
|
143
|
+
res.send(200);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.send404(res, instanceId);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
closeServer = (req, res) => {
|
|
150
|
+
if (this.server) {
|
|
151
|
+
(0, logger_1.debug)(`${i18nKey}.close`);
|
|
152
|
+
res.send(200);
|
|
153
|
+
this.server.close();
|
|
154
|
+
this.reset();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
exports.default = new PortManagerServer();
|
package/utils/cms/modules.js
CHANGED
|
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const path_2 = require("../../lib/path");
|
|
9
9
|
const extensions_1 = require("../../constants/extensions");
|
|
10
10
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
11
|
+
const i18nKey = 'utils.cms.modules';
|
|
11
12
|
const isBool = (x) => !!x === x;
|
|
12
13
|
function isPathInput(pathInput) {
|
|
13
14
|
return !!(pathInput &&
|
|
@@ -18,7 +19,7 @@ exports.isPathInput = isPathInput;
|
|
|
18
19
|
function throwInvalidPathInput(pathInput) {
|
|
19
20
|
if (isPathInput(pathInput))
|
|
20
21
|
return;
|
|
21
|
-
(0, standardErrors_1.throwTypeErrorWithMessage)(
|
|
22
|
+
(0, standardErrors_1.throwTypeErrorWithMessage)(`${i18nKey}.throwInvalidPathInput`);
|
|
22
23
|
}
|
|
23
24
|
function isModuleFolder(pathInput) {
|
|
24
25
|
throwInvalidPathInput(pathInput);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function detectPort(port?: number | null, exclude?: Array<number>): Promise<number>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
From https://github.com/node-modules/detect-port/tree/master
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2014 - present node-modules and other contributors
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
10
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
11
|
+
the Software without restriction, including without limitation the rights to
|
|
12
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
13
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
14
|
+
subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
21
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
22
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
23
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
24
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.detectPort = void 0;
|
|
31
|
+
const net_1 = __importDefault(require("net"));
|
|
32
|
+
const address_1 = require("address");
|
|
33
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
34
|
+
const ports_1 = require("../constants/ports");
|
|
35
|
+
const i18nKey = 'utils.detectPort';
|
|
36
|
+
function detectPort(port, exclude = []) {
|
|
37
|
+
if (port && (port < ports_1.MIN_PORT_NUMBER || port > ports_1.MAX_PORT_NUMBER)) {
|
|
38
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidPort`, {
|
|
39
|
+
minPort: ports_1.MIN_PORT_NUMBER,
|
|
40
|
+
maxPort: ports_1.MAX_PORT_NUMBER,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const portToUse = port || 0;
|
|
44
|
+
const maxPort = Math.min(portToUse + 10, ports_1.MAX_PORT_NUMBER);
|
|
45
|
+
return new Promise(resolve => {
|
|
46
|
+
tryListen(portToUse, maxPort, exclude, (_, resolvedPort) => {
|
|
47
|
+
resolve(resolvedPort);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.detectPort = detectPort;
|
|
52
|
+
function tryListen(port, maxPort, exclude, callback) {
|
|
53
|
+
const shouldGiveUp = port >= maxPort;
|
|
54
|
+
const nextPort = shouldGiveUp ? 0 : port + 1;
|
|
55
|
+
const nextMaxPort = shouldGiveUp ? 0 : maxPort;
|
|
56
|
+
listen(port, undefined, (err, realPort) => {
|
|
57
|
+
// ignore random listening
|
|
58
|
+
if (port === 0) {
|
|
59
|
+
return callback(err, realPort);
|
|
60
|
+
}
|
|
61
|
+
if (exclude.includes(port)) {
|
|
62
|
+
return tryListen(nextPort, nextMaxPort, exclude, callback);
|
|
63
|
+
}
|
|
64
|
+
if (err) {
|
|
65
|
+
return tryListen(nextPort, nextMaxPort, exclude, callback);
|
|
66
|
+
}
|
|
67
|
+
// 2. check 0.0.0.0
|
|
68
|
+
listen(port, '0.0.0.0', err => {
|
|
69
|
+
if (err) {
|
|
70
|
+
return tryListen(nextPort, nextMaxPort, exclude, callback);
|
|
71
|
+
}
|
|
72
|
+
// 3. check localhost
|
|
73
|
+
listen(port, 'localhost', err => {
|
|
74
|
+
if (err && err.code !== 'EADDRNOTAVAIL') {
|
|
75
|
+
return tryListen(nextPort, nextMaxPort, exclude, callback);
|
|
76
|
+
}
|
|
77
|
+
// 4. check current ip
|
|
78
|
+
listen(port, (0, address_1.ip)(), (err, realPort) => {
|
|
79
|
+
if (err) {
|
|
80
|
+
return tryListen(nextPort, nextMaxPort, exclude, callback);
|
|
81
|
+
}
|
|
82
|
+
callback(null, realPort);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function listen(port, hostname, callback) {
|
|
89
|
+
const server = new net_1.default.Server();
|
|
90
|
+
server.on('error', (err) => {
|
|
91
|
+
server.close();
|
|
92
|
+
if (err.code === 'ENOTFOUND') {
|
|
93
|
+
return callback(null, port);
|
|
94
|
+
}
|
|
95
|
+
return callback(err, 0);
|
|
96
|
+
});
|
|
97
|
+
server.listen(port, hostname, () => {
|
|
98
|
+
const addressInfo = server.address();
|
|
99
|
+
server.close();
|
|
100
|
+
return callback(null, addressInfo.port);
|
|
101
|
+
});
|
|
102
|
+
}
|
package/utils/lang.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
[key: string]: LanguageObject | string;
|
|
3
|
-
};
|
|
1
|
+
import { LanguageObject, LangKey } from '../types/Lang';
|
|
4
2
|
type InterpolationData = {
|
|
5
3
|
[identifier: string]: string | number;
|
|
6
4
|
};
|
|
7
5
|
export declare function interpolate(stringValue: string, interpolationData: InterpolationData): string;
|
|
8
|
-
export declare function i18n(lookupDotNotation:
|
|
6
|
+
export declare function i18n(lookupDotNotation: LangKey, options?: {
|
|
9
7
|
[identifier: string]: string | number;
|
|
10
8
|
}): string;
|
|
11
9
|
export declare const setLangData: (newLocale: string, newLangObj: LanguageObject) => void;
|
package/utils/lang.js
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.setLangData = exports.i18n = exports.interpolate = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
+
const en_json_1 = __importDefault(require("../lang/en.json"));
|
|
8
|
+
const LANGUAGES = {
|
|
9
|
+
en: en_json_1.default,
|
|
10
|
+
};
|
|
7
11
|
const MISSING_LANGUAGE_DATA_PREFIX = '[Missing language data]';
|
|
8
|
-
let locale = '';
|
|
9
12
|
let languageObj;
|
|
10
|
-
function
|
|
13
|
+
function loadLanguageForLocale() {
|
|
11
14
|
if (languageObj)
|
|
12
15
|
return;
|
|
13
16
|
try {
|
|
14
17
|
const nodeLocale = Intl.DateTimeFormat()
|
|
15
18
|
.resolvedOptions()
|
|
16
19
|
.locale.split('-')[0];
|
|
17
|
-
|
|
18
|
-
const languageFileExists = (0, fs_extra_1.existsSync)(languageFilePath);
|
|
19
|
-
// Fall back to using the default language file
|
|
20
|
-
locale = languageFileExists ? nodeLocale : 'en';
|
|
21
|
-
languageObj = (0, js_yaml_1.load)((0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, `../lang/${locale}.lyaml`), 'utf8'));
|
|
20
|
+
languageObj = LANGUAGES[nodeLocale] || LANGUAGES.en;
|
|
22
21
|
}
|
|
23
22
|
catch (e) {
|
|
24
23
|
throw new Error(`Error loading language data: ${e}`);
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
function getTextValue(lookupDotNotation) {
|
|
28
|
-
const lookupProps =
|
|
29
|
-
const missingTextData = `${MISSING_LANGUAGE_DATA_PREFIX}: ${
|
|
27
|
+
const lookupProps = lookupDotNotation.split('.');
|
|
28
|
+
const missingTextData = `${MISSING_LANGUAGE_DATA_PREFIX}: ${lookupDotNotation}`;
|
|
30
29
|
let textValue = languageObj;
|
|
31
30
|
let previouslyCheckedProp = lookupProps[0];
|
|
32
31
|
lookupProps.forEach(prop => {
|
|
@@ -73,7 +72,7 @@ function interpolate(stringValue, interpolationData) {
|
|
|
73
72
|
exports.interpolate = interpolate;
|
|
74
73
|
function i18n(lookupDotNotation, options = {}) {
|
|
75
74
|
if (!languageObj) {
|
|
76
|
-
|
|
75
|
+
loadLanguageForLocale();
|
|
77
76
|
}
|
|
78
77
|
if (typeof lookupDotNotation !== 'string') {
|
|
79
78
|
throw new Error(`i18n must be passed a string value for lookupDotNotation, received ${typeof lookupDotNotation}`);
|
|
@@ -84,7 +83,6 @@ function i18n(lookupDotNotation, options = {}) {
|
|
|
84
83
|
}
|
|
85
84
|
exports.i18n = i18n;
|
|
86
85
|
const setLangData = (newLocale, newLangObj) => {
|
|
87
|
-
locale = newLocale;
|
|
88
86
|
languageObj = newLangObj;
|
|
89
87
|
};
|
|
90
88
|
exports.setLangData = setLangData;
|
package/utils/logger.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { LogCallbacks } from '../types/LogCallbacks';
|
|
2
|
-
|
|
2
|
+
import { LangKey } from '../types/Lang';
|
|
3
|
+
export declare function log<T extends string>(key: T, callbacks?: LogCallbacks<T>, debugKey?: LangKey, debugInterpolation?: {
|
|
3
4
|
[key: string]: string | number;
|
|
4
5
|
}): void;
|
|
5
|
-
export declare function makeTypedLogger<T extends readonly string[]>(callbacks?: LogCallbacks<T[number]
|
|
6
|
+
export declare function makeTypedLogger<T extends readonly string[]>(callbacks?: LogCallbacks<T[number]>): (key: T[number], debugKey?: LangKey, debugInterpolation?: {
|
|
6
7
|
[key: string]: string | number;
|
|
7
8
|
} | undefined) => void;
|
|
8
|
-
export declare function debug(identifier:
|
|
9
|
+
export declare function debug(identifier: LangKey, interpolation?: {
|
|
9
10
|
[key: string]: string | number;
|
|
10
11
|
}): void;
|
package/utils/logger.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.debug = exports.makeTypedLogger = exports.log = void 0;
|
|
4
4
|
const lang_1 = require("./lang");
|
|
5
|
+
const logger_1 = require("../lib/logging/logger");
|
|
5
6
|
function log(key, callbacks, debugKey, debugInterpolation) {
|
|
6
7
|
if (callbacks && callbacks[key]) {
|
|
7
8
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -12,11 +13,11 @@ function log(key, callbacks, debugKey, debugInterpolation) {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
exports.log = log;
|
|
15
|
-
function makeTypedLogger(callbacks
|
|
16
|
-
return (key, debugInterpolation) => log(key, callbacks,
|
|
16
|
+
function makeTypedLogger(callbacks) {
|
|
17
|
+
return (key, debugKey, debugInterpolation) => log(key, callbacks, debugKey, debugInterpolation);
|
|
17
18
|
}
|
|
18
19
|
exports.makeTypedLogger = makeTypedLogger;
|
|
19
20
|
function debug(identifier, interpolation) {
|
|
20
|
-
|
|
21
|
+
logger_1.logger.debug((0, lang_1.i18n)(identifier, interpolation));
|
|
21
22
|
}
|
|
22
23
|
exports.debug = debug;
|
package/utils/notify.js
CHANGED
|
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
9
|
const debounce_1 = __importDefault(require("debounce"));
|
|
10
10
|
const standardErrors_1 = require("../errors/standardErrors");
|
|
11
|
+
const i18nKey = 'utils.notify';
|
|
11
12
|
const notifyQueue = [];
|
|
12
13
|
const notifyPromises = [];
|
|
13
14
|
const debouncedWaitForActionsToCompleteAndWriteQueueToFile = (0, debounce_1.default)(waitForActionsToCompleteAndWriteQueueToFile, 500);
|
|
@@ -36,7 +37,7 @@ function notifyFilePath(filePathToNotify, outputToWrite) {
|
|
|
36
37
|
fs_1.default.appendFileSync(filePathToNotify, outputToWrite);
|
|
37
38
|
}
|
|
38
39
|
catch (e) {
|
|
39
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
40
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.filePath`, { filePath: filePathToNotify }, e);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|