@@ -33,11 +33,73 @@ public static string NpmVersion(this ICakeContext context)
3333 }
3434
3535 AddinInformation . LogVersionInformation ( context . Log ) ;
36- var settings = new NpmVersionSettings
36+ return context . NpmVersion ( new NpmVersionSettings ( ) ) ;
37+ }
38+
39+ /// <summary>
40+ /// Versions all packages for the project in the current working directory
41+ /// using the settings returned by a configurator.
42+ /// </summary>
43+ /// <param name="context">The context.</param>
44+ /// <param name="configurator">The settings configurator.</param>
45+ /// <example>
46+ /// <code>
47+ /// <![CDATA[
48+ /// var versionString = NpmVersion(settings => settings.WithLogLevel(NpmLogLevel.Verbose));
49+ /// ]]>
50+ /// </code>
51+ /// </example>
52+ [ CakeMethodAlias ]
53+ [ CakeAliasCategory ( "Version" ) ]
54+ public static string NpmVersion ( this ICakeContext context , Action < NpmVersionSettings > configurator )
55+ {
56+ if ( context == null )
57+ {
58+ throw new ArgumentNullException ( nameof ( context ) ) ;
59+ }
60+
61+ if ( configurator == null )
62+ {
63+ throw new ArgumentNullException ( nameof ( configurator ) ) ;
64+ }
65+
66+ var settings = new NpmVersionSettings ( ) ;
67+ configurator ( settings ) ;
68+ return context . NpmVersion ( settings ) ;
69+ }
70+
71+ /// <summary>
72+ /// Versions all packages for the project in the current working directory
73+ /// using the specified settings.
74+ /// </summary>
75+ /// <param name="context">The context.</param>
76+ /// <param name="settings">The settings.</param>
77+ /// <example>
78+ /// <code>
79+ /// <![CDATA[
80+ /// var settings = new NpmVersionSettings();
81+ /// settings.WithLogLevel(NpmLogLevel.Verbose);
82+ /// var versionString = NpmVersion(settings);
83+ /// ]]>
84+ /// </code>
85+ /// </example>
86+ [ CakeMethodAlias ]
87+ [ CakeAliasCategory ( "Version" ) ]
88+ public static string NpmVersion ( this ICakeContext context , NpmVersionSettings settings )
89+ {
90+ if ( context == null )
3791 {
38- RedirectStandardOutput = true
39- } ;
40- return new NpmVersionTool ( context . FileSystem , context . Environment , context . ProcessRunner , context . Tools , context . Log ) . Version ( settings ) ;
92+ throw new ArgumentNullException ( nameof ( context ) ) ;
93+ }
94+
95+ if ( settings == null )
96+ {
97+ throw new ArgumentNullException ( nameof ( settings ) ) ;
98+ }
99+
100+ AddinInformation . LogVersionInformation ( context . Log ) ;
101+ var tool = new NpmVersionTool ( context . FileSystem , context . Environment , context . ProcessRunner , context . Tools , context . Log ) ;
102+ return tool . Version ( settings ) ;
41103 }
42104 }
43105}
0 commit comments