@hubspot/local-dev-lib 0.6.1-experimental.0 → 0.6.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/api/appsDev.d.ts +2 -2
- package/api/appsDev.js +13 -22
- package/api/crm.d.ts +2 -2
- package/api/crm.js +9 -16
- package/api/customObjects.d.ts +2 -2
- package/api/customObjects.js +13 -22
- package/api/designManager.d.ts +2 -2
- package/api/designManager.js +5 -10
- package/api/devSecrets.d.ts +2 -2
- package/api/devSecrets.js +9 -16
- package/api/developerTestAccounts.d.ts +2 -4
- package/api/developerTestAccounts.js +23 -55
- package/api/fileManager.d.ts +2 -2
- package/api/fileManager.js +14 -24
- package/api/fileMapper.d.ts +2 -3
- package/api/fileMapper.js +34 -49
- package/api/fileTransport.d.ts +1 -1
- package/api/fileTransport.js +12 -21
- package/api/fireAlarm.d.ts +2 -3
- package/api/fireAlarm.js +5 -9
- package/api/functions.d.ts +2 -2
- package/api/functions.js +11 -19
- package/api/github.d.ts +2 -4
- package/api/github.js +16 -27
- package/api/hubdb.d.ts +2 -2
- package/api/hubdb.js +19 -31
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +7 -13
- package/api/localDevAuth.d.ts +3 -6
- package/api/localDevAuth.js +10 -40
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +7 -13
- package/api/projects.d.ts +6 -8
- package/api/projects.js +65 -100
- package/api/sandboxHubs.d.ts +2 -5
- package/api/sandboxHubs.js +15 -45
- package/api/sandboxSync.d.ts +2 -2
- package/api/sandboxSync.js +7 -12
- package/api/secrets.d.ts +2 -2
- package/api/secrets.js +9 -16
- package/api/validateHubl.d.ts +2 -2
- package/api/validateHubl.js +3 -7
- package/config/defaultAccountOverride.d.ts +2 -1
- package/config/defaultAccountOverride.js +16 -26
- package/config/index.d.ts +4 -4
- package/config/index.js +144 -177
- package/config/migrate.d.ts +2 -2
- package/config/migrate.js +26 -37
- package/config/state.d.ts +1 -1
- package/config/state.js +17 -45
- package/config/utils.d.ts +4 -4
- package/config/utils.js +85 -108
- package/constants/api.js +3 -6
- package/constants/auth.js +9 -12
- package/constants/config.d.ts +30 -1
- package/constants/config.js +65 -42
- package/constants/endpoints.d.ts +6 -0
- package/constants/endpoints.js +6 -0
- package/constants/environments.js +1 -4
- package/constants/extensions.js +6 -9
- package/constants/files.js +5 -8
- package/constants/ports.js +3 -6
- package/constants/projects.js +2 -5
- package/enums/build.d.ts +1 -0
- package/enums/build.js +6 -8
- package/enums/deploy.js +2 -5
- package/enums/project.js +1 -4
- package/errors/index.d.ts +4 -5
- package/errors/index.js +17 -39
- package/errors/isSystemError.d.ts +2 -0
- package/errors/isSystemError.js +9 -0
- package/http/addQueryParams.d.ts +1 -1
- package/http/addQueryParams.js +1 -5
- package/http/client.d.ts +1 -0
- package/http/client.js +54 -0
- package/http/getAxiosConfig.d.ts +1 -1
- package/http/getAxiosConfig.js +21 -31
- package/http/index.d.ts +2 -2
- package/http/index.js +39 -124
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -21
- package/lang/en.json +3 -2
- package/lib/archive.d.ts +1 -3
- package/lib/archive.js +37 -67
- package/lib/cms/functions.d.ts +1 -1
- package/lib/cms/functions.js +45 -55
- package/lib/cms/handleFieldsJS.js +36 -44
- package/lib/cms/modules.d.ts +2 -2
- package/lib/cms/modules.js +49 -59
- package/lib/cms/processFieldsJs.js +17 -32
- package/lib/cms/templates.js +17 -26
- package/lib/cms/themes.js +10 -18
- package/lib/cms/uploadFolder.d.ts +4 -4
- package/lib/cms/uploadFolder.js +55 -64
- package/lib/cms/validate.d.ts +1 -1
- package/lib/cms/validate.js +11 -18
- package/lib/cms/watch.d.ts +2 -2
- package/lib/cms/watch.js +66 -73
- package/lib/crm.d.ts +1 -1
- package/lib/crm.js +15 -23
- package/lib/customObjects.d.ts +1 -1
- package/lib/customObjects.js +15 -25
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +5 -11
- package/lib/escapeRegExp.js +1 -5
- package/lib/fileManager.js +43 -51
- package/lib/fileMapper.d.ts +1 -1
- package/lib/fileMapper.js +68 -84
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +18 -27
- package/lib/github.d.ts +1 -3
- package/lib/github.js +39 -51
- package/lib/gitignore.d.ts +1 -1
- package/lib/gitignore.js +16 -24
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +29 -40
- package/lib/ignoreRules.js +25 -34
- package/lib/isDeepEqual.js +1 -5
- package/lib/logger.d.ts +8 -20
- package/lib/logger.js +47 -59
- package/lib/notify.js +9 -16
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +12 -17
- package/lib/path.d.ts +0 -1
- package/lib/path.js +30 -48
- package/lib/personalAccessKey.d.ts +2 -4
- package/lib/personalAccessKey.js +43 -60
- package/lib/portManager.d.ts +2 -2
- package/lib/portManager.js +26 -41
- package/lib/text.js +2 -7
- package/lib/trackUsage.d.ts +0 -2
- package/lib/trackUsage.js +27 -31
- package/lib/urls.js +4 -9
- package/models/FileSystemError.d.ts +1 -1
- package/models/FileSystemError.js +12 -16
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +8 -12
- package/models/HubSpotHttpError.d.ts +1 -1
- package/models/HubSpotHttpError.js +22 -26
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +17 -24
- package/package.json +21 -17
- package/types/Accounts.d.ts +6 -5
- package/types/Accounts.js +1 -2
- package/types/Activity.d.ts +3 -3
- package/types/Activity.js +1 -2
- package/types/Api.d.ts +1 -1
- package/types/Api.js +1 -2
- package/types/Apps.js +1 -2
- package/types/Archive.js +1 -2
- package/types/Build.d.ts +4 -5
- package/types/Build.js +1 -2
- package/types/CLIOptions.js +1 -2
- package/types/ComponentStructure.d.ts +2 -2
- package/types/ComponentStructure.js +1 -2
- package/types/Config.d.ts +4 -6
- package/types/Config.js +1 -2
- package/types/Crm.js +1 -2
- package/types/Deploy.d.ts +5 -11
- package/types/Deploy.js +1 -2
- package/types/DesignManager.js +1 -2
- package/types/DevSecrets.js +1 -2
- package/types/Error.js +1 -2
- package/types/FieldsJS.js +1 -2
- package/types/FileManager.js +1 -2
- package/types/Files.d.ts +4 -4
- package/types/Files.js +1 -2
- package/types/FireAlarm.js +1 -2
- package/types/Functions.js +1 -2
- package/types/Github.d.ts +1 -1
- package/types/Github.js +1 -2
- package/types/Http.d.ts +0 -4
- package/types/Http.js +1 -2
- package/types/Hubdb.js +1 -2
- package/types/HublValidation.js +1 -2
- package/types/Lang.d.ts +1 -1
- package/types/Lang.js +1 -2
- package/types/Lighthouse.js +1 -2
- package/types/MarketplaceValidation.js +1 -2
- package/types/Migration.d.ts +2 -2
- package/types/Migration.js +1 -4
- package/types/Modules.js +1 -2
- package/types/PortManager.js +1 -2
- package/types/Project.d.ts +3 -21
- package/types/Project.js +1 -2
- package/types/ProjectComponents.d.ts +24 -0
- package/types/ProjectComponents.js +1 -0
- package/types/ProjectLog.js +1 -2
- package/types/Sandbox.js +2 -5
- package/types/Schemas.js +1 -2
- package/types/Secrets.js +1 -2
- package/types/Utils.js +1 -2
- package/types/developerTestAccounts.js +1 -2
- package/utils/PortManagerServer.d.ts +1 -2
- package/utils/PortManagerServer.js +32 -38
- package/utils/cms/fieldsJS.d.ts +1 -1
- package/utils/cms/fieldsJS.js +1 -5
- package/utils/cms/modules.d.ts +1 -1
- package/utils/cms/modules.js +13 -22
- package/utils/detectPort.js +12 -19
- package/utils/git.js +17 -26
- package/utils/lang.d.ts +1 -1
- package/utils/lang.js +5 -14
- package/utils/personalAccessKey.d.ts +8 -0
- package/utils/personalAccessKey.js +51 -0
- package/errors/errors_DEPRECATED.d.ts +0 -3
- package/errors/errors_DEPRECATED.js +0 -60
package/lib/archive.js
CHANGED
|
@@ -1,97 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.extractZipArchive = void 0;
|
|
30
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
31
|
-
const path_1 = __importStar(require("path"));
|
|
32
|
-
const os_1 = require("os");
|
|
33
|
-
const extract_zip_1 = __importDefault(require("extract-zip"));
|
|
34
|
-
const logger_1 = require("./logger");
|
|
35
|
-
const lang_1 = require("../utils/lang");
|
|
36
|
-
const FileSystemError_1 = require("../models/FileSystemError");
|
|
37
|
-
const fs_1 = require("./fs");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path, { join } from 'path';
|
|
3
|
+
import { tmpdir } from 'os';
|
|
4
|
+
import extract from 'extract-zip';
|
|
5
|
+
import { logger } from './logger.js';
|
|
6
|
+
import { i18n } from '../utils/lang.js';
|
|
7
|
+
import { FileSystemError } from '../models/FileSystemError.js';
|
|
8
|
+
import { walk } from './fs.js';
|
|
38
9
|
const i18nKey = 'lib.archive';
|
|
39
10
|
async function extractZip(name, zip, hideLogs = false) {
|
|
40
11
|
const result = { extractDir: '', tmpDir: '' };
|
|
41
12
|
const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
|
|
42
13
|
if (!hideLogs) {
|
|
43
|
-
|
|
14
|
+
logger.log(i18n(`${i18nKey}.extractZip.init`));
|
|
44
15
|
}
|
|
45
16
|
// Write zip to disk
|
|
46
17
|
let tmpZipPath = '';
|
|
47
18
|
try {
|
|
48
|
-
result.tmpDir = await
|
|
49
|
-
tmpZipPath =
|
|
50
|
-
await
|
|
51
|
-
await
|
|
19
|
+
result.tmpDir = await fs.mkdtemp(join(tmpdir(), TMP_FOLDER_PREFIX));
|
|
20
|
+
tmpZipPath = join(result.tmpDir, 'hubspot-temp.zip');
|
|
21
|
+
await fs.ensureFile(tmpZipPath);
|
|
22
|
+
await fs.writeFile(tmpZipPath, zip, {
|
|
52
23
|
mode: 0o777,
|
|
53
24
|
});
|
|
54
25
|
}
|
|
55
26
|
catch (err) {
|
|
56
27
|
if (tmpZipPath || result.tmpDir) {
|
|
57
|
-
throw new
|
|
28
|
+
throw new FileSystemError({ cause: err }, {
|
|
58
29
|
filepath: tmpZipPath || result.tmpDir,
|
|
59
30
|
operation: 'write',
|
|
60
31
|
});
|
|
61
32
|
}
|
|
62
33
|
else {
|
|
63
|
-
throw new Error(
|
|
34
|
+
throw new Error(i18n(`${i18nKey}.extractZip.errors.write`), {
|
|
64
35
|
cause: err,
|
|
65
36
|
});
|
|
66
37
|
}
|
|
67
38
|
}
|
|
68
39
|
// Extract zip
|
|
69
40
|
try {
|
|
70
|
-
const tmpExtractPath =
|
|
71
|
-
await (
|
|
41
|
+
const tmpExtractPath = join(result.tmpDir, 'extracted');
|
|
42
|
+
await extract(tmpZipPath, { dir: tmpExtractPath });
|
|
72
43
|
result.extractDir = tmpExtractPath;
|
|
73
44
|
}
|
|
74
45
|
catch (err) {
|
|
75
|
-
throw new Error(
|
|
46
|
+
throw new Error(i18n(`${i18nKey}.extractZip.errors.extract`), {
|
|
76
47
|
cause: err,
|
|
77
48
|
});
|
|
78
49
|
}
|
|
79
|
-
|
|
50
|
+
logger.debug(i18n(`${i18nKey}.extractZip.success`));
|
|
80
51
|
return result;
|
|
81
52
|
}
|
|
82
53
|
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, handleCollision, } = {}) {
|
|
83
54
|
try {
|
|
84
55
|
if (!hideLogs) {
|
|
85
|
-
|
|
56
|
+
logger.log(i18n(`${i18nKey}.copySourceToDest.init`));
|
|
86
57
|
}
|
|
87
58
|
const srcDirPath = [src];
|
|
88
59
|
if (includesRootDir) {
|
|
89
|
-
const files = await
|
|
60
|
+
const files = await fs.readdir(src);
|
|
90
61
|
const rootDir = files[0];
|
|
91
62
|
if (!rootDir) {
|
|
92
|
-
|
|
63
|
+
logger.debug(i18n(`${i18nKey}.copySourceToDest.sourceEmpty`));
|
|
93
64
|
// Create the dest path if it doesn't already exist
|
|
94
|
-
await
|
|
65
|
+
await fs.ensureDir(dest);
|
|
95
66
|
// No root found so nothing to copy
|
|
96
67
|
return true;
|
|
97
68
|
}
|
|
@@ -102,19 +73,19 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true,
|
|
|
102
73
|
sourceDirs.push(...(Array.isArray(sourceDir) ? new Set(sourceDir) : [sourceDir]));
|
|
103
74
|
}
|
|
104
75
|
if (sourceDirs.length === 0) {
|
|
105
|
-
const projectSrcDir =
|
|
106
|
-
await
|
|
76
|
+
const projectSrcDir = join(...srcDirPath);
|
|
77
|
+
await fs.copy(projectSrcDir, dest);
|
|
107
78
|
}
|
|
108
79
|
else {
|
|
109
80
|
for (let i = 0; i < sourceDirs.length; i++) {
|
|
110
|
-
const projectSrcDir =
|
|
81
|
+
const projectSrcDir = join(...srcDirPath, sourceDirs[i]);
|
|
111
82
|
let collisions = [];
|
|
112
83
|
let filesWithoutCollisions = [];
|
|
113
|
-
if (
|
|
84
|
+
if (fs.existsSync(dest) &&
|
|
114
85
|
handleCollision &&
|
|
115
86
|
typeof handleCollision === 'function') {
|
|
116
|
-
const existingFiles = (await
|
|
117
|
-
const newFiles = (await
|
|
87
|
+
const existingFiles = (await walk(dest, ['node_modules'])).map(file => path.normalize(path.relative(dest, file)));
|
|
88
|
+
const newFiles = (await walk(projectSrcDir, ['node_modules'])).map(file => path.relative(projectSrcDir, file));
|
|
118
89
|
// Find files that exist in the same positions in both directories
|
|
119
90
|
collisions = existingFiles.filter(currentFile => newFiles.includes(currentFile));
|
|
120
91
|
filesWithoutCollisions = newFiles.filter(currentFile => !collisions.includes(currentFile));
|
|
@@ -127,19 +98,19 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true,
|
|
|
127
98
|
src: projectSrcDir,
|
|
128
99
|
collisions,
|
|
129
100
|
});
|
|
130
|
-
await Promise.all(filesWithoutCollisions.map(currentFile =>
|
|
101
|
+
await Promise.all(filesWithoutCollisions.map(currentFile => fs.copy(path.join(projectSrcDir, currentFile), path.join(dest, currentFile))));
|
|
131
102
|
}
|
|
132
103
|
else {
|
|
133
|
-
await
|
|
104
|
+
await fs.copy(projectSrcDir, dest);
|
|
134
105
|
}
|
|
135
106
|
}
|
|
136
107
|
}
|
|
137
|
-
|
|
108
|
+
logger.debug(i18n(`${i18nKey}.copySourceToDest.success`));
|
|
138
109
|
return true;
|
|
139
110
|
}
|
|
140
111
|
catch (err) {
|
|
141
|
-
|
|
142
|
-
throw new
|
|
112
|
+
logger.debug(i18n(`${i18nKey}.copySourceToDest.error`, { dest }));
|
|
113
|
+
throw new FileSystemError({ cause: err }, {
|
|
143
114
|
filepath: dest,
|
|
144
115
|
operation: 'write',
|
|
145
116
|
});
|
|
@@ -149,13 +120,13 @@ async function cleanupTempDir(tmpDir) {
|
|
|
149
120
|
if (!tmpDir)
|
|
150
121
|
return;
|
|
151
122
|
try {
|
|
152
|
-
await
|
|
123
|
+
await fs.remove(tmpDir);
|
|
153
124
|
}
|
|
154
125
|
catch (e) {
|
|
155
|
-
|
|
126
|
+
logger.debug(i18n(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
|
|
156
127
|
}
|
|
157
128
|
}
|
|
158
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs, handleCollision, } = {}) {
|
|
129
|
+
export async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs, handleCollision, } = {}) {
|
|
159
130
|
let success = false;
|
|
160
131
|
if (zip) {
|
|
161
132
|
const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
|
|
@@ -171,4 +142,3 @@ async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir,
|
|
|
171
142
|
}
|
|
172
143
|
return success;
|
|
173
144
|
}
|
|
174
|
-
exports.extractZipArchive = extractZipArchive;
|
package/lib/cms/functions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions';
|
|
1
|
+
import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions.js';
|
|
2
2
|
export declare function isObjectOrFunction(value: object): boolean;
|
|
3
3
|
export declare function createEndpoint(endpointMethod: string, filename: string): {
|
|
4
4
|
method: string;
|
package/lib/cms/functions.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
10
|
-
const path_2 = require("../path");
|
|
11
|
-
const github_1 = require("../github");
|
|
12
|
-
const logger_1 = require("../logger");
|
|
13
|
-
const lang_1 = require("../../utils/lang");
|
|
14
|
-
const FileSystemError_1 = require("../../models/FileSystemError");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import findup from 'findup-sync';
|
|
4
|
+
import { getCwd } from '../path.js';
|
|
5
|
+
import { fetchFileFromRepository } from '../github.js';
|
|
6
|
+
import { logger } from '../logger.js';
|
|
7
|
+
import { i18n } from '../../utils/lang.js';
|
|
8
|
+
import { FileSystemError } from '../../models/FileSystemError.js';
|
|
15
9
|
const i18nKey = 'lib.cms.functions';
|
|
16
|
-
function isObjectOrFunction(value) {
|
|
10
|
+
export function isObjectOrFunction(value) {
|
|
17
11
|
const type = typeof value;
|
|
18
12
|
return value != null && (type === 'object' || type === 'function');
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
function createEndpoint(endpointMethod, filename) {
|
|
14
|
+
export function createEndpoint(endpointMethod, filename) {
|
|
22
15
|
return {
|
|
23
16
|
method: endpointMethod || 'GET',
|
|
24
17
|
file: filename,
|
|
25
18
|
};
|
|
26
19
|
}
|
|
27
|
-
|
|
28
|
-
function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
20
|
+
export function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
29
21
|
return {
|
|
30
22
|
runtime: 'nodejs18.x',
|
|
31
23
|
version: '1.0',
|
|
@@ -36,21 +28,20 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
|
36
28
|
},
|
|
37
29
|
};
|
|
38
30
|
}
|
|
39
|
-
exports.createConfig = createConfig;
|
|
40
31
|
function writeConfig(configFilePath, config) {
|
|
41
32
|
const configJson = JSON.stringify(config, null, ' ');
|
|
42
|
-
|
|
33
|
+
fs.writeFileSync(configFilePath, configJson);
|
|
43
34
|
}
|
|
44
35
|
function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, functionFile }) {
|
|
45
36
|
let configString;
|
|
46
37
|
try {
|
|
47
|
-
configString =
|
|
38
|
+
configString = fs.readFileSync(configFilePath).toString();
|
|
48
39
|
}
|
|
49
40
|
catch (err) {
|
|
50
|
-
|
|
41
|
+
logger.debug(i18n(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
|
|
51
42
|
configFilePath,
|
|
52
43
|
}));
|
|
53
|
-
throw new
|
|
44
|
+
throw new FileSystemError({ cause: err }, {
|
|
54
45
|
filepath: configFilePath,
|
|
55
46
|
operation: 'read',
|
|
56
47
|
});
|
|
@@ -60,22 +51,22 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
60
51
|
config = JSON.parse(configString);
|
|
61
52
|
}
|
|
62
53
|
catch (err) {
|
|
63
|
-
|
|
54
|
+
logger.debug(i18n(`${i18nKey}.updateExistingConfig.invalidJSON`, {
|
|
64
55
|
configFilePath,
|
|
65
56
|
}));
|
|
66
|
-
throw new
|
|
57
|
+
throw new FileSystemError({ cause: err }, {
|
|
67
58
|
filepath: configFilePath,
|
|
68
59
|
operation: 'read',
|
|
69
60
|
});
|
|
70
61
|
}
|
|
71
62
|
if (!isObjectOrFunction(config)) {
|
|
72
|
-
throw new Error(
|
|
63
|
+
throw new Error(i18n(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
|
|
73
64
|
configFilePath,
|
|
74
65
|
}));
|
|
75
66
|
}
|
|
76
67
|
if (config.endpoints) {
|
|
77
68
|
if (config.endpoints[endpointPath]) {
|
|
78
|
-
throw new Error(
|
|
69
|
+
throw new Error(i18n(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
|
|
79
70
|
configFilePath,
|
|
80
71
|
endpointPath,
|
|
81
72
|
}));
|
|
@@ -93,65 +84,65 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
93
84
|
writeConfig(configFilePath, config);
|
|
94
85
|
}
|
|
95
86
|
catch (err) {
|
|
96
|
-
|
|
87
|
+
logger.debug(i18n(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
|
|
97
88
|
configFilePath,
|
|
98
89
|
}));
|
|
99
|
-
throw new
|
|
90
|
+
throw new FileSystemError({ cause: err }, {
|
|
100
91
|
filepath: configFilePath,
|
|
101
92
|
operation: 'read',
|
|
102
93
|
});
|
|
103
94
|
}
|
|
104
95
|
}
|
|
105
|
-
async function createFunction(functionInfo, dest, options = {}) {
|
|
96
|
+
export async function createFunction(functionInfo, dest, options = {}) {
|
|
106
97
|
const { functionsFolder, filename, endpointPath, endpointMethod } = functionInfo;
|
|
107
98
|
const allowExistingFile = options.allowExistingFile || false;
|
|
108
|
-
const ancestorFunctionsConfig = (
|
|
109
|
-
cwd:
|
|
99
|
+
const ancestorFunctionsConfig = findup('serverless.json', {
|
|
100
|
+
cwd: getCwd(),
|
|
110
101
|
nocase: true,
|
|
111
102
|
});
|
|
112
103
|
if (ancestorFunctionsConfig) {
|
|
113
|
-
throw new Error(
|
|
114
|
-
ancestorConfigPath:
|
|
104
|
+
throw new Error(i18n(`${i18nKey}.createFunction.errors.nestedConfigError`, {
|
|
105
|
+
ancestorConfigPath: path.dirname(ancestorFunctionsConfig),
|
|
115
106
|
}));
|
|
116
107
|
}
|
|
117
108
|
const folderName = functionsFolder.endsWith('.functions')
|
|
118
109
|
? functionsFolder
|
|
119
110
|
: `${functionsFolder}.functions`;
|
|
120
111
|
const functionFile = filename.endsWith('.js') ? filename : `${filename}.js`;
|
|
121
|
-
const destPath =
|
|
122
|
-
if (
|
|
123
|
-
|
|
112
|
+
const destPath = path.join(dest, folderName);
|
|
113
|
+
if (fs.existsSync(destPath)) {
|
|
114
|
+
logger.log(i18n(`${i18nKey}.createFunction.destPathAlreadyExists`, {
|
|
124
115
|
path: destPath,
|
|
125
116
|
}));
|
|
126
117
|
}
|
|
127
118
|
else {
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
fs.mkdirp(destPath);
|
|
120
|
+
logger.log(i18n(`${i18nKey}.createFunction.createdDest`, {
|
|
130
121
|
path: destPath,
|
|
131
122
|
}));
|
|
132
123
|
}
|
|
133
|
-
const functionFilePath =
|
|
134
|
-
const configFilePath =
|
|
135
|
-
if (!allowExistingFile &&
|
|
136
|
-
throw new Error(
|
|
124
|
+
const functionFilePath = path.join(destPath, functionFile);
|
|
125
|
+
const configFilePath = path.join(destPath, 'serverless.json');
|
|
126
|
+
if (!allowExistingFile && fs.existsSync(functionFilePath)) {
|
|
127
|
+
throw new Error(i18n(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
|
|
137
128
|
functionFilePath,
|
|
138
129
|
}));
|
|
139
130
|
}
|
|
140
|
-
const result = await
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
const result = await fetchFileFromRepository('HubSpot/cms-sample-assets', 'functions/sample-function.js', 'main');
|
|
132
|
+
fs.writeFileSync(functionFilePath, result);
|
|
133
|
+
logger.log(i18n(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
143
134
|
path: functionFilePath,
|
|
144
135
|
}));
|
|
145
|
-
if (
|
|
136
|
+
if (fs.existsSync(configFilePath)) {
|
|
146
137
|
updateExistingConfig(configFilePath, {
|
|
147
138
|
endpointPath,
|
|
148
139
|
endpointMethod,
|
|
149
140
|
functionFile,
|
|
150
141
|
});
|
|
151
|
-
|
|
142
|
+
logger.log(i18n(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
152
143
|
path: functionFilePath,
|
|
153
144
|
}));
|
|
154
|
-
|
|
145
|
+
logger.log(i18n(`${i18nKey}.createFunction.success`, {
|
|
155
146
|
endpointPath: endpointPath,
|
|
156
147
|
folderName,
|
|
157
148
|
}));
|
|
@@ -162,21 +153,20 @@ async function createFunction(functionInfo, dest, options = {}) {
|
|
|
162
153
|
writeConfig(configFilePath, config);
|
|
163
154
|
}
|
|
164
155
|
catch (err) {
|
|
165
|
-
|
|
156
|
+
logger.debug(i18n(`${i18nKey}.createFunction.failedToCreateFile`, {
|
|
166
157
|
configFilePath,
|
|
167
158
|
}));
|
|
168
|
-
throw new
|
|
159
|
+
throw new FileSystemError({ cause: err }, {
|
|
169
160
|
filepath: configFilePath,
|
|
170
161
|
operation: 'write',
|
|
171
162
|
});
|
|
172
163
|
}
|
|
173
|
-
|
|
164
|
+
logger.log(i18n(`${i18nKey}.createFunction.createdConfigFile`, {
|
|
174
165
|
path: configFilePath,
|
|
175
166
|
}));
|
|
176
|
-
|
|
167
|
+
logger.log(i18n(`${i18nKey}.createFunction.success`, {
|
|
177
168
|
endpointPath: endpointPath,
|
|
178
169
|
folderName,
|
|
179
170
|
}));
|
|
180
171
|
}
|
|
181
172
|
}
|
|
182
|
-
exports.createFunction = createFunction;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const escapeRegExp_1 = require("../escapeRegExp");
|
|
12
|
-
const modules_1 = require("../../utils/cms/modules");
|
|
13
|
-
const logger_1 = require("../logger");
|
|
14
|
-
const lang_1 = require("../../utils/lang");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fork } from 'child_process';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { escapeRegExp } from '../escapeRegExp.js';
|
|
7
|
+
import { isModuleFolderChild } from '../../utils/cms/modules.js';
|
|
8
|
+
import { logger } from '../logger.js';
|
|
9
|
+
import { i18n } from '../../utils/lang.js';
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
11
|
const i18nKey = 'lib.cms.handleFieldsJs';
|
|
16
|
-
class FieldsJs {
|
|
12
|
+
export class FieldsJs {
|
|
17
13
|
projectDir;
|
|
18
14
|
filePath;
|
|
19
15
|
rootWriteDir;
|
|
@@ -40,12 +36,12 @@ class FieldsJs {
|
|
|
40
36
|
// Converts a fields.js file into a fields.json file, writes, and returns of fields.json
|
|
41
37
|
convertFieldsJs(writeDir) {
|
|
42
38
|
const filePath = this.filePath;
|
|
43
|
-
const dirName =
|
|
39
|
+
const dirName = path.dirname(filePath);
|
|
44
40
|
return new Promise((resolve, reject) => {
|
|
45
41
|
const fieldOptionsAsString = Array.isArray(this.fieldOptions)
|
|
46
42
|
? this.fieldOptions.join(',')
|
|
47
43
|
: this.fieldOptions;
|
|
48
|
-
const convertFieldsProcess =
|
|
44
|
+
const convertFieldsProcess = fork(path.join(__dirname, './processFieldsJs.js'), [], {
|
|
49
45
|
cwd: dirName,
|
|
50
46
|
env: {
|
|
51
47
|
dirName,
|
|
@@ -54,7 +50,7 @@ class FieldsJs {
|
|
|
54
50
|
writeDir,
|
|
55
51
|
},
|
|
56
52
|
});
|
|
57
|
-
|
|
53
|
+
logger.debug(i18n(`${i18nKey}.convertFieldsJs.creating`, {
|
|
58
54
|
pid: convertFieldsProcess.pid || '',
|
|
59
55
|
}));
|
|
60
56
|
convertFieldsProcess.on('message', function (message) {
|
|
@@ -66,12 +62,12 @@ class FieldsJs {
|
|
|
66
62
|
}
|
|
67
63
|
});
|
|
68
64
|
convertFieldsProcess.on('close', () => {
|
|
69
|
-
|
|
65
|
+
logger.debug(i18n(`${i18nKey}.convertFieldsJs.terminating`, {
|
|
70
66
|
pid: convertFieldsProcess.pid || '',
|
|
71
67
|
}));
|
|
72
68
|
});
|
|
73
69
|
}).catch((e) => {
|
|
74
|
-
throw new Error(
|
|
70
|
+
throw new Error(i18n(`${i18nKey}.convertFieldsJs.errors.errorConverting`, { filePath }), { cause: e });
|
|
75
71
|
});
|
|
76
72
|
}
|
|
77
73
|
/**
|
|
@@ -80,18 +76,18 @@ class FieldsJs {
|
|
|
80
76
|
* Ex: path/to/tmp/example.module/fields.json => path/to/project/example.module/fields.output.json
|
|
81
77
|
*/
|
|
82
78
|
saveOutput() {
|
|
83
|
-
if (!this.outputPath || !
|
|
84
|
-
throw new Error(
|
|
79
|
+
if (!this.outputPath || !fs.existsSync(this.outputPath)) {
|
|
80
|
+
throw new Error(i18n(`${i18nKey}.saveOutput.errors.saveFailed`, {
|
|
85
81
|
path: this.filePath,
|
|
86
82
|
}));
|
|
87
83
|
}
|
|
88
|
-
const relativePath =
|
|
89
|
-
const savePath =
|
|
84
|
+
const relativePath = path.relative(this.rootWriteDir, path.dirname(this.outputPath));
|
|
85
|
+
const savePath = path.join(this.projectDir, relativePath, 'fields.output.json');
|
|
90
86
|
try {
|
|
91
|
-
|
|
87
|
+
fs.copyFileSync(this.outputPath, savePath);
|
|
92
88
|
}
|
|
93
89
|
catch (err) {
|
|
94
|
-
throw new Error(
|
|
90
|
+
throw new Error(i18n(`${i18nKey}.saveOutput.errors.saveFailed`, { path: savePath }), { cause: err });
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
93
|
/**
|
|
@@ -101,51 +97,47 @@ class FieldsJs {
|
|
|
101
97
|
* Ex: If rootWriteDir = 'path/to/temp', filePath = 'projectRoot/sample.module/fields.js'. Then getWriteDir() => path/to/temp/sample.module
|
|
102
98
|
*/
|
|
103
99
|
getWriteDir() {
|
|
104
|
-
const projectDirRegex = new RegExp(`^${
|
|
100
|
+
const projectDirRegex = new RegExp(`^${escapeRegExp(this.projectDir)}`);
|
|
105
101
|
const relativePath = this.filePath.replace(projectDirRegex, '');
|
|
106
|
-
return
|
|
102
|
+
return path.dirname(path.join(this.rootWriteDir, relativePath));
|
|
107
103
|
}
|
|
108
104
|
getOutputPathPromise() {
|
|
109
105
|
const writeDir = this.getWriteDir();
|
|
110
106
|
return this.convertFieldsJs(writeDir).then(outputPath => outputPath);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
|
-
exports.FieldsJs = FieldsJs;
|
|
114
109
|
/**
|
|
115
110
|
* Determines if file is a convertable fields.js file i.e., if it is called
|
|
116
111
|
* 'fields.js' and in a root or in a module folder, and if convertFields flag is true.
|
|
117
112
|
*/
|
|
118
|
-
function isConvertableFieldJs(rootDir, filePath, convertFields = false) {
|
|
113
|
+
export function isConvertableFieldJs(rootDir, filePath, convertFields = false) {
|
|
119
114
|
const allowedFieldsNames = ['fields.js', 'fields.mjs', 'fields.cjs'];
|
|
120
|
-
const regex = new RegExp(`^${
|
|
121
|
-
const relativePath =
|
|
122
|
-
const baseName =
|
|
123
|
-
const inModuleFolder =
|
|
115
|
+
const regex = new RegExp(`^${escapeRegExp(rootDir)}`);
|
|
116
|
+
const relativePath = path.dirname(filePath.replace(regex, ''));
|
|
117
|
+
const baseName = path.basename(filePath);
|
|
118
|
+
const inModuleFolder = isModuleFolderChild({ path: filePath, isLocal: true });
|
|
124
119
|
return !!(convertFields &&
|
|
125
120
|
allowedFieldsNames.includes(baseName) &&
|
|
126
|
-
(inModuleFolder || relativePath ==
|
|
121
|
+
(inModuleFolder || relativePath == path.sep));
|
|
127
122
|
}
|
|
128
|
-
exports.isConvertableFieldJs = isConvertableFieldJs;
|
|
129
123
|
// Try creating tempdir
|
|
130
|
-
function createTmpDirSync(prefix) {
|
|
124
|
+
export function createTmpDirSync(prefix) {
|
|
131
125
|
let tmpDir;
|
|
132
126
|
try {
|
|
133
|
-
tmpDir =
|
|
127
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
134
128
|
}
|
|
135
129
|
catch (err) {
|
|
136
|
-
throw new Error(
|
|
130
|
+
throw new Error(i18n(`${i18nKey}.createTmpDirSync.errors.writeFailed`), {
|
|
137
131
|
cause: err,
|
|
138
132
|
});
|
|
139
133
|
}
|
|
140
134
|
return tmpDir;
|
|
141
135
|
}
|
|
142
|
-
exports.createTmpDirSync = createTmpDirSync;
|
|
143
136
|
// Try cleaning up resources from os's tempdir
|
|
144
|
-
function cleanupTmpDirSync(tmpDir) {
|
|
145
|
-
|
|
137
|
+
export function cleanupTmpDirSync(tmpDir) {
|
|
138
|
+
fs.rm(tmpDir, { recursive: true }, err => {
|
|
146
139
|
if (err) {
|
|
147
|
-
throw new Error(
|
|
140
|
+
throw new Error(i18n(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`), { cause: err });
|
|
148
141
|
}
|
|
149
142
|
});
|
|
150
143
|
}
|
|
151
|
-
exports.cleanupTmpDirSync = cleanupTmpDirSync;
|
package/lib/cms/modules.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules';
|
|
2
|
-
import { GithubRepoFile } from '../../types/Github';
|
|
1
|
+
import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules.js';
|
|
2
|
+
import { GithubRepoFile } from '../../types/Github.js';
|
|
3
3
|
export declare const ValidationIds: {
|
|
4
4
|
SRC_REQUIRED: string;
|
|
5
5
|
DEST_REQUIRED: string;
|