Skip to content
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

add basic npm support #993

Merged
merged 2 commits into from
Nov 4, 2015
Merged

add basic npm support #993

merged 2 commits into from
Nov 4, 2015

Conversation

mastoj
Copy link
Contributor

@mastoj mastoj commented Nov 1, 2015

This small feature makes it really easy to run Npm task for build frontend projects. This also opens up for running gulp, grunt or some other frontend build tool by calling them from Npm.

To get started on Windows:

Add the following to build.cmd:

NuGet.exe "Install" "Node.js" "-OutputDirectory" "packages" "-ExcludeVersion"
NuGet.exe "Install" "Npm.js" "-OutputDirectory" "packages" "-ExcludeVersion"

Then you can run task like:

Target "Web" (fun _ ->
    Npm (fun p ->
      { p with
          Command = Install Standard
          WorkingDirectory = "./src/FAKESimple.Web/"
      })

    Npm (fun p ->
      { p with
          Command = (Run "build")
          WorkingDirectory = "./src/FAKESimple.Web/"
      })
)

Haven't tried it on *nix yet, but it should work there as well since you can override the path to npm. I have also provided defaults for *nix and Windows.

@bjartwolf
Copy link
Contributor

I was able to make this work on Windows like this, running tasks in Grunt etc.
Confirmed that it worked on TeamCity CI build but I haven't yet uninstalled node.js from the build servers, but I tried to uninstall node.js from my machine and was able to build and run tests through grunt.

Target "RestoreLocalPackages" (fun _ -> 
     RestorePackageId (fun p -> { p with ExcludeVersion = true 
                                         ToolPath = "../.nuget/NuGet.exe"
                                         OutputPath = "packages" 
                                         Version = Some (new System.Version(4,0,0)) }) "Node.js" 
     RestorePackageId (fun p -> { p with ExcludeVersion = true 
                                         ToolPath = "../.nuget/NuGet.exe"
                                         OutputPath = "packages" 
                                         Version = Some (new System.Version(2,13,1)) }) "Npm.js" 

)


Target "PreBuild" (fun _ ->
    Npm (fun p ->
            { p with
                Command = Custom ("install grunt") })
    Npm (fun p ->
            { p with
                Command = Run ("fakeprebuild") })
    Npm (fun p ->
            { p with
                Command = Run ("faketest") })
)

Target "NpmInstall" (fun _ ->
    Npm (fun p ->
            { p with
                Command = Install Standard
                WorkingDirectory = "Nrk.Programspiller.Frontend" }))

A trick which could probably be documented in a separate page about using Npm with Fake is that to run grunt tasks without installing node.js and grunt etc globally I had to do this:

  "scripts": {
    "faketest": "Frontend\\packages\\Node.js\\node.exe -e \"require('grunt').tasks(['karma:ci', 'zip'], {color: false});\"",
    "fakeprebuild": "Frontend\\packages\\Node.js\\node.exe -e \"require('grunt').tasks(['publish'], {color: false});\""
  },```

@forki
Copy link
Member

forki commented Nov 4, 2015

please let me know when if this is ready to merge.

@mastoj
Copy link
Contributor Author

mastoj commented Nov 4, 2015

@bjartwolf do you think it is good enough to work? I think so, since it is really hard to know exactly how the users want to use npm. The helper tries to be helpful in that you can override where npm is.

I can try to run it using a global installed version of node and npm since that is another use case as well as try it on osx. I'll try to do that later today.

@mastoj
Copy link
Contributor Author

mastoj commented Nov 4, 2015

I've now tried it with global npm in Windows and also in OSX and get it to run without problem. So if you think it looks good I think it is ready be merged.

forki added a commit that referenced this pull request Nov 4, 2015
@forki forki merged commit a9e289c into fsprojects:master Nov 4, 2015
@forki
Copy link
Member

forki commented Nov 4, 2015

very cool!

@bjartwolf
Copy link
Contributor

I see it is already closed but I agree and thanks, very useful for us!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants