@hubspot/project-parsing-lib 0.13.0-beta.0 → 0.13.0-beta.1
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/lib/migrate.d.ts +1 -0
- package/src/lib/migrate.js +16 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/project-parsing-lib",
|
|
3
|
-
"version": "0.13.0-beta.
|
|
3
|
+
"version": "0.13.0-beta.1",
|
|
4
4
|
"description": "Parsing library for converting projects directory structures to their intermediate representation",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
package/src/lib/migrate.d.ts
CHANGED
package/src/lib/migrate.js
CHANGED
|
@@ -2,12 +2,12 @@ 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';
|
|
9
9
|
const filesDirectory = 'files';
|
|
10
|
-
const OUTPUT_IR_FILE = 'FULL_IR.json';
|
|
10
|
+
export const OUTPUT_IR_FILE = 'FULL_IR.json';
|
|
11
11
|
export async function migrate(inputDir, outputDir) {
|
|
12
12
|
if (!fs.existsSync(inputDir)) {
|
|
13
13
|
throw new Error(`Input directory ${inputDir} does not exist`);
|
|
@@ -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,9 +83,12 @@ 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
|
-
throw Error(
|
|
91
|
+
throw Error(`Unsupported component type: "${componentType}"`);
|
|
84
92
|
}
|
|
85
93
|
const parentDirectory = component.parentComponent
|
|
86
94
|
? Components[component.parentComponent].dir
|