@hubspot/project-parsing-lib 0.10.3 → 0.11.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.
Files changed (50) hide show
  1. package/package.json +48 -11
  2. package/src/exports/constants.d.ts +1 -0
  3. package/src/exports/constants.js +1 -0
  4. package/src/exports/migrate.d.ts +1 -0
  5. package/src/exports/migrate.js +1 -0
  6. package/src/exports/profiles.d.ts +3 -0
  7. package/src/exports/profiles.js +2 -0
  8. package/src/exports/projects.d.ts +3 -0
  9. package/src/exports/projects.js +2 -0
  10. package/src/exports/schema.d.ts +2 -0
  11. package/src/exports/schema.js +1 -0
  12. package/src/exports/themes.d.ts +2 -0
  13. package/src/exports/themes.js +1 -0
  14. package/src/exports/transform.d.ts +2 -0
  15. package/src/exports/transform.js +1 -0
  16. package/src/exports/translate.d.ts +3 -0
  17. package/src/exports/translate.js +2 -0
  18. package/src/exports/uid.d.ts +1 -0
  19. package/src/exports/uid.js +1 -0
  20. package/src/lang/copy.d.ts +1 -1
  21. package/src/lang/copy.js +21 -31
  22. package/src/lib/constants.d.ts +38 -38
  23. package/src/lib/constants.js +120 -153
  24. package/src/lib/errors.d.ts +2 -2
  25. package/src/lib/errors.js +19 -29
  26. package/src/lib/files.d.ts +1 -1
  27. package/src/lib/files.js +36 -47
  28. package/src/lib/localDev.d.ts +1 -1
  29. package/src/lib/localDev.js +8 -16
  30. package/src/lib/migrate.js +34 -40
  31. package/src/lib/migrateThemes.d.ts +3 -4
  32. package/src/lib/migrateThemes.js +31 -38
  33. package/src/lib/profiles.d.ts +1 -1
  34. package/src/lib/profiles.js +12 -20
  35. package/src/lib/project.js +11 -17
  36. package/src/lib/schemas.d.ts +2 -2
  37. package/src/lib/schemas.js +8 -11
  38. package/src/lib/transform.d.ts +1 -1
  39. package/src/lib/transform.js +50 -64
  40. package/src/lib/translate.d.ts +3 -0
  41. package/src/lib/translate.js +52 -0
  42. package/src/lib/types.d.ts +1 -1
  43. package/src/lib/types.js +1 -2
  44. package/src/lib/uid.js +9 -14
  45. package/src/lib/utils.d.ts +1 -1
  46. package/src/lib/utils.js +7 -14
  47. package/src/lib/validation.d.ts +3 -3
  48. package/src/lib/validation.js +46 -46
  49. package/src/index.d.ts +0 -19
  50. package/src/index.js +0 -94
