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

How to compose generators in our own ESM-based generator #1505

Closed
springcomp opened this issue Mar 7, 2024 · 8 comments
Closed

How to compose generators in our own ESM-based generator #1505

springcomp opened this issue Mar 7, 2024 · 8 comments
Labels
needs triage Awaiting triage stale

Comments

@springcomp
Copy link

I’m authoring a custom ESM generator using TypeScript.
I’m having a hard time finding documentation for composing existing generator.

Is there any documentation available ?
Is this possible ? If so how one would achieve such features.

I have created a simple generator-readme to demonstrate the issue I have.

I’m having a hard time trying to compose with the existing generator-license generator:

  public async default() {

    if (this.options.license) {
      console.log(import.meta.url);
      const path = resolve('generator-license', import.meta.url);
      console.log(path);
      const licenseOpts: LicenseOptions = {
        publish: false,
      };
      this.composeWith<GeneratorLicense>('license', [], licenseOpts);
    }
  }
@springcomp springcomp added the needs triage Awaiting triage label Mar 7, 2024
@springcomp springcomp changed the title How to compose compose generators in our own ESM-based generator How to compose generators in our own ESM-based generator Mar 7, 2024
@mshima
Copy link
Member

mshima commented Mar 18, 2024

  • composeWith is async, you need to await it.
  • is generator-license registered. If it’s not you can composeWith the resolved path.

@mshima
Copy link
Member

mshima commented Mar 18, 2024

  • composeWith is async, you need to await it.
  • is generator-license registered? If it’s not you can composeWith the resolved path.

@springcomp
Copy link
Author

springcomp commented Mar 19, 2024

  • composeWith is async, you need to await it.
  • is generator-license registered? If it’s not you can composeWith the resolved path.

Would you please help me out ?

I have not been able to make your suggestions work.
It still fails with a error:

You don’t seem to have a generator with the name "undefined" installed.

  public async default() {

    if (this.options.license) {
      const path = resolve('generator-license', import.meta.url);
      const licenseOpts: LicenseOptions = {
        publish: false,
      };
      await this.composeWith<GeneratorLicense>(path, licenseOpts);
    }
  }

I would like to compose with an embedded generator included as a dependency, rather than relying on the user having to install the required generator themselves.

@mshima
Copy link
Member

mshima commented Mar 19, 2024

If path is an url you should convert to file path.

@springcomp
Copy link
Author

springcomp commented Mar 19, 2024

If path is an url you should convert to file path.

path is a file system path that points to the generator-license library under the node_modules/ folder.

@mshima
Copy link
Member

mshima commented Mar 19, 2024

I don’t know if you understood, but resolve return is an url.
See https://www.npmjs.com/package/import-meta-resolve#use
It’s file://* you should convert to file path.

@springcomp
Copy link
Author

Hello @mshima thanks for clarifying.

I have indeed converted the file:// URL to a local path.
However, that still does not work.
In fact, it turns out that the composeWith method really expects a URL with a file:// scheme.
So the error remains.

import { fileURLToPath } from 'node:url';

  public async default() {

    if (this.options.license) {
      const path = resolve('generator-license', import.meta.url);
      const localPath = fileURLToPath(path);
      console.log(localPath);
      const licenseOpts: LicenseOptions = {
        publish: false,
      };
      await this.composeWith<GeneratorLicense>(localPath, licenseOpts);
    }
  }

I’m still having a hard time figuring out how to compose generators.

Copy link
Contributor

This issue is stale because it has been open with no activity. Remove stale label or comment or this will be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Awaiting triage stale
Projects
None yet
Development

No branches or pull requests

2 participants