Skip to content

Commit db96271

Browse files
committed
Updated documentation and changed the NPM Options to use child objects like the C# Update Options
1 parent bd85edb commit db96271

File tree

6 files changed

+77
-53
lines changed

6 files changed

+77
-53
lines changed

README.md

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,54 @@ It would be great to get this to work for all kinds of languages/frameworks some
1616

1717
## How to Use It
1818

19-
Remember, the purpose of this is to update code. It is assumed, and recommended, a developer runs this locally and verifies the changes before comitting to source control. Below are the assumed steps a user would follow.
19+
Remember, the purpose of this is to update code and dependencies. It is assumed, and recommended, a developer runs this locally and verifies the changes before comitting the changes to source control. Below are the assumed steps a user would follow.
2020

21-
There are 2 ways to run this. As a .NET Tool installed on your machine, or downloading the repository and running the code yourself.
22-
23-
1. Install the application. Choose one:
21+
1. Install the Tool
2422
- Install the tool globally by running `dotnet tool install --global ProgrammerAL.Tools.CodeUpdater --version <<version number>>`
25-
- Or clone this repository locally
26-
2. Run the application
27-
- If you installed the tool, run it with the command: `code-updater --config "C:/my-repos/my-app-1"`
28-
- If you downloaded the code, open a terminal to the `~/src/CodeUpdater/CodeUpdater` directory and run the application using dotnet run while passing in the required arguments. Example: `dotnet run -- --config "C:/my-repos/my-app-1"`
29-
3. Wait for the application to finish. It will output the number of projects updated, and the number of projects that failed to update.
30-
4. Manually check a diff of all the file changes to ensure everything is as you expect
23+
2. Create an Options File
24+
- The options file specifys what updates to run on the code
25+
- Instructions on how to create the file are below. See the `Options File` and `Example Options File` sections
26+
3. Run the Tool
27+
- Run it with the command: `code-updater --options "C:/my-repos/my-app-1/my-options-file.json"`
28+
4. Wait for the application to finish. It will output the number of projects updated, and the number of projects that failed to update.
29+
5. Manually check a diff of all the file changes to ensure everything is as you expect
3130
- Make any manual changes you feel you need to
3231
- If there were any build failures that were caused by the updates, fix those
33-
5. Commit the code changes to source control. Wait for a CI/CD pipeline to run and ensure everything is still working as expected.
32+
6. Commit the code changes to source control. Wait for a CI/CD pipeline to run and ensure everything is still working as expected. You do have a CI/CD pipeline, right?
3433

3534
## CLI Options
3635

3736
- `-o|--options`
38-
- Required
39-
- Path to the file to use for config values when updating code
37+
- Path to the options file to use for updating code
4038
- `-h|--help`
4139
- Outputs CLI help
4240

4341
## Options File
4442

45-
This is a config file used by the app to determine what updates to run. It is composed of different objects which enable update features. Setting an object means that feature will run, leaving it null will disable that update feature.
46-
43+
This is a config file used by the app to determine what updates to run. It is composed of different objects which enable certain update features. Setting an object means that feature will run. Omitting it from the file will disable that update feature.
4744