@@ -1,23 +1,15 @@
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) {
1
+ import path from 'path';
2
+ import { isDeepEqual } from '@hubspot/local-dev-lib/isDeepEqual';
3
+ export function getLocalDevProjectNodes(intermediateNodesIndexedByUid, projectSourceDir, projectNodesAtLastUpload) {
12
4
  const localDevProjectNodes = {};
13
5
  Object.entries(intermediateNodesIndexedByUid).forEach(([uid, node]) => {
14
6
  const component = intermediateNodesIndexedByUid[uid];
15
- const componentConfigPath = path_1.default.join(projectSourceDir, component.metaFilePath);
7
+ const componentConfigPath = path.join(projectSourceDir, component.metaFilePath);
16
8
  let configUpdatedSinceLastUpload = false;
17
9
  if (projectNodesAtLastUpload) {
18
10
  const componentAtLastUpload = projectNodesAtLastUpload[uid];
19
11
  if (componentAtLastUpload) {
20
- configUpdatedSinceLastUpload = !(0, isDeepEqual_1.isDeepEqual)(component.config, componentAtLastUpload.config);
12
+ configUpdatedSinceLastUpload = !isDeepEqual(component.config, componentAtLastUpload.config);
21
13
  }
22
14
  else {
23
15
  // Component is net new
@@ -27,7 +19,7 @@ function getLocalDevProjectNodes(intermediateNodesIndexedByUid, projectSourceDir
27
19
  localDevProjectNodes[uid] = {
28
20
  ...node,
29
21
  localDev: {
30
- componentRoot: path_1.default.dirname(componentConfigPath),
22
+ componentRoot: path.dirname(componentConfigPath),
31
23
  componentConfigPath,
32
24
  configUpdatedSinceLastUpload,
33
25
  removed: false,
@@ -37,7 +29,7 @@ function getLocalDevProjectNodes(intermediateNodesIndexedByUid, projectSourceDir
37
29
  });
38
30
  return localDevProjectNodes;
39
31
  }
40
- function getRemovedNodesAndNodesWithErrors(intermediateNodesIndexedByUid, projectNodesAtLastUpload, parsingErrors) {
32
+ export function getRemovedNodesAndNodesWithErrors(intermediateNodesIndexedByUid, projectNodesAtLastUpload, parsingErrors) {
41
33
  const nodesWithErrors = {};
42
34
  Object.entries(projectNodesAtLastUpload).forEach(([uid, node]) => {
43
35
  // Node is still in the project
@@ -68,7 +60,7 @@ function getRemovedNodesAndNodesWithErrors(intermediateNodesIndexedByUid, projec
68
60
  });
69
61
  return nodesWithErrors;
70
62
  }
71
- function getLocalDevProfileData(profileVariables) {
63
+ export function getLocalDevProfileData(profileVariables) {
72
64
  if (!profileVariables) {
73
65
  return {};
74
66
  }
@@ -1,36 +1,30 @@
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.migrate = migrate;
7
- const fs_1 = require("@hubspot/local-dev-lib/fs");
8
- const path_1 = __importDefault(require("path"));
9
- const fs_2 = __importDefault(require("fs"));
10
- const transform_1 = require("./transform");
11
- const constants_1 = require("./constants");
12
- const index_1 = require("../index");
13
- const utils_1 = require("./utils");
1
+ import { walk } from '@hubspot/local-dev-lib/fs';
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+ import { mapToUserFacingType } from './transform.js';
5
+ import { METAFILE_EXTENSION, Components, HS_PROJECT_JSON_FILENAME, } from './constants.js';
6
+ import { translate } from './translate.js';
7
+ import { loadJsonFile } from './utils.js';
14
8
  const IR_FILENAME = 'ir.json';
15
9
  const filesDirectory = 'files';
16
10
  const OUTPUT_IR_FILE = 'FULL_IR.json';
17
- async function migrate(inputDir, outputDir) {
18
- if (!fs_2.default.existsSync(inputDir)) {
11
+ export async function migrate(inputDir, outputDir) {
12
+ if (!fs.existsSync(inputDir)) {
19
13
  throw new Error(`Input directory ${inputDir} does not exist`);
20
14
  }
21
- const hsProjectJsonPath = path_1.default.join(inputDir, constants_1.hsProjectJsonFilename);
22
- if (!fs_2.default.existsSync(hsProjectJsonPath)) {
23
- throw new Error(`${constants_1.hsProjectJsonFilename} file does not exist in ${inputDir}`);
15
+ const hsProjectJsonPath = path.join(inputDir, HS_PROJECT_JSON_FILENAME);
16
+ if (!fs.existsSync(hsProjectJsonPath)) {
17
+ throw new Error(`${HS_PROJECT_JSON_FILENAME} file does not exist in ${inputDir}`);
24
18
  }
25
19
  let hsProjectJson;
26
20
  try {
27
- hsProjectJson = (0, utils_1.loadJsonFile)(hsProjectJsonPath);
21
+ hsProjectJson = loadJsonFile(hsProjectJsonPath);
28
22
  }
29
23
  catch (e) {
30
- throw new Error(`Error parsing ${constants_1.hsProjectJsonFilename}: ${e}`);
24
+ throw new Error(`Error parsing ${HS_PROJECT_JSON_FILENAME}: ${e}`);
31
25
  }
32
- const files = await (0, fs_1.walk)(inputDir);
33
- const sourceCodeOutputDir = path_1.default.join(outputDir, 'src');
26
+ const files = await walk(inputDir);
27
+ const sourceCodeOutputDir = path.join(outputDir, 'src');
34
28
  // Create the output directory if it doesn't exist
35
29
  ensureDirExists(sourceCodeOutputDir);
36
30
  files.forEach((filename) => {
@@ -38,38 +32,38 @@ async function migrate(inputDir, outputDir) {
38
32
  if (!isIRFile(filename)) {
39
33
  return;
40
34
  }
41
- const irDirName = path_1.default.dirname(filename);
42
- const IR = (0, utils_1.loadJsonFile)(filename);
35
+ const irDirName = path.dirname(filename);
36
+ const IR = loadJsonFile(filename);
43
37
  const { metaFilePath } = IR;
44
38
  const projectConfig = convertIRToProjectConfig(IR);
45
- const fullOutputPath = path_1.default.join(sourceCodeOutputDir, getTargetDirectoryFromComponentType(projectConfig.type));
39
+ const fullOutputPath = path.join(sourceCodeOutputDir, getTargetDirectoryFromComponentType(projectConfig.type));
46
40
  // Ensure the output directory exists
47
- const currentFilesDirectory = path_1.default.join(irDirName, filesDirectory);
41
+ const currentFilesDirectory = path.join(irDirName, filesDirectory);
48
42
  ensureDirExists(currentFilesDirectory);
49
- fs_2.default.cpSync(currentFilesDirectory, fullOutputPath, {
43
+ fs.cpSync(currentFilesDirectory, fullOutputPath, {
50
44
  recursive: true,
51
45
  });
52
46
  // Use the metaFilePath if provided, otherwise use the project UID
53
- const hsmetaFilePath = path_1.default.join(fullOutputPath, metaFilePath
54
- ? path_1.default.basename(metaFilePath)
55
- : `${projectConfig.uid}${constants_1.metafileExtension}`);
47
+ const hsmetaFilePath = path.join(fullOutputPath, metaFilePath
48
+ ? path.basename(metaFilePath)
49
+ : `${projectConfig.uid}${METAFILE_EXTENSION}`);
56
50
  // Write the hsmeta file to the output directory
57
- fs_2.default.writeFileSync(hsmetaFilePath, JSON.stringify(projectConfig, null, 2));
51
+ fs.writeFileSync(hsmetaFilePath, JSON.stringify(projectConfig, null, 2));
58
52
  });
59
- const IR = await (0, index_1.translate)({
53
+ const IR = await translate({
60
54
  projectSourceDir: sourceCodeOutputDir,
61
55
  platformVersion: hsProjectJson.platformVersion,
62
56
  }, { skipValidation: true });
63
57
  // Write the IR file to the output directory
64
- fs_2.default.writeFileSync(path_1.default.join(outputDir, OUTPUT_IR_FILE), JSON.stringify(IR, null, 2));
58
+ fs.writeFileSync(path.join(outputDir, OUTPUT_IR_FILE), JSON.stringify(IR, null, 2));
65
59
  }
66
60
  function ensureDirExists(dir) {
67
- if (!fs_2.default.existsSync(dir)) {
68
- fs_2.default.mkdirSync(dir, { recursive: true });
61
+ if (!fs.existsSync(dir)) {
62
+ fs.mkdirSync(dir, { recursive: true });
69
63
  }
70
64
  }
71
65
  function isIRFile(filename) {
72
- const { base } = path_1.default.parse(filename);
66
+ const { base } = path.parse(filename);
73
67
  return base.toLowerCase() === IR_FILENAME;
74
68
  }
75
69
  function convertIRToProjectConfig(IR) {
@@ -77,19 +71,19 @@ function convertIRToProjectConfig(IR) {
77
71
  return {
78
72
  config,
79
73
  uid,
80
- type: (0, transform_1.mapToUserFacingType)(componentType),
74
+ type: mapToUserFacingType(componentType),
81
75
  // We are assuming no dependencies for now since this will be a freshly migrated
82
76
  // project and the current supported components don't have non-hierarchical dependencies
83
77
  dependencies: undefined,
84
78
  };
85
79
  }
86
80
  function getTargetDirectoryFromComponentType(componentType) {
87
- const component = constants_1.Components[componentType];
81
+ const component = Components[componentType];
88
82
  if (!component) {
89
83
  throw Error('Unsupported component type');
90
84
  }
91
85
  const parentDirectory = component.parentComponent
92
- ? constants_1.Components[component.parentComponent].dir
86
+ ? Components[component.parentComponent].dir
93
87
  : '';
94
- return path_1.default.join(parentDirectory, component.dir);
88
+ return path.join(parentDirectory, component.dir);
95
89
  }
@@ -1,18 +1,18 @@
1
- type ThemeDetails = {
1
+ export type ThemeDetails = {
2
2
  configFilepath: string;
3
3
  themePath: string;
4
4
  themeConfig: {
5
5
  secret_names?: string[];
6
6
  };
7
7
  };
8
- type ReactThemeDetails = {
8
+ export type ReactThemeDetails = {
9
9
  configFilepath: string;
10
10
  themePath: string;
11
11
  themeConfig: {
12
12
  secretNames?: string[];
13
13
  };
14
14
  };
15
- type ProjectThemeDetails = {
15
+ export type ProjectThemeDetails = {
16
16
  legacyThemeDetails: ThemeDetails[];
17
17
  legacyReactThemeDetails: ReactThemeDetails[];
18
18
  };
@@ -23,4 +23,3 @@ export declare function migrateThemes(projectDir: string, projectSourceDir: stri
23
23
  migrated: boolean;
24
24
  failureReason?: string;
25
25
  }>;
26
- export {};
@@ -1,33 +1,26 @@
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.getProjectThemeDetails = getProjectThemeDetails;
7
- exports.migrateThemes = migrateThemes;
8
- const fs_1 = __importDefault(require("fs"));
9
- const os_1 = __importDefault(require("os"));
10
- const path_1 = __importDefault(require("path"));
11
- const util_1 = require("util");
12
- const fs_2 = require("@hubspot/local-dev-lib/fs");
13
- const constants_1 = require("./constants");
14
- const utils_1 = require("./utils");
15
- const copy_1 = require("../lang/copy");
16
- const mkdtempAsync = (0, util_1.promisify)(fs_1.default.mkdtemp);
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import { promisify } from 'util';
5
+ import { walk } from '@hubspot/local-dev-lib/fs';
6
+ import { THEME_KEY, CMS_ASSETS_KEY, METAFILE_EXTENSION } from './constants.js';
7
+ import { loadJsonFile } from './utils.js';
8
+ import { errorMessages } from '../lang/copy.js';
9
+ const mkdtempAsync = promisify(fs.mkdtemp);
17
10
  const LEGACY_THEME_CONFIG = 'theme.json';
18
11
  const LEGACY_REACT_THEME_CONFIG = 'cms-assets.json';
19
- async function getProjectThemeDetails(projectSourceDir) {
20
- const files = await (0, fs_2.walk)(projectSourceDir, ['node_modules']);
12
+ export async function getProjectThemeDetails(projectSourceDir) {
13
+ const files = await walk(projectSourceDir, ['node_modules']);
21
14
  const legacyThemeDetails = [];
22
15
  const legacyReactThemeDetails = [];
23
16
  files.forEach((filename) => {
24
17
  const isLegacyThemeConfig = filename.endsWith(LEGACY_THEME_CONFIG);
25
18
  const isLegacyReactThemeConfig = filename.endsWith(LEGACY_REACT_THEME_CONFIG);
26
19
  if (isLegacyThemeConfig || isLegacyReactThemeConfig) {
27
- const parsedConfig = (0, utils_1.loadJsonFile)(filename);
20
+ const parsedConfig = loadJsonFile(filename);
28
21
  const themeDetails = {
29
22
  configFilepath: filename,
30
- themePath: path_1.default.dirname(filename),
23
+ themePath: path.dirname(filename),
31
24
  themeConfig: parsedConfig,
32
25
  };
33
26
  if (isLegacyThemeConfig) {
@@ -44,10 +37,10 @@ async function getProjectThemeDetails(projectSourceDir) {
44
37
  };
45
38
  }
46
39
  function buildNewTheme(componentKey, migratedProjectTempDir, themeDetails) {
47
- const themeName = path_1.default.basename(themeDetails.themePath);
48
- const componentDir = path_1.default.join(migratedProjectTempDir, componentKey);
49
- const newThemeDir = path_1.default.join(componentDir, themeName);
50
- fs_1.default.cpSync(themeDetails.themePath, newThemeDir, {
40
+ const themeName = path.basename(themeDetails.themePath);
41
+ const componentDir = path.join(migratedProjectTempDir, componentKey);
42
+ const newThemeDir = path.join(componentDir, themeName);
43
+ fs.cpSync(themeDetails.themePath, newThemeDir, {
51
44
  recursive: true,
52
45
  });
53
46
  const newThemeConfig = {
@@ -75,20 +68,20 @@ function buildNewTheme(componentKey, migratedProjectTempDir, themeDetails) {
75
68
  }
76
69
  }
77
70
  if (updatedLegacyThemeConfig) {
78
- const newLegacyConfigFilepath = path_1.default.join(newThemeDir, path_1.default.basename(themeDetails.configFilepath));
79
- fs_1.default.writeFileSync(newLegacyConfigFilepath, JSON.stringify(updatedLegacyThemeConfig, null, 2));
71
+ const newLegacyConfigFilepath = path.join(newThemeDir, path.basename(themeDetails.configFilepath));
72
+ fs.writeFileSync(newLegacyConfigFilepath, JSON.stringify(updatedLegacyThemeConfig, null, 2));
80
73
  }
81
- fs_1.default.writeFileSync(path_1.default.join(componentDir, `${themeName}${constants_1.metafileExtension}`), JSON.stringify(newThemeConfig, null, 2));
74
+ fs.writeFileSync(path.join(componentDir, `${themeName}${METAFILE_EXTENSION}`), JSON.stringify(newThemeConfig, null, 2));
82
75
  }
83
- async function migrateThemes(projectDir, projectSourceDir) {
84
- const { legacyThemeDetails, legacyReactThemeDetails, } = await getProjectThemeDetails(projectSourceDir);
76
+ export async function migrateThemes(projectDir, projectSourceDir) {
77
+ const { legacyThemeDetails, legacyReactThemeDetails } = await getProjectThemeDetails(projectSourceDir);
85
78
  // Migrate the project to a temporary directory to avoid file conflicts in the original project
86
- const migratedProjectTempDir = await mkdtempAsync(path_1.default.join(os_1.default.tmpdir(), 'hubspot-migrated-project-'));
79
+ const migratedProjectTempDir = await mkdtempAsync(path.join(os.tmpdir(), 'hubspot-migrated-project-'));
87
80
  let isRootReactThemeProject = false;
88
81
  legacyReactThemeDetails.forEach(themeDetails => {
89
82
  isRootReactThemeProject = themeDetails.themePath === projectSourceDir;
90
83
  if (!isRootReactThemeProject) {
91
- buildNewTheme(constants_1.CmsAssetsKey, migratedProjectTempDir, themeDetails);
84
+ buildNewTheme(CMS_ASSETS_KEY, migratedProjectTempDir, themeDetails);
92
85
  }
93
86
  });
94
87
  // Do not support migrating themes that live at the root of the project src directory
@@ -97,14 +90,14 @@ async function migrateThemes(projectDir, projectSourceDir) {
97
90
  legacyThemeDetails,
98
91
  legacyReactThemeDetails,
99
92
  migrated: false,
100
- failureReason: copy_1.errorMessages.migrateThemes.rootReactThemeNotSupported,
93
+ failureReason: errorMessages.migrateThemes.rootReactThemeNotSupported,
101
94
  };
102
95
  }
103
96
  legacyThemeDetails.forEach(themeDetails => {
104
- buildNewTheme(constants_1.ThemeKey, migratedProjectTempDir, themeDetails);
97
+ buildNewTheme(THEME_KEY, migratedProjectTempDir, themeDetails);
105
98
  });
106
99
  // Copy the rest of the project files to the temp directory
107
- fs_1.default.cpSync(projectSourceDir, migratedProjectTempDir, {
100
+ fs.cpSync(projectSourceDir, migratedProjectTempDir, {
108
101
  recursive: true,
109
102
  filter: src => {
110
103
  return (!legacyThemeDetails.some(file => src.includes(file.themePath)) &&
@@ -112,13 +105,13 @@ async function migrateThemes(projectDir, projectSourceDir) {
112
105
  },
113
106
  });
114
107
  // Archive the legacy theme files
115
- const archiveDest = path_1.default.join(projectDir, 'archive');
116
- fs_1.default.renameSync(projectSourceDir, archiveDest);
108
+ const archiveDest = path.join(projectDir, 'archive');
109
+ fs.renameSync(projectSourceDir, archiveDest);
117
110
  // Copy the new theme config files to the project source directory
118
- fs_1.default.cpSync(migratedProjectTempDir, projectSourceDir, {
111
+ fs.cpSync(migratedProjectTempDir, projectSourceDir, {
119
112
  recursive: true,
120
113
  });
121
- fs_1.default.rmSync(migratedProjectTempDir, { recursive: true });
114
+ fs.rmSync(migratedProjectTempDir, { recursive: true });
122
115
  return {
123
116
  legacyThemeDetails,
124
117
  legacyReactThemeDetails,
@@ -1,4 +1,4 @@
1
- import { FileParseResult, HsProfileFile, HSProfileVariables } from './types';
1
+ import { FileParseResult, HsProfileFile, HSProfileVariables } from './types.js';
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;
@@ -1,32 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIsProfileFile = getIsProfileFile;
4
- exports.getHsProfileFilename = getHsProfileFilename;
5
- exports.getHsProfileName = getHsProfileName;
6
- exports.getHsProfileVariables = getHsProfileVariables;
7
- exports.validateProfileVariables = validateProfileVariables;
8
- exports.applyHsProfileVariables = applyHsProfileVariables;
9
- const constants_1 = require("./constants");
10
- const copy_1 = require("../lang/copy");
11
- const profileFilenameRegex = new RegExp(`^${constants_1.profileFilePrefix}\\.([^.]+)\\.json$`);
1
+ import { PROFILE_FILE_PREFIX } from './constants.js';
2
+ import { errorMessages } from '../lang/copy.js';
3
+ const profileFilenameRegex = new RegExp(`^${PROFILE_FILE_PREFIX}\\.([^.]+)\\.json$`);
12
4
  const profileInsertRegex = /\${(.*?)}/g;
13
- function getIsProfileFile(filename) {
5
+ export function getIsProfileFile(filename) {
14
6
  return profileFilenameRegex.test(filename);
15
7
  }
16
- function getHsProfileFilename(profileName) {
17
- return `${constants_1.profileFilePrefix}.${profileName}.json`;
8
+ export function getHsProfileFilename(profileName) {
9
+ return `${PROFILE_FILE_PREFIX}.${profileName}.json`;
18
10
  }
19
- function getHsProfileName(profileFilename) {
11
+ export function getHsProfileName(profileFilename) {
20
12
  const match = profileFilename.match(profileFilenameRegex);
21
13
  return match ? match[1] : '';
22
14
  }
23
- function getHsProfileVariables(hsProfileContents) {
15
+ export function getHsProfileVariables(hsProfileContents) {
24
16
  const profileVariablesAreValid = hsProfileContents?.variables &&
25
17
  typeof hsProfileContents.variables === 'object' &&
26
18
  !Array.isArray(hsProfileContents.variables);
27
19
  return profileVariablesAreValid ? hsProfileContents.variables : {};
28
20
  }
29
- function validateProfileVariables(profileVariables, filename) {
21
+ export function validateProfileVariables(profileVariables, filename) {
30
22
  const errors = [];
31
23
  Object.entries(profileVariables).forEach(([key, value]) => {
32
24
  try {
@@ -48,10 +40,10 @@ function validateProfileVariables(profileVariables, filename) {
48
40
  }
49
41
  function validateProfileVariable(profileVariableType, key, file) {
50
42
  if (profileVariableType === 'undefined') {
51
- throw new Error(copy_1.errorMessages.profile.missingValue(key, file));
43
+ throw new Error(errorMessages.profile.missingValue(key, file));
52
44
  }
53
45
  if (!['string', 'number', 'boolean'].includes(profileVariableType)) {
54
- throw new Error(copy_1.errorMessages.profile.invalidValue(key));
46
+ throw new Error(errorMessages.profile.invalidValue(key));
55
47
  }
56
48
  }
57
49
  function interpolate(file, template, profileVariables) {
@@ -61,7 +53,7 @@ function interpolate(file, template, profileVariables) {
61
53
  return String(profileVariables[key]);
62
54
  });
63
55
  }
64
- function applyHsProfileVariables(fileParseResults, hsProfileContents) {
56
+ export function applyHsProfileVariables(fileParseResults, hsProfileContents) {
65
57
  const profileVariables = getHsProfileVariables(hsProfileContents);
66
58
  return fileParseResults.map(fileParseResult => {
67
59
  const { content, file } = fileParseResult;
@@ -1,25 +1,19 @@
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.getProjectMetadata = getProjectMetadata;
7
- const constants_1 = require("./constants");
8
- const files_1 = require("./files");
9
- const path_1 = __importDefault(require("path"));
10
- const fs_1 = __importDefault(require("fs"));
11
- async function getProjectMetadata(projectSrcDir) {
1
+ import { Components } from './constants.js';
2
+ import { locateHsMetaFiles } from './files.js';
3
+ import path from 'path';
4
+ import fs from 'fs';
5
+ export async function getProjectMetadata(projectSrcDir) {
12
6
  const hsMetaFiles = [];
13
7
  const components = {};
14
8
  let metafiles = [];
15
- if (fs_1.default.existsSync(projectSrcDir)) {
16
- metafiles = await (0, files_1.locateHsMetaFiles)(projectSrcDir, { silent: true });
9
+ if (fs.existsSync(projectSrcDir)) {
10
+ metafiles = await locateHsMetaFiles(projectSrcDir, { silent: true });
17
11
  }
18
- Object.keys(constants_1.Components).forEach(componentType => {
19
- const { parentComponent, singularComponent, dir } = constants_1.Components[componentType];
20
- const componentPath = path_1.default.join(projectSrcDir, parentComponent ? path_1.default.join(parentComponent, dir) : dir);
12
+ Object.keys(Components).forEach(componentType => {
13
+ const { parentComponent, singularComponent, dir } = Components[componentType];
14
+ const componentPath = path.join(projectSrcDir, parentComponent ? path.join(parentComponent, dir) : dir);
21
15
  const metaFilesByType = metafiles
22
- .filter(metafile => path_1.default.parse(metafile.file).dir === componentPath)
16
+ .filter(metafile => path.parse(metafile.file).dir === componentPath)
23
17
  .map(metaFile => metaFile.file);
24
18
  hsMetaFiles.push(...metaFilesByType);
25
19
  components[componentType] = {
@@ -1,3 +1,3 @@
1
- import { AnySchema } from 'ajv/dist/2020';
2
- import { TranslationContext } from './types';
1
+ import type { AnySchema } from 'ajv';
2
+ import { TranslationContext } from './types.js';
3
3
  export declare function getIntermediateRepresentationSchema(translationContext: TranslationContext): Promise<Record<string, AnySchema>>;
@@ -1,24 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIntermediateRepresentationSchema = getIntermediateRepresentationSchema;
4
- const http_1 = require("@hubspot/local-dev-lib/http");
5
- const index_1 = require("@hubspot/local-dev-lib/errors/index");
6
- const copy_1 = require("../lang/copy");
7
- async function getIntermediateRepresentationSchema(translationContext) {
1
+ import { http } from '@hubspot/local-dev-lib/http';
2
+ import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
3
+ import { errorMessages } from '../lang/copy.js';
4
+ export async function getIntermediateRepresentationSchema(translationContext) {
8
5
  if (!translationContext.accountId) {
9
- throw new Error(copy_1.errorMessages.api.accountIdIsRequiredToFetchSchemas);
6
+ throw new Error(errorMessages.api.accountIdIsRequiredToFetchSchemas);
10
7
  }
11
8
  try {
12
9
  const { accountId, platformVersion } = translationContext;
13
- const { data } = await http_1.http.get(accountId, {
10
+ const { data } = await http.get(accountId, {
14
11
  url: `project-components-external/project-schemas/v3/${platformVersion}`,
15
12
  });
16
13
  return data;
17
14
  }
18
15
  catch (e) {
19
- if ((0, index_1.isHubSpotHttpError)(e)) {
16
+ if (isHubSpotHttpError(e)) {
20
17
  throw e;
21
18
  }
22
- throw new Error(copy_1.errorMessages.api.failedToFetchSchemas, { cause: e });
19
+ throw new Error(errorMessages.api.failedToFetchSchemas, { cause: e });
23
20
  }
24
21
  }
@@ -1,4 +1,4 @@
1
- import { Dependencies, FileParseResult, HsProfileFile, IntermediateRepresentation, Transformation, TranslationContext } from './types';
1
+ import { Dependencies, FileParseResult, HsProfileFile, IntermediateRepresentation, Transformation, TranslationContext } from './types.js';
2
2
  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;