Skip to content
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(cli): Add shortest init command #297

Merged
merged 22 commits into from
Jan 30, 2025

Conversation

khalatevarun
Copy link
Contributor

@khalatevarun khalatevarun commented Jan 27, 2025

Resolves #294

CleanShot 2025-01-29 at 23 31 36@2x

Copy link

vercel bot commented Jan 27, 2025

@khalatevarun is attempting to deploy a commit to the Antiwork Team on Vercel.

A member of the Team first needs to authorize it.

@khalatevarun khalatevarun marked this pull request as ready for review January 27, 2025 05:56
@slavingia
Copy link
Contributor

Should update the README too

@rmarescu rmarescu changed the title add shortest init command to setup library in a fresh repo with config files (feat)cli: Add shortest init command Jan 27, 2025
@gladyshcodes
Copy link
Contributor

gladyshcodes commented Jan 27, 2025

nit: I think the purpose of the util folder is to store files that are frequently reused throughout the project. since most of the functions are not reused, they don't belong there. while detectProjectType has the potential for reuse, it’s currently only used once, so there’s no need to place it in the util folder at this time

I would suggest inlining them

@khalatevarun khalatevarun changed the title (feat)cli: Add shortest init command feat(cli): Add shortest init command Jan 28, 2025
@khalatevarun
Copy link
Contributor Author

the changes seem to be working fine when the package is built locally and used in another project

@khalatevarun
Copy link
Contributor Author

open to any additional reviews - @gladyshcodes @rmarescu

@rmarescu rmarescu self-assigned this Jan 29, 2025
@rmarescu
Copy link
Member

I've started reviewing, will wrap up tomorrow!

@khalatevarun
Copy link
Contributor Author

thank you for the review and code changes, learning alot in the process @rmarescu
will try following better practices going forward

Copy link
Member

@rmarescu rmarescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on a empty folder, and on a fresh Next.js install, seems to be working fine. Thanks for the contribution @khalatevarun!

@@ -24,18 +24,20 @@ If helpful, [here's a short video](https://github.com/anti-work/shortest/issues/

### Installation

```bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual instructions can be removed. The description below outlines the steps, in case someone would like to do it manually.

@@ -111,6 +111,11 @@ function isValidArg(arg: string): boolean {
async function main() {
const args = process.argv.slice(2);

if (args[0] === "init") {
await require("../commands/init").default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted all the logic to its own module.

import { addToGitignore } from "../../utils/add-to-gitignore";

export default async function main() {
console.log(pc.blue("Setting up Shortest..."));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blue doesn't look great on a dark terminal. We should consider improving the contrast at some point.

packageJson?.devDependencies?.["@antiwork/shortest"]
) {
console.log(pc.green("✔ Package already installed"));
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important to exit early if the package is already installed, otherwise there would be some considerable effort to ensure the install doesn't overwrite any existing data.

const configPath = join(process.cwd(), CONFIG_FILENAME);
const exampleConfigPath = join(
fileURLToPath(new URL("../../src", import.meta.url)),
`${CONFIG_FILENAME}.example`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the logic to use an example file.

console.log(pc.green(`✔ ${CONFIG_FILENAME} created`));

const envResult = await addToEnv(process.cwd(), {
ANTHROPIC_API_KEY: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth adding Mailosaur at this time, although other ENVs can be easily added in the future.

}

const resultGitignore = await addToGitignore(process.cwd(), [
".env*.local",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth the effort trying to group with other env*-like values already present (e.g. .env from a fresh Next.js install).

@rmarescu rmarescu merged commit 28e226e into anti-work:main Jan 30, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add shortest init command for simplified setup
4 participants