4845
- UpdatePathOptions
4946
- Required
50-
- This object holds settings for what to update
47+
- This object determines what will be updated based on file paths
5148
- Properties:
5249
- RootDirectory
5350
- Root directory to run from. Code Updater will search all child directories within this for projects to update.
5451
- IgnorePatterns
55-
- String to ignore within file paths when looking for projects to update. This is OS sensitive, so use \ as the path separator for Windows, and / as the path separator everywhere else. Eg: `\my-skip-path\` will ignore all projects that have the text `\my-skip-path\` within the full path. Note this example will only happen on Windows because that uses backslashes for path separators.- NpmBuildCommand
52+
- Strings to ignore within file paths when looking for projects to update. This is OS sensitive, so use \ as the path separator for Windows, and / as the path separator everywhere else. Ex: `\my-skip-path\` will ignore all projects that have the text `\my-skip-path\` within the full path. Note this example will only work on Windows because that uses backslashes for path separators.
5653
- LoggingOptions
5754
- Optional
58-
- Options for output logging of the operation
59-
- Required Properties:
55+
- Options for output logging of the tool
56+
- Properties:
6057
- OutputFile
61-
- If this is set, it will be the file to write logs to, in addition to the console
58+
- Optional
59+
- Path to a file to write logs to. Note that logs are always written to the console, even if you choose to output to a file.
6260
- LogLevel
63-
- Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.
61+
- Optional
62+
- Default Value: verbose
63+
- Verbosity level to log. Valid values are: Verbose, Info, Warn, Error
6464
- CSharpOptions
6565
- Optional
66-
- This stores different options for what updates to perform on C# code
66+
- This stores different objects, each are a set of options for what updates to perform on C# code and csproj files
6767
- Child Objects:
6868
- CsProjVersioningOptions
6969
- Optional
@@ -76,18 +76,21 @@ This is a config file used by the app to determine what updates to run. It is co
7676
- TreatWarningsAsErrors
7777
- Boolean. The value to set for the TreatWarningsAsErrors flag in all `*.csproj` files
7878
- CsProjDotNetAnalyzerOptions
79-
- .NET Analyzer settings to set in all `*.csproj` files
79+
- Optional
80+
- .NET First Party Analyzer settings to set in all `*.csproj` files. You can read more at https://learn.microsoft.com/en-us/visualstudio/code-quality/install-net-analyzers?view=vs-2022
8081
- Required Properties:
8182
- EnableNetAnalyzers
82-
- Boolean. True to set the `EnableNetAnalyzers` csproj value to true, false to set it to false
83+
- Boolean. Value to set the `EnableNetAnalyzers` csproj value to
8384
- EnforceCodeStyleInBuild
84-
- Boolean. True to set the `EnforceCodeStyleInBuild` csproj value to true, false to set it to false
85+
- Boolean. Value to set the `EnforceCodeStyleInBuild` csproj value to
8586
- CSharpStyleOptions
87+
- Optional
8688
- Options for any code styling updates that will be performed over C# code
8789
- Required Properties:
8890
- RunDotnetFormat
8991
- Boolean. True to run the `dotnet format` command
9092
- NugetAuditOptions
93+
- Optional
9194
- Settings to use for configuring Nuget Audit settings in csproj files. You can read more at https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages#configuring-nuget-audit
9295
- Required Properties:
9396
- NuGetAudit
@@ -97,6 +100,7 @@ This is a config file used by the app to determine what updates to run. It is co
97100
- AuditLevel
98101
- String. What value to set for the `NuGetAuditLevel` property in the csproj file. Valid values are: `low`, `moderate`, `high`, and `critical`
99102
- NuGetUpdateOptions
103+
- Optional
100104
- Settings to use for updating NuGet packages in csproj files
101105
- Required Properties:
102106
- UpdateTopLevelNugetsInCsProj
@@ -105,11 +109,15 @@ This is a config file used by the app to determine what updates to run. It is co
105109
- Boolean. True to updates all indirect nugets to the latest version. These are the nugets that are referenced automatically based on SDK chosen or something like that.
106110
- NpmOptions
107111
- Optional
108-
- Options for updating Npm packages
109-
- Required Properties:
110-
- NpmBuildCommand
111-
- NpmBuildCommand
112-
- String. Npm command to \"compile\" the npm directory. Format of the command run is: `npm run {{NpmBuildCommand}}`
112+
- Options for updating Npm packages. If this is not set, NPM packages will not be updated
113+
- Properties:
114+
- NpmCompileOptions
115+
- Optional
116+
- Options for compiling Npm packages after updates. Note if this is not set, but the parent NpmOptions is set, NPM Packages will be updated but not tested with a compile.
117+
- Required Properties:
118+
- NpmBuildCommand
119+
- NpmBuildCommand
120+
- String. Npm command to "compile" the npm directory. The CLI command that will be run is: `npm run {{NpmBuildCommand}}`
113121

114122

115123
### Example Options File
@@ -151,14 +159,16 @@ This is a config file used by the app to determine what updates to run. It is co
151159
}
152160
},
153161
"NpmOptions": {
154-
"NpmBuildCommand": "publish"
162+
"NpmCompileOptions":{
163+
"NpmBuildCommand": "publish"
164+
}
155165
}
156166
}
157167
```
158-
168+
159169
## Ignore Patterns
160170

