@hubspot/project-parsing-lib 0.0.5 → 0.0.6-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.d.ts +2 -2
- package/src/index.js +10 -4
- package/src/lib/constants.d.ts +2 -0
- package/src/lib/constants.js +11 -1
- package/src/lib/transform.js +27 -15
- package/src/lib/types.d.ts +6 -2
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IntermediateRepresentation, TranslationContext } from './lib/types';
|
|
2
|
-
export declare function translate(translationContext: TranslationContext): Promise<IntermediateRepresentation>;
|
|
1
|
+
import { IntermediateRepresentation, TranslationContext, TranslationOptions } from './lib/types';
|
|
2
|
+
export declare function translate(translationContext: TranslationContext, translationOptions?: TranslationOptions): Promise<IntermediateRepresentation>;
|
|
3
3
|
export { isTranslationError } from './lib/errors';
|
package/src/index.js
CHANGED
|
@@ -7,16 +7,22 @@ const validation_1 = require("./lib/validation");
|
|
|
7
7
|
const transform_1 = require("./lib/transform");
|
|
8
8
|
const errors_1 = require("./lib/errors");
|
|
9
9
|
const copy_1 = require("./lang/copy");
|
|
10
|
-
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
skipValidation: false,
|
|
12
|
+
};
|
|
13
|
+
async function translate(translationContext, translationOptions = defaultOptions) {
|
|
14
|
+
const { skipValidation } = translationOptions;
|
|
11
15
|
const metafileContents = await (0, files_1.loadHsMetaFiles)(translationContext);
|
|
12
16
|
if (metafileContents.length === 0) {
|
|
13
17
|
throw new Error(copy_1.errorMessages.project.noHsMetaFiles);
|
|
14
18
|
}
|
|
15
19
|
const transformation = (0, transform_1.transform)(metafileContents);
|
|
16
20
|
const intermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
if (!skipValidation) {
|
|
22
|
+
const { valid, errors } = await (0, validation_1.validateIntermediateRepresentation)(intermediateRepresentation, transformation, translationContext);
|
|
23
|
+
if (!valid) {
|
|
24
|
+
throw new errors_1.TranslationError(copy_1.errorMessages.project.failedToTranslateProject, errors);
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
return intermediateRepresentation;
|
|
22
28
|
}
|
package/src/lib/constants.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const AppKey = "app";
|
|
2
2
|
export declare const ThemeKey = "theme";
|
|
3
|
+
export declare const AppObjectKey = "app-object";
|
|
4
|
+
export declare const AppObjectAssociationKey = "app-object-association";
|
|
3
5
|
export declare const CallingKey = "calling";
|
|
4
6
|
export declare const CardsKey = "card";
|
|
5
7
|
export declare const FunctionsKey = "function";
|
package/src/lib/constants.js
CHANGED
|
@@ -33,13 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.allowedSubComponentDirectories = exports.allowedComponentDirectories = exports.ProjectStructure = exports.allowedThemeSubComponentsDirs = exports.allowedAppSubComponentsDirs = exports.metafileExtension = exports.externalTypeToInternalType = exports.Components = exports.WorkflowActionsKey = exports.WebhooksKey = exports.VideoConferencingKey = exports.TimelineEventsKey = exports.MediaBridgeKey = exports.MarketingEventsKey = exports.FunctionsKey = exports.CardsKey = exports.CallingKey = exports.ThemeKey = exports.AppKey = void 0;
|
|
36
|
+
exports.allowedSubComponentDirectories = exports.allowedComponentDirectories = exports.ProjectStructure = exports.allowedThemeSubComponentsDirs = exports.allowedAppSubComponentsDirs = exports.metafileExtension = exports.externalTypeToInternalType = exports.Components = exports.WorkflowActionsKey = exports.WebhooksKey = exports.VideoConferencingKey = exports.TimelineEventsKey = exports.MediaBridgeKey = exports.MarketingEventsKey = exports.FunctionsKey = exports.CardsKey = exports.CallingKey = exports.AppObjectAssociationKey = exports.AppObjectKey = exports.ThemeKey = exports.AppKey = void 0;
|
|
37
37
|
// Top Level Component types
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
// Component types
|
|
40
40
|
exports.AppKey = 'app';
|
|
41
41
|
exports.ThemeKey = 'theme';
|
|
42
42
|
// Sub-Component types
|
|
43
|
+
exports.AppObjectKey = 'app-object';
|
|
44
|
+
exports.AppObjectAssociationKey = 'app-object-association';
|
|
43
45
|
exports.CallingKey = 'calling';
|
|
44
46
|
exports.CardsKey = 'card';
|
|
45
47
|
exports.FunctionsKey = 'function';
|
|
@@ -54,6 +56,14 @@ exports.Components = {
|
|
|
54
56
|
dir: exports.AppKey,
|
|
55
57
|
isToplevel: true,
|
|
56
58
|
},
|
|
59
|
+
[exports.AppObjectKey]: {
|
|
60
|
+
dir: 'app-objects',
|
|
61
|
+
parentComponent: exports.AppKey,
|
|
62
|
+
},
|
|
63
|
+
[exports.AppObjectAssociationKey]: {
|
|
64
|
+
dir: 'app-object-associations',
|
|
65
|
+
parentComponent: exports.AppKey,
|
|
66
|
+
},
|
|
57
67
|
[exports.ThemeKey]: {
|
|
58
68
|
dir: exports.ThemeKey,
|
|
59
69
|
isToplevel: true,
|
package/src/lib/transform.js
CHANGED
|
@@ -4,29 +4,41 @@ exports.transform = transform;
|
|
|
4
4
|
exports.getIntermediateRepresentation = getIntermediateRepresentation;
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const copy_1 = require("../lang/copy");
|
|
7
|
-
function calculateComponentDeps(fileValidationResult, parentComponents) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
...
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
function calculateComponentDeps(fileValidationResult, parentComponents, appObjects) {
|
|
8
|
+
let dependencies = {};
|
|
9
|
+
// If there are dependencies in the config file, pass them through
|
|
10
|
+
if (!fileValidationResult.content?.dependencies) {
|
|
11
|
+
dependencies = { ...fileValidationResult.content?.dependencies };
|
|
12
|
+
}
|
|
13
|
+
const { type } = fileValidationResult.content;
|
|
14
|
+
// If the component is a child of the App component, add the app and appObjects as dependencies
|
|
15
|
+
if (constants_1.Components[type]?.parentComponent === constants_1.AppKey) {
|
|
16
|
+
const parentUid = parentComponents[fileValidationResult.parentDirectory];
|
|
17
|
+
if (parentUid) {
|
|
18
|
+
dependencies.app = parentUid;
|
|
19
|
+
}
|
|
20
|
+
if (type !== constants_1.AppObjectKey) {
|
|
21
|
+
dependencies.allAppObjects = appObjects;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return dependencies;
|
|
17
25
|
}
|
|
18
26
|
function mapToInternalType(type) {
|
|
19
27
|
return (constants_1.externalTypeToInternalType[type] || type || '').toUpperCase();
|
|
20
28
|
}
|
|
21
29
|
function transform(fileParseResults) {
|
|
22
30
|
const parentTypes = Object.keys(constants_1.ProjectStructure);
|
|
31
|
+
const parentComponents = {};
|
|
32
|
+
const appObjects = [];
|
|
23
33
|
// Compute the parent components, so we can add them as dependencies to the child components
|
|
24
|
-
|
|
34
|
+
fileParseResults.forEach(file => {
|
|
25
35
|
if (file.content?.type && parentTypes.includes(file.content.type)) {
|
|
26
|
-
|
|
36
|
+
parentComponents[file.content.type] = file.content.uid;
|
|
27
37
|
}
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
if (file.content?.type === constants_1.AppObjectKey) {
|
|
39
|
+
appObjects.push(file.content.uid);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
30
42
|
return fileParseResults.map((currentFile) => {
|
|
31
43
|
if (!currentFile.content) {
|
|
32
44
|
currentFile.errors?.push(`File content is missing for ${currentFile.file}`);
|
|
@@ -38,7 +50,7 @@ function transform(fileParseResults) {
|
|
|
38
50
|
uid,
|
|
39
51
|
config,
|
|
40
52
|
componentType: mapToInternalType(type),
|
|
41
|
-
componentDeps: calculateComponentDeps(currentFile, parentComponents),
|
|
53
|
+
componentDeps: calculateComponentDeps(currentFile, parentComponents, appObjects),
|
|
42
54
|
metaFilePath: currentFile.file,
|
|
43
55
|
files: {},
|
|
44
56
|
},
|
package/src/lib/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export type Dependencies = Record<string, string | string[]>;
|
|
1
2
|
export interface Components {
|
|
2
3
|
uid: string;
|
|
3
4
|
type: string;
|
|
4
5
|
config: unknown;
|
|
5
|
-
dependencies?:
|
|
6
|
+
dependencies?: Dependencies;
|
|
6
7
|
}
|
|
7
8
|
export interface FileActionResult {
|
|
8
9
|
file: string;
|
|
@@ -17,7 +18,7 @@ export interface FileParseResult extends FileActionResult {
|
|
|
17
18
|
}
|
|
18
19
|
export interface IntermediateRepresentationNode {
|
|
19
20
|
componentType: string;
|
|
20
|
-
componentDeps:
|
|
21
|
+
componentDeps: Dependencies;
|
|
21
22
|
metaFilePath: string;
|
|
22
23
|
uid: string;
|
|
23
24
|
config: unknown;
|
|
@@ -41,3 +42,6 @@ export interface TranslationContext {
|
|
|
41
42
|
platformVersion: string;
|
|
42
43
|
accountId: number;
|
|
43
44
|
}
|
|
45
|
+
export interface TranslationOptions {
|
|
46
|
+
skipValidation?: boolean;
|
|
47
|
+
}
|