How can I run grunt on AppHarbor through MSBuild? - msbuild

I can build my solution with MSBuild. It runs grunt and generates a "dist" folder within the solution directory, and MSBuild then copy those files to $(OutDir).
Let's say my solution is called  MySolution.sln. I have next to it another file called after.MySolution.sln.targets which contains
<!--?xml version="1.0" encoding="utf-8"?-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Grunt" AfterTargets="Build">
<Exec Command="grunt build --no-color" WorkingDirectory="$(MSBuildProjectDirectory)" />
<ItemGroup>
<DistFiles Include="$(MSBuildProjectDirectory)\dist\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(DistFiles)" DestinationFolder="$(OutDir)\www\%(RecursiveDir)" />
</Target>
</Project>
When AppHarbor builds the solution, I receive this error
Grunt:
grunt build --no-color
'grunt' is not recognized as an internal or external command,
operable program or batch file.
Which is understandable, if grunt-cli was not already made available by AppHarbor. How then can I run my grunt build on AppHarbor?
Note: Technically, to run grunt successfully, I need to run npm install and bower install, so kudos if the answer also covers grunt packages and bower packages!

In order to run my build, I had to use node directly rather than grunt-cli. My MSBuild now simply calls run-grunt.bat, which contains:
#echo off
echo Installing npm dependencies
call npm config set registry http://registry.npmjs.org/
call npm install
echo Running bower.commands.install()
call node -e "var b = require('bower'); b.commands.install()"
echo Running grunt.cli()
call node -e "var g = require('grunt'); g.cli.tasks = ['build']; g.cli.options.color = false; g.cli();"
It seems to work; the next issue is that node on the build servers is still at version 0.6.10, but that's another problem :)
Note that I add the registry because otherwise it didn't work (I'll have to check with AppHarbor), and since I use bower and probably other people will too, I included in my example how to run bower install.
Important: you'll need to include grunt (and bower if you use it) in your packages.json file!

Related

MSBuild can't exec command `npm i` while compiling a project in Rider/Visual Studio

I need to build and run a .NET 5 project in Mac using Visual Studio for Mac or Jetbrains Rider.
In csproj file of one of the projects in the solution, I have following Target:
<Target Name="SassBuild" BeforeTargets="Build" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Exec Command="npm i" />
<Exec Command="npm rebuild node-sass" />
<Exec Command="npm run gulp-sass" />
<Exec Command="npm run gulp-js" />
</Target>
When I run dotnet build or dotnet msbuild project builds just fine, however building it in VS/Rider throws the following error:
Error MSB3073: The command "npm i" exited with code 127. (MSB3073)
Details in the log:
Target SassBuild:
npm i
/var/folders/9l/d02_tk1j5f93vklft82p1z996dm09b/T/tmp89785a0aeebb4347a3696de11d8c281e.exec.cmd: line 2: npm: command not found
PATH_TO_CSPROJ_HERE.csproj(232,5): error MSB3073: The command "npm i" exited with code 127.
Done building target "SassBuild" in project "X.csproj" -- FAILED.
npm is installed already and I can run the npm commands in terminal. I use nvm for node versioning.
Any ideas?
Alright, I figured out that Mac OS terminal and VS/Rider terminals are not fed from the same terminal configuration files; that's why the IDEs weren't able to find the npm in their paths.
I copied all the nvm related configuration from ~/.zprofile to ~/.profile and now I am able to build the project in VS/Rider.
Hope it helps anyone having the same problem.

Can "npm run build" only be run from the folder that contains the package.json file?

When running npm run build from the command line, can it only be used in the folder that contains the package.json file?
I think yes because npm build is an internal command and npm build [<package-folder>] So, the folder containing a package.json file in its root.And as per documentation.
This is the plumbing command called by npm link and npm install. It should generally not be called directly.
From here,we can say that the env script is a special built-in command that can be used to list environment variables that will be available to the script at runtime. If an “env” command is defined in your package, it will take precedence over the built-in.
In addition to the shell’s pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix. For example, if there is a devDependency on tap in your package

Bamboo build fails because webpack donesn't find node_modules

I have configured my project on angular 1.7 with webpack. In local when I run the task npm run build (launchin webpack) everything goes correctly.
But I have a plan for my CI bamboo and when a run the NPM task with npm run build I got a message, which said:
Error: Cannot find module './yargs'
I have the intuition that webpack is not able to reach the node_modules or is not in current directory.
But node_modules is installed and yargs is there after making the npm install task before.
if I run a script before the npm run build with just "ls -l" command I get:
node_modules
package-lock.json
package.json
src
webpack.config.js
So the folder is there.
Any idea where I can take a look?
I found the solution for the issue. In the Source code checkout configuration the "Force clean build" has been checked and now the build succed.
I'm not sure why, but there must have been a conflict with a previous node_modules.
The spelling of the file that you're referring is case-sensitive when building via bamboo
building locally wouldn't give you any error nor warnings in the console.
I encountered this issue with a local file (not a node_module)... Hoping this would help someone in the future;

configure a different path per client deps in npm

In an asp.net core project all the client files must to be copied under the approot directory to be deployed correctly: jspm let you define a proper directory for client deps, but with npm I have to copy the files from node_modules
directory to the approot\node_modules using a gulp task.
Since I'm not interested in filtering or manipulating the files before the deploy, but I just what that the files in the installed module are deployed, there is some way to do this without use gulp ?
You can use npm to do that. Add a script to your package.json:
"scripts": {
"copy": "xcopy from to"
}
Then you can call npm run-script copy to have it executed. I used xcopy as an example, you can use whatever you like. There is some more documentation about scripts in npm.

Do we have to install/deploy parent maven module to use submodule?

lets say we have a ParentPom.xml and there are sub child modules under it; subModule-A and subModule-B. I want to use subModule-A.jar in an another project. If i run "mvn install" command only in subModule-A directory i can install it into my M2 repository but after i define dependency to it from my other project it says something "no parent found for subModule-A". It is OK if i run install command for ParentPom.xml.
Any idea about this problem?
Thx...
You need to install / deploy all modules that are referenced by submodule-A, including the parent.
You can do it like this:
mvn deploy -pl submodule-a -am
Which translates to
deploy module submodule (-pl submodule-a)
and all of it's dependencies in the current reactor project (-am)
Call mvn -help to see all possible command line options