161-
The Code Updater application has a default set of paths to ignore. The list is below. Note that all paths are in the list using both forwardslashes and backslashes. These are in addition to any skip paths passed in with the `IgnorePatterns` config file property. As of right now, there is no way to remove these.
171+
The Code Updater application has a default set of paths to ignore. The list is below. Note that all paths are in the list using both forwardslashes and backslashes. These are in addition to any skip paths passed in with the `IgnorePatterns` config file property. There is no way to remove these. Think of these like an ignore file, but no wildcard syntax. it's just basic string matching.
162172

163173
Ignore all C# `obj` and `bin` folders:
164174
- /obj/Debug/
@@ -176,7 +186,7 @@ Ignore packages inside node_modules folder:
176186

177187
## Installing Locally vs Downloading the Code
178188

179-
The tool can be very opinionated. When updating packages it will only update to the latest version. If the tool does some things you can't use for your projects, you can download the code, make changes, and keep that for yourself (OSS FTW). If this is something you have to do, feel free to file an issue in the repo and and we can discuss it.
189+
The tool can be very opinionated. For example, when updating packages it will only update to the latest version. If the tool does some things you can't use for your projects, you can download the code, make changes, and keep that for yourself (OSS FTW). If this is something you have to do, feel free to file an issue in the repo and and we can discuss it. Maybe a change you need can be incorporated into the project.
180190

181191
## Required 3rd Party Software
182192

code-update-runner-sample/code-updater-config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
}
3535
},
3636
"NpmOptions": {
37-
"NpmBuildCommand": "publish"
37+
"NpmCompileOptions":{
38+
"NpmBuildCommand": "publish"
39+
}
3840
}
3941
}

src/CodeUpdater/CodeUpdater/CompileRunner.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ public class CompileRunner(ILogger Logger, IRunProcessHelper RunProcessHelper)
1616
public async ValueTask<CompileResults> CompileProjectsAsync(UpdateWork updateWork, UpdateOptions updateOptions)
1717
{
1818
var csharpBuildResults = await CompileAllCSharpProjectsAsync(updateWork);
19-
20-
var npmBuildCommand = updateOptions.NpmOptions?.NpmBuildCommand;
21-
var npmDirectoryBuildResults = new CompileNpmDirectoryResults(ImmutableArray<CompileNpmDirectoryResult>.Empty);
22-
if (!string.IsNullOrWhiteSpace(npmBuildCommand))
23-
{
24-
npmDirectoryBuildResults = await BuildAllNpmDirectoriesAsync(updateWork, npmBuildCommand);
25-
}
19+
var npmDirectoryBuildResults = await BuildAllNpmDirectoriesAsync(updateWork, updateOptions);
2620

2721
return new CompileResults(csharpBuildResults, npmDirectoryBuildResults);
2822
}
2923

