@hubspot/local-dev-lib 0.0.10 → 0.1.0-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 -7
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +5 -13
- package/api/designManager.js +6 -9
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +6 -5
- package/api/fileManager.js +13 -12
- package/api/fileMapper.d.ts +8 -8
- package/api/fileMapper.js +19 -18
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +7 -3
- package/api/functions.js +22 -11
- package/api/github.d.ts +11 -0
- package/api/github.js +71 -0
- package/api/hubdb.d.ts +11 -9
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -3
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +7 -15
- package/api/localDevAuth.js +28 -13
- package/api/marketplaceValidation.d.ts +4 -3
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +34 -21
- package/api/projects.js +135 -45
- package/api/sandboxHubs.d.ts +5 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +5 -14
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +13 -10
- package/config/CLIConfiguration.js +129 -77
- package/config/configFile.js +12 -18
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +5 -4
- package/config/config_DEPRECATED.d.ts +6 -8
- package/config/config_DEPRECATED.js +73 -24
- package/config/environment.js +5 -4
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +10 -7
- package/config/index.js +83 -55
- package/constants/api.d.ts +10 -12
- package/constants/api.js +10 -12
- package/constants/config.d.ts +15 -1
- package/constants/config.js +17 -3
- package/constants/environments.d.ts +1 -0
- package/constants/environments.js +1 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +3 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/errors/errors_DEPRECATED.d.ts +1 -5
- package/errors/errors_DEPRECATED.js +3 -16
- 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 +6 -3
- package/http/getAxiosConfig.js +51 -7
- package/http/index.d.ts +10 -11
- package/http/index.js +35 -41
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +374 -368
- package/lib/archive.d.ts +2 -6
- package/lib/archive.js +34 -29
- package/lib/cms/functions.d.ts +7 -12
- package/lib/cms/functions.js +47 -50
- package/lib/cms/handleFieldsJS.js +16 -14
- package/lib/cms/modules.d.ts +5 -15
- package/lib/cms/modules.js +100 -39
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +43 -3
- package/lib/cms/templates.js +51 -11
- package/lib/cms/uploadFolder.d.ts +3 -14
- package/lib/cms/uploadFolder.js +58 -42
- package/lib/{validate.d.ts → cms/validate.d.ts} +1 -1
- package/lib/{validate.js → cms/validate.js} +5 -5
- package/lib/cms/watch.d.ts +2 -18
- package/lib/cms/watch.js +63 -68
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.d.ts +2 -0
- package/lib/fileManager.js +184 -0
- package/lib/fileMapper.d.ts +4 -15
- package/lib/fileMapper.js +68 -89
- package/lib/fs.js +2 -2
- package/lib/github.d.ts +6 -18
- package/lib/github.js +97 -76
- package/lib/gitignore.d.ts +2 -0
- package/lib/gitignore.js +21 -4
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/lib/{logging/logger.d.ts → logger.d.ts} +20 -8
- package/{utils → lib}/notify.js +2 -2
- package/lib/oauth.d.ts +2 -5
- package/lib/oauth.js +14 -25
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +7 -10
- package/lib/personalAccessKey.js +75 -48
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/text.d.ts +1 -0
- package/lib/text.js +9 -1
- package/lib/trackUsage.js +18 -11
- package/lib/urls.js +5 -1
- 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 +5 -27
- package/models/OAuth2Manager.js +41 -64
- package/package.json +19 -18
- package/types/Accounts.d.ts +86 -3
- package/types/Apps.d.ts +77 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +12 -34
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +12 -7
- package/types/Files.d.ts +43 -4
- package/types/Functions.d.ts +26 -0
- package/types/Github.d.ts +12 -0
- package/types/Http.d.ts +11 -12
- package/types/Hubdb.d.ts +9 -0
- package/types/Lang.d.ts +3 -0
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +4 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +37 -47
- package/types/Schemas.d.ts +12 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +12 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +24 -18
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/utils/git.d.ts +1 -7
- package/utils/git.js +2 -18
- package/utils/lang.d.ts +1 -5
- package/constants/github.d.ts +0 -4
- package/constants/github.js +0 -7
- package/errors/apiErrors.d.ts +0 -23
- package/errors/apiErrors.js +0 -197
- package/errors/fileSystemErrors.d.ts +0 -5
- package/errors/fileSystemErrors.js +0 -31
- package/errors/standardErrors.d.ts +0 -26
- package/errors/standardErrors.js +0 -64
- package/lang/lang/en.json +0 -383
- package/lib/logging/git.d.ts +0 -2
- package/lib/logging/git.js +0 -54
- package/lib/logging/logs.d.ts +0 -22
- package/lib/logging/logs.js +0 -86
- package/lib/logging/table.d.ts +0 -3
- package/lib/logging/table.js +0 -47
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -71
- package/models/HubSpotAuthError.d.ts +0 -9
- package/models/HubSpotAuthError.js +0 -20
- package/types/LogCallbacks.d.ts +0 -6
- package/utils/logger.d.ts +0 -11
- package/utils/logger.js +0 -23
- package/utils/objectUtils.d.ts +0 -8
- package/utils/objectUtils.js +0 -33
- /package/{utils → lib}/escapeRegExp.d.ts +0 -0
- /package/{utils → lib}/escapeRegExp.js +0 -0
- /package/lib/{logging/logger.js → logger.js} +0 -0
- /package/{utils → lib}/notify.d.ts +0 -0
- /package/types/{LogCallbacks.js → Apps.js} +0 -0
package/lib/archive.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
includesRootDir?: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions): Promise<boolean>;
|
|
7
|
-
export {};
|
|
2
|
+
import { CopySourceToDestOptions } from '../types/Archive';
|
|
3
|
+
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir, hideLogs }?: CopySourceToDestOptions): Promise<boolean>;
|
package/lib/archive.js
CHANGED
|
@@ -7,17 +7,17 @@ exports.extractZipArchive = void 0;
|
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const os_1 = require("os");
|
|
10
|
-
const util_1 = require("util");
|
|
11
10
|
const extract_zip_1 = __importDefault(require("extract-zip"));
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const extract = (0, util_1.promisify)(extract_zip_1.default);
|
|
11
|
+
const logger_1 = require("./logger");
|
|
12
|
+
const lang_1 = require("../utils/lang");
|
|
13
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
16
14
|
const i18nKey = 'lib.archive';
|
|
17
|
-
async function extractZip(name, zip) {
|
|
15
|
+
async function extractZip(name, zip, hideLogs = false) {
|
|
18
16
|
const result = { extractDir: '', tmpDir: '' };
|
|
19
17
|
const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
|
|
20
|
-
(
|
|
18
|
+
if (!hideLogs) {
|
|
19
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.extractZip.init`));
|
|
20
|
+
}
|
|
21
21
|
// Write zip to disk
|
|
22
22
|
let tmpZipPath = '';
|
|
23
23
|
try {
|
|
@@ -30,39 +30,44 @@ async function extractZip(name, zip) {
|
|
|
30
30
|
}
|
|
31
31
|
catch (err) {
|
|
32
32
|
if (tmpZipPath || result.tmpDir) {
|
|
33
|
-
|
|
33
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
34
34
|
filepath: tmpZipPath || result.tmpDir,
|
|
35
|
-
|
|
35
|
+
operation: 'write',
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
(0,
|
|
39
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.extractZip.errors.write`), {
|
|
40
|
+
cause: err,
|
|
41
|
+
});
|
|
40
42
|
}
|
|
41
|
-
return result;
|
|
42
43
|
}
|
|
43
44
|
// Extract zip
|
|
44
45
|
try {
|
|
45
46
|
const tmpExtractPath = (0, path_1.join)(result.tmpDir, 'extracted');
|
|
46
|
-
await
|
|
47
|
+
await (0, extract_zip_1.default)(tmpZipPath, { dir: tmpExtractPath });
|
|
47
48
|
result.extractDir = tmpExtractPath;
|
|
48
49
|
}
|
|
49
50
|
catch (err) {
|
|
50
|
-
(0,
|
|
51
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.extractZip.errors.extract`), {
|
|
52
|
+
cause: err,
|
|
53
|
+
});
|
|
51
54
|
}
|
|
52
|
-
(0,
|
|
55
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.extractZip.success`));
|
|
53
56
|
return result;
|
|
54
57
|
}
|
|
55
|
-
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}) {
|
|
58
|
+
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, } = {}) {
|
|
56
59
|
try {
|
|
57
|
-
(
|
|
60
|
+
if (!hideLogs) {
|
|
61
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.init`));
|
|
62
|
+
}
|
|
58
63
|
const srcDirPath = [src];
|
|
59
64
|
if (includesRootDir) {
|
|
60
65
|
const files = await fs_extra_1.default.readdir(src);
|
|
61
66
|
const rootDir = files[0];
|
|
62
67
|
if (!rootDir) {
|
|
63
|
-
(0,
|
|
68
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.sourceEmpty`));
|
|
64
69
|
// Create the dest path if it doesn't already exist
|
|
65
|
-
fs_extra_1.default.ensureDir(dest);
|
|
70
|
+
await fs_extra_1.default.ensureDir(dest);
|
|
66
71
|
// No root found so nothing to copy
|
|
67
72
|
return true;
|
|
68
73
|
}
|
|
@@ -73,39 +78,39 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true }
|
|
|
73
78
|
}
|
|
74
79
|
const projectSrcDir = (0, path_1.join)(...srcDirPath);
|
|
75
80
|
await fs_extra_1.default.copy(projectSrcDir, dest);
|
|
76
|
-
(0,
|
|
81
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.success`));
|
|
77
82
|
return true;
|
|
78
83
|
}
|
|
79
84
|
catch (err) {
|
|
80
|
-
(0,
|
|
81
|
-
|
|
85
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.error`, { dest }));
|
|
86
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
82
87
|
filepath: dest,
|
|
83
|
-
|
|
88
|
+
operation: 'write',
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
|
-
return false;
|
|
87
91
|
}
|
|
88
|
-
function cleanupTempDir(tmpDir) {
|
|
92
|
+
async function cleanupTempDir(tmpDir) {
|
|
89
93
|
if (!tmpDir)
|
|
90
94
|
return;
|
|
91
95
|
try {
|
|
92
|
-
fs_extra_1.default.remove(tmpDir);
|
|
96
|
+
await fs_extra_1.default.remove(tmpDir);
|
|
93
97
|
}
|
|
94
98
|
catch (e) {
|
|
95
|
-
(0,
|
|
99
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}) {
|
|
102
|
+
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs } = {}) {
|
|
99
103
|
let success = false;
|
|
100
104
|
if (zip) {
|
|
101
|
-
const { extractDir, tmpDir } = await extractZip(name, zip);
|
|
105
|
+
const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
|
|
102
106
|
if (extractDir !== null) {
|
|
103
107
|
success = await copySourceToDest(extractDir, dest, {
|
|
104
108
|
sourceDir,
|
|
105
109
|
includesRootDir,
|
|
110
|
+
hideLogs,
|
|
106
111
|
});
|
|
107
112
|
}
|
|
108
|
-
cleanupTempDir(tmpDir);
|
|
113
|
+
await cleanupTempDir(tmpDir);
|
|
109
114
|
}
|
|
110
115
|
return success;
|
|
111
116
|
}
|
package/lib/cms/functions.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
endpointMethod: string;
|
|
1
|
+
import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions';
|
|
2
|
+
export declare function isObjectOrFunction(value: object): boolean;
|
|
3
|
+
export declare function createEndpoint(endpointMethod: string, filename: string): {
|
|
4
|
+
method: string;
|
|
5
|
+
file: string;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
declare const createFunctionCallbackKeys: string[];
|
|
12
|
-
export declare function createFunction(functionInfo: FunctionInfo, dest: string, options: FunctionOptions, logCallbacks?: LogCallbacksArg<typeof createFunctionCallbackKeys>): Promise<void>;
|
|
13
|
-
export {};
|
|
7
|
+
export declare function createConfig({ endpointPath, endpointMethod, functionFile, }: FunctionConfigInfo): FunctionConfig;
|
|
8
|
+
export declare function createFunction(functionInfo: FunctionInfo, dest: string, options?: FunctionOptions): Promise<void>;
|
package/lib/cms/functions.js
CHANGED
|
@@ -3,26 +3,28 @@ 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.createFunction = void 0;
|
|
6
|
+
exports.createFunction = exports.createConfig = exports.createEndpoint = exports.isObjectOrFunction = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
10
10
|
const path_2 = require("../path");
|
|
11
11
|
const github_1 = require("../github");
|
|
12
|
-
const logger_1 = require("
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const lang_1 = require("../../utils/lang");
|
|
14
|
+
const FileSystemError_1 = require("../../models/FileSystemError");
|
|
15
15
|
const i18nKey = 'lib.cms.functions';
|
|
16
16
|
function isObjectOrFunction(value) {
|
|
17
17
|
const type = typeof value;
|
|
18
18
|
return value != null && (type === 'object' || type === 'function');
|
|
19
19
|
}
|
|
20
|
+
exports.isObjectOrFunction = isObjectOrFunction;
|
|
20
21
|
function createEndpoint(endpointMethod, filename) {
|
|
21
22
|
return {
|
|
22
23
|
method: endpointMethod || 'GET',
|
|
23
24
|
file: filename,
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
exports.createEndpoint = createEndpoint;
|
|
26
28
|
function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
27
29
|
return {
|
|
28
30
|
runtime: 'nodejs18.x',
|
|
@@ -34,6 +36,7 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
|
34
36
|
},
|
|
35
37
|
};
|
|
36
38
|
}
|
|
39
|
+
exports.createConfig = createConfig;
|
|
37
40
|
function writeConfig(configFilePath, config) {
|
|
38
41
|
const configJson = JSON.stringify(config, null, ' ');
|
|
39
42
|
fs_extra_1.default.writeFileSync(configFilePath, configJson);
|
|
@@ -44,12 +47,12 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
44
47
|
configString = fs_extra_1.default.readFileSync(configFilePath).toString();
|
|
45
48
|
}
|
|
46
49
|
catch (err) {
|
|
47
|
-
(0,
|
|
50
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
|
|
48
51
|
configFilePath,
|
|
49
|
-
});
|
|
50
|
-
|
|
52
|
+
}));
|
|
53
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
51
54
|
filepath: configFilePath,
|
|
52
|
-
|
|
55
|
+
operation: 'read',
|
|
53
56
|
});
|
|
54
57
|
}
|
|
55
58
|
let config;
|
|
@@ -57,23 +60,25 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
57
60
|
config = JSON.parse(configString);
|
|
58
61
|
}
|
|
59
62
|
catch (err) {
|
|
60
|
-
(0,
|
|
63
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
|
|
61
64
|
configFilePath,
|
|
62
|
-
});
|
|
63
|
-
|
|
65
|
+
}));
|
|
66
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
64
67
|
filepath: configFilePath,
|
|
65
|
-
|
|
68
|
+
operation: 'read',
|
|
66
69
|
});
|
|
67
70
|
}
|
|
68
71
|
if (!isObjectOrFunction(config)) {
|
|
69
|
-
(0,
|
|
72
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
|
|
73
|
+
configFilePath,
|
|
74
|
+
}));
|
|
70
75
|
}
|
|
71
76
|
if (config.endpoints) {
|
|
72
77
|
if (config.endpoints[endpointPath]) {
|
|
73
|
-
(0,
|
|
78
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
|
|
74
79
|
configFilePath,
|
|
75
80
|
endpointPath,
|
|
76
|
-
});
|
|
81
|
+
}));
|
|
77
82
|
}
|
|
78
83
|
else {
|
|
79
84
|
config.endpoints[endpointPath] = createEndpoint(endpointMethod, functionFile);
|
|
@@ -88,24 +93,16 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
88
93
|
writeConfig(configFilePath, config);
|
|
89
94
|
}
|
|
90
95
|
catch (err) {
|
|
91
|
-
(0,
|
|
96
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
|
|
92
97
|
configFilePath,
|
|
93
|
-
});
|
|
94
|
-
|
|
98
|
+
}));
|
|
99
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
95
100
|
filepath: configFilePath,
|
|
96
|
-
|
|
101
|
+
operation: 'read',
|
|
97
102
|
});
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
'destPathAlreadyExists',
|
|
102
|
-
'createdDest',
|
|
103
|
-
'createdFunctionFile',
|
|
104
|
-
'createdConfigFile',
|
|
105
|
-
'success',
|
|
106
|
-
];
|
|
107
|
-
async function createFunction(functionInfo, dest, options, logCallbacks) {
|
|
108
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
105
|
+
async function createFunction(functionInfo, dest, options = {}) {
|
|
109
106
|
const { functionsFolder, filename, endpointPath, endpointMethod } = functionInfo;
|
|
110
107
|
const allowExistingFile = options.allowExistingFile || false;
|
|
111
108
|
const ancestorFunctionsConfig = (0, findup_sync_1.default)('serverless.json', {
|
|
@@ -113,9 +110,9 @@ async function createFunction(functionInfo, dest, options, logCallbacks) {
|
|
|
113
110
|
nocase: true,
|
|
114
111
|
});
|
|
115
112
|
if (ancestorFunctionsConfig) {
|
|
116
|
-
(0,
|
|
113
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.nestedConfigError`, {
|
|
117
114
|
ancestorConfigPath: path_1.default.dirname(ancestorFunctionsConfig),
|
|
118
|
-
});
|
|
115
|
+
}));
|
|
119
116
|
}
|
|
120
117
|
const folderName = functionsFolder.endsWith('.functions')
|
|
121
118
|
? functionsFolder
|
|
@@ -123,40 +120,40 @@ async function createFunction(functionInfo, dest, options, logCallbacks) {
|
|
|
123
120
|
const functionFile = filename.endsWith('.js') ? filename : `${filename}.js`;
|
|
124
121
|
const destPath = path_1.default.join(dest, folderName);
|
|
125
122
|
if (fs_extra_1.default.existsSync(destPath)) {
|
|
126
|
-
logger(
|
|
123
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.destPathAlreadyExists`, {
|
|
127
124
|
path: destPath,
|
|
128
|
-
});
|
|
125
|
+
}));
|
|
129
126
|
}
|
|
130
127
|
else {
|
|
131
128
|
fs_extra_1.default.mkdirp(destPath);
|
|
132
|
-
logger(
|
|
129
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdDest`, {
|
|
133
130
|
path: destPath,
|
|
134
|
-
});
|
|
131
|
+
}));
|
|
135
132
|
}
|
|
136
133
|
const functionFilePath = path_1.default.join(destPath, functionFile);
|
|
137
134
|
const configFilePath = path_1.default.join(destPath, 'serverless.json');
|
|
138
135
|
if (!allowExistingFile && fs_extra_1.default.existsSync(functionFilePath)) {
|
|
139
|
-
(0,
|
|
136
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
|
|
140
137
|
functionFilePath,
|
|
141
|
-
});
|
|
138
|
+
}));
|
|
142
139
|
}
|
|
143
140
|
await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', 'functions/sample-function.js', functionFilePath);
|
|
144
|
-
logger(
|
|
141
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
145
142
|
path: functionFilePath,
|
|
146
|
-
});
|
|
143
|
+
}));
|
|
147
144
|
if (fs_extra_1.default.existsSync(configFilePath)) {
|
|
148
145
|
updateExistingConfig(configFilePath, {
|
|
149
146
|
endpointPath,
|
|
150
147
|
endpointMethod,
|
|
151
148
|
functionFile,
|
|
152
149
|
});
|
|
153
|
-
logger(
|
|
150
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
154
151
|
path: functionFilePath,
|
|
155
|
-
});
|
|
156
|
-
logger(
|
|
152
|
+
}));
|
|
153
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
|
|
157
154
|
endpointPath: endpointPath,
|
|
158
155
|
folderName,
|
|
159
|
-
});
|
|
156
|
+
}));
|
|
160
157
|
}
|
|
161
158
|
else {
|
|
162
159
|
const config = createConfig({ endpointPath, endpointMethod, functionFile });
|
|
@@ -164,21 +161,21 @@ async function createFunction(functionInfo, dest, options, logCallbacks) {
|
|
|
164
161
|
writeConfig(configFilePath, config);
|
|
165
162
|
}
|
|
166
163
|
catch (err) {
|
|
167
|
-
(0,
|
|
164
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createFunction.failedToCreateFile`, {
|
|
168
165
|
configFilePath,
|
|
169
|
-
});
|
|
170
|
-
|
|
166
|
+
}));
|
|
167
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
171
168
|
filepath: configFilePath,
|
|
172
|
-
|
|
169
|
+
operation: 'write',
|
|
173
170
|
});
|
|
174
171
|
}
|
|
175
|
-
logger(
|
|
172
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdConfigFile`, {
|
|
176
173
|
path: configFilePath,
|
|
177
|
-
});
|
|
178
|
-
logger(
|
|
174
|
+
}));
|
|
175
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
|
|
179
176
|
endpointPath: endpointPath,
|
|
180
177
|
folderName,
|
|
181
|
-
});
|
|
178
|
+
}));
|
|
182
179
|
}
|
|
183
180
|
}
|
|
184
181
|
exports.createFunction = createFunction;
|
|
@@ -8,10 +8,10 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
|
-
const escapeRegExp_1 = require("
|
|
11
|
+
const escapeRegExp_1 = require("../escapeRegExp");
|
|
12
12
|
const modules_1 = require("../../utils/cms/modules");
|
|
13
|
-
const logger_1 = require("
|
|
14
|
-
const
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
const lang_1 = require("../../utils/lang");
|
|
15
15
|
const i18nKey = 'lib.cms.handleFieldsJs';
|
|
16
16
|
class FieldsJs {
|
|
17
17
|
projectDir;
|
|
@@ -51,9 +51,9 @@ class FieldsJs {
|
|
|
51
51
|
writeDir,
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
|
-
(0,
|
|
54
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.creating`, {
|
|
55
55
|
pid: convertFieldsProcess.pid || '',
|
|
56
|
-
});
|
|
56
|
+
}));
|
|
57
57
|
convertFieldsProcess.on('message', function (message) {
|
|
58
58
|
if (message.action === 'ERROR') {
|
|
59
59
|
reject(message.message);
|
|
@@ -63,12 +63,12 @@ class FieldsJs {
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
convertFieldsProcess.on('close', () => {
|
|
66
|
-
(0,
|
|
66
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.terminating`, {
|
|
67
67
|
pid: convertFieldsProcess.pid || '',
|
|
68
|
-
});
|
|
68
|
+
}));
|
|
69
69
|
});
|
|
70
70
|
}).catch((e) => {
|
|
71
|
-
(0,
|
|
71
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.errors.errorConverting`, { filePath }), { cause: e });
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
@@ -78,9 +78,9 @@ class FieldsJs {
|
|
|
78
78
|
*/
|
|
79
79
|
saveOutput() {
|
|
80
80
|
if (!this.outputPath || !fs_extra_1.default.existsSync(this.outputPath)) {
|
|
81
|
-
(0,
|
|
81
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.saveOutput.errors.saveFailed`, {
|
|
82
82
|
path: this.filePath,
|
|
83
|
-
});
|
|
83
|
+
}));
|
|
84
84
|
}
|
|
85
85
|
const relativePath = path_1.default.relative(this.rootWriteDir, path_1.default.dirname(this.outputPath));
|
|
86
86
|
const savePath = path_1.default.join(this.projectDir, relativePath, 'fields.output.json');
|
|
@@ -88,7 +88,7 @@ class FieldsJs {
|
|
|
88
88
|
fs_extra_1.default.copyFileSync(this.outputPath, savePath);
|
|
89
89
|
}
|
|
90
90
|
catch (err) {
|
|
91
|
-
(0,
|
|
91
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.saveOutput.errors.saveFailed`, { path: savePath }), { cause: err });
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
@@ -120,7 +120,7 @@ function isConvertableFieldJs(rootDir, filePath, convertFields = false) {
|
|
|
120
120
|
const inModuleFolder = (0, modules_1.isModuleFolderChild)({ path: filePath, isLocal: true });
|
|
121
121
|
return !!(convertFields &&
|
|
122
122
|
allowedFieldsNames.includes(baseName) &&
|
|
123
|
-
(inModuleFolder || relativePath ==
|
|
123
|
+
(inModuleFolder || relativePath == path_1.default.sep));
|
|
124
124
|
}
|
|
125
125
|
exports.isConvertableFieldJs = isConvertableFieldJs;
|
|
126
126
|
// Try creating tempdir
|
|
@@ -130,7 +130,9 @@ function createTmpDirSync(prefix) {
|
|
|
130
130
|
tmpDir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), prefix));
|
|
131
131
|
}
|
|
132
132
|
catch (err) {
|
|
133
|
-
(0,
|
|
133
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.createTmpDirSync.errors.writeFailed`), {
|
|
134
|
+
cause: err,
|
|
135
|
+
});
|
|
134
136
|
}
|
|
135
137
|
return tmpDir;
|
|
136
138
|
}
|
|
@@ -139,7 +141,7 @@ exports.createTmpDirSync = createTmpDirSync;
|
|
|
139
141
|
function cleanupTmpDirSync(tmpDir) {
|
|
140
142
|
fs_extra_1.default.rm(tmpDir, { recursive: true }, err => {
|
|
141
143
|
if (err) {
|
|
142
|
-
(0,
|
|
144
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`), { cause: err });
|
|
143
145
|
}
|
|
144
146
|
});
|
|
145
147
|
}
|
package/lib/cms/modules.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PathInput } from '../../types/Modules';
|
|
1
|
+
import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules';
|
|
3
2
|
export declare const ValidationIds: {
|
|
4
3
|
SRC_REQUIRED: string;
|
|
5
4
|
DEST_REQUIRED: string;
|
|
@@ -7,18 +6,9 @@ export declare const ValidationIds: {
|
|
|
7
6
|
MODULE_TO_MODULE_NESTING: string;
|
|
8
7
|
MODULE_NESTING: string;
|
|
9
8
|
};
|
|
10
|
-
type ValidationResult = {
|
|
11
|
-
id: string;
|
|
12
|
-
message: string;
|
|
13
|
-
};
|
|
14
9
|
export declare function validateSrcAndDestPaths(src?: PathInput, dest?: PathInput): Promise<Array<ValidationResult>>;
|
|
15
|
-
|
|
16
|
-
contentTypes: Array<string>;
|
|
17
|
-
moduleLabel: string;
|
|
18
|
-
global: boolean;
|
|
19
|
-
};
|
|
20
|
-
declare const createModuleCallbackKeys: readonly ["creatingPath", "creatingModule"];
|
|
21
|
-
export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, options?: {
|
|
10
|
+
export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, getInternalVersion: boolean, options?: {
|
|
22
11
|
allowExistingDir: boolean;
|
|
23
|
-
}
|
|
24
|
-
export
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function retrieveDefaultModule(name: string | undefined, dest: string): Promise<import("../../types/Github").GithubRepoFile[] | undefined>;
|
|
14
|
+
export declare const isModuleHTMLFile: (filePath: string) => boolean;
|