cake-contrib / cake.npm Goto Github PK
View Code? Open in Web Editor NEWA set of aliases for Cake to help with running Npm (Node Package Manager) commands
Home Page: https://cake-contrib.github.io/Cake.Npm/
License: MIT License
A set of aliases for Cake to help with running Npm (Node Package Manager) commands
Home Page: https://cake-contrib.github.io/Cake.Npm/
License: MIT License
Add the ability to specify --registry
in NpmInstallSettings
Build against Cake 0.22
There are currently aliases for running Npm scripts and running Npm install. There is no alias or available way to call Npm update. https://docs.npmjs.com/cli/update
In CI builds I would like to run Npm update from Cake so that I don't have to clear out all node_modules on each build and then install to ensure I have the latest versions. I should be able to run Npm update to update out of date packages without re-installing everything.
With the latest NuGet v0.9.0 we have started getting compile time error
The name 'Npm' does not exist in the current context
If I specify v0.8.0 in the cake script, it works just fine: #addin "nuget:?package=Cake.Npm&version=0.8.0"
So something is broken with the latest release.
Support for the npm publish
command would be nice.
It would be nice if the npm.pack alias would return the name, or even better FilePath
of the created package.
My project has a bunch of them defined in the packages.json and I'm not able to execute them with the install command alone. https://docs.npmjs.com/cli/run-script. I'll fix it in my fork and create a PR.
As Cake.Npm is often run on build servers, adding support for npm-cache sounds logical.
https://www.npmjs.com/package/npm-cache
Since npm-cache is just a wrapper around npm|bower|composer|jspm, it would rather easy to implement by just
protected override IEnumerable<string> GetToolExecutableNames()
{
yield return "npm-cache.cmd";
yield return "npm-cache";
yield return "npm.cmd";
yield return "npm";
}
On my machine that would improve the speed of running npm(-cache) install
from 6 minutes down to 1 min 15 secs on the second run provided that my package.json hasn't changed.
@Philo I am pretty much at the point where my not so secret project, Cake.Recipe, is ready to be rolled out.
Would you be interested in me adding it to this repository?
The benefits would be...
Things that Cake.Recipe already does:
Probably other stuff that I have forgotten.
The main thing being, if we add something to Cake.Recipe, then all projects that are already using Cake.Recipe should be able to immediately take advantage of it.
Thoughts? If you were interested, would you be happy to have me make the changes directly to repo, or would you prefer it as a PR?
I think the "error" log level is missing from NpmLogLevel.
Although it has no shortcut option (e.g. -d) it is a valid value when passed to the long from of --loglevel (at least on Windows).
Cheers,
Gian
In npm version 5.7.1 new npm ci
command was added - link
It would be helpful to have a possibility running this from Npm cake package in order to improve CI build time.
I am trying to generate an npm package using cakebuild. I am nearly there, and would like to add this support to this package.
We can do a few things:
What's the easiest?
I don't know what the reasons were why this addin only provides one alias npm
instead of individual aliases for all commands (like NpmInstall
, NpmRun
). While the current approach seems to be nice from an implementation point of view from the addin, IMHO it is more difficult to use in a build script, results in worse documentation since otherwise all aliases would be nicely be documented and now one needs to browse the API documentation. Also currently there's no editor providing IntelliSense support for Cake which also makes it harder to use.
If there is interested in having this addin changed to use individual aliases instead, I can create a PR for this.
moved from #27
Hi,
In the previous version of Cake.Npm we used the fluent syntax to enable running scripts from a specific path. Like Npm.FromPath("./SomeFolder").RunScript("some-script");
We used this since our build uses two working folders, one installed with Production, one without.
In the 0.9.0 release, the fluent syntax is gone and I can't seem to figure out how to do that same operation given the new aliases. This was a great feature and bringing it back (or explaining how it is supposed to be done now) would be much appreciated.
Thanks!
Add alias for calling npm rebuild
This is in relation to #3 and #8 in particular. The Tool<T>
class now has a GetWorkingDirectory
method that can be used to "natively" switch directory a given tool. My thinking is rather than baking it just in to the Install
or RunScript
command, we could add it at an alias level.
Currently, Npm
is a CakePropertyAlias
, but if we add a CakeMethodAlias
that takes a Path
as a parameter, it could apply no matter the command. Syntax would be something like:
//for the default (current behaviour)
Npm.RunScript("test");
Npm.Install();
// or to operate on another directory
Npm("./path/to/package.json").RunScript("test");
Npm("./path/to/package/dir").Install();
That way, we can pass the path straight to NpmRunner
and have access, no matter what command we're running.
I have only seen this with the .WithArguments extension on NpmRunScriptSettings (https://github.com/cake-contrib/Cake.Npm/blob/develop/src/Cake.Npm/RunScript/NpmRunScriptSettingsExtensions.cs#L16-L31). If I try to use it like so:
Task("JS-Tests")
.IsDependentOn("NPM-Install")
.DoesForEach(GetFiles("../root/*/karma.conf.js"), (suite) =>
{
var settings = new NpmRunScriptSettings { ScriptName = "test", WorkingDirectory = "../root" };
settings = settings.WithArguments(suite).WithArguments(suite).WithArguments("--single-run");
NpmRunScript(settings);
});
I get the following error on script compilation:
error CS1929: 'NpmRunScriptSettings' does not contain a definition for 'WithArguments' and the best extension method overload 'ProcessSettingsExtensions.WithArguments(ProcessSettings, Action)' requires a receiver of type 'ProcessSettings'
The only way around I have found is to define my task like so:
Task("JS-Tests")
.IsDependentOn("NPM-Install")
.DoesForEach(GetFiles("../root/*/karma.conf.js"), (suite) =>
{
var settings = new NpmRunScriptSettings { ScriptName = "test", WorkingDirectory = "../root" };
settings = Cake.Npm.RunScript.NpmRunScriptSettingsExtensions.WithArguments(settings, suite.ToString());
settings = Cake.Npm.RunScript.NpmRunScriptSettingsExtensions.WithArguments(settings, "--single-run");
NpmRunScript(settings);
});
Is there something special I need to do in my build script to use .WithArguments as an extension method?
Add the ability to specify --prefer-offline
in NpmInstallSettings
Can I run an npm module with these extensions?
I'd need to run the command:
markdown-pdf -o output.pdf input.md
Should I use these extensions to both install the module and run it, or just to install it but run it using a normal process call?
I have only just started using this Addin, so I could be missing something REALLY obvious, but...
When I use this Addin to do an NPM install of a tool that is required in my Cake Build, the resulting logs in my AppVeyor window become almost unusable, as they are populated with multiple warnings, which actually show up as red error text in AppVeyor.
Have a look here:
https://ci.appveyor.com/project/cakebuild/cake-vso/build/0.3.0-unstable.16.build.21#L132
As an example.
Is there anything that can be done about this? Thanks!
My original cake script for executing eslint task in package.json was:
Npm.FromPath("./Frontend/").RunScript("eslint -- -f html -o ./../reports/eslint.html");
To make it compatible with version 0.9.0 I changed it to this:
var settings = new NpmRunScriptSettings()
{
WorkingDirectory = "./Frontend/",
ScriptName = "eslint"
};
settings.Arguments.Add("-f html");
settings.Arguments.Add("-o ./../reports/eslint.html");
NpmRunScript(settings);
Now the script will fail during the run time with following error.
========================================
RunEslintFrontend
========================================
Executing task: RunEslintFrontend
Using addin: Cake.Npm v0.9.0.0 (0.9.0+Branch.master.Sha.41a1dc81c79996314343b2f8ef8840581ac56f36)
npm arguments: run-script "eslint" -- -f html -o ./../reports/eslint.html --loglevel info
> [email protected] eslint D:\git\Engage\Frontend
> eslint . --ext .js --ext .jsx "-f" "html" "-o" "./../reports/eslint.html" "--loglevel" "info"
Invalid option '--loglevel' - perhaps you meant '--global'?
If I understand it correctly the --loglevel info
should be before the double dash to be recognized as argument for npm itself. Now it is sent to underlying command (eslint in my case).
Use default cake-contrib readme
As of writing this is v0.19.3
It would be helpful to support npm version
to be able to bump the version easily from Cake.
Reference: https://docs.npmjs.com/cli/version
Add CONTRIBUTING.md
Add the ability to specify --no-optional
in NpmInstallSettings
Description
Cake Core has been updated but Cake.Npm still referencing older version.
My guess is that all Cake.XXX needs this fix. It has already been solved for Cake.MsDeploy
Related
cake-contrib/Cake.MsDeploy#31
Error
Error: The assembly 'Cake.Npm, Version=0.12.1.0, Culture=neutral, PublicKeyToken=null'
is referencing an older version of Cake.Core (0.22.0).
This assembly need to reference at least Cake.Core version 0.26.0.
Another option is to downgrade Cake to an earlier version.
It's not recommended, but you can explicitly opt-out of assembly verification
by configuring the Skip Verification setting to true
(i.e. command line parameter "--settings_skipverification=true",
environment variable "CAKE_SETTINGS_SKIPVERIFICATION=true",
read more about configuration at https://cakebuild.net/docs/fundamentals/configuration)
Cake documentation is out of date on master branch; haven't checked others.
When running the example
#addin "Cake.Npm"
var target = Argument("target", "Default");
Task("Example").Does(() => {
var settings = new NpmInstallSettings();
settings.Global = true;
settings.Production = false;
settings.LogLevel = NpmLogLevel.Verbose;
settings.AddPackage("gulp");
settings.AddPackage("left-pad");
NpmInstall(settings);
});
Task("PackageJsonFromDirectory").Does(() => {
var settings = new NpmInstallSettings();
settings.LogLevel = NpmLogLevel.Info;
settings.WorkingDirectory = "usage/";
settings.Production = true;
NpmInstall(settings);
});
Task("Default")
.IsDependentOn("Example")
.IsDependentOn("PackageJsonFromDirectory");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);
I get the error
scripts/build/FED-Marketing-Website.cake(10,9): error CS0103: The name 'Npm' does not exist in the current context
However, modifying the build scripts to perform similarly to this Stackoverflow post It works as expected.
Since yesterday, I am seeing strange issues when using this addin:
Downloading NuGet.exe...
Installing Cake...
Running build script...
Analyzing build script...
Processing build script...
Installing tools...
Installing addins...
Could not find any assemblies compatible with .NETFramework,Version=v4.5.
Error: Failed to install addin 'Cake.Npm'.
We performed an automated audit of your Cake addin and found that it does not follow all the best practices.
We encourage you to make the following modifications:
Apologies if this is already being worked on, or if there are existing open issues, this issue was created based on what is currently published for this package on NuGet.org and in the project on github.
This will also implement the addin for both netstandard1.6
and net46
The use of the INpmRunnerCommands
and INpmRunnerConfiguration
interfaces seems to be quite inconsistent.
While INpmRunnerConfiguration.FromPath
returns an INpmRunnerCommands
, INpmRunnerConfiguration. WithLogLevel
returns an INpmRunnerConfiguration
. IMHO it should be possible to write either Npm.FromPath("C:\foo").WithLogLevel(NpmLogLevel.Silent).Install()
or Npm.WithLogLevel(NpmLogLevel.Silent).FromPath("C:\foo").Install()
.
Also it is not clear to me why the methods of INpmRunnerCommands
return an INpmRunnerCommands
object and not void
or the output of the specific npm command?
One last thing is that there is an NpmRunner.Pack
, but no INpmRunnerCommands.Pack
, which makes it impossible to use with the INpmRunnerConfiguration
functions.
If there's interested in having this cleaned up I can write a PR.
Some people prefere a fluent syntax for building the settings for an alias. We should add overloads to the aliases which an Action
can be passed returning the concrete settings class. Additional there should be extensions on the settings classes which allow to build the settings object in a fluent syntax.
Similar to http://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildAliases/F36093FE and http://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildSettings/.
Build against Cake 0.28.0
The NuGet package should contain the XML documentation files to allow proper documentation on http://cakebuild.net/api/Cake.Npm.dll/
I am using Cake.Npm in a cake build file and recently started receiving this error:
Error: Method not found: "Cake.Core.Tooling.IToolLocator Cake.Core.ICakeContext.get_Tools()"
Is Cake.Npm not compatible with the newest versions of Cake?
It looks like Cake just pushed 0.22.0 so the addin is currently failing on install.
Restoring NuGet package Cake.0.22.0.
GET https://api.nuget.org/v3-flatcontainer/cake/0.22.0/cake.0.22.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/cake/0.22.0/cake.0.22.0.nupkg 128ms
Installing Cake 0.22.0.
Adding package 'Cake.0.22.0' to folder 'Path'
Added package 'Cake.0.22.0' to folder 'Path'
Analyzing build script...
Processing build script...
Installing tools...
Installing addins...
Error: The assembly 'Cake.Npm, Version=0.11.0.0, Culture=neutral, PublicKeyToken=null'
is referencing an older version of Cake.Core (0.18.0).
This assembly need to reference at least Cake.Core version 0.22.0.
Another option is to downgrade Cake to an earlier version.
It's not recommended, but you can explicitly opt-out of assembly verification
by configuring the Skip Verification setting to true
(i.e. command line parameter "--settings_skipverification=true",
envrionment variable "CAKE_SETTINGS_SKIPVERIFICATION=true",
read more about configuration at https://cakebuild.net/docs/fundamentals/configuration)
This is more as a Public Service Announcement than an issue.
If you enable Experimental
mode in Cake to get some of lovely C# 6 features, you will get the following error for:
Npm.WithLogLevel(NpmLogLevel.Silent).Install();
error CS1061: 'INpmRunnerConfiguration' does not contain a definition for 'Install' and
no extension method 'Install' accepting a first argument of type 'INpmRunnerConfiguration'
could be found (are you missing a using directive or an assembly reference?)
Workaround, you need to cast the INpmRunnerConfiguration
to NpmRunner
.
((NpmRunner)Npm.WithLogLevel(NpmLogLevel.Silent)).Install();
In preparation for moving to Cake.Recip (#18) it would be helpful to change Git workflow to GitFlow as most projects in the cake-contrib organization are using.
Use Cake Contrib icon instead of official Cake icon
It sounds reasonable to be able to use npm set
on build servers. I'd like for instance to be able to disable the progress just before running npm install as that would improve the speed significantly. Having an extra cake command to use "npm set", would enable us to configure the npm settings on the build server.
http://biercoff.com/how-to-crazy-easily-speed-up-your-npm-install-speed/
This would also allow for setting the registry to be used on the build server/agent for npm to use. Of course you would need a login command there as well ;)
Add option to redirect standard error and output streams
Add Wyam documentation site
Most project in the cake-contrib organization use the following issue labels:
We should consider to also switch to use the same labels
From discussion in #2
.Package(DirectoryPath path)
.Package(FilePath path)
Hi.
This morning the cake version with Cake.Npkm went out of sync. Please build and publish with latest cake.core :-)
Add the ability to specify --production
in NpmCiSettings
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.