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

cleanup #45

Merged
merged 12 commits into from
Jun 14, 2024
Merged

cleanup #45

merged 12 commits into from
Jun 14, 2024

Conversation

technophile-04
Copy link
Collaborator

@technophile-04 technophile-04 commented Jun 6, 2024

Summary:

  1. Removed deprecated stuff from copy-template-files.ts
  2. Fixes While processing templates, allow undefined args #34

Basic flow on how CLI works:

  1. The starting point is cli.ts
  2. parseArgumentsIntoOptions parses argument which are explicitly mentioned by user (like --install etc)
  3. promptForMissingOptions, it does multiple jobs:
    1. Validates questions mentioned in config.ts are in proper format
    2. Prompts the user with question mentioned in config.ts file
    3. It also ask the questions for implicit extensions (nested extension) example :
      1. lets suppose we have templates/extensions/nextORM which has two extensions in that folder : temapltes/extensions/nextDB/extensions/primsa and teamplates/extensions/nextDB/extensions/drizzle
      2. So we have two extensions prisma & drizzle inside nextORM extension so it will ask the user to select one of them or none
      3. checkout this on Nested extensions
    4. The above logic of finding implicit extensions is done by traverseExtensions which is present in extensions-tree.ts
      1. This function traverseExtensions also sets extensionDict (extension descriptor) basically metadata about extension for eg in above nextORM case : {name: 'nextORM', subExtensions: ['prisma', 'drizzle'] } and also the extending extensions
      2. This file is also important / wierd file, notice it has dangling await traverseExtensions(...) at end of file
      3. So when you do this import { extensionDict } from "./extensions-tree"; it will set the extensionDict with the metadata of extension which we use all over the places especially in copy-template-files.ts file
  4. main.ts this file has pretty intuitive straight line flow, the imp file here is copy-template-files.ts

cc @carletex, I didn't remove the Nested extensions and extending extensions (point 3 from above notes) logic in this PR, was thinking to do it in another PR just incase if we plan to add similar functionality back. But please let me know if we should do it in this PR itself !

Currently both Nested extensions and extending extensions are not used at all and also doesn't work with external extensions.

I think we could completely remove extending extensions but I see some value in Nested extensions and we can make it work for external extensions with minor tweaks

@technophile-04 technophile-04 marked this pull request as ready for review June 10, 2024 11:47
@carletex
Copy link
Member

Currently both Nested extensions and extending extensions are not used at all and also doesn't work with external extensions.
I think we could completely remove extending extensions but I see some value in Nested extensions and we can make it work for external extensions with minor tweaks

I'd remove both if we are not using them since the idea is to clean up the codebase and make everything easier to understand (code & instructions) If at some point we decide that we need any of the two... we can come back to this PR and add it back!

@rin-st
Copy link
Member

rin-st commented Jun 11, 2024

lgtm!

Fixes #34

As I understand it already worked before this pr, when it was added to

export default withDefaults(contents, {
  ...
  extraContents: "",
});

on templates/base/README.md.template.mjs? Because for me it works on main branch. Or am I doing something wrong?

I'd remove both if we are not using them since the idea is to clean up the codebase and make everything easier to understand (code & instructions) If at some point we decide that we need any of the two... we can come back to this PR and add it back!

Agree

@technophile-04
Copy link
Collaborator Author

As I understand it already worked before this pr, when it was added to

Ohh actually if you remove extraContents: "" from other's in main branch and then run yarn cli -e subgraph and look at generated README.md of instance created it won't have "Setup The graph integration" i.e this thing

I'd remove both if we are not using them since the idea is to clean up the codebase and make everything easier to understand (code & instructions) If at some point we decide that we need any of the two... we can come back to this PR and add it back!

Yup agree will remove it in this PR itself 🙌

@rin-st
Copy link
Member

rin-st commented Jun 11, 2024

Ohh actually if you remove extraContents: "" from other's in main branch and then run yarn cli -e subgraph and look at generated README.md of instance created it won't have "Setup The graph integration" i.e this thing

Got it, thanks! I didn't notice that

Copy link
Member

Choose a reason for hiding this comment

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

What if we change this filename to core-extensions or something like that? So then we can create external-extensions for extensions that will live in other repos. Or are we planning to put all of them together here?

Copy link
Member

Choose a reason for hiding this comment

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

voting for first option

Comment on lines 45 to 52
const isPackageJson = isPackageJsonRegex.test(fileName);
const isYarnLock = isYarnLockRegex.test(fileName);
const isNextGenerated = isNextGeneratedRegex.test(fileName);

const skipAlways = isTemplate || isPackageJson;
const skipDevOnly = isYarnLock || isNextGenerated;
const shouldSkip = skipAlways || (isDev && skipDevOnly);

Copy link
Member

Choose a reason for hiding this comment

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

Trying to understand this.

  • why were we not copying package.json before?
  • dev is not important anymore here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ohh my bad actually I planned to write a comment on why did I remove all this and forgot about it but here is description:

So basically this function copies "base" dir into user mentioned path.

why were we not copying package.json before?

We were ignore package.json here because just below this copyOrLink func we were using mergePackageJson to merge package.json's :

const basePackageJsonPaths = findFilesRecursiveSync(basePath, path => isPackageJsonRegex.test(path));
basePackageJsonPaths.forEach(packageJsonPath => {
const partialPath = packageJsonPath.split(basePath)[1];
mergePackageJson(path.join(targetDir, partialPath), path.join(basePath, partialPath), isDev);
});

I have removed this part in this PR since:

  1. "base" dir is the first dir copied to user mentioned path.
  2. which means the user mentioned path is empty.
  3. So we don't need merging of package.json at all. we could just copy the whole "base" dir to user mentioned path directly except template files. (hence we are not skipping package.json in copyOrLink func in this PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dev is not important anymore here?

I initially thought it was not needed since we have removed "nextjs/generated" but just updated the logic and added it back so that we don't symlink yarn.lock and packages/nextjs/contracts/deployedContracts.ts since both are reproducible and we don't want to commit them while creating extension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haven't removed this file it's just rename checkout #45 (comment)

Comment on lines -295 to -296
// 2. Add "parent" extensions (set via config.json#extend field)
options.extensions = expandExtensions(options);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We no more need this since we are not allowing extending extension anymore

@carletex carletex mentioned this pull request Jun 14, 2024
@technophile-04 technophile-04 merged commit 2b60c23 into main Jun 14, 2024
1 check passed
@technophile-04 technophile-04 deleted the cleanup branch June 14, 2024 17:30
@carletex carletex mentioned this pull request Jun 21, 2024
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.

While processing templates, allow undefined args
3 participants