-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
Question: Reusing script utils? #488
Comments
Because of the current code generation, extension methods aren't allowed as they need to be in a static non nested class. Probably not impossible but would indeed need some refactoring to work. |
We should be able to extract extension methods from the code, but it would be a lot of work. I would rather wait until Roslyn is used on all platforms. Then it will be a cake walk (pun intended). |
This discussion also reminds me of something I've been meaning to ask you guys. |
At this point, I generally divvy bits and pieces into other .cake files and |
@RichiCoder1, I'd like to hear more about your approach. Where do you define your script args? I'd assume you'd define them in the separated file containing the tasks they relate to. That also implies that it might be a bit difficult to see at a glance which args are needed (kind of analogous to constructor injection vs. service location when discussing dependency injection). Do your separate files assume anything about the externally defined variables/args available to them? Is there a clean way to declare/define such items in those files? Also, in terms of Cake's script processing, I assume that Cake pretty much combines all the loaded cake scripts into a single scripting context, rather than encapsulating them in specific closures / scopes (thinking about variable scoping between one script and another -- so you wouldn't be able to declare variables of the same name in two different files to be used by the same top-level script). Is that correct? |
@jrnail23 at work we package and fetch common scripts and resources via nuget packages. We have a common repository that has a cake script that packages and deploys them to a private feed continuously. |
@devlead, that's another interesting wrinkle! How do you load those packages? They don't quite seem to fit the definition of EDIT: oh duh, I'm sure you're adding those packages to your packages.config file then just doing |
Though we have an package.json our bootstrapper PowerShell uses and that also can be used as dependency for build server caching of binaries. |
I think that would be a great article for cakebuild.net, perhaps in a "how-to" section. |
@devlead, Looking at the So installing the nuget as a That brings up an interesting question though -- should we consider extending |
Sort of related to this... I have a set of For now, I'll just deal with requiring consumers to do a |
Actually, it looks like one can't even (simply) declare tasks from an addin, given only a reference to an I worked around this by requiring consumers to do Registering tasks seems like a common use case for addins; am I missing a better option here? |
@kibiz0r haven't seen this use case yet, though as you call Init method from script you could probably pass Task method body to it as a delegate parameter, eliminating the need for reflection. |
@kibiz0r I have to agree with @devlead here. My approach is the following... I have a NuGet Package which contains my common scripts: https://github.com/gep13/ChocolateyPackages/tree/master/gep13.DefaultBuild/Content And then these are consumed with a parent script, after the NuGet Package is bootstrapped into my environment. From there, I can then use the https://github.com/gep13/ReSharperReports/blob/improvements/setup.cake NOTE: this is still very much a work in progress. |
@jrnail23 I am going to go ahead and close this, as this is now a known solution, and seems to work for the most part. Please re-open if you feel more is required. |
@kibiz0r I know this is old and it's been a while, but have you progressed when building you addin? I'm trying to do something similar - define a addin that will only be used internally, but has common tasks and sequences with useful defaults. We have dozens of repos and creating the same cake script logic over and over again is tedious. Having a set of conventions and enough configurable points makes script creation /setup a whole lot easier. Mainly I'm looking for how to register Setup, TaskSetup, TaskTeardown and Tasks from the addin lib. |
@MiguelAlho Checkout Cake.Recipe. You can create a similar approach for an internal shared script library, which can be reused across multiple repositories. |
@MiguelAlho: My memory is a little hazy on where my team really landed with this. I think we just used the You might also be interested to check out FAKE. |
Hey guys, what would be the best way to extract some common utils (things like extension methods, helpers, etc.) for reuse without having to build a true add-in?
I'm trying to refactor a Cake script that's getting a bit too complex for my comfort, so I'm looking for ways to pull common behavior out into other "util" script files that I can reference from my main Cake script.
It looks like
#load ./utils/MyHelpers.cake
seems to work, and I can define classes and methods there, so that's nice. Unfortunately it doesn't work for extension methods, which is what I'd really prefer for a lot of these kinds of things, for fluency's sake.Any ideas?
Might it be possible to pull in other referenced files as CakeAliases?
The text was updated successfully, but these errors were encountered: