@hubspot/project-parsing-lib 0.2.0-experimental.1 → 0.2.0-experimental.3
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 +3 -3
- package/src/lib/constants.js +9 -14
- package/src/lib/migrate.js +14 -6
- package/src/lib/project.js +9 -2
- package/src/lib/transform.js +13 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/project-parsing-lib",
|
|
3
|
-
"version": "0.2.0-experimental.
|
|
3
|
+
"version": "0.2.0-experimental.3",
|
|
4
4
|
"description": "Parsing library for converting projects directory structures to their intermediate representation",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@inquirer/prompts": "^7.1.0",
|
|
48
48
|
"@types/node": "^24.9.0",
|
|
49
49
|
"@types/semver": "^7.5.8",
|
|
50
|
-
"@typescript-eslint/eslint-plugin": "
|
|
51
|
-
"@typescript-eslint/parser": "
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "8.46.3",
|
|
51
|
+
"@typescript-eslint/parser": "8.46.3",
|
|
52
52
|
"eslint": "^9.38.0",
|
|
53
53
|
"eslint-plugin-import": "^2.31.0",
|
|
54
54
|
"husky": "^9.1.7",
|
package/src/lib/constants.js
CHANGED
|
@@ -36,6 +36,13 @@ const SUB_COMPONENT_FIELDS = {
|
|
|
36
36
|
userFriendlyType: 'feature',
|
|
37
37
|
userFriendlyTypePlural: 'features',
|
|
38
38
|
};
|
|
39
|
+
const PAGE_COMPONENT = {
|
|
40
|
+
dir: 'pages',
|
|
41
|
+
parentComponent: APP_KEY,
|
|
42
|
+
...SUB_COMPONENT_FIELDS,
|
|
43
|
+
userFriendlyName: 'Page',
|
|
44
|
+
singularComponent: true,
|
|
45
|
+
};
|
|
39
46
|
export const Components = {
|
|
40
47
|
[APP_KEY]: {
|
|
41
48
|
dir: APP_KEY,
|
|
@@ -55,20 +62,8 @@ export const Components = {
|
|
|
55
62
|
...SUB_COMPONENT_FIELDS,
|
|
56
63
|
userFriendlyName: 'App Object Association',
|
|
57
64
|
},
|
|
58
|
-
[PAGE_KEY]:
|
|
59
|
-
|
|
60
|
-
parentComponent: APP_KEY,
|
|
61
|
-
...SUB_COMPONENT_FIELDS,
|
|
62
|
-
userFriendlyName: 'Page',
|
|
63
|
-
singularComponent: true,
|
|
64
|
-
},
|
|
65
|
-
[PAGES_KEY]: {
|
|
66
|
-
dir: 'pages',
|
|
67
|
-
parentComponent: APP_KEY,
|
|
68
|
-
...SUB_COMPONENT_FIELDS,
|
|
69
|
-
userFriendlyName: 'Pages',
|
|
70
|
-
singularComponent: true,
|
|
71
|
-
},
|
|
65
|
+
[PAGE_KEY]: PAGE_COMPONENT,
|
|
66
|
+
[PAGES_KEY]: PAGE_COMPONENT,
|
|
72
67
|
[THEME_KEY]: {
|
|
73
68
|
dir: THEME_KEY,
|
|
74
69
|
userFriendlyName: 'Theme',
|
package/src/lib/migrate.js
CHANGED
|
@@ -2,7 +2,7 @@ import { walk } from '@hubspot/local-dev-lib/fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { mapToUserFacingType } from './transform.js';
|
|
5
|
-
import { METAFILE_EXTENSION, Components, HS_PROJECT_JSON_FILENAME, } from './constants.js';
|
|
5
|
+
import { METAFILE_EXTENSION, Components, HS_PROJECT_JSON_FILENAME, APP_FUNCTIONS_PACKAGE_KEY, APP_FUNCTIONS_KEY, } from './constants.js';
|
|
6
6
|
import { translate } from './translate.js';
|
|
7
7
|
import { loadJsonFile } from './utils.js';
|
|
8
8
|
const IR_FILENAME = 'ir.json';
|
|
@@ -35,20 +35,25 @@ export async function migrate(inputDir, outputDir) {
|
|
|
35
35
|
const irDirName = path.dirname(filename);
|
|
36
36
|
const IR = loadJsonFile(filename);
|
|
37
37
|
const { metaFilePath } = IR;
|
|
38
|
-
const
|
|
39
|
-
const fullOutputPath = path.join(sourceCodeOutputDir, getTargetDirectoryFromComponentType(
|
|
38
|
+
const component = convertIRToProjectConfig(IR);
|
|
39
|
+
const fullOutputPath = path.join(sourceCodeOutputDir, getTargetDirectoryFromComponentType(component.type));
|
|
40
40
|
// Ensure the output directory exists
|
|
41
41
|
const currentFilesDirectory = path.join(irDirName, filesDirectory);
|
|
42
42
|
ensureDirExists(currentFilesDirectory);
|
|
43
43
|
fs.cpSync(currentFilesDirectory, fullOutputPath, {
|
|
44
44
|
recursive: true,
|
|
45
45
|
});
|
|
46
|
+
// In the current component is a APP_FUNCTIONS_PACKAGE we don't want to write a hsmeta.json file
|
|
47
|
+
// since it is an auto generate component
|
|
48
|
+
if (component.type === APP_FUNCTIONS_PACKAGE_KEY) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
46
51
|
// Use the metaFilePath if provided, otherwise use the project UID
|
|
47
52
|
const hsmetaFilePath = path.join(fullOutputPath, metaFilePath
|
|
48
53
|
? path.basename(metaFilePath)
|
|
49
|
-
: `${
|
|
54
|
+
: `${component.uid}${METAFILE_EXTENSION}`);
|
|
50
55
|
// Write the hsmeta file to the output directory
|
|
51
|
-
fs.writeFileSync(hsmetaFilePath, JSON.stringify(
|
|
56
|
+
fs.writeFileSync(hsmetaFilePath, JSON.stringify(component, null, 2));
|
|
52
57
|
});
|
|
53
58
|
const IR = await translate({
|
|
54
59
|
projectSourceDir: sourceCodeOutputDir,
|
|
@@ -78,7 +83,10 @@ function convertIRToProjectConfig(IR) {
|
|
|
78
83
|
};
|
|
79
84
|
}
|
|
80
85
|
function getTargetDirectoryFromComponentType(componentType) {
|
|
81
|
-
|
|
86
|
+
let component = Components[componentType];
|
|
87
|
+
if (componentType === APP_FUNCTIONS_PACKAGE_KEY) {
|
|
88
|
+
component = Components[APP_FUNCTIONS_KEY];
|
|
89
|
+
}
|
|
82
90
|
if (!component) {
|
|
83
91
|
throw Error('Unsupported component type');
|
|
84
92
|
}
|
package/src/lib/project.js
CHANGED
|
@@ -9,18 +9,25 @@ export async function getProjectMetadata(projectSrcDir) {
|
|
|
9
9
|
if (fs.existsSync(projectSrcDir)) {
|
|
10
10
|
metafiles = await locateHsMetaFiles(projectSrcDir, { silent: true });
|
|
11
11
|
}
|
|
12
|
+
const seenComponentPaths = new Map();
|
|
12
13
|
Object.keys(Components).forEach(componentType => {
|
|
13
14
|
const { parentComponent, singularComponent, dir } = Components[componentType];
|
|
14
15
|
const componentPath = path.join(projectSrcDir, parentComponent ? path.join(parentComponent, dir) : dir);
|
|
16
|
+
if (seenComponentPaths.has(componentPath)) {
|
|
17
|
+
components[componentType] = seenComponentPaths.get(componentPath);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
15
20
|
const metaFilesByType = metafiles
|
|
16
21
|
.filter(metafile => path.parse(metafile.file).dir === componentPath)
|
|
17
22
|
.map(metaFile => metaFile.file);
|
|
18
|
-
|
|
19
|
-
components[componentType] = {
|
|
23
|
+
const metadata = {
|
|
20
24
|
hsMetaFiles: metaFilesByType,
|
|
21
25
|
count: metaFilesByType.length,
|
|
22
26
|
maxCount: singularComponent ? 1 : Infinity,
|
|
23
27
|
};
|
|
28
|
+
hsMetaFiles.push(...metaFilesByType);
|
|
29
|
+
seenComponentPaths.set(componentPath, metadata);
|
|
30
|
+
components[componentType] = metadata;
|
|
24
31
|
});
|
|
25
32
|
return {
|
|
26
33
|
hsMetaFiles,
|
package/src/lib/transform.js
CHANGED
|
@@ -2,11 +2,11 @@ import path from 'path';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { logger } from '@hubspot/local-dev-lib/logger';
|
|
4
4
|
import { applyHsProfileVariables, getHsProfileVariables } from './profiles.js';
|
|
5
|
-
import { APP_KEY, APP_OBJECT_KEY, Components, PROJECT_STRUCTURE, APP_FUNCTIONS_KEY, APP_FUNCTIONS_PACKAGE_KEY, USER_FACING_TO_INTERNAL_TYPE, INTERNAL_TYPE_TO_USER_FACING, PACKAGE_JSON, PACKAGE_LOCK_JSON, PROFILE_VARIABLE_TYPES, } from './constants.js';
|
|
5
|
+
import { APP_KEY, APP_OBJECT_KEY, CARDS_KEY, Components, PROJECT_STRUCTURE, APP_FUNCTIONS_KEY, APP_FUNCTIONS_PACKAGE_KEY, USER_FACING_TO_INTERNAL_TYPE, INTERNAL_TYPE_TO_USER_FACING, PACKAGE_JSON, PACKAGE_LOCK_JSON, PROFILE_VARIABLE_TYPES, } from './constants.js';
|
|
6
6
|
import { errorMessages } from '../lang/copy.js';
|
|
7
7
|
import { getJavaNumberType } from './utils.js';
|
|
8
8
|
import { convertPathToPosixPath } from './files.js';
|
|
9
|
-
function calculateComponentDeps(fileValidationResult, parentComponents, appObjects, appFunctionsPackageUid) {
|
|
9
|
+
function calculateComponentDeps(fileValidationResult, parentComponents, appObjects, appFunctions, appFunctionsPackageUid) {
|
|
10
10
|
let dependencies = {};
|
|
11
11
|
// If there are dependencies in the config file, pass them through
|
|
12
12
|
if (!fileValidationResult.content?.dependencies) {
|
|
@@ -32,6 +32,14 @@ function calculateComponentDeps(fileValidationResult, parentComponents, appObjec
|
|
|
32
32
|
if (type === APP_FUNCTIONS_KEY && appFunctionsPackageUid) {
|
|
33
33
|
dependencies.serverlessPackage = appFunctionsPackageUid;
|
|
34
34
|
}
|
|
35
|
+
if (type === CARDS_KEY) {
|
|
36
|
+
if (appFunctionsPackageUid) {
|
|
37
|
+
dependencies.serverlessPackage = appFunctionsPackageUid;
|
|
38
|
+
}
|
|
39
|
+
if (appFunctions.length > 0) {
|
|
40
|
+
dependencies.allAppFunctions = appFunctions;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
44
|
return { dependencies };
|
|
37
45
|
}
|
|
@@ -54,6 +62,7 @@ export function transform(fileParseResults, translationContext, hsProfileContent
|
|
|
54
62
|
const parentTypes = Object.keys(PROJECT_STRUCTURE);
|
|
55
63
|
const parentComponents = {};
|
|
56
64
|
const allAppObjects = [];
|
|
65
|
+
const allAppFunctions = [];
|
|
57
66
|
let appUid = '';
|
|
58
67
|
let appFunctionsDirectory;
|
|
59
68
|
// Apply the profile variable overrides to the config
|
|
@@ -73,6 +82,7 @@ export function transform(fileParseResults, translationContext, hsProfileContent
|
|
|
73
82
|
}
|
|
74
83
|
if (file.content?.type === APP_FUNCTIONS_KEY) {
|
|
75
84
|
appFunctionsDirectory = path.dirname(file.file);
|
|
85
|
+
allAppFunctions.push(file.content.uid);
|
|
76
86
|
}
|
|
77
87
|
});
|
|
78
88
|
const autoGeneratedComponents = [];
|
|
@@ -96,7 +106,7 @@ export function transform(fileParseResults, translationContext, hsProfileContent
|
|
|
96
106
|
};
|
|
97
107
|
}
|
|
98
108
|
const { config, uid, type } = currentFile.content;
|
|
99
|
-
const { dependencies, errors } = calculateComponentDeps(currentFile, parentComponents, allAppObjects, serverlessPackageUid);
|
|
109
|
+
const { dependencies, errors } = calculateComponentDeps(currentFile, parentComponents, allAppObjects, allAppFunctions, serverlessPackageUid);
|
|
100
110
|
if (errors) {
|
|
101
111
|
currentFile.errors?.push(...errors);
|
|
102
112
|
}
|