@hubspot/project-parsing-lib 0.5.3 → 0.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/project-parsing-lib",
3
- "version": "0.5.3",
3
+ "version": "0.6.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
@@ -26,7 +26,7 @@ async function translate(translationContext, translationOptions = defaultOptions
26
26
  hsProfileContents = (0, files_1.loadHsProfileFile)(translationContext.projectSourceDir, translationOptions.profile);
27
27
  }
28
28
  const transformation = (0, transform_1.transform)(metafileContents, translationContext, hsProfileContents);
29
- const intermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation, skipValidation);
29
+ const intermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation, hsProfileContents, skipValidation);
30
30
  // Remove once extensions and serverless functions are supported
31
31
  if (!skipValidation) {
32
32
  await (0, validation_1.validateIntermediateRepresentation)(intermediateRepresentation, transformation, translationContext);
@@ -1,5 +1,6 @@
1
- import { FileParseResult, HsProfileFile } from './types';
1
+ import { FileParseResult, HsProfileFile, HSProfileVariables } from './types';
2
2
  export declare function getIsProfileFile(filename: string): boolean;
3
3
  export declare function getHsProfileFilename(profileName: string): string;
4
4
  export declare function getHsProfileName(profileFilename: string): string;
5
+ export declare function getHsProfileVariables(hsProfileContents: HsProfileFile): HSProfileVariables;
5
6
  export declare function applyHsProfileVariables(fileParseResults: FileParseResult[], hsProfileContents: HsProfileFile): FileParseResult[];
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIsProfileFile = getIsProfileFile;
4
4
  exports.getHsProfileFilename = getHsProfileFilename;
5
5
  exports.getHsProfileName = getHsProfileName;
6
+ exports.getHsProfileVariables = getHsProfileVariables;
6
7
  exports.applyHsProfileVariables = applyHsProfileVariables;
7
8
  const constants_1 = require("./constants");
8
9
  const copy_1 = require("../lang/copy");
@@ -18,6 +19,12 @@ function getHsProfileName(profileFilename) {
18
19
  const match = profileFilename.match(profileFilenameRegex);
19
20
  return match ? match[1] : '';
20
21
  }
22
+ function getHsProfileVariables(hsProfileContents) {
23
+ const profileVariablesAreValid = hsProfileContents?.variables &&
24
+ typeof hsProfileContents.variables === 'object' &&
25
+ !Array.isArray(hsProfileContents.variables);
26
+ return profileVariablesAreValid ? hsProfileContents.variables : {};
27
+ }
21
28
  function interpolate(file, template, profileVariables) {
22
29
  return template.replace(profileInsertRegex, (__match, key) => {
23
30
  const profileVariableType = typeof profileVariables[key];
@@ -31,11 +38,7 @@ function interpolate(file, template, profileVariables) {
31
38
  });
32
39
  }
33
40
  function applyHsProfileVariables(fileParseResults, hsProfileContents) {
34
- const profileVariables = hsProfileContents?.variables &&
35
- typeof hsProfileContents.variables === 'object' &&
36
- !Array.isArray(hsProfileContents.variables)
37
- ? hsProfileContents.variables
38
- : {};
41
+ const profileVariables = getHsProfileVariables(hsProfileContents);
39
42
  return fileParseResults.map(fileParseResult => {
40
43
  const { content, file } = fileParseResult;
41
44
  if (content && content.config) {
@@ -3,7 +3,7 @@ export declare function mapToInternalType(type: string): string;
3
3
  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
- export declare function getIntermediateRepresentation(transformations: Transformation[], skipValidation: boolean | undefined): IntermediateRepresentation;
6
+ export declare function getIntermediateRepresentation(transformations: Transformation[], hsProfileContents?: HsProfileFile, skipValidation?: boolean): IntermediateRepresentation;
7
7
  export declare function generateServerlessPackageComponent(appFunctionsDirectory: string, translationContext: TranslationContext, componentDeps: Dependencies): {
8
8
  uid: string;
9
9
  transformation: Transformation;
@@ -111,7 +111,7 @@ function transform(fileParseResults, translationContext, hsProfileContents) {
111
111
  });
112
112
  return [...autoGeneratedComponents, ...transformations];
113
113
  }
114
- function getIntermediateRepresentation(transformations, skipValidation) {
114
+ function getIntermediateRepresentation(transformations, hsProfileContents, skipValidation) {
115
115
  const nodes = transformations.reduce((acc, current) => {
116
116
  if (!current.intermediateRepresentation) {
117
117
  return acc;
@@ -137,10 +137,50 @@ function getIntermediateRepresentation(transformations, skipValidation) {
137
137
  [uid]: current.intermediateRepresentation,
138
138
  };
139
139
  }, {});
140
+ const profileData = getProfileData(hsProfileContents);
140
141
  return {
141
142
  intermediateNodesIndexedByUid: nodes,
143
+ profileData,
142
144
  };
143
145
  }
146
+ function getProfileData(hsProfileContents) {
147
+ const profileVariablesForBE = {};
148
+ if (hsProfileContents && hsProfileContents.variables) {
149
+ const profileVariables = (0, profiles_1.getHsProfileVariables)(hsProfileContents);
150
+ Object.keys(profileVariables).forEach(key => {
151
+ const profileVar = profileVariables[key];
152
+ let variableTypeForBE;
153
+ switch (typeof profileVar) {
154
+ case 'string':
155
+ variableTypeForBE = 'PROFILE_STRING';
156
+ break;
157
+ case 'number':
158
+ variableTypeForBE = 'PROFILE_INT';
159
+ break;
160
+ case 'boolean':
161
+ variableTypeForBE = 'PROFILE_BOOLEAN';
162
+ break;
163
+ default:
164
+ break;
165
+ }
166
+ if (variableTypeForBE) {
167
+ profileVariablesForBE[key] = {
168
+ variableType: variableTypeForBE,
169
+ value: profileVar,
170
+ };
171
+ }
172
+ });
173
+ }
174
+ let profileData = {};
175
+ if (Object.keys(profileVariablesForBE).length > 0) {
176
+ profileData = {
177
+ vars: {
178
+ profileVariables: profileVariablesForBE,
179
+ },
180
+ };
181
+ }
182
+ return profileData;
183
+ }
144
184
  function generateServerlessPackageComponent(appFunctionsDirectory, translationContext, componentDeps) {
145
185
  const packageFile = path_1.default.join(appFunctionsDirectory, constants_1.packageJson);
146
186
  const packageLockFile = path_1.default.join(appFunctionsDirectory, constants_1.packageLockJson);
@@ -25,10 +25,22 @@ export interface IntermediateRepresentationNode {
25
25
  config: unknown;
26
26
  files: unknown;
27
27
  }
28
+ export type BEProfileVariableType = 'PROFILE_INT' | 'PROFILE_STRING' | 'PROFILE_BOOLEAN';
29
+ export interface BEProfileVariables {
30
+ [key: string]: {
31
+ variableType: BEProfileVariableType;
32
+ value: HSProfileVariableType;
33
+ };
34
+ }
28
35
  export interface IntermediateRepresentation {
29
36
  intermediateNodesIndexedByUid: {
30
37
  [key: string]: IntermediateRepresentationNode;
31
38
  };
39
+ profileData?: {
40
+ vars?: {
41
+ profileVariables: BEProfileVariables;
42
+ };
43
+ };
32
44
  }
33
45
  export interface IntermediateRepresentationNodeLocalDev extends IntermediateRepresentationNode {
34
46
  localDev: {
@@ -64,9 +76,12 @@ export interface TranslationOptionsLocalDev extends TranslationOptions {
64
76
  [key: string]: IntermediateRepresentationNodeLocalDev;
65
77
  };
66
78
  }
79
+ type HSProfileVariableType = string | number | boolean;
80
+ export type HSProfileVariables = {
81
+ [key: string]: HSProfileVariableType;
82
+ };
67
83
  export interface HsProfileFile {
68
84
  accountId: number;
69
- variables?: {
70
- [key: string]: string | number | boolean;
71
- };
85
+ variables?: HSProfileVariables;
72
86
  }
87
+ export {};