-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: project structure ts port #1302
Conversation
lib/projectStructure.ts
Outdated
function getIsLegacyApp( | ||
appConfig: PublicAppComponentConfigType | PrivateAppComponentConfigType, | ||
appPath: string | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a return type
lib/projectStructure.ts
Outdated
} | ||
} | ||
}); | ||
|
||
return components; | ||
} | ||
|
||
function getProjectComponentTypes(components) { | ||
const projectContents = {}; | ||
export function getProjectComponentTypes(components: Array<Component>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a return type
lib/projectStructure.ts
Outdated
export function getAppCardConfigs( | ||
appConfig: PublicAppComponentConfigType | PrivateAppComponentConfigType, | ||
appPath: string | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a return type
lib/projectStructure.ts
Outdated
if (CONFIG_FILES[key] === configFile) { | ||
return key; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
function loadConfigFile(configPath) { | ||
function loadConfigFile(configPath: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me; there's no changes in behavior, etc. Just need to add some return types
lib/projectStructure.ts
Outdated
import { logError } from './errorHandlers/index'; | ||
|
||
type ComponentTypes = 'private-app' | 'public-app' | 'hubl-theme'; | ||
type ValueOf<T> = T[keyof T]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We export ValueOf
from @hubspot/local-dev-lib/types/Utils
so you don't need to redefine it here
lib/projectStructure.ts
Outdated
function getTypeFromConfigFile(configFile) { | ||
for (const key in CONFIG_FILES) { | ||
function getTypeFromConfigFile( | ||
configFile: ValueOf<typeof CONFIG_FILES> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this just resolves to string
. Which... I think is probably fine but we can just type at that way directly. I messed around with adding an as const
to CONFIG_FILES
to fix this and it caused its own set of problems
lib/projectStructure.ts
Outdated
import { logger } from '@hubspot/local-dev-lib/logger'; | ||
import { logError } from './errorHandlers/index'; | ||
|
||
type ComponentTypes = 'private-app' | 'public-app' | 'hubl-theme'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you already declare the COMPONENT_TYPES
object below, you could derive this type from that
type ComponentTypes = ValueOf<typeof COMPONENT_TYPES>;
Description and Context
Porting projectStructure to TS. I had to add types for project components which doesn't feel great, but I'm not sure that there's another option. Eventually we should offload this type of thing into the new package that will specialize in interacting with project schema, but in the meantime I think we need to keep this here.
I could also add these types to Local Dev Lib, but I think I'd just be adding more work for us down the road when we eventually start to use the translation lib.
Screenshots
TODO
Who to Notify