Can I invoke gulp from a cake-build file? - asp.net

I have an ASP.NET solution where I perform some tasks using gulp (e.g. less-compilation). Inside Visual Studio the corresponding gulp-task is bound to the BeforeBuild event, so it is automatically started whenever I build the solution.
I was experimenting with cake for building and packaging the solution. While building the solution works fine using either the DotNetBuild() or MSBuild() tasks, the gulp tasks are not executed during the build.
It seems that gulp (and probably also other task runners) are not automatically "integrated" in the build process.
Does cake somehow support invoking gulp during the build?
(Of course, it should ideally also restore gulp itself (using npm / package.json) if it is not available.)

Note: This answer was copied from the
Cake issue response
by Mattias Karlsson (with his permission).
Just did a quick look so I might be missing something, but checking the
csproj file, the BeforeBuild MSBuild target seems to be empty?
Visual Studio 2015 has a built-in task runner for Gulp/Grunt so this
might be what's kicking in.
Currently we don't have aliases for NPM or Gulp (that would be an
great addin though), but what you could do is to invoke Gulp yourself
via the StartProcess alias. I tweaked your build.cake slighly below:
var target = Argument("target", "Default");
DirectoryPath solutionDir = MakeAbsolute(Directory("./"));
FilePath solution = solutionDir.CombineWithFilePath("WebApplication1.sln");
DirectoryPath projectDir = solutionDir.Combine("WebApplication1");
FilePath lessOutput = projectDir.CombineWithFilePath("css/style.css");
Task("Default")
.Does(() =>
{
NuGetRestore(solution);
if (FileExists(lessOutput))
{
Information("Cleaning old less output {0}", lessOutput);
DeleteFile(lessOutput);
}
StartProcess("cmd", new ProcessSettings {
Arguments = "/c \"set CI=true && npm install && gulp compile-less\"",
WorkingDirectory = projectDir
});
if (!FileExists(lessOutput))
{
throw new Exception("Less failed to create " + lessOutput);
}
Information("Less created {0}", lessOutput);
MSBuild(solution);
});
RunTarget(target);
This assumes you have Node & Gulp installed globally (you install Gulp
globally via running npm install -g gulp), also this was 5 min quick
and dirty, so you would want to divide clean/restore/less into separate
cake tasks. I set environment CI=true because some node modules
could require user interaction on restore otherwise.
Discarding MSBuild / NuGet restore above will output something like:
Cleaning old less output C:/temp/cake_issue_672/WebApplication1/WebApplication1/css/style.css
[11:26:12] Using gulpfile C:\temp\cake_issue_672\WebApplication1\WebApplication1\gulpfile.js
[11:26:12] Starting 'compile-less'...
[11:26:13] Finished 'compile-less' after 29 ms
Less created C:/temp/cake_issue_672/WebApplication1/WebApplication1/css/style.css
This might not be the solution you were working for, but it "should"
work.

UPDATE: There is now an addin for Cake for running Gulp Tasks. You can find it here
As to why using the MSBuild Alias in Cake is not invoking the BeforeBuild target we are not sure. Could I ask that you raise an issue here so that we can discuss it. Ideally, a sample project that demonstrates the problem could be provided so that we can investigate.
To answer your overall question though...
No, currently, there are no Cake Aliases/Addin's that support running Gulp Tasks as part of the build pipeline. That is not to say that this couldn't be done, simply that it hasn't been on our radar yet.
Having said that, given that you can write any arbitrary C# as part of your build script, there is no reason that you couldn't spawn out a process to invoke gulp with the necessary arguments to do the work.

Related

How to debug a Meteor plugin file?

I've followed Meteor Doc to register a plug-in package.
Created a plug-in file in the package/plugin/ folder
Added a debugger; in that file.
ran $ meteor debug;
Problem: debugger; directive is ignored. How to debug the plug-in file?
Thx!
plugin/compile-atscript.js:
Plugin.registerSourceHandler(
'ats'
, function (compileStep) {
var source = compileStep.read().toString('utf8');
console.log('source: ' + source);
debugger;
console.log('compiled source: ' + source);
});
The Meteor tool runs build plugins in-process, so you just need to run it under the debugger. On Linux and Mac OS X, the launcher script supports a TOOL_NODE_FLAGS variable that can be used to pass arguments to the Node.js runtime to enable debugging. See the instructions for debugging the Meteor tool, although these are geared toward use with a git checkout of Meteor. A hacky shortcut:
METEOR_INSTALLATION=~/.meteor/packages/meteor-tool/$(meteor --long-version | sed -ne 's/^meteor-tool#//p')/mt-$(meteor --arch)
TOOL_NODE_FLAGS=$METEOR_INSTALLATION/dev_bundle/lib/node_modules/node-inspector/bin/node-debug.js $METEOR_INSTALLATION/meteor
(Note, using just meteor on the last line may not work because when the default version of the Meteor tool executes the proper version for the app, the debugger would be started a second time.)
On Windows, support for TOOL_NODE_FLAGS was added to the launcher script in Meteor 1.4.4. If the app is using an older version of Meteor, one could manually edit the launcher script. The commands to start debugging would look like:
set METEOR_INSTALLATION=%LOCALAPPDATA%\.meteor\packages\meteor-tool\TOOL_VERSION\mt-os.windows.x86_32
set TOOL_NODE_FLAGS=%METEOR_INSTALLATION%\dev_bundle\lib\node_modules\node-inspector\bin\node-debug.js
%METEOR_INSTALLATION%\meteor.bat
(Someone else is welcome to add copy-and-pasteable code to figure out the correct TOOL_VERSION!)
On macOS
Set Environment variable
export TOOL_NODE_FLAGS="--inspect-brk"
List env vars
printenv
Run meteor
meteor
Debugger will be listening and will get attached to Chrome dev tools on opening the Chrome Browser.

