@hubspot/project-parsing-lib 0.8.6-beta.0 → 0.9.0-beta.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/package.json +1 -1
- package/src/index.js +24 -41
- package/src/lib/localDev.d.ts +4 -0
- package/src/lib/localDev.js +80 -0
- package/src/lib/transform.d.ts +1 -0
- package/src/lib/transform.js +6 -0
- package/src/lib/types.d.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/project-parsing-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-beta.0",
|
|
4
4
|
"description": "Parsing library for converting projects directory structures to their intermediate representation",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "src/index.js",
|
package/src/index.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getProjectThemeDetails = exports.migrateThemes = exports.getUnsupportedTypeError = exports.getFailedToFetchSchemasError = exports.getMissingRequiredFieldError = exports.getMissingAccountIdError = exports.getMissingConfigError = exports.getMissingTypeError = exports.getInvalidJsonError = exports.AjvErrorKeyword = exports.hsProjectJsonFilename = exports.metafileExtension = exports.createAjvInstance = exports.getIntermediateRepresentationSchema = exports.mapToInternalType = exports.mapToUserFriendlyName = exports.coerceToValidUid = exports.validateUid = exports.migrate = exports.projectContainsHsMetaFiles = exports.getAllHsProfiles = exports.loadHsProfileFile = exports.getHsProfileFilename = exports.isTranslationError = void 0;
|
|
7
4
|
exports.translate = translate;
|
|
8
5
|
exports.translateForLocalDev = translateForLocalDev;
|
|
9
|
-
const isDeepEqual_1 = require("@hubspot/local-dev-lib/isDeepEqual");
|
|
10
6
|
const files_1 = require("./lib/files");
|
|
11
7
|
const validation_1 = require("./lib/validation");
|
|
12
8
|
const transform_1 = require("./lib/transform");
|
|
13
9
|
const copy_1 = require("./lang/copy");
|
|
14
|
-
const
|
|
10
|
+
const localDev_1 = require("./lib/localDev");
|
|
15
11
|
const defaultOptions = {
|
|
16
12
|
skipValidation: false,
|
|
17
13
|
};
|
|
@@ -34,43 +30,30 @@ async function translate(translationContext, translationOptions = defaultOptions
|
|
|
34
30
|
return intermediateRepresentation;
|
|
35
31
|
}
|
|
36
32
|
async function translateForLocalDev(translationContext, translationOptions) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
const localDevIr = {
|
|
42
|
-
intermediateNodesIndexedByUid: {},
|
|
43
|
-
profileData: {},
|
|
44
|
-
};
|
|
45
|
-
Object.entries(IR.intermediateNodesIndexedByUid).forEach(([uid, node]) => {
|
|
46
|
-
const component = IR.intermediateNodesIndexedByUid[uid];
|
|
47
|
-
const componentConfigPath = path_1.default.join(translationContext.projectSourceDir, component.metaFilePath);
|
|
48
|
-
let configUpdatedSinceLastUpload = false;
|
|
49
|
-
if (translationOptions?.projectNodesAtLastUpload) {
|
|
50
|
-
const componentAtLastUpload = translationOptions.projectNodesAtLastUpload[uid];
|
|
51
|
-
if (componentAtLastUpload) {
|
|
52
|
-
configUpdatedSinceLastUpload = !(0, isDeepEqual_1.isDeepEqual)(component.config, componentAtLastUpload.config);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Component is net new
|
|
56
|
-
configUpdatedSinceLastUpload = true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
localDevIr.intermediateNodesIndexedByUid[uid] = {
|
|
60
|
-
...node,
|
|
61
|
-
localDev: {
|
|
62
|
-
componentRoot: path_1.default.dirname(componentConfigPath),
|
|
63
|
-
componentConfigPath,
|
|
64
|
-
configUpdatedSinceLastUpload,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
if (IR.profileData?.vars.profileVariables) {
|
|
69
|
-
Object.entries(IR.profileData.vars.profileVariables).forEach(([key, value]) => {
|
|
70
|
-
localDevIr.profileData[key] = value.value;
|
|
71
|
-
});
|
|
33
|
+
const metafileContents = await (0, files_1.loadHsMetaFiles)(translationContext);
|
|
34
|
+
if (metafileContents.length === 0) {
|
|
35
|
+
throw new Error(copy_1.errorMessages.project.noHsMetaFiles);
|
|
72
36
|
}
|
|
73
|
-
|
|
37
|
+
let hsProfileContents;
|
|
38
|
+
if (translationOptions?.profile) {
|
|
39
|
+
hsProfileContents = (0, files_1.loadHsProfileFile)(translationContext.projectSourceDir, translationOptions.profile);
|
|
40
|
+
}
|
|
41
|
+
const transformation = (0, transform_1.transform)(metafileContents, translationContext, hsProfileContents);
|
|
42
|
+
const baseIntermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation, hsProfileContents, true);
|
|
43
|
+
const parsingErrors = (0, transform_1.getParsingErrors)(transformation);
|
|
44
|
+
const projectNodes = (0, localDev_1.getLocalDevProjectNodes)(baseIntermediateRepresentation.intermediateNodesIndexedByUid, translationContext.projectSourceDir, translationOptions?.projectNodesAtLastUpload);
|
|
45
|
+
let projectNodesWithErrors = {};
|
|
46
|
+
if (translationOptions?.projectNodesAtLastUpload) {
|
|
47
|
+
projectNodesWithErrors = (0, localDev_1.getRemovedNodesAndNodesWithErrors)(baseIntermediateRepresentation.intermediateNodesIndexedByUid, translationOptions.projectNodesAtLastUpload, parsingErrors);
|
|
48
|
+
}
|
|
49
|
+
const profileData = (0, localDev_1.getLocalDevProfileData)(baseIntermediateRepresentation.profileData?.vars.profileVariables);
|
|
50
|
+
return {
|
|
51
|
+
intermediateNodesIndexedByUid: {
|
|
52
|
+
...projectNodes,
|
|
53
|
+
...projectNodesWithErrors,
|
|
54
|
+
},
|
|
55
|
+
profileData,
|
|
56
|
+
};
|
|
74
57
|
}
|
|
75
58
|
var errors_1 = require("./lib/errors");
|
|
76
59
|
Object.defineProperty(exports, "isTranslationError", { enumerable: true, get: function () { return errors_1.isTranslationError; } });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BEProfileVariables, HSProfileVariables, IntermediateRepresentationNode, IntermediateRepresentationNodeLocalDev, FileParseResult } from './types';
|
|
2
|
+
export declare function getLocalDevProjectNodes(intermediateNodesIndexedByUid: Record<string, IntermediateRepresentationNode>, projectSourceDir: string, projectNodesAtLastUpload?: Record<string, IntermediateRepresentationNodeLocalDev>): Record<string, IntermediateRepresentationNodeLocalDev>;
|
|
3
|
+
export declare function getRemovedNodesAndNodesWithErrors(intermediateNodesIndexedByUid: Record<string, IntermediateRepresentationNode>, projectNodesAtLastUpload: Record<string, IntermediateRepresentationNodeLocalDev>, parsingErrors: FileParseResult[]): Record<string, IntermediateRepresentationNodeLocalDev>;
|
|
4
|
+
export declare function getLocalDevProfileData(profileVariables?: BEProfileVariables): HSProfileVariables;
|
|
@@ -0,0 +1,80 @@
|
|
|
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.getLocalDevProjectNodes = getLocalDevProjectNodes;
|
|
7
|
+
exports.getRemovedNodesAndNodesWithErrors = getRemovedNodesAndNodesWithErrors;
|
|
8
|
+
exports.getLocalDevProfileData = getLocalDevProfileData;
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const isDeepEqual_1 = require("@hubspot/local-dev-lib/isDeepEqual");
|
|
11
|
+
function getLocalDevProjectNodes(intermediateNodesIndexedByUid, projectSourceDir, projectNodesAtLastUpload) {
|
|
12
|
+
const localDevProjectNodes = {};
|
|
13
|
+
Object.entries(intermediateNodesIndexedByUid).forEach(([uid, node]) => {
|
|
14
|
+
const component = intermediateNodesIndexedByUid[uid];
|
|
15
|
+
const componentConfigPath = path_1.default.join(projectSourceDir, component.metaFilePath);
|
|
16
|
+
let configUpdatedSinceLastUpload = false;
|
|
17
|
+
if (projectNodesAtLastUpload) {
|
|
18
|
+
const componentAtLastUpload = projectNodesAtLastUpload[uid];
|
|
19
|
+
if (componentAtLastUpload) {
|
|
20
|
+
configUpdatedSinceLastUpload = !(0, isDeepEqual_1.isDeepEqual)(component.config, componentAtLastUpload.config);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// Component is net new
|
|
24
|
+
configUpdatedSinceLastUpload = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
localDevProjectNodes[uid] = {
|
|
28
|
+
...node,
|
|
29
|
+
localDev: {
|
|
30
|
+
componentRoot: path_1.default.dirname(componentConfigPath),
|
|
31
|
+
componentConfigPath,
|
|
32
|
+
configUpdatedSinceLastUpload,
|
|
33
|
+
removed: false,
|
|
34
|
+
parsingErrors: [],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return localDevProjectNodes;
|
|
39
|
+
}
|
|
40
|
+
function getRemovedNodesAndNodesWithErrors(intermediateNodesIndexedByUid, projectNodesAtLastUpload, parsingErrors) {
|
|
41
|
+
const nodesWithErrors = {};
|
|
42
|
+
Object.entries(projectNodesAtLastUpload).forEach(([uid, node]) => {
|
|
43
|
+
// Node is still in the project
|
|
44
|
+
if (intermediateNodesIndexedByUid[uid]) {
|
|
45
|
+
return;
|
|
46
|
+
// Node has parsing errors but was not removed
|
|
47
|
+
}
|
|
48
|
+
const errorForNode = parsingErrors.find(error => error.file === node.metaFilePath);
|
|
49
|
+
if (errorForNode) {
|
|
50
|
+
nodesWithErrors[uid] = {
|
|
51
|
+
...node,
|
|
52
|
+
localDev: {
|
|
53
|
+
...node.localDev,
|
|
54
|
+
parsingErrors: errorForNode.errors,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// Node was removed since the last upload
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
nodesWithErrors[uid] = {
|
|
61
|
+
...node,
|
|
62
|
+
localDev: {
|
|
63
|
+
...node.localDev,
|
|
64
|
+
removed: true,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return nodesWithErrors;
|
|
70
|
+
}
|
|
71
|
+
function getLocalDevProfileData(profileVariables) {
|
|
72
|
+
if (!profileVariables) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
const localDevProfileData = {};
|
|
76
|
+
Object.entries(profileVariables).forEach(([key, value]) => {
|
|
77
|
+
localDevProfileData[key] = value.value;
|
|
78
|
+
});
|
|
79
|
+
return localDevProfileData;
|
|
80
|
+
}
|
package/src/lib/transform.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare function mapToUserFacingType(type: string): string;
|
|
|
4
4
|
export declare function mapToUserFriendlyName(internalType: string): string;
|
|
5
5
|
export declare function transform(fileParseResults: FileParseResult[], translationContext: TranslationContext, hsProfileContents?: HsProfileFile): Transformation[];
|
|
6
6
|
export declare function getIntermediateRepresentation(transformations: Transformation[], hsProfileContents?: HsProfileFile, skipValidation?: boolean): IntermediateRepresentation;
|
|
7
|
+
export declare function getParsingErrors(transformations: Transformation[]): FileParseResult[];
|
|
7
8
|
export declare function generateServerlessPackageComponent(appFunctionsDirectory: string, translationContext: TranslationContext, componentDeps: Dependencies): {
|
|
8
9
|
uid: string;
|
|
9
10
|
transformation: Transformation;
|
package/src/lib/transform.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.mapToUserFacingType = mapToUserFacingType;
|
|
|
8
8
|
exports.mapToUserFriendlyName = mapToUserFriendlyName;
|
|
9
9
|
exports.transform = transform;
|
|
10
10
|
exports.getIntermediateRepresentation = getIntermediateRepresentation;
|
|
11
|
+
exports.getParsingErrors = getParsingErrors;
|
|
11
12
|
exports.generateServerlessPackageComponent = generateServerlessPackageComponent;
|
|
12
13
|
const path_1 = __importDefault(require("path"));
|
|
13
14
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -154,6 +155,11 @@ function getIntermediateRepresentation(transformations, hsProfileContents, skipV
|
|
|
154
155
|
profileData,
|
|
155
156
|
};
|
|
156
157
|
}
|
|
158
|
+
function getParsingErrors(transformations) {
|
|
159
|
+
return transformations
|
|
160
|
+
.filter(t => t.fileParseResult.errors.length > 0)
|
|
161
|
+
.map(t => t.fileParseResult);
|
|
162
|
+
}
|
|
157
163
|
function getProfileData(hsProfileContents) {
|
|
158
164
|
const profileVariablesForBE = {};
|
|
159
165
|
if (hsProfileContents && hsProfileContents.variables) {
|
package/src/lib/types.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface IntermediateRepresentationNodeLocalDev extends IntermediateRepr
|
|
|
47
47
|
componentRoot: string;
|
|
48
48
|
componentConfigPath: string;
|
|
49
49
|
configUpdatedSinceLastUpload: boolean;
|
|
50
|
+
removed: boolean;
|
|
51
|
+
parsingErrors: string[];
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
export interface IntermediateRepresentationLocalDev {
|
|
@@ -72,7 +74,7 @@ export interface TranslationOptions {
|
|
|
72
74
|
skipValidation?: boolean;
|
|
73
75
|
profile?: string;
|
|
74
76
|
}
|
|
75
|
-
export interface TranslationOptionsLocalDev extends TranslationOptions {
|
|
77
|
+
export interface TranslationOptionsLocalDev extends Omit<TranslationOptions, 'skipValidation'> {
|
|
76
78
|
projectNodesAtLastUpload?: {
|
|
77
79
|
[key: string]: IntermediateRepresentationNodeLocalDev;
|
|
78
80
|
};
|