@hubspot/local-dev-lib 0.2.2 → 0.2.3-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 +4 -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 +5 -4
- package/api/fileManager.js +11 -11
- package/api/fileMapper.d.ts +8 -7
- package/api/fileMapper.js +17 -17
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +7 -4
- package/api/functions.js +22 -11
- package/api/github.d.ts +7 -9
- package/api/github.js +31 -13
- package/api/hubdb.d.ts +11 -10
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -4
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +8 -16
- package/api/localDevAuth.js +34 -13
- package/api/marketplaceValidation.d.ts +4 -4
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +31 -24
- package/api/projects.js +164 -44
- package/api/sandboxHubs.d.ts +6 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +4 -13
- 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 +15 -11
- package/config/CLIConfiguration.js +175 -90
- 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 +79 -25
- package/config/environment.js +5 -4
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +14 -8
- package/config/index.js +108 -57
- package/constants/config.d.ts +18 -1
- package/constants/config.js +20 -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 +2 -2
- 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 +11 -12
- package/http/index.js +35 -41
- package/http/unauthed.d.ts +14 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +378 -386
- package/lib/archive.d.ts +2 -8
- package/lib/archive.js +34 -30
- package/lib/cms/functions.d.ts +7 -12
- package/lib/cms/functions.js +49 -51
- package/lib/cms/handleFieldsJS.js +16 -14
- package/lib/cms/modules.d.ts +4 -15
- package/lib/cms/modules.js +81 -78
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +43 -3
- package/lib/cms/templates.js +53 -11
- package/lib/cms/uploadFolder.d.ts +3 -14
- package/lib/cms/uploadFolder.js +58 -42
- package/lib/cms/validate.js +1 -1
- 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 -6
- package/lib/fileManager.js +54 -65
- package/lib/fileMapper.d.ts +4 -15
- package/lib/fileMapper.js +67 -88
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +10 -6
- package/lib/github.d.ts +12 -14
- package/lib/github.js +70 -35
- 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/{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 +8 -11
- package/lib/personalAccessKey.js +75 -38
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- 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 +34 -35
- package/types/Accounts.d.ts +103 -3
- package/types/Apps.d.ts +77 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +4 -2
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/Deploy.d.ts +3 -2
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +9 -5
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +1 -1
- package/types/Files.d.ts +43 -4
- package/types/Functions.d.ts +52 -0
- package/types/Github.d.ts +13 -0
- package/types/Http.d.ts +12 -11
- package/types/Hubdb.d.ts +9 -0
- package/types/MarketplaceValidation.d.ts +7 -3
- 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 +30 -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 +56 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +13 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +22 -16
- 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/errors/apiErrors.d.ts +0 -19
- package/errors/apiErrors.js +0 -179
- package/errors/fileSystemErrors.d.ts +0 -5
- package/errors/fileSystemErrors.js +0 -31
- package/errors/standardErrors.d.ts +0 -27
- package/errors/standardErrors.js +0 -59
- package/lang/lang/en.json +0 -401
- 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 -12
- package/models/HubSpotAuthError.js +0 -20
- package/types/LogCallbacks.d.ts +0 -7
- package/utils/logger.d.ts +0 -5
- 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.d.ts → logger.d.ts} +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,9 +1,3 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
declare
|
|
4
|
-
type CopySourceToDestOptions = {
|
|
5
|
-
sourceDir?: string;
|
|
6
|
-
includesRootDir?: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions, logCallbacks?: LogCallbacksArg<typeof archiveCallbackKeys>): Promise<boolean>;
|
|
9
|
-
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
|
@@ -8,16 +8,16 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const os_1 = require("os");
|
|
10
10
|
const extract_zip_1 = __importDefault(require("extract-zip"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const logger_1 = require("./logger");
|
|
12
|
+
const lang_1 = require("../utils/lang");
|
|
13
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
14
14
|
const i18nKey = 'lib.archive';
|
|
15
|
-
|
|
16
|
-
async function extractZip(name, zip, logCallbacks) {
|
|
17
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
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,15 +30,16 @@ async function extractZip(name, zip, logCallbacks) {
|
|
|
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 {
|
|
@@ -47,23 +48,26 @@ async function extractZip(name, zip, logCallbacks) {
|
|
|
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
|
-
|
|
58
|
-
|
|
60
|
+
if (!hideLogs) {
|
|
61
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.init`));
|
|
62
|
+
}
|
|
59
63
|
const srcDirPath = [src];
|
|
60
64
|
if (includesRootDir) {
|
|
61
65
|
const files = await fs_extra_1.default.readdir(src);
|
|
62
66
|
const rootDir = files[0];
|
|
63
67
|
if (!rootDir) {
|
|
64
|
-
(0,
|
|
68
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.sourceEmpty`));
|
|
65
69
|
// Create the dest path if it doesn't already exist
|
|
66
|
-
fs_extra_1.default.ensureDir(dest);
|
|
70
|
+
await fs_extra_1.default.ensureDir(dest);
|
|
67
71
|
// No root found so nothing to copy
|
|
68
72
|
return true;
|
|
69
73
|
}
|
|
@@ -74,39 +78,39 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true }
|
|
|
74
78
|
}
|
|
75
79
|
const projectSrcDir = (0, path_1.join)(...srcDirPath);
|
|
76
80
|
await fs_extra_1.default.copy(projectSrcDir, dest);
|
|
77
|
-
(0,
|
|
81
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.success`));
|
|
78
82
|
return true;
|
|
79
83
|
}
|
|
80
84
|
catch (err) {
|
|
81
|
-
(0,
|
|
82
|
-
|
|
85
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.error`, { dest }));
|
|
86
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
83
87
|
filepath: dest,
|
|
84
|
-
|
|
88
|
+
operation: 'write',
|
|
85
89
|
});
|
|
86
90
|
}
|
|
87
|
-
return false;
|
|
88
91
|
}
|
|
89
|
-
function cleanupTempDir(tmpDir) {
|
|
92
|
+
async function cleanupTempDir(tmpDir) {
|
|
90
93
|
if (!tmpDir)
|
|
91
94
|
return;
|
|
92
95
|
try {
|
|
93
|
-
fs_extra_1.default.remove(tmpDir);
|
|
96
|
+
await fs_extra_1.default.remove(tmpDir);
|
|
94
97
|
}
|
|
95
98
|
catch (e) {
|
|
96
|
-
(0,
|
|
99
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}
|
|
102
|
+
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs } = {}) {
|
|
100
103
|
let success = false;
|
|
101
104
|
if (zip) {
|
|
102
|
-
const { extractDir, tmpDir } = await extractZip(name, zip,
|
|
105
|
+
const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
|
|
103
106
|
if (extractDir !== null) {
|
|
104
107
|
success = await copySourceToDest(extractDir, dest, {
|
|
105
108
|
sourceDir,
|
|
106
109
|
includesRootDir,
|
|
107
|
-
|
|
110
|
+
hideLogs,
|
|
111
|
+
});
|
|
108
112
|
}
|
|
109
|
-
cleanupTempDir(tmpDir);
|
|
113
|
+
await cleanupTempDir(tmpDir);
|
|
110
114
|
}
|
|
111
115
|
return success;
|
|
112
116
|
}
|
package/lib/cms/functions.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
endpointPath: string;
|
|
7
|
-
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;
|
|
8
6
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
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,33 +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
|
-
const createFunctionCallbackKeys = [
|
|
17
|
-
'destPathAlreadyExists',
|
|
18
|
-
'createdDest',
|
|
19
|
-
'createdFunctionFile',
|
|
20
|
-
'createdConfigFile',
|
|
21
|
-
'success',
|
|
22
|
-
];
|
|
23
16
|
function isObjectOrFunction(value) {
|
|
24
17
|
const type = typeof value;
|
|
25
18
|
return value != null && (type === 'object' || type === 'function');
|
|
26
19
|
}
|
|
20
|
+
exports.isObjectOrFunction = isObjectOrFunction;
|
|
27
21
|
function createEndpoint(endpointMethod, filename) {
|
|
28
22
|
return {
|
|
29
23
|
method: endpointMethod || 'GET',
|
|
30
24
|
file: filename,
|
|
31
25
|
};
|
|
32
26
|
}
|
|
27
|
+
exports.createEndpoint = createEndpoint;
|
|
33
28
|
function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
34
29
|
return {
|
|
35
30
|
runtime: 'nodejs18.x',
|
|
@@ -41,6 +36,7 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
|
41
36
|
},
|
|
42
37
|
};
|
|
43
38
|
}
|
|
39
|
+
exports.createConfig = createConfig;
|
|
44
40
|
function writeConfig(configFilePath, config) {
|
|
45
41
|
const configJson = JSON.stringify(config, null, ' ');
|
|
46
42
|
fs_extra_1.default.writeFileSync(configFilePath, configJson);
|
|
@@ -51,12 +47,12 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
51
47
|
configString = fs_extra_1.default.readFileSync(configFilePath).toString();
|
|
52
48
|
}
|
|
53
49
|
catch (err) {
|
|
54
|
-
(0,
|
|
50
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
|
|
55
51
|
configFilePath,
|
|
56
|
-
});
|
|
57
|
-
|
|
52
|
+
}));
|
|
53
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
58
54
|
filepath: configFilePath,
|
|
59
|
-
|
|
55
|
+
operation: 'read',
|
|
60
56
|
});
|
|
61
57
|
}
|
|
62
58
|
let config;
|
|
@@ -64,23 +60,25 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
64
60
|
config = JSON.parse(configString);
|
|
65
61
|
}
|
|
66
62
|
catch (err) {
|
|
67
|
-
(0,
|
|
63
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
|
|
68
64
|
configFilePath,
|
|
69
|
-
});
|
|
70
|
-
|
|
65
|
+
}));
|
|
66
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
71
67
|
filepath: configFilePath,
|
|
72
|
-
|
|
68
|
+
operation: 'read',
|
|
73
69
|
});
|
|
74
70
|
}
|
|
75
71
|
if (!isObjectOrFunction(config)) {
|
|
76
|
-
(0,
|
|
72
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
|
|
73
|
+
configFilePath,
|
|
74
|
+
}));
|
|
77
75
|
}
|
|
78
76
|
if (config.endpoints) {
|
|
79
77
|
if (config.endpoints[endpointPath]) {
|
|
80
|
-
(0,
|
|
78
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
|
|
81
79
|
configFilePath,
|
|
82
80
|
endpointPath,
|
|
83
|
-
});
|
|
81
|
+
}));
|
|
84
82
|
}
|
|
85
83
|
else {
|
|
86
84
|
config.endpoints[endpointPath] = createEndpoint(endpointMethod, functionFile);
|
|
@@ -95,17 +93,16 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
95
93
|
writeConfig(configFilePath, config);
|
|
96
94
|
}
|
|
97
95
|
catch (err) {
|
|
98
|
-
(0,
|
|
96
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
|
|
99
97
|
configFilePath,
|
|
100
|
-
});
|
|
101
|
-
|
|
98
|
+
}));
|
|
99
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
102
100
|
filepath: configFilePath,
|
|
103
|
-
|
|
101
|
+
operation: 'read',
|
|
104
102
|
});
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
|
-
async function createFunction(functionInfo, dest, options = {}
|
|
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,41 @@ 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
|
-
await (0, github_1.
|
|
144
|
-
|
|
140
|
+
const result = await (0, github_1.fetchFileFromRepository)('HubSpot/cms-sample-assets', 'functions/sample-function.js', 'main');
|
|
141
|
+
fs_extra_1.default.writeFileSync(functionFilePath, result);
|
|
142
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
145
143
|
path: functionFilePath,
|
|
146
|
-
});
|
|
144
|
+
}));
|
|
147
145
|
if (fs_extra_1.default.existsSync(configFilePath)) {
|
|
148
146
|
updateExistingConfig(configFilePath, {
|
|
149
147
|
endpointPath,
|
|
150
148
|
endpointMethod,
|
|
151
149
|
functionFile,
|
|
152
150
|
});
|
|
153
|
-
logger(
|
|
151
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
154
152
|
path: functionFilePath,
|
|
155
|
-
});
|
|
156
|
-
logger(
|
|
153
|
+
}));
|
|
154
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
|
|
157
155
|
endpointPath: endpointPath,
|
|
158
156
|
folderName,
|
|
159
|
-
});
|
|
157
|
+
}));
|
|
160
158
|
}
|
|
161
159
|
else {
|
|
162
160
|
const config = createConfig({ endpointPath, endpointMethod, functionFile });
|
|
@@ -164,21 +162,21 @@ async function createFunction(functionInfo, dest, options = {}, logCallbacks) {
|
|
|
164
162
|
writeConfig(configFilePath, config);
|
|
165
163
|
}
|
|
166
164
|
catch (err) {
|
|
167
|
-
(0,
|
|
165
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createFunction.failedToCreateFile`, {
|
|
168
166
|
configFilePath,
|
|
169
|
-
});
|
|
170
|
-
|
|
167
|
+
}));
|
|
168
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
171
169
|
filepath: configFilePath,
|
|
172
|
-
|
|
170
|
+
operation: 'write',
|
|
173
171
|
});
|
|
174
172
|
}
|
|
175
|
-
logger(
|
|
173
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdConfigFile`, {
|
|
176
174
|
path: configFilePath,
|
|
177
|
-
});
|
|
178
|
-
logger(
|
|
175
|
+
}));
|
|
176
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
|
|
179
177
|
endpointPath: endpointPath,
|
|
180
178
|
folderName,
|
|
181
|
-
});
|
|
179
|
+
}));
|
|
182
180
|
}
|
|
183
181
|
}
|
|
184
182
|
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,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PathInput } from '../../types/Modules';
|
|
3
|
-
declare const createModuleCallbackKeys: readonly ["creatingPath", "creatingModule"];
|
|
1
|
+
import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules';
|
|
4
2
|
export declare const ValidationIds: {
|
|
5
3
|
SRC_REQUIRED: string;
|
|
6
4
|
DEST_REQUIRED: string;
|
|
@@ -8,18 +6,9 @@ export declare const ValidationIds: {
|
|
|
8
6
|
MODULE_TO_MODULE_NESTING: string;
|
|
9
7
|
MODULE_NESTING: string;
|
|
10
8
|
};
|
|
11
|
-
type ValidationResult = {
|
|
12
|
-
id: string;
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
9
|
export declare function validateSrcAndDestPaths(src?: PathInput, dest?: PathInput): Promise<Array<ValidationResult>>;
|
|
16
|
-
type ModuleDefinition = {
|
|
17
|
-
contentTypes: Array<string>;
|
|
18
|
-
moduleLabel: string;
|
|
19
|
-
reactType: boolean;
|
|
20
|
-
global: boolean;
|
|
21
|
-
};
|
|
22
10
|
export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, getInternalVersion: boolean, options?: {
|
|
23
11
|
allowExistingDir: boolean;
|
|
24
|
-
}
|
|
25
|
-
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;
|