Code Monkey home page Code Monkey logo

cake.npm's Introduction

Cake.Npm Addin

This Addin for the Cake Build Automation System allows you to run npm. More about Cake at cakebuild.net.

License

Information

Stable Pre-release
GitHub Release - GitHub release
NuGet NuGet NuGet

Build Status

Develop Master
Build status Build status

Code Coverage

Coverage Status

Quick Links

Discussion

If you have questions, search for an existing one, or create a new discussion on the Cake GitHub repository, using the Extension Q&A category.

Join in the discussion on the Cake repository

Contributing

Contributions are welcome. See Contribution Guidelines.

cake.npm's People

Contributors

agc93 avatar andriwandres avatar augustoproiete avatar austinlparker avatar bulldetektor avatar davemiscampbell avatar devlead avatar eoehen avatar gep13 avatar gitfool avatar jeffpardy avatar jokay avatar mdenny-visaglobal avatar nils-a avatar pascalberger avatar phillipsj avatar philo avatar renovate[bot] avatar wozzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cake.npm's Issues

Convert this repo to use Cake.Recipe

@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...

  • a single place to control all the builds in the cake-contrib organisation
  • access to notifications on twitter and gitter when new releases are available

Things that Cake.Recipe already does:

  • Version with GitVersion
  • Build
  • Compile
  • Run Unit Tests
  • Submit results to coveralls.io
  • NuGet Package everything
  • Upload all artifacts to AppVeyor
  • Runs DupFinder
  • Runs InspectCode
  • Handles publishing to both MyGet and NuGet (for interim releases)
  • Runs GitLink, meaning that addin code is debuggable doing debug session in visual studio when debugging build.cake
  • Documentation Website generation using Wyam

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?

Use same issue labels as other cake-contrib projects

Most project in the cake-contrib organization use the following issue labels:

  • Breaking change
  • Bug
  • Build
  • Documentation
  • Feature
  • Improvement
  • Up-for-grabs

We should consider to also switch to use the same labels

Add option to use `npm set`

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 ;)

Run an nom module

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?

How to implement directory switching

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.

Thoughts @Philo , @nengberg or anyone else?

add support for npm update

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.

Unable to use .WithArguments as extension method

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 fluent API to settings classes

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/.

Npm Logging Level

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!

/cc @Philo @agc93

Support for npm ci

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.

CakeBuild Experimental mode (Rosyln C# 6) breaks WithLogLevel()

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();

Bring back possibility to run scripts from another path

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!

Clean up use of interfaces in NpmRunner

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.

Update Documentation

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.

Recommended changes resulting from automated audit

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:

  • You are currently referencing Cake.Core 0.26.0. Please upgrade to 0.28.0
  • Your addin should target netstandard2.0. Please note that there is no need to multi-target, netstandard2.0 is sufficient.

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.

https://github.com/cake-contrib/Cake.MsDeploy/pull/31

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)

Latest version breaks build

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.

Add support for npm-cache

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.

Passing invalid logLevel argument after migration to 0.9.0

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).

Switch to GitFlow

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.

Support pack command

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:

  1. Add the pack command to this library, then I will call it myself
  2. Copy most of my code (which also does the copy/paste from a specific directory, updates the version, then packs it (still requires 1 though).

What's the easiest?

Cake.Npm Failing to Install

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)

Using aliases for each command

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.

Add "error" log level

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

Support Cake 0.26.0

Hi.
This morning the cake version with Cake.Npkm went out of sync. Please build and publish with latest cake.core :-)

Error: Failed to install addin 'Cake.Npm'.

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'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.