@hubspot/local-dev-lib 0.0.1-experimental.0
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/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -0
- package/api/customObjects.js +45 -0
- package/api/designManager.d.ts +5 -0
- package/api/designManager.js +18 -0
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +6 -0
- package/api/fileManager.js +63 -0
- package/api/fileMapper.d.ts +12 -0
- package/api/fileMapper.js +106 -0
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +8 -0
- package/api/functions.js +43 -0
- package/api/github.d.ts +11 -0
- package/api/github.js +71 -0
- package/api/hubdb.d.ts +12 -0
- package/api/hubdb.js +67 -0
- package/api/lighthouseScore.d.ts +6 -0
- package/api/lighthouseScore.js +26 -0
- package/api/localDevAuth.d.ts +8 -0
- package/api/localDevAuth.js +53 -0
- package/api/marketplaceValidation.d.ts +6 -0
- package/api/marketplaceValidation.js +26 -0
- package/api/projects.d.ts +40 -0
- package/api/projects.js +216 -0
- package/api/sandboxHubs.d.ts +7 -0
- package/api/sandboxHubs.js +49 -0
- package/api/sandboxSync.d.ts +4 -0
- package/api/sandboxSync.js +26 -0
- package/api/secrets.d.ts +6 -0
- package/api/secrets.js +37 -0
- package/api/validateHubl.d.ts +3 -0
- package/api/validateHubl.js +15 -0
- package/config/CLIConfiguration.d.ts +62 -0
- package/config/CLIConfiguration.js +467 -0
- package/config/configFile.d.ts +21 -0
- package/config/configFile.js +102 -0
- package/config/configUtils.d.ts +5 -0
- package/config/configUtils.js +87 -0
- package/config/config_DEPRECATED.d.ts +75 -0
- package/config/config_DEPRECATED.js +678 -0
- package/config/environment.d.ts +2 -0
- package/config/environment.js +60 -0
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +41 -0
- package/config/index.js +260 -0
- package/constants/api.d.ts +15 -0
- package/constants/api.js +18 -0
- package/constants/auth.d.ts +37 -0
- package/constants/auth.js +38 -0
- package/constants/config.d.ts +18 -0
- package/constants/config.js +22 -0
- package/constants/environments.d.ts +15 -0
- package/constants/environments.js +18 -0
- package/constants/extensions.d.ts +6 -0
- package/constants/extensions.js +28 -0
- package/constants/files.d.ts +21 -0
- package/constants/files.js +24 -0
- package/constants/ports.d.ts +3 -0
- package/constants/ports.js +6 -0
- package/enums/build.d.ts +36 -0
- package/enums/build.js +39 -0
- package/enums/deploy.d.ts +11 -0
- package/enums/deploy.js +14 -0
- package/enums/project.d.ts +6 -0
- package/enums/project.js +9 -0
- package/errors/errors_DEPRECATED.d.ts +3 -0
- package/errors/errors_DEPRECATED.js +60 -0
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +9 -0
- package/http/getAxiosConfig.js +66 -0
- package/http/index.d.ts +17 -0
- package/http/index.js +173 -0
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +389 -0
- package/lib/archive.d.ts +3 -0
- package/lib/archive.js +117 -0
- package/lib/cms/functions.d.ts +8 -0
- package/lib/cms/functions.js +181 -0
- package/lib/cms/handleFieldsJS.d.ts +33 -0
- package/lib/cms/handleFieldsJS.js +148 -0
- package/lib/cms/modules.d.ts +14 -0
- package/lib/cms/modules.js +186 -0
- package/lib/cms/processFieldsJs.d.ts +1 -0
- package/lib/cms/processFieldsJs.js +97 -0
- package/lib/cms/templates.d.ts +65 -0
- package/lib/cms/templates.js +107 -0
- package/lib/cms/themes.d.ts +2 -0
- package/lib/cms/themes.js +34 -0
- package/lib/cms/uploadFolder.d.ts +7 -0
- package/lib/cms/uploadFolder.js +202 -0
- package/lib/cms/validate.d.ts +2 -0
- package/lib/cms/validate.js +40 -0
- package/lib/cms/watch.d.ts +4 -0
- package/lib/cms/watch.js +201 -0
- package/lib/customObjects.d.ts +5 -0
- package/lib/customObjects.js +42 -0
- package/lib/environment.d.ts +2 -0
- package/lib/environment.js +16 -0
- package/lib/escapeRegExp.d.ts +1 -0
- package/lib/escapeRegExp.js +7 -0
- package/lib/fileManager.d.ts +2 -0
- package/lib/fileManager.js +184 -0
- package/lib/fileMapper.d.ts +18 -0
- package/lib/fileMapper.js +317 -0
- package/lib/fs.d.ts +4 -0
- package/lib/fs.js +71 -0
- package/lib/github.d.ts +8 -0
- package/lib/github.js +167 -0
- package/lib/gitignore.d.ts +3 -0
- package/lib/gitignore.js +49 -0
- package/lib/hubdb.d.ts +17 -0
- package/lib/hubdb.js +133 -0
- package/lib/ignoreRules.d.ts +3 -0
- package/lib/ignoreRules.js +69 -0
- package/lib/logger.d.ts +56 -0
- package/lib/logger.js +146 -0
- package/lib/notify.d.ts +1 -0
- package/lib/notify.js +43 -0
- package/lib/oauth.d.ts +4 -0
- package/lib/oauth.js +34 -0
- package/lib/path.d.ts +14 -0
- package/lib/path.js +134 -0
- package/lib/personalAccessKey.d.ts +10 -0
- package/lib/personalAccessKey.js +163 -0
- package/lib/portManager.d.ts +10 -0
- package/lib/portManager.js +46 -0
- package/lib/text.d.ts +2 -0
- package/lib/text.js +24 -0
- package/lib/trackUsage.d.ts +1 -0
- package/lib/trackUsage.js +63 -0
- package/lib/urls.d.ts +2 -0
- package/lib/urls.js +24 -0
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +12 -0
- package/models/OAuth2Manager.js +105 -0
- package/package.json +81 -0
- package/types/Accounts.d.ts +178 -0
- package/types/Accounts.js +2 -0
- package/types/Activity.d.ts +20 -0
- package/types/Activity.js +2 -0
- package/types/Api.d.ts +2 -0
- package/types/Api.js +2 -0
- package/types/Apps.d.ts +77 -0
- package/types/Apps.js +2 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +41 -0
- package/types/Build.js +2 -0
- package/types/CLIOptions.d.ts +8 -0
- package/types/CLIOptions.js +2 -0
- package/types/ComponentStructure.d.ts +40 -0
- package/types/ComponentStructure.js +2 -0
- package/types/Config.d.ts +37 -0
- package/types/Config.js +2 -0
- package/types/Deploy.d.ts +42 -0
- package/types/Deploy.js +2 -0
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +37 -0
- package/types/Error.js +2 -0
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +71 -0
- package/types/FileManager.js +2 -0
- package/types/Files.d.ts +79 -0
- package/types/Files.js +2 -0
- package/types/Functions.d.ts +66 -0
- package/types/Functions.js +2 -0
- package/types/Github.d.ts +76 -0
- package/types/Github.js +2 -0
- package/types/Http.d.ts +29 -0
- package/types/Http.js +2 -0
- package/types/Hubdb.d.ts +109 -0
- package/types/Hubdb.js +2 -0
- package/types/HublValidation.d.ts +59 -0
- package/types/HublValidation.js +2 -0
- package/types/Lang.d.ts +10 -0
- package/types/Lang.js +2 -0
- package/types/Lighthouse.d.ts +25 -0
- package/types/Lighthouse.js +2 -0
- package/types/MarketplaceValidation.d.ts +28 -0
- package/types/MarketplaceValidation.js +2 -0
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +16 -0
- package/types/Modules.js +2 -0
- package/types/PortManager.d.ts +11 -0
- package/types/PortManager.js +2 -0
- package/types/Project.d.ts +42 -0
- package/types/Project.js +2 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +155 -0
- package/types/Sandbox.js +2 -0
- package/types/Schemas.d.ts +39 -0
- package/types/Schemas.js +2 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/Utils.d.ts +6 -0
- package/types/Utils.js +2 -0
- package/types/developerTestAccounts.d.ts +12 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +26 -0
- package/utils/PortManagerServer.js +158 -0
- package/utils/accounts.d.ts +4 -0
- package/utils/accounts.js +28 -0
- package/utils/cms/fieldsJS.d.ts +2 -0
- package/utils/cms/fieldsJS.js +18 -0
- package/utils/cms/modules.d.ts +4 -0
- package/utils/cms/modules.js +54 -0
- package/utils/detectPort.d.ts +1 -0
- package/utils/detectPort.js +102 -0
- package/utils/git.d.ts +3 -0
- package/utils/git.js +71 -0
- package/utils/lang.d.ts +6 -0
- package/utils/lang.js +88 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Express, Request, Response } from 'express';
|
|
3
|
+
import { Server } from 'http';
|
|
4
|
+
import { RequestPortsData, ServerPortMap } from '../types/PortManager';
|
|
5
|
+
declare class _PortManagerServer {
|
|
6
|
+
app?: Express;
|
|
7
|
+
server?: Server;
|
|
8
|
+
serverPortMap: ServerPortMap;
|
|
9
|
+
constructor();
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
reset(): void;
|
|
12
|
+
listen(): Promise<Server>;
|
|
13
|
+
setupRoutes(): void;
|
|
14
|
+
setPort(instanceId: string, port: number): void;
|
|
15
|
+
deletePort(instanceId: string): void;
|
|
16
|
+
send404(res: Response, instanceId: string): void;
|
|
17
|
+
getServers: (req: Request, res: Response) => Promise<void>;
|
|
18
|
+
getServerPortByInstanceId: (req: Request, res: Response) => void;
|
|
19
|
+
assignPortsToServers: (req: Request<never, never, {
|
|
20
|
+
portData: Array<RequestPortsData>;
|
|
21
|
+
}>, res: Response) => Promise<void>;
|
|
22
|
+
deleteServerInstance: (req: Request, res: Response) => void;
|
|
23
|
+
closeServer: (req: Request, res: Response) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare const PortManagerServer: _PortManagerServer;
|
|
26
|
+
export {};
|
|
@@ -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
|
+
exports.PortManagerServer = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const cors_1 = __importDefault(require("cors"));
|
|
9
|
+
const detectPort_1 = require("./detectPort");
|
|
10
|
+
const ports_1 = require("../constants/ports");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
12
|
+
const logger_1 = require("../lib/logger");
|
|
13
|
+
const lang_1 = require("./lang");
|
|
14
|
+
const i18nKey = 'utils.PortManagerServer';
|
|
15
|
+
class _PortManagerServer {
|
|
16
|
+
app;
|
|
17
|
+
server;
|
|
18
|
+
serverPortMap;
|
|
19
|
+
constructor() {
|
|
20
|
+
this.serverPortMap = {};
|
|
21
|
+
}
|
|
22
|
+
async init() {
|
|
23
|
+
if (this.app) {
|
|
24
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.duplicateInstance`));
|
|
25
|
+
}
|
|
26
|
+
this.app = (0, express_1.default)();
|
|
27
|
+
this.app.use(express_1.default.json());
|
|
28
|
+
this.app.use((0, cors_1.default)());
|
|
29
|
+
this.setupRoutes();
|
|
30
|
+
try {
|
|
31
|
+
this.server = await this.listen();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
if ((0, errors_1.isSystemError)(e) && e.code === 'EADDRINUSE') {
|
|
35
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.portInUse`, {
|
|
36
|
+
port: ports_1.PORT_MANAGER_SERVER_PORT,
|
|
37
|
+
}), { cause: e });
|
|
38
|
+
}
|
|
39
|
+
throw e;
|
|
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
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${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
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.setPort`, { instanceId, port }));
|
|
71
|
+
this.serverPortMap[instanceId] = port;
|
|
72
|
+
}
|
|
73
|
+
deletePort(instanceId) {
|
|
74
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${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.sendStatus(200);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.send404(res, instanceId);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
closeServer = (req, res) => {
|
|
150
|
+
if (this.server) {
|
|
151
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.close`));
|
|
152
|
+
res.sendStatus(200);
|
|
153
|
+
this.server.close();
|
|
154
|
+
this.reset();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
exports.PortManagerServer = new _PortManagerServer();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CLIAccount } from '../types/Accounts';
|
|
2
|
+
import { CLIConfig } from '../types/Config';
|
|
3
|
+
export declare function getAccounts(config?: CLIConfig | null): Array<CLIAccount>;
|
|
4
|
+
export declare function getDefaultAccount(config?: CLIConfig | null): string | number | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultAccount = exports.getAccounts = void 0;
|
|
4
|
+
function getAccounts(config) {
|
|
5
|
+
if (!config) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
else if (Object.hasOwn(config, 'portals')) {
|
|
9
|
+
return config.portals;
|
|
10
|
+
}
|
|
11
|
+
else if (Object.hasOwn(config, 'accounts')) {
|
|
12
|
+
return config.accounts;
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
exports.getAccounts = getAccounts;
|
|
17
|
+
function getDefaultAccount(config) {
|
|
18
|
+
if (!config) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
else if (Object.hasOwn(config, 'defaultPortal')) {
|
|
22
|
+
return config.defaultPortal;
|
|
23
|
+
}
|
|
24
|
+
else if (Object.hasOwn(config, 'defaultAccount')) {
|
|
25
|
+
return config.defaultAccount;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.getDefaultAccount = getDefaultAccount;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fieldsArrayToJson = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Polyfill for `Array.flat(Infinity)` since the `flat` is only available for Node v11+
|
|
6
|
+
* https://stackoverflow.com/a/15030117
|
|
7
|
+
*/
|
|
8
|
+
function flattenArray(arr) {
|
|
9
|
+
return arr.reduce((flat, toFlatten) => {
|
|
10
|
+
return flat.concat(Array.isArray(toFlatten) ? flattenArray(toFlatten) : toFlatten);
|
|
11
|
+
}, []);
|
|
12
|
+
}
|
|
13
|
+
//Transform fields array to JSON
|
|
14
|
+
function fieldsArrayToJson(fields) {
|
|
15
|
+
const flattened = flattenArray(fields);
|
|
16
|
+
return JSON.stringify(flattened, null, 2);
|
|
17
|
+
}
|
|
18
|
+
exports.fieldsArrayToJson = fieldsArrayToJson;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PathInput } from '../../types/Modules';
|
|
2
|
+
export declare function isPathInput(pathInput?: PathInput): boolean;
|
|
3
|
+
export declare function isModuleFolder(pathInput: PathInput): boolean;
|
|
4
|
+
export declare function isModuleFolderChild(pathInput: PathInput, ignoreLocales?: boolean): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
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.isModuleFolderChild = exports.isModuleFolder = exports.isPathInput = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const path_2 = require("../../lib/path");
|
|
9
|
+
const extensions_1 = require("../../constants/extensions");
|
|
10
|
+
const lang_1 = require("../lang");
|
|
11
|
+
const i18nKey = 'utils.cms.modules';
|
|
12
|
+
const isBool = (x) => !!x === x;
|
|
13
|
+
function isPathInput(pathInput) {
|
|
14
|
+
return !!(pathInput &&
|
|
15
|
+
typeof pathInput.path === 'string' &&
|
|
16
|
+
(isBool(pathInput.isLocal) || isBool(pathInput.isHubSpot)));
|
|
17
|
+
}
|
|
18
|
+
exports.isPathInput = isPathInput;
|
|
19
|
+
function throwInvalidPathInput(pathInput) {
|
|
20
|
+
if (isPathInput(pathInput))
|
|
21
|
+
return;
|
|
22
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.throwInvalidPathInput`));
|
|
23
|
+
}
|
|
24
|
+
function isModuleFolder(pathInput) {
|
|
25
|
+
throwInvalidPathInput(pathInput);
|
|
26
|
+
const _path = pathInput.isHubSpot
|
|
27
|
+
? path_1.default.posix.normalize(pathInput.path)
|
|
28
|
+
: path_1.default.normalize(pathInput.path);
|
|
29
|
+
return (0, path_2.getExt)(_path) === extensions_1.MODULE_EXTENSION;
|
|
30
|
+
}
|
|
31
|
+
exports.isModuleFolder = isModuleFolder;
|
|
32
|
+
function isModuleFolderChild(pathInput, ignoreLocales = false) {
|
|
33
|
+
throwInvalidPathInput(pathInput);
|
|
34
|
+
let pathParts = [];
|
|
35
|
+
if (pathInput.isLocal) {
|
|
36
|
+
pathParts = (0, path_2.splitLocalPath)(pathInput.path);
|
|
37
|
+
}
|
|
38
|
+
else if (pathInput.isHubSpot) {
|
|
39
|
+
pathParts = (0, path_2.splitHubSpotPath)(pathInput.path);
|
|
40
|
+
}
|
|
41
|
+
const { length } = pathParts;
|
|
42
|
+
// Not a child path?
|
|
43
|
+
if (length <= 1)
|
|
44
|
+
return false;
|
|
45
|
+
// Check if we should ignore this file
|
|
46
|
+
if (ignoreLocales && pathParts.find(part => part === '_locales')) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
// Check if any parent folders are module folders.
|
|
50
|
+
return pathParts
|
|
51
|
+
.slice(0, length - 1)
|
|
52
|
+
.some(part => isModuleFolder({ ...pathInput, path: part }));
|
|
53
|
+
}
|
|
54
|
+
exports.isModuleFolderChild = isModuleFolderChild;
|
|
@@ -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 ports_1 = require("../constants/ports");
|
|
34
|
+
const lang_1 = require("./lang");
|
|
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
|
+
throw new Error((0, lang_1.i18n)(`${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/git.d.ts
ADDED
package/utils/git.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = exports.getGitignoreFiles = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
10
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
11
|
+
const GITIGNORE_FILE = '.gitignore';
|
|
12
|
+
function makeComparisonDir(filepath) {
|
|
13
|
+
if (typeof filepath !== 'string')
|
|
14
|
+
return null;
|
|
15
|
+
// Append sep to make comparisons easier e.g. 'foos'.startsWith('foo')
|
|
16
|
+
return path_1.default.dirname(path_1.default.resolve(filepath)).toLowerCase() + path_1.default.sep;
|
|
17
|
+
}
|
|
18
|
+
function getGitComparisonDir() {
|
|
19
|
+
return makeComparisonDir((0, findup_sync_1.default)('.git'));
|
|
20
|
+
}
|
|
21
|
+
// Get all .gitignore files since they can cascade down directory structures
|
|
22
|
+
function getGitignoreFiles(configPath) {
|
|
23
|
+
const gitDir = getGitComparisonDir();
|
|
24
|
+
const files = [];
|
|
25
|
+
if (!gitDir) {
|
|
26
|
+
// Not in git
|
|
27
|
+
return files;
|
|
28
|
+
}
|
|
29
|
+
// Start findup from config dir
|
|
30
|
+
let cwd = configPath && path_1.default.dirname(configPath);
|
|
31
|
+
while (cwd) {
|
|
32
|
+
const ignorePath = (0, findup_sync_1.default)(GITIGNORE_FILE, { cwd });
|
|
33
|
+
const cmpIgnorePath = makeComparisonDir(ignorePath);
|
|
34
|
+
const cmpGitDir = makeComparisonDir(gitDir);
|
|
35
|
+
if (ignorePath &&
|
|
36
|
+
cmpIgnorePath &&
|
|
37
|
+
cmpGitDir &&
|
|
38
|
+
// Stop findup after .git dir is reached
|
|
39
|
+
cmpIgnorePath.startsWith(cmpGitDir)) {
|
|
40
|
+
const file = path_1.default.resolve(ignorePath);
|
|
41
|
+
files.push(file);
|
|
42
|
+
cwd = path_1.default.resolve(path_1.default.dirname(file) + '..');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
cwd = null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return files;
|
|
49
|
+
}
|
|
50
|
+
exports.getGitignoreFiles = getGitignoreFiles;
|
|
51
|
+
function isConfigPathInGitRepo(configPath) {
|
|
52
|
+
const gitDir = getGitComparisonDir();
|
|
53
|
+
if (!gitDir)
|
|
54
|
+
return false;
|
|
55
|
+
const configDir = makeComparisonDir(configPath);
|
|
56
|
+
if (!configDir)
|
|
57
|
+
return false;
|
|
58
|
+
return configDir.startsWith(gitDir);
|
|
59
|
+
}
|
|
60
|
+
exports.isConfigPathInGitRepo = isConfigPathInGitRepo;
|
|
61
|
+
function configFilenameIsIgnoredByGitignore(ignoreFiles, configPath) {
|
|
62
|
+
return ignoreFiles.some(gitignore => {
|
|
63
|
+
const gitignoreContents = fs_extra_1.default.readFileSync(gitignore).toString();
|
|
64
|
+
const gitignoreConfig = (0, ignore_1.default)().add(gitignoreContents);
|
|
65
|
+
if (gitignoreConfig.ignores(path_1.default.relative(path_1.default.dirname(gitignore), configPath))) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.configFilenameIsIgnoredByGitignore = configFilenameIsIgnoredByGitignore;
|
package/utils/lang.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LanguageObject, LangKey, InterpolationData } from '../types/Lang';
|
|
2
|
+
export declare function interpolate(stringValue: string, interpolationData: InterpolationData): string;
|
|
3
|
+
export declare function i18n(lookupDotNotation: LangKey, options?: {
|
|
4
|
+
[identifier: string]: string | number;
|
|
5
|
+
}): string;
|
|
6
|
+
export declare const setLangData: (newLocale: string, newLangObj: LanguageObject) => void;
|
package/utils/lang.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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.setLangData = exports.i18n = exports.interpolate = void 0;
|
|
7
|
+
const en_json_1 = __importDefault(require("../lang/en.json"));
|
|
8
|
+
const LANGUAGES = {
|
|
9
|
+
en: en_json_1.default,
|
|
10
|
+
};
|
|
11
|
+
const MISSING_LANGUAGE_DATA_PREFIX = '[Missing language data]';
|
|
12
|
+
let languageObj;
|
|
13
|
+
function loadLanguageForLocale() {
|
|
14
|
+
if (languageObj)
|
|
15
|
+
return;
|
|
16
|
+
try {
|
|
17
|
+
const nodeLocale = Intl.DateTimeFormat()
|
|
18
|
+
.resolvedOptions()
|
|
19
|
+
.locale.split('-')[0];
|
|
20
|
+
languageObj = LANGUAGES[nodeLocale] || LANGUAGES.en;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw new Error(`Error loading language data: ${e}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function getTextValue(lookupDotNotation) {
|
|
27
|
+
const lookupProps = lookupDotNotation.split('.');
|
|
28
|
+
const missingTextData = `${MISSING_LANGUAGE_DATA_PREFIX}: ${lookupDotNotation}`;
|
|
29
|
+
let textValue = languageObj;
|
|
30
|
+
let previouslyCheckedProp = lookupProps[0];
|
|
31
|
+
lookupProps.forEach(prop => {
|
|
32
|
+
previouslyCheckedProp = prop;
|
|
33
|
+
if (typeof textValue === 'object') {
|
|
34
|
+
textValue = textValue[prop];
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.debug(`Unable to access language property: ${lookupProps.join('.')}. Failed to access prop "${previouslyCheckedProp}".`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (typeof textValue !== 'string') {
|
|
41
|
+
return missingTextData;
|
|
42
|
+
}
|
|
43
|
+
return textValue;
|
|
44
|
+
}
|
|
45
|
+
const delimiters = {
|
|
46
|
+
interpolation: {
|
|
47
|
+
start: '{{',
|
|
48
|
+
end: '}}',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
function generateReplaceFn(matchedText, startIndex, replacementString) {
|
|
52
|
+
return function (currentStringValue) {
|
|
53
|
+
return `${currentStringValue.slice(0, startIndex)}${replacementString || ''}${currentStringValue.slice(startIndex + matchedText.length)}`;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function interpolate(stringValue, interpolationData) {
|
|
57
|
+
const interpolationIdentifierRegEx = new RegExp(`${delimiters.interpolation.start}(.*?)${delimiters.interpolation.end}`, 'g');
|
|
58
|
+
const replaceQueue = [];
|
|
59
|
+
let match;
|
|
60
|
+
// while & reduce necessary because RegExp.exec is stateful and only runs
|
|
61
|
+
// from beginning to end of string
|
|
62
|
+
while ((match = interpolationIdentifierRegEx.exec(stringValue)) != null) {
|
|
63
|
+
const { 0: matchedText, 1: rawIdentifier, index } = match;
|
|
64
|
+
const identifier = rawIdentifier.trim();
|
|
65
|
+
if (identifier) {
|
|
66
|
+
replaceQueue.unshift(generateReplaceFn(matchedText, index, interpolationData[identifier]));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const compiledString = replaceQueue.reduce((currentValue, replaceFn) => replaceFn(currentValue), stringValue);
|
|
70
|
+
return compiledString;
|
|
71
|
+
}
|
|
72
|
+
exports.interpolate = interpolate;
|
|
73
|
+
function i18n(lookupDotNotation, options = {}) {
|
|
74
|
+
if (!languageObj) {
|
|
75
|
+
loadLanguageForLocale();
|
|
76
|
+
}
|
|
77
|
+
if (typeof lookupDotNotation !== 'string') {
|
|
78
|
+
throw new Error(`i18n must be passed a string value for lookupDotNotation, received ${typeof lookupDotNotation}`);
|
|
79
|
+
}
|
|
80
|
+
const textValue = getTextValue(lookupDotNotation);
|
|
81
|
+
const shouldInterpolate = !textValue.startsWith(MISSING_LANGUAGE_DATA_PREFIX);
|
|
82
|
+
return shouldInterpolate ? interpolate(textValue, options) : textValue;
|
|
83
|
+
}
|
|
84
|
+
exports.i18n = i18n;
|
|
85
|
+
const setLangData = (newLocale, newLangObj) => {
|
|
86
|
+
languageObj = newLangObj;
|
|
87
|
+
};
|
|
88
|
+
exports.setLangData = setLangData;
|