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

Apply multiple route replacements to a resource #42

Open
ferventcoder opened this issue Apr 3, 2012 · 11 comments
Open

Apply multiple route replacements to a resource #42

ferventcoder opened this issue Apr 3, 2012 · 11 comments
Labels

Comments

@ferventcoder
Copy link

I just want to say, autosave is one bad-a$$ tool. I am having a bit of an issue with multiple route replacements in the routes.js file.

exports.routes = [
  {
     from: new RegExp('^http://localhost/'),
     to: 'src\/some.Web'
  },
  {
    from: new RegExp('otherpartof/samepath/'),
    to: ''
  }
];

The second one seems to be ignored...if I change the order, the one in the first spot now works.

@ferventcoder
Copy link
Author

Example:

exports.routes = [
  {
     from: new RegExp('^http://localhost/'),
     to: 'src\/some.Web'
  },
  {
    from: new RegExp('otherpartof/samepath/'),
    to: ''
  }
];

I use a tool that hashes the resources and changes the url to the items. I was hoping autosave would apply both route replacements before it tried to save the file.

@ferventcoder
Copy link
Author

Looks like it goes off of the first match https://github.com/NV/chrome-devtools-autosave-server/blob/master/index.js#L72-73

It would be awesome if it would find all the matches and apply them in the order it finds them.

@ferventcoder
Copy link
Author

I just sent a pull request with the change - NV/chrome-devtools-autosave-server#15

Thanks again for an awesome tool!

@NV
Copy link
Owner

NV commented Apr 3, 2012

Why, exactly, do you need a single resource to be saved in two different places?

I use a tool that hashes the resources and changes the url to the items. I was hoping autosave would apply both route replacements before it tried to save the file.

I’m not following. What kind of tool is that?

Also, see NV/chrome-devtools-autosave-server#11

@ferventcoder
Copy link
Author

Sorry for the confusion. Not saved to two different routes. Multiple route replacements applied to same resource. Take a look at the pull request I sent to the server project.

@ferventcoder
Copy link
Author

I'm using cassette. It changes the url to resources to /_cassette/assets/resourcepath.

@ferventcoder
Copy link
Author

Having it apply multiple route replacements would allow me to apply parts of replacements to multiple urls without having to repeat myself.

@NV
Copy link
Owner

NV commented Apr 3, 2012

I believe it could be done by using a single rule, e.g.:

{
  from: new RegExp('^http://localhost/(otherpartof/samepath/)?'),
  to: 'src/some.Web'
}

@ferventcoder
Copy link
Author

It could. But then I would do a copy paste change for new rules. Cleaner and simpler from a readability standpoint to have it apply each. And it makes for an easier maintenance aspect from the user perspective.

And if the paths are not next to each other, do you allow for regex tag replacement? e.g:

{
  from: new RegExp('^http://localhost/(?<KEEP>somesection)/otherpart/of/samepath'),
  to: 'src/somepath/${KEEP}'
}

RegEx may not be completely valid, but I think it defines the gist. Up to you really. Pull request is there.

@NV
Copy link
Owner

NV commented Apr 3, 2012

And if the paths are not next to each other, do you allow for regex tag replacement?

Capture groups work, e.g.:

{
  from: new RegExp('^http://localhost/(somesection)/otherpart/of/samepath'),
  to: 'src/somepath/$1'
}

Although, JS doesn’t support named capture groups.

I have to think some time about usefulness of your enhancement.

@markcellus
Copy link

Any word on this enhancement? I would like to do the capture groups mentioned above.

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

No branches or pull requests

3 participants