-
Notifications
You must be signed in to change notification settings - Fork 3
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
Relative paths inconsistency between 'src', 'build', and 'bin' #3
Comments
I often run into subtle path problems with Gulp streams. Let me tease out a couple of distinct issues here. First, a less file at Second, paths to assets in LESS or CSS files should always be relative to where the assets are in the build and not where they are in the sources. Lastly, while these solve most instances of this problem, they certainly don't fix them all. Anything in a subdirectory of However, I do have an idea to fix it. I'll post it later - it's hard to type code on a mobile. |
Forgive me, this happened purely because of my messing about with the directory structure. You are right, it builds to
I don't agree with that though, because:
What are your thoughts? |
I would disagree for a couple reasons. Resources will require different paths between build and compile. This is unavoidable because we are organizing by feature. A CSS file could be at Speaking of organizing by feature, if we had a reference to an icon in the above file, the path would be I agree in principal that Warlock should stay out of the way as much as is possible, but without being completely prescriptive in its structure, this isn't completely possible because some inevitable variation must be accounted for between applications. And that brings us to the only solution of which I can think that doesn't compromise on existing features: running the files through templating: .whatever {
background-image: url(<%= assets %>/images/icons.png);
} This solves the build, but the compile takes its files from the build, at which point the template had already been compiled with the wrong path. The solution, I think, is to allow flows to have multiple endpoints. E.g.: warlock.flow "webapp-javascript",
source: [ "<%= globs.source.js %>" ]
source_options:
base: "<%= paths.source_app %>"
dest:
"webapp-build":
path: "<%= paths.build.scripts %>"
at: 30 # priorities, like with merges
"webapp-compile":
path: "<%= paths.compile.assets %>"
at: 100
.add( 10, "lint", jshint )
.add( 40, "concat", concat )
.add( 50, "uflify", uglify )
# this doesn't actually change
warlock.flow "webapp-coffeescript"
source: [ "<%= globs.source.coffee %>" ]
source_options:
base: "<%= paths.source_app %>"
merge: "webapp-javascript@20" Running We've obviously now required a variable in the CSS, making it more difficult to switch away from Warlock, which is a small disadvantage, but we do gain readability and flexibility I think. What do you think? PS (completely unrelated): You've been super helpful. If you'd like to be "official" and added to the ngbp/warlock org on github, shoot me an email (yours isn't on your github page). Post-PS: It's after 3am. What the hell am I still doing awake? |
You're right - that's unavoidable. I'm still going to insist and try to find a way to keep IDEs happy though... If I have a relative path like It doesn't normally highlight the project tree like that if a path is wrong. In this instance, it sees the template code as syntax error. I could suppress that message, but I'm too arrogant :) Here's an idea. I must admit the suggestion does make some assumptions, but I'm going to leave them up to you to validate. Let's assume this is the path to our file as it appears in the source: .whatever {
background-image: url(../../../assets/boom.png);
} With some regex find/replace we can prepare this for the build. Find:
and replace with If it is too bold of an assumption to assume that any occurrence of P.S. I'd love to. An email will be coming your way. Post-PS: I don't know, but I understand. |
I'm not sure how big an assumption that is; I'll have to think about that. I use vim for my development (I'm one of "those" guys) so this is a problem that is foreign to me. An undocumented feature of Warlock is being able to prevent steps in a flow from running. So let's say this regular-expression-based step was called {
"prevent": [ "webapp.styles-to-build.replace-paths" ]
} So as long as it's something most people will want and as long as it's well-documented, things like this aren't too much of a problem. Convention over configuration with an emphasis on customization is a key philosophy of the tool, I think. That said, we'd still have a problem between build and compile because the first regex already replaced the original source values. We could use a different regex to replace the build value with the compile value, but I predict this becoming very fragile if someone starts changing the default paths or file structure. So perhaps something like the above restructuring of flows is still needed (not really a "restructuring"; more a "refactoring" because existing flows would still work). |
Actually, you've sort of documented the It may seem like a big assumption at first, but I don't think it is anymore, especially if we add the extra step to verify the match as a valid existing relative path. About your point:
How would replacing occurrences of My point is, if it's going to break, it'll break during |
Because: {
"paths": {
"source_assets": " src/static"
}
} Boom! Broken. While we could user the path variables themselves to build the expressions, I think it will get very fragile as people move parts about. The source assets, build assets, compile assets, and all their surrounding and containing directories are configurable. I don't see how we can reliably ensure that kind of replacement. |
Right. I think this could be my last suggestion before I give up and suppress those warnings. A hybrid approach... Early on in the flow, and before any files are processed, for every file we determine what the relative path to the /* <project_folder>/src/app/common/widget/widget.less */
.widget-container {
background-image: url(../../../misc/static/images/widget-bg.png);
} And let's assume {
"paths": {
"source_assets": "<%= paths.source %>/misc/static",
}
} Based on Without using a regular expression, we can do a find/replace on After that, the rest of the flows can be implemented as you suggested. Being a hybrid approach, it also has the benefit of allowing the user to directly use template code, if that's how the user prefers to do it. Doable? |
It's probably doable, but I'm still concerned with fragility. If you want to take a stab at implementing it, go for it. Otherwise, we can keep it open and circle back to it later.
You mean instead of using the template cache? |
I mean, the user can do either this: .widget-container {
background-image: url(../../../misc/static/images/widget-bg.png);
} Or this: .widget-container {
background-image: url(<%= assets %>/images/widget-bg.png);
} If they specify the path using a relative path, it gets changed on the fly to I think at this point we should probably just go with your suggestion of running files through templating, and requiring I'd be happy to try and implement that, but I'm not sure how to do that in Warlock. I presume every file, regardless of its type (?) under |
Following our discussion about code organisation, I've done some playing around, and noticed an issue with relative paths and how they are affected by the
build
andbin
directory structure.If you use a relative path in your
less
file to reference an image inassets
, it would look like this when working out ofsrc
:When the app builds into the
build
directory,app.css
appears underbuild/styles/app
folder, whileassets
isbuild/assets
. The above relative URL breaks.When the app compiles into the
bin
directory, everything is put into anassets
directory, which means that the relative URL will actually work just fine, although it looks up one level and back to where it started inassets
.Obviously the same issue could happen with any sort of relative path and not just in
less
files. I can't really think of a clean solution right away, all I know is that it needs one, so I'm just putting it out there! :-)The text was updated successfully, but these errors were encountered: