@hubspot/project-parsing-lib 0.8.1-beta.0 → 0.8.2-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.
- package/package.json +1 -1
- package/src/lang/copy.d.ts +3 -0
- package/src/lang/copy.js +3 -0
- package/src/lib/files.d.ts +1 -2
- package/src/lib/migrateThemes.d.ts +1 -0
- package/src/lib/migrateThemes.js +17 -3
- package/src/lib/project.js +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/project-parsing-lib",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2-beta.0",
|
|
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",
|
package/src/lang/copy.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ export declare const errorMessages: {
|
|
|
33
33
|
invalidJson: string;
|
|
34
34
|
wrongDirectoryForComponent: (directory: string, componentType: string, componentMetadata: ComponentMetadata, correctDir: string) => string;
|
|
35
35
|
};
|
|
36
|
+
migrateThemes: {
|
|
37
|
+
rootReactThemeNotSupported: string;
|
|
38
|
+
};
|
|
36
39
|
};
|
|
37
40
|
export declare function getInvalidJsonError(): string;
|
|
38
41
|
export declare function getMissingTypeError(): string;
|
package/src/lang/copy.js
CHANGED
|
@@ -44,6 +44,9 @@ exports.errorMessages = {
|
|
|
44
44
|
invalidJson: 'Invalid JSON',
|
|
45
45
|
wrongDirectoryForComponent: (directory, componentType, componentMetadata, correctDir) => `The directory '${directory}' is incorrect for type '${componentType}'. ${componentMetadata.userFriendlyName} ${componentMetadata.userFriendlyTypePlural} should only be placed in the '${correctDir}' directory`,
|
|
46
46
|
},
|
|
47
|
+
migrateThemes: {
|
|
48
|
+
rootReactThemeNotSupported: 'Migrating themes that live at the root of the project src directory is not supported. Please move the theme to a subdirectory.',
|
|
49
|
+
},
|
|
47
50
|
};
|
|
48
51
|
function getInvalidJsonError() {
|
|
49
52
|
return exports.errorMessages.validation.invalidJson;
|
package/src/lib/files.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileParseResult, TranslationContext, HsProfileFile } from './types';
|
|
2
|
-
type MetaFileLocation = {
|
|
2
|
+
export type MetaFileLocation = {
|
|
3
3
|
file: string;
|
|
4
4
|
parentDirectory?: string;
|
|
5
5
|
};
|
|
@@ -10,4 +10,3 @@ export declare function locateHsMetaFiles(projectSourceDir: string, options?: {
|
|
|
10
10
|
silent: boolean;
|
|
11
11
|
}): Promise<MetaFileLocation[]>;
|
|
12
12
|
export declare function projectContainsHsMetaFiles(projectSourceDir: string): Promise<boolean>;
|
|
13
|
-
export {};
|
package/src/lib/migrateThemes.js
CHANGED
|
@@ -12,6 +12,7 @@ const util_1 = require("util");
|
|
|
12
12
|
const fs_2 = require("@hubspot/local-dev-lib/fs");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
|
+
const copy_1 = require("../lang/copy");
|
|
15
16
|
const mkdtempAsync = (0, util_1.promisify)(fs_1.default.mkdtemp);
|
|
16
17
|
const LEGACY_THEME_CONFIG = 'theme.json';
|
|
17
18
|
const LEGACY_REACT_THEME_CONFIG = 'cms-assets.json';
|
|
@@ -83,12 +84,25 @@ async function migrateThemes(projectDir, projectSourceDir) {
|
|
|
83
84
|
const { legacyThemeDetails, legacyReactThemeDetails, } = await getProjectThemeDetails(projectSourceDir);
|
|
84
85
|
// Migrate the project to a temporary directory to avoid file conflicts in the original project
|
|
85
86
|
const migratedProjectTempDir = await mkdtempAsync(path_1.default.join(os_1.default.tmpdir(), 'hubspot-migrated-project-'));
|
|
87
|
+
let isRootReactThemeProject = false;
|
|
88
|
+
legacyReactThemeDetails.forEach(themeDetails => {
|
|
89
|
+
isRootReactThemeProject = themeDetails.themePath === projectSourceDir;
|
|
90
|
+
if (!isRootReactThemeProject) {
|
|
91
|
+
buildNewTheme(constants_1.ReactThemeKey, migratedProjectTempDir, themeDetails);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
// Do not support migrating themes that live at the root of the project src directory
|
|
95
|
+
if (isRootReactThemeProject) {
|
|
96
|
+
return {
|
|
97
|
+
legacyThemeDetails,
|
|
98
|
+
legacyReactThemeDetails,
|
|
99
|
+
migrated: false,
|
|
100
|
+
failureReason: copy_1.errorMessages.migrateThemes.rootReactThemeNotSupported,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
86
103
|
legacyThemeDetails.forEach(themeDetails => {
|
|
87
104
|
buildNewTheme(constants_1.ThemeKey, migratedProjectTempDir, themeDetails);
|
|
88
105
|
});
|
|
89
|
-
legacyReactThemeDetails.forEach(themeDetails => {
|
|
90
|
-
buildNewTheme(constants_1.ReactThemeKey, migratedProjectTempDir, themeDetails);
|
|
91
|
-
});
|
|
92
106
|
// Copy the rest of the project files to the temp directory
|
|
93
107
|
fs_1.default.cpSync(projectSourceDir, migratedProjectTempDir, {
|
|
94
108
|
recursive: true,
|
package/src/lib/project.js
CHANGED
|
@@ -7,10 +7,14 @@ exports.getProjectMetadata = getProjectMetadata;
|
|
|
7
7
|
const constants_1 = require("./constants");
|
|
8
8
|
const files_1 = require("./files");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
11
|
async function getProjectMetadata(projectSrcDir) {
|
|
11
12
|
const hsMetaFiles = [];
|
|
12
13
|
const components = {};
|
|
13
|
-
|
|
14
|
+
let metafiles = [];
|
|
15
|
+
if (fs_1.default.existsSync(projectSrcDir)) {
|
|
16
|
+
metafiles = await (0, files_1.locateHsMetaFiles)(projectSrcDir, { silent: true });
|
|
17
|
+
}
|
|
14
18
|
Object.keys(constants_1.Components).forEach(componentType => {
|
|
15
19
|
const { parentComponent, singularComponent, dir } = constants_1.Components[componentType];
|
|
16
20
|
const componentPath = path_1.default.join(projectSrcDir, parentComponent ? path_1.default.join(parentComponent, dir) : dir);
|