@hubspot/project-parsing-lib 0.1.6 → 0.1.7

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.1.6",
3
+ "version": "0.1.7",
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",
@@ -2,6 +2,7 @@ import { ComponentMetadata } from '../lib/constants';
2
2
  export declare const errorMessages: {
3
3
  api: {
4
4
  failedToFetchSchemas: string;
5
+ accountIdIsRequiredToFetchSchemas: string;
5
6
  };
6
7
  project: {
7
8
  noHsMetaFiles: string;
package/src/lang/copy.js CHANGED
@@ -4,6 +4,7 @@ exports.logMessages = exports.errorMessages = void 0;
4
4
  exports.errorMessages = {
5
5
  api: {
6
6
  failedToFetchSchemas: 'Failed to fetch schemas',
7
+ accountIdIsRequiredToFetchSchemas: 'Account id is required to fetch schemas',
7
8
  },
8
9
  project: {
9
10
  noHsMetaFiles: 'No *-hsmeta.json files found in the current directory. Please make sure you are inside the correct project directory.',
@@ -16,7 +17,7 @@ exports.errorMessages = {
16
17
  missingRequiredField: (field) => `Missing required field: '${field}'`,
17
18
  missingUid: `Missing required field: 'uid'`,
18
19
  emptyUid: `'uid' must be at least one character long`,
19
- invalidUid: `'uid' should be in lowercase, using only letters, numbers, and underscores. For example: app_id_123`,
20
+ invalidUid: `'uid' should use only letters, numbers, periods, hyphens, and underscores (for example: app-id_1.2.3)`,
20
21
  uidTooLong: `'uid' must be 64 characters or less`,
21
22
  missingType: `Missing required field: 'type'`,
22
23
  missingConfig: `Missing required field: 'config'`,
@@ -9,9 +9,11 @@ const path_1 = __importDefault(require("path"));
9
9
  const fs_2 = __importDefault(require("fs"));
10
10
  const transform_1 = require("./transform");
11
11
  const constants_1 = require("./constants");
12
+ const index_1 = require("../index");
12
13
  const IR_FILENAME = 'ir.json';
13
14
  const filesDirectory = 'files';
14
15
  const hsProjectJsonFilename = 'hsproject.json';
16
+ const OUTPUT_IR_FILE = 'FULL_IR.json';
15
17
  async function migrate(inputDir, outputDir) {
16
18
  if (!fs_2.default.existsSync(inputDir)) {
17
19
  throw new Error(`Input directory ${inputDir} does not exist`);
@@ -20,9 +22,17 @@ async function migrate(inputDir, outputDir) {
20
22
  if (!fs_2.default.existsSync(hsProjectJsonPath)) {
21
23
  throw new Error(`hsproject.json file does not exist in ${inputDir}`);
22
24
  }
25
+ let hsProjectJson;
26
+ try {
27
+ hsProjectJson = loadJsonFile(hsProjectJsonPath);
28
+ }
29
+ catch (e) {
30
+ throw new Error(`Error parsing hsproject.json: ${e}`);
31
+ }
23
32
  const files = await (0, fs_1.walk)(inputDir);
33
+ const sourceCodeOutputDir = path_1.default.join(outputDir, 'src');
24
34
  // Create the output directory if it doesn't exist
25
- ensureDirExists(outputDir);
35
+ ensureDirExists(sourceCodeOutputDir);
26
36
  files.forEach((filename) => {
27
37
  // Skip everything that's not an IR file
28
38
  if (!isIRFile(filename)) {
@@ -32,7 +42,7 @@ async function migrate(inputDir, outputDir) {
32
42
  const IR = loadJsonFile(filename);
33
43
  const { metaFilePath } = IR;
34
44
  const projectConfig = convertIRToProjectConfig(IR);
35
- const fullOutputPath = path_1.default.join(outputDir, getTargetDirectoryFromComponentType(projectConfig.type));
45
+ const fullOutputPath = path_1.default.join(sourceCodeOutputDir, getTargetDirectoryFromComponentType(projectConfig.type));
36
46
  // Ensure the output directory exists
37
47
  const currentFilesDirectory = path_1.default.join(irDirName, filesDirectory);
38
48
  ensureDirExists(currentFilesDirectory);
@@ -46,6 +56,12 @@ async function migrate(inputDir, outputDir) {
46
56
  // Write the hsmeta file to the output directory
47
57
  fs_2.default.writeFileSync(hsmetaFilePath, JSON.stringify(projectConfig, null, 2));
48
58
  });
59
+ const IR = await (0, index_1.translate)({
60
+ projectSourceDir: sourceCodeOutputDir,
61
+ platformVersion: hsProjectJson.platformVersion,
62
+ }, { skipValidation: true });
63
+ // 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));
49
65
  }
50
66
  function ensureDirExists(dir) {
51
67
  if (!fs_2.default.existsSync(dir)) {
@@ -5,6 +5,9 @@ const http_1 = require("@hubspot/local-dev-lib/http");
5
5
  const index_1 = require("@hubspot/local-dev-lib/errors/index");
6
6
  const copy_1 = require("../lang/copy");
7
7
  async function getIntermediateRepresentationSchema(translationContext) {
8
+ if (!translationContext.accountId) {
9
+ throw new Error(copy_1.errorMessages.api.accountIdIsRequiredToFetchSchemas);
10
+ }
8
11
  try {
9
12
  const { accountId, platformVersion } = translationContext;
10
13
  const { data } = await http_1.http.get(accountId, {
@@ -52,7 +52,7 @@ export type CompiledError = {
52
52
  export interface TranslationContext {
53
53
  projectSourceDir: string;
54
54
  platformVersion: string;
55
- accountId: number;
55
+ accountId?: number;
56
56
  }
57
57
  export interface TranslationOptions {
58
58
  skipValidation?: boolean;
package/src/lib/uid.js CHANGED
@@ -9,7 +9,7 @@ function validateUid(uid) {
9
9
  if (uid.length > 64) {
10
10
  return copy_1.errorMessages.validation.uidTooLong;
11
11
  }
12
- if (!/^[a-z0-9_]+$/.test(uid)) {
12
+ if (!/^[a-zA-Z0-9_\-.]+$/.test(uid)) {
13
13
  return copy_1.errorMessages.validation.invalidUid;
14
14
  }
15
15
  }