30-
private async ValueTask<CompileNpmDirectoryResults> BuildAllNpmDirectoriesAsync(UpdateWork updateWork, string npmBuildCommand)
24+
private async ValueTask<CompileNpmDirectoryResults> BuildAllNpmDirectoriesAsync(UpdateWork updateWork, UpdateOptions updateOptions)
3125
{
26+
var npmBuildCommand = updateOptions.NpmOptions?.NpmCompileOptions?.NpmBuildCommand;
27+
if (!string.IsNullOrWhiteSpace(npmBuildCommand))
28+
{
29+
Logger.Information("Np NpmOptions config set, meaning no NPM Packages Updated, meaning nothing to compile");
30+
return new CompileNpmDirectoryResults(ImmutableArray<CompileNpmDirectoryResult>.Empty);
31+
}
32+
3233
if (!updateWork.NpmDirectories.Any())
3334
{
3435
Logger.Information($"No NPM directories to build");

src/CodeUpdater/CodeUpdater/Options/UpdateOptions.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ProgrammerAL.Tools.CodeUpdater;
66
public class UpdateOptions
77
{
88
/// <summary>
9-
/// Options for path to use when updating code
9+
/// This object determines what will be updated based on file paths
1010
/// </summary>
1111
[Required]
1212
public required UpdatePathOptions UpdatePathOptions { get; set; }
@@ -44,13 +44,20 @@ public class UpdatePathOptions
4444
/// </summary>
4545
[Required]
4646
public required IEnumerable<string> IgnorePatterns { get; set; }
47-
4847
}
4948

5049
public class NpmOptions
5150
{
5251
/// <summary>
53-
/// Npm command to \"compile\" the npm directory. Format run is: npm run <NpmBuildCommand>.
52+
/// Options for compiling Npm packages after updates. Note if this is not set, but the parent NpmOptions is set, NPM Packages will be updated but not tested with a compile.
53+
/// </summary>
54+
public NpmCompileOptions? NpmCompileOptions { get; set; }
55+
}
56+
57+
public class NpmCompileOptions
58+
{
59+
/// <summary>
60+
/// Npm command to \"compile\" the npm directory. The CLI command that will be run is: npm run {{NpmBuildCommand}}
5461
/// </summary>
5562
[Required(AllowEmptyStrings = false)]
5663
public required string NpmBuildCommand { get; set; }
@@ -64,7 +71,7 @@ public class CSharpOptions
6471
public CsProjVersioningOptions? CsProjVersioningOptions { get; set; }
6572

6673
/// <summary>
67-
/// .NET Analyzer settings to set in all csproj files
74+
/// .NET First Party Analyzer settings to set in all `*.csproj` files. You can read more at https://learn.microsoft.com/en-us/visualstudio/code-quality/install-net-analyzers?view=vs-2022
6875
/// </summary>
6976
public CsProjDotNetAnalyzerOptions? CsProjDotNetAnalyzerOptions { get; set; }
7077

@@ -171,12 +178,10 @@ public class LoggingOptions
171178
/// <summary>
172179
/// If this is set, it will be the file to write logs to, in addition to the console
173180
/// </summary>
174-
[Required(AllowEmptyStrings = false)]
175-
public required string OutputFile { get; set; }
181+
public string? OutputFile { get; set; }
176182

177183
/// <summary>
178184
/// Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.
179185
/// </summary>
180-
[Required(AllowEmptyStrings = false)]
181-
public required string LogLevel { get; set; } = "verbose";
186+
public string LogLevel { get; set; } = "verbose";
182187
}

src/CodeUpdater/CodeUpdater/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static async ValueTask RunAsync(CommandOptions commandOptions)
2525
var logger = SetupLogger(updateOptions);
2626

2727
var runProcessHelper = new RunProcessHelper(logger);
28-
var workLocator = new WorkLocator(logger);
28+
var workLocator = new WorkLocator(logger, updateOptions);
2929
var validator = new PreRunValidator(logger, runProcessHelper);
3030
var cSharpUpdater = new CSharpUpdater(logger, runProcessHelper, updateOptions);
3131
var npmUpdater = new NpmUpdater(logger, runProcessHelper);

src/CodeUpdater/CodeUpdater/WorkLocator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ProgrammerAL.Tools.CodeUpdater;
1111

1212
public record UpdateWork(ImmutableArray<string> CsProjectFiles, ImmutableArray<string> NpmDirectories);
1313

14-
public class WorkLocator(ILogger Logger)
14+
public class WorkLocator(ILogger Logger, UpdateOptions UpdateOptions)
1515
{
1616
public ImmutableArray<string> DetermineSkipPaths(IEnumerable<string> additionalSkipPaths)
1717
{
@@ -67,6 +67,12 @@ public ImmutableArray<string> FindCsProjFiles(string rootDirectory, ImmutableArr
6767

6868
public ImmutableArray<string> FindNpmDirectories(string rootDirectory, ImmutableArray<string> skipPaths)
6969
{
70+
if (UpdateOptions.NpmOptions is null)
71+
{
72+
Logger.Information("Np NpmOptions config set, will not attempt to update NPM Packages");
73+
return ImmutableArray<string>.Empty;
74+
}
75+
7076
var allPackageJsonPaths = Directory.GetFiles(rootDirectory, "package.json", SearchOption.AllDirectories);
7177
var validPaths = new List<string>();
7278

0 commit comments

Comments
 (0)