excubo-ag / WebCompiler

Apache License 2.0
151 stars 30 forks source link

paths in files.conf should be relative to the conf file #39

Closed Liero closed 2 years ago

Liero commented 3 years ago

I think the file paths in files.conf should be relative to the config file, because it should build regardless of what current directory is.

For example, only one of following options will currently build, depending on paths in files.conf

  1. C:\mysolution> dotnet webcompiler -f src\myproject\files.conf

    requires paths in files.conf to start with src\myproject, which is weird

  2. C:\mysolution\src\myproject> dotnet webcompiler -f files.conf

    will build if paths are relative to files.conf

stefanloerwald commented 3 years ago

Hi @Liero,

I understand what you want the behavior to be, but to me, both approaches seem valid to me and it would be a breaking change. Most tools, including compilers, actually behave differently depending on where they are executed.

Would you consider a solution where you supply another command line parameter to change the behavior? For example something like -f src\myproject\files.conf --relative-to-files-json-path?

Liero commented 3 years ago

Would you consider a solution where you supply another command line parameter?

sure, but no need to hurry. I've found another way to deal with it. Would you mind leaving this issue opened for a while?

stefanloerwald commented 3 years ago

Would you mind leaving this issue opened for a while?

No problem at all!

If you don't mind: could you maybe think of what that command line parameter should be named? --relative-to-files-json-path feels too long, and doesn't have a logical one-character shorthand (-r is already taken for --recursive). Can you think of something better?

Thanks Stefan

Liero commented 3 years ago

What about a first line comment in the files.config?

//root: ./

resp //root: currentdirectory

Anyway, I was thinking that maybe there will be a need for extended configuration of the files in the future. Something similar to the original webcompiler, where each file can be configured separately.

Personally I would like to configure list of the files in the webcompilerconfig.json, but that's a different story.

Although I'm skeptical, whether anybody would ever need the filepaths to be relative to anything else than the config file. Can you imagine, that files in .csproj would not be relative to the csproj? Or files in tsconfig would not be relative to tsconfig, or files in angular.json would not be relative to angular.json?

Only files passed as command line arguments should be relative to current directory.

stefanloerwald commented 3 years ago

I personally don't use the --files option at all, so I don't have strong preferences.

I find handling each file separately incredibly tedious, so that's why I didn't go for that route. I always wanted a recursive mode and/or wildcard support, and with the existing tool (adding it through command line), this works just fine.

What's your use case to configure files individually?

Liero commented 3 years ago

Yeah, why don't you add wildcard support to the files.config? :D That was my second feature request, but one step at a time. I could create a PR for it, btw.

My problem was, that I had some files, like common.scss, that I used to import to site.scss. I don't want to compile common.scss separately.

stefanloerwald commented 3 years ago

I'm not going to add wildcard support in the files option, because I don't use it at all ;-) But I'm always willing to review PRs.

Compiling common.scss might be useless, but is it harmful? I personally would probably just ignore its compilation. Or I'd move it to a folder that I don't include in the compilation step.

Liero commented 3 years ago

Also I would like to compile pages/** AND wwwroot/styles/**, but not wwwroot/lib/**

stefanloerwald commented 3 years ago

Also I would like to compile pages/** AND wwwroot/styles/**, but not wwwroot/lib/**

webcompiler -r ./pages/ ./wwwroot/styles/ should work for that, right?

mejobloggs commented 3 years ago

Editing my reply because I just found why my files.conf wasn't working.

I thought the pathing wasnt working, but I just needed to remove "" from around my file names.

Will leave this note here in case someone else has the same problem as me

stefanloerwald commented 3 years ago

The way the --files option is implemented makes it quite clear how it'll work:

https://github.com/excubo-ag/WebCompiler/blob/bbe41744f6ab25fe44c1254cc12f108f0ec1cc58/WebCompiler/Program.cs#L360-L363

Every line in that file is interpreted as if it were a single command line parameter. In the command line, you need quotation marks around file names containing spaces, because otherwise the spaces separate the file name into multiple arguments, which individually will not be found. When reading from file, the entire line is interpreted as one path.