@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 +1 -1
- package/src/lang/copy.d.ts +1 -0
- package/src/lang/copy.js +2 -1
- package/src/lib/migrate.js +18 -2
- package/src/lib/schemas.js +3 -0
- package/src/lib/types.d.ts +1 -1
- package/src/lib/uid.js +1 -1
package/package.json
CHANGED
package/src/lang/copy.d.ts
CHANGED
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
|
|
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'`,
|
package/src/lib/migrate.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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)) {
|
package/src/lib/schemas.js
CHANGED
|
@@ -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, {
|
package/src/lib/types.d.ts
CHANGED
package/src/lib/uid.js
CHANGED