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

Convert YarnHelper to module #1868

Merged
merged 1 commit into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E09B72E4-D
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Core.CommandLine.UnitTests", "src/test/Fake.Core.CommandLine.UnitTests/Fake.Core.CommandLine.UnitTests.fsproj", "{8561A35A-C2A4-43C7-A938-CB35A7747121}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.JavaScript.Yarn", "src/app/Fake.JavaScript.Yarn/Fake.JavaScript.Yarn.fsproj", "{DE7579F2-C20F-4C35-BC04-C10362912243}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -666,6 +668,18 @@ Global
{8561A35A-C2A4-43C7-A938-CB35A7747121}.Release|x64.Build.0 = Release|x64
{8561A35A-C2A4-43C7-A938-CB35A7747121}.Release|x86.ActiveCfg = Release|x86
{8561A35A-C2A4-43C7-A938-CB35A7747121}.Release|x86.Build.0 = Release|x86
{DE7579F2-C20F-4C35-BC04-C10362912243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE7579F2-C20F-4C35-BC04-C10362912243}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE7579F2-C20F-4C35-BC04-C10362912243}.Debug|x64.ActiveCfg = Debug|x64
{DE7579F2-C20F-4C35-BC04-C10362912243}.Debug|x64.Build.0 = Debug|x64
{DE7579F2-C20F-4C35-BC04-C10362912243}.Debug|x86.ActiveCfg = Debug|x86
{DE7579F2-C20F-4C35-BC04-C10362912243}.Debug|x86.Build.0 = Debug|x86
{DE7579F2-C20F-4C35-BC04-C10362912243}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE7579F2-C20F-4C35-BC04-C10362912243}.Release|Any CPU.Build.0 = Release|Any CPU
{DE7579F2-C20F-4C35-BC04-C10362912243}.Release|x64.ActiveCfg = Release|x64
{DE7579F2-C20F-4C35-BC04-C10362912243}.Release|x64.Build.0 = Release|x64
{DE7579F2-C20F-4C35-BC04-C10362912243}.Release|x86.ActiveCfg = Release|x86
{DE7579F2-C20F-4C35-BC04-C10362912243}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -719,6 +733,7 @@ Global
{CA6EB1B3-EB3A-4063-8A6C-DE099A53A8B1} = {901F162F-8925-4390-89C5-9EE2C343F744}
{E09B72E4-D890-46A8-8D14-7367C2E23E9D} = {539D7B9A-18A1-4D79-86AB-C8B48090CA84}
{8561A35A-C2A4-43C7-A938-CB35A7747121} = {E09B72E4-D890-46A8-8D14-7367C2E23E9D}
{DE7579F2-C20F-4C35-BC04-C10362912243} = {901F162F-8925-4390-89C5-9EE2C343F744}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {058A0C5E-2216-4306-8AFB-0AE28320C26A}
Expand Down
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ let dotnetAssemblyInfos =
"Fake.DotNet.Testing.MSTest", "Running mstest test runner"
"Fake.DotNet.Xamarin", "Running Xamarin builds"
"Fake.JavaScript.Npm", "Running npm commands"
"Fake.JavaScript.Yarn", "Running Yarn commands"
"Fake.IO.FileSystem", "Core Filesystem utilities and globbing support"
"Fake.IO.Zip", "Core Zip functionality"
"Fake.Net.Http", "HTTP Client"
Expand Down
17 changes: 17 additions & 0 deletions src/app/Fake.JavaScript.Yarn/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Running Yarn commands")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0-rc004")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Running Yarn commands"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0-rc004"
let [<Literal>] AssemblyFileVersion = "5.0.0"
17 changes: 17 additions & 0 deletions src/app/Fake.JavaScript.Yarn/Fake.JavaScript.Yarn.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>netstandard1.6;netstandard2.0</TargetFrameworks>
<AssemblyName>Fake.JavaScript.Yarn</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Yarn.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
170 changes: 170 additions & 0 deletions src/app/Fake.JavaScript.Yarn/Yarn.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
namespace Fake.JavaScript

open Fake.Core
open Fake.IO
open System
open System.IO

[<RequireQualifiedAccess>]
module Yarn =

/// Default paths to Yarn
let private yarnFileName =
Process.tryFindFileOnPath "yarn"
|> function
| Some yarn when File.Exists yarn -> yarn
| _ ->
match Environment.isWindows with
| true -> "./packages/Yarnpkg.js/tools/yarn.cmd"
| _ -> "/usr/bin/yarn"

/// Arguments for the Yarn install command
type InstallArgs =
| Standard
| Flat
| Force
| Har
| NoLockFile
| Production
| PureLockFile

/// The list of supported Yarn commands. The `Custom` alternative
/// can be used for other commands not in the list until they are
/// implemented
type YarnCommand =
| Install of InstallArgs
| Custom of string

/// The Yarn parameter type
type YarnParams =
{ Src: string
YarnFilePath: string
WorkingDirectory: string
Timeout: TimeSpan }

/// Yarn default parameters
let defaultYarnParams =
{ Src = ""
YarnFilePath = yarnFileName
WorkingDirectory = "."
Timeout = TimeSpan.MaxValue }