Combine sbt tasks from different scopes

I use sbt with the native packager plugin, in order to build Debian packages for our Play 2.2 applications. We use the debian:publish in order to upload the packages to our Artifactory server, and the publish command to publish the regular Java jars.
I'd like to be able to use the regular publish command to published both the jar files and the Debian packages. I think I need to somehow combine the publish task in the Debian scope with the regular one in the Compile scope, but I can't really find any documentation on how to do that.
I came up with the following code, which works, but seems to me to be the 'wrong' way to do it:
publish := { // Also publish deb files
val value = publish.value
(publish in Debian).value
}
Especially the second line seems wrong, since it's ignoring the value. The val is there to quiet a warning, which is another smell.
Is there a better way to do this?
You can use triggeredBy. In your build.sbt add following line:
publish in Debian <<= (publish in Debian).triggeredBy(publish in Compile)
PS. I think the way you did it is also fine. If you're worried about the warning you can assign the result to some val.
Here, the dependsOn task is appropriate, if you don't care about the return value:
publish := publish.dependsOn(publish in Debian).value

Building Brackets Shell (After running the grunt build command)

On windows after running the grunt build command for creating brackets shell it gives done without errors but i dont see any .exe file generated..
What might be the problem???
Here are some possible solutions:
Are you following the full brackets-shell build instructions, including all prerequisites?
Make sure Brackets isn't running at the same time. The build will fail silently if the .exe file is currently in use (see bug).
Try with a fresh git clone of the repo. If your brackets-shell local copy has been around for a while, sometimes the build & deps folders can get in a bad state. (I'm assuming you haven't modified the source at all. If you have, try with an unmodified copy of the source first to make sure it builds correctly without any of your changes).
Check that python --version shows 2.7.x
Verbose build output would also be helpful in diagnosing issues like this, but unfortunately there's not yet an easy way to get that...
If you follow the instructions on bracket-shell's wiki page, the Windows executable should be created in the Release directory.

Generating a SpecRunner for jasmine using grunt

When i add and remove tests i often have to create/edit a SpecRunner.html file.
I know i can run a test server using karma. But for developing tests i prefer to inspect the results in the browser. I've tried using karma and i currently run tests with grunt; but sometimes i prefer the console better for writing tests.
Are there yeoman generators that will generate a specrunner for me automatically at this point in time?
I've found this npm package: https://npmjs.org/package/atropa-jasmine-spec-runner-generator-html
but it doesn't seem widely supported or runs via grunt.
grunt-template-jasmine-requirejs is a good option for Angular/Backbone projects. It is meant to work with grunt-contrib-jasmine, but it will generate a spec runner html file for you on the fly using grunt.
Specify the output in the gruntfile
jasmine:{
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfigFile: 'src/test/js/require-unit-config.js'
},
test:{
options:{
outfile:'mySpecRunner.html'
}
}
}

adobe brackets-shell : cef extract failed

I followed all the step is mention in given below url to build my project( I am using win7 OS).
https://github.com/adobe/brackets-shell/wiki/Building-brackets-shell.
actullly i want to create brackets installer (installed wix 3.7).
but i am getting cef-extract failed error.
even though i also used grunt cef-extract --force.
after that its throunging new error.
create -project failed after that i am not able to process further.
can some one help me.
thanks in advanced.
Regards
ashish .
If you include the exact console output you're seeing, it would be much easier to help you. But based on snags other people have encountered recently, you can try these things:
Make sure your PATH includes Python 2.7 (otherwise "create-project" will fail).
Delete all these folders to be sure you're starting from a clean slate: deps, Debug, include, libcef_dll, Release, Resources.
Just run the high-level tasks grunt setup and grunt build, following the Building brackets-shell instructions. (There's a known bug where grunt cef-extract fails when run standalone).

Resources