-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: add liara init
command
#200
base: master
Are you sure you want to change the base?
Conversation
related: #151 |
src/utils/getSupportedVersions.ts
Outdated
export default function supportedVersions(platform: string) { | ||
if (platform in versions) { | ||
return versions[platform as keyof typeof versions]; | ||
} | ||
return null; | ||
} |
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.
I suggest avoiding the use of null
here.
In JavaScript, undefined
is the default for uninitialized or missing values, which helps align with the language's conventions. Using undefined
simplifies checks and ensures consistency, reducing the need to handle both null
and undefined
separately.
I think when designing APIs, returning undefined
for missing data is often more intuitive and aligns with JavaScript conventions.
export default function supportedVersions(platform: string) {
return versions[platform as keyof typeof versions]
}
Test it and let me know what you think!
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.
You're right! Also we can simplify the null checks in the init.ts file (lines: 272, 227, 291). Since both null and undefined are considered falsy in JavaScript, we can replace the explicit null checks with a straightforward truthy/falsy evaluation.
For example:
if (platformVersion == null) {
return null;
}
Can be simplified to:
if (!platformVersion) {
return null;
}
If you agree with this approach, I’ll proceed with committing these changes.
src/base.ts
Outdated
async promptPort(platform: string): Promise<number> { | ||
const { port } = (await inquirer.prompt({ | ||
name: 'port', | ||
type: 'input', | ||
default: getDefaultPort(platform), | ||
message: 'Enter the port your app listens to:', | ||
validate: validatePort, | ||
})) as { port: number }; | ||
|
||
return port; | ||
} |
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.
I noticed that the promptPort
method is repeated in deploy.ts
as well. Additionally, base.ts
doesn’t seem like the appropriate place for a utility function like this.
Why not move promptPort
to the utils
directory? This would allow us to reuse it wherever needed and keep base.ts
focused and simple.
Keeping base.ts
as clean as possible is important for maintainability and readability.
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.
I tried to follow the approach that has been used so far. there is also promptNetwork() and promptProject() that is defined in base.ts. I suggest that we let them be in base.ts for now and move them later.
src/base.ts
Outdated
interface IMount { | ||
name: string; | ||
mountedTo: string; | ||
} | ||
export interface IGetDiskResponse { | ||
disks: { | ||
name: string; | ||
size: number; | ||
updatedAt: string; | ||
createdAt: string; | ||
filebrowserUrl: string; | ||
}[]; | ||
mounts: IMount[]; | ||
} |
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.
Why not move these interfaces to the types directory?
} | ||
return null; | ||
} catch (error) { | ||
throw error; |
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.
Appropriate errors should be thrown to inform the user.
IMO : The typeof null; // "object" Handling both function greet(name = "Guest") {
console.log(name);
}
greet(null); // Outputs: null Default values in object destructuring also fail with null, and using null in nested destructuring can even cause runtime errors. These are the main reasons I avoid using |
src/commands/init.ts
Outdated
It includes only the essential settings; additional configurations must be added manually. | ||
📚 For more details on each field and its usage, visit: https://docs.liara.ir/paas/liarajson/. | ||
|
||
Afterwards, use liara deploy to deploy your project. |
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.
Afterwards, use liara deploy to deploy your project. | |
Afterwards, use liara deploy to deploy your app. |
cron, | ||
); | ||
|
||
this.createLiaraJsonFile(configs); |
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.
Don't we need an await
for this?
this.createLiaraJsonFile(configs); | |
this.createLiaraJsonFile(configs); |
The following pattern: try {
//
}
catch (error) {
throw error;
} Doesn't accomplish anything. You can remove them all. |
This command provides an interactive process to generate a basic liara.json configuration file.
The generated configuration file will include only the basic parameters to get started, such as application name, port, platform, and other necessary fields. However, any additional or advanced configurations (such as cron, healthCheck, etc.) will not be included by default and must be manually added after the file is created.