let private parseInstallArgs = function
| Standard -> ""
| Flat -> " --flat"
| Force -> " --force"
| Har -> " --har"
| NoLockFile -> " --no-lockfile"
| Production -> " --production"
| PureLockFile -> " --pure-lockfile"

let private parse = function
| Install installArgs -> sprintf "install%s" (installArgs |> parseInstallArgs)
| Custom str -> str

let private run yarnParams command =
let yarnPath = Path.GetFullPath(yarnParams.YarnFilePath)
let arguments = command |> parse
let exitCode =
Process.execSimple (fun info ->
{ info with
FileName = yarnPath
WorkingDirectory = yarnParams.WorkingDirectory
Arguments = arguments
}
) yarnParams.Timeout

if exitCode <> 0 then failwith (sprintf "'yarn %s' task failed" arguments)

let private yarn setParams = defaultYarnParams |> setParams |> run


/// Run `yarn install`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.install (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let install setParams = yarn setParams <| Install Standard

/// Run `yarn install --production`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.installProduction (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })

let installProduction setParams = yarn setParams <| Install Production

/// Run `yarn install --force`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.installForced (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let installForced setParams = yarn setParams <| Install Force

/// Run `yarn install --flat`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.installFlat (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let installFlat setParams = yarn setParams <| Install Flat


/// Run `yarn install --har`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.installHar (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let installHar setParams = yarn setParams <| Install Har

/// Run `yarn install --no-lockfile`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.installNoLock (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let installNoLock setParams = yarn setParams <| Install NoLockFile

/// Run `yarn install --pure-lockfile`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.installPureLock (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let installPureLock setParams = yarn setParams <| Install PureLockFile

/// Run `yarn <command>`
/// ## Parameters
/// - 'setParams' - set command parameters
/// ## Sample
///
/// Yarn.exec "someCommand" (fun o ->
/// { o with
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
let exec command setParams = yarn setParams <| Custom command
4 changes: 4 additions & 0 deletions src/app/Fake.JavaScript.Yarn/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
group netcore

FSharp.Core
NETStandard.Library
3 changes: 3 additions & 0 deletions src/legacy/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@
<Compile Include="..\..\app\Fake.JavaScript.Npm\Npm.fs">
<Link>Fake.JavaScript.Npm/Npm.fs</Link>
</Compile>
<Compile Include="..\..\app\Fake.JavaScript.Yarn\Yarn.fs">
<Link>Fake.JavaScript.Yarn/Yarn.fs</Link>
</Compile>
<Compile Include="..\..\app\Fake.Tools.Git\CommandHelper.fs">
<Link>Fake.Tools.Git/CommandHelper.fs</Link>
</Compile>
Expand Down
9 changes: 9 additions & 0 deletions src/legacy/FakeLib/YarnHelper.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// Contains function to run yarn tasks
[<System.Obsolete("FAKE0001 Use the Fake.JavaScript.Yarn module instead")>]
module Fake.YarnHelper
open Fake
open System
Expand Down Expand Up @@ -29,6 +30,7 @@ let private yarnFileName =
proc.StandardOutput.ReadLine()
| _ -> "/usr/bin/yarn"

[<System.Obsolete("FAKE0001 Use the Fake.JavaScript.Yarn module instead")>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the attribute to the module as well.

/// Arguments for the Yarn install command
type InstallArgs =
| Standard
Expand All @@ -42,13 +44,15 @@ type InstallArgs =
/// The list of supported Yarn commands. The `Custom` alternative
/// can be used for other commands not in the list until they are
/// implemented
[<System.Obsolete("FAKE0001 Use the Fake.JavaScript.Yarn module instead")>]
type YarnCommand =
| Install of InstallArgs
| Add of string
| Custom of string

/// The Yarn parameter type
[<CLIMutable>]
[<System.Obsolete("FAKE0001 Use the Fake.JavaScript.Yarn module instead")>]
type YarnParams =
{ Src: string
YarnFilePath: string
Expand All @@ -57,6 +61,7 @@ type YarnParams =
Timeout: TimeSpan }

/// Yarn default parameters
[<System.Obsolete("FAKE0001 Use the Fake.JavaScript.Yarn module instead")>]
let defaultYarnParams =
{ Src = ""
YarnFilePath = yarnFileName
Expand All @@ -78,6 +83,8 @@ let private parse = function
| Add str -> sprintf "add %s" str
| Custom str -> str


[<System.Obsolete("FAKE0001 Use the Fake.JavaScript.Yarn module instead")>]
let run yarnParams =
let yarnPath = Path.GetFullPath(yarnParams.YarnFilePath)
let arguments = yarnParams.Command |> parse
Expand Down Expand Up @@ -111,5 +118,7 @@ let run yarnParams =
/// WorkingDirectory = "./src/FAKESimple.Web/"
/// })
/// )

[<System.Obsolete("FAKE0001 Use the Fake.JavaScript.Yarn module instead")>]
let Yarn setParams =
defaultYarnParams |> setParams |> run