chrome-devtools-autosave icon indicating copy to clipboard operation
chrome-devtools-autosave copied to clipboard

Apply multiple route replacements to a resource

Open ferventcoder opened this issue 12 years ago • 11 comments

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 avatar Apr 03 '12 21:04 ferventcoder

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 avatar Apr 03 '12 21:04 ferventcoder

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 avatar Apr 03 '12 21:04 ferventcoder

I just sent a pull request with the change - https://github.com/NV/chrome-devtools-autosave-server/pull/15

Thanks again for an awesome tool!

ferventcoder avatar Apr 03 '12 22:04 ferventcoder

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 https://github.com/NV/chrome-devtools-autosave-server/pull/11

NV avatar Apr 03 '12 22:04 NV

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 avatar Apr 03 '12 22:04 ferventcoder

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

ferventcoder avatar Apr 03 '12 22:04 ferventcoder

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

ferventcoder avatar Apr 03 '12 22:04 ferventcoder

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

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

NV avatar Apr 03 '12 23:04 NV

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.

ferventcoder avatar Apr 03 '12 23:04 ferventcoder

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.

NV avatar Apr 03 '12 23:04 NV

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

markcellus avatar Jun 04 '13 15:06 markcellus