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

Give a warning if two components have the same handle/url #188

Closed
mihkeleidast opened this issue Dec 7, 2016 · 3 comments
Closed

Give a warning if two components have the same handle/url #188

mihkeleidast opened this issue Dec 7, 2016 · 3 comments

Comments

@mihkeleidast
Copy link
Member

This is a problem with a large system. I have come across two separate issues:

  1. We typically have an examples folder in the component folder, and some examples under separate components have the same name.
  2. We manage view prototypes for multiple environments, and, for example, every environment has a "front-page".

Both of these result in the same handle and url.

I can (sort-of) fix these issues by specifying a prefix in a collection/component config, but first I would need to now where I'm having an overwrite issue without manually going through my component tree.

The second possible solution would be to automatically prefix certain collections with the collection name (eg if I have nested collections I should only set prefix: true on the first level collection) and all duplicate url issues for that collection are solved.

@allmarkedup
Copy link
Member

@Risker I think some sort of warning in the CLI when fractal comes across two duplicate handles is definitely a good idea to have and should be pretty easy to add in.

In the meantime, and similar to my answer to #189 if you want to do a 'check' on all your components to see if any have any duplicate handles you could use a custom command like the following:

fractal.cli.command('check-handles', function(opts, done){
    fractal.load().then(src => {
        const used = [];
        let error = false;
        for (let comp of fractal.components.flatten()) {
            const handle = comp.handle;
            const previous = used.filter(u => u.handle === handle);
            if (previous.length) {
                error = true;
                let paths = previous.map(p => p.path);
                paths.push(comp.viewPath);
                this.console.error(`Duplicate handle @${handle} - used in
 - ${paths.join('\n - ')}
                `);
            }
            used.push({
                handle: handle,
                path: comp.viewPath
            });
        }
        if (!error) {
            this.console.success('No duplicate handles found!');
        }
    });
    done();
});

Add that into your fractal.js file and then you should be able to run it using fractal check-handles to identify any duplicate handle issues.

@custa1200
Copy link

This is a bit awesome :)

@allmarkedup
Copy link
Member

I'm going to close this issue now - @Risker if you have any probs with the above feel free to re-open.

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

No branches or pull requests

3 participants