Skip to content

Commit 9514edc

Browse files
committed
Made more changes to config stuff. Fully updated the ReadMe to know about all the config options.
1 parent d42bb8d commit 9514edc

File tree

7 files changed

+156
-99
lines changed

7 files changed

+156
-99
lines changed

README.md

Lines changed: 106 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -34,78 +34,125 @@ There are 2 ways to run this. As a .NET Tool installed on your machine, or downl
3434

3535
## CLI Options
3636

37-
- `-d|--config`
37+
- `-o|--options`
3838
- Required
3939
- Path to the file to use for config values when updating code
4040
- `-h|--help`
4141
- Outputs CLI help
4242

43-
## Config File
43+
## Options File
4444

45-
The config file holds all values to determine what changes to make. The reason this is separate from CLI input arguments is to let a developer store this config in different repos but have this .NET Tool installed globally on their machine. That makes it easy to let other developers run this tool with specific settings for each repository, while only needing to provide a single CLI input argument.
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.
4646

47-
Below are the list of properties in the config file.
4847

49-
- RootDirectory
48+
- UpdatePathOptions
5049
- Required
51-
- Root directory to run from. Code Updater will search all child directories within this for projects to update.
52-
- IgnorePatterns
53-
- Required
54-
- 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
55-
- NpmBuildCommand
56-
- Required
57-
- After upgrading all of the code, this application will attempt to build all applications it updated. This option sets the npm command to run to do the build.
58-
- Npm command to run to "compile" the npm directory. Default value is `publish`. Format run is: npm run <npmBuildCommand>.
59-
- DotNetTargetFramework
60-
- Required
61-
- Target Framework to set in all *.CsProj files
62-
- DotNetLangVersion
63-
- Required
64-
- C# language version to set in all *.CsProj files
65-
- EnableNetAnalyzers
66-
- Required
67-
- Boolean value to set the `EnableNetAnalyzers` csproj element to. If the `EnableNetAnalyzers` element does not exist in the project file, it will be added.
68-
- EnforceCodeStyleInBuild
69-
- Required
70-
- Boolean value to set the `EnforceCodeStyleInBuild` csproj element to. If the `EnableNetAnalyzers` element does not exist in the project file, it will be added.
71-
- RunDotnetFormat
72-
- Required
73-
- True to run the `dotnet format` command on all csproj files
74-
- NugetAudit
75-
- Required
76-
- This is an object with 3 properties, each is required. For more information see the Microsoft documentation at https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages#configuring-nuget-audit
77-
- NuGetAudit
78-
- Boolean to enable/disable the NuGet Audit features. Note that even if this is set to false, you still need to provide values for the other 2 properties even though they won't be used.
79-
- AuditMode
80-
- String. Which mode to audit, `direct` dependencies, or `all` dependencies.
81-
- AuditLevel
82-
- String. Minimum severity level to report. Ex: If you set it to moderate, you get `moderate`, `high`, and `critical` advisories. If you set it to `low`, you get all advisories.
83-
- OutputFile
50+
- This object holds settings for what to update
51+
- Properties:
52+
- RootDirectory
53+
- Root directory to run from. Code Updater will search all child directories within this for projects to update.
54+
- 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
56+
- LoggingOptions
57+
- Optional
58+
- Options for output logging of the operation
59+
- Required Properties:
60+
- OutputFile
61+
- If this is set, it will be the file to write logs to, in addition to the console
62+
- LogLevel
63+
- Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.
64+
- CSharpOptions
8465
- Optional
85-
- If this is set, it will be the file to write logs to, in addition to the console
86-
- LogLevel
66+
- This stores different options for what updates to perform on C# code
67+
- Child Objects:
68+
- CsProjVersioningOptions
69+
- Optional
70+
- Versioning options for csproj files
71+
- Required Properties:
72+
- TargetFramework
73+
- String. Target Framework to set in all *.csproj files
74+
- LangVersion
75+
- String. C# language version to set in all *.csproj files
76+
- TreatWarningsAsErrors
77+
- Boolean. The value to set for the TreatWarningsAsErrors flag in all *.csproj files
78+
- CsProjDotNetAnalyzerOptions
79+
- .NET Analyzer settings to set in all csproj files
80+
- Required Properties:
81+
- EnableNetAnalyzers
82+
- Boolean. True to set the `EnableNetAnalyzers` csproj value to true, false to set it to false
83+
- EnforceCodeStyleInBuild
84+
- Boolean. True to set the `EnforceCodeStyleInBuild` csproj value to true, false to set it to false
85+
- CSharpStyleOptions
86+
- Options for any code styling updates that will be performed over C# code
87+
- Required Properties:
88+
- RunDotnetFormat
89+
- Boolean. True to run the `dotnet format` command
90+
- NugetAuditOptions
91+
- 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
92+
- Required Properties:
93+
- NuGetAudit
94+
- Boolean. What value to set for the `NuGetAudit` property in the csproj file.
95+
- AuditMode
96+
- String. What value to set for the `NuGetAuditMode` property in the csproj file. Valid values are `direct` and `all`.
97+
- AuditLevel
98+
- String. What value to set for the `NuGetAuditLevel` property in the csproj file. Valid values are: `low`, `moderate`, `high`, and `critical`
99+
- NuGetUpdateOptions
100+
- Settings to use for updating NuGet packages in csproj files
101+
- Required Properties:
102+
- UpdateTopLevelNugetsInCsProj
103+
- Boolean. True to updates all referenced nugets to the latest version. These are the references in the csproj files.
104+
- UpdateTopLevelNugetsNotInCsProj
105+
- 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.
106+
- NpmOptions
87107
- Optional
88-
- Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.
108+
- Options for updating Npm packages
109+
- Required Properties:
110+
- NpmBuildCommand
111+
- NpmBuildCommand
112+
- String. Npm command to \"compile\" the npm directory. Format run is: npm run <NpmBuildCommand>.
113+
89114

90-
### Example Config File
115+
### Example Options File
91116

92117
```json
93118
{
94-
"RootDirectory": "C:\\GitHub\\ProgrammerAl\\ProgrammerAlSite",
95-
"IgnorePatterns": [],
96-
"NpmBuildCommand": "publish",
97-
"DotNetTargetFramework": "net8.0",
98-
"DotNetLangVersion": "latest",
99-
"EnableNetAnalyzers": true,
100-
"EnforceCodeStyleInBuild": true,
101-
"RunDotnetFormat": true,
102-
"NugetAudit": {
103-
"NuGetAudit": true,
104-
"AuditMode": "all",
105-
"AuditLevel": "low"
119+
"UpdatePathOptions": {
120+
"RootDirectory": "C:/my-repos/my-app-1",
121+
"IgnorePatterns": [
122+
"/samples/",
123+
"\\samples\\"
124+
]
106125
},
107-
"OutputFile": "./code-updater-output.txt",
108-
"LogLevel": "Verbose"
126+
"LoggingOptions": {
127+
"LogLevel": "Verbose",
128+
"OutputFile": "./code-updater-output.txt"
129+
},
130+
"CSharpOptions": {
131+
"CsProjVersioningOptions": {
132+
"TreatWarningsAsErrors": true,
133+
"TargetFramework": "net8.0",
134+
"LangVersion": "latest"
135+
},
136+
"CsProjDotNetAnalyzerOptions": {
137+
"EnableNetAnalyzers": true,
138+
"EnforceCodeStyleInBuild": true
139+
},
140+
"CSharpStyleOptions": {
141+
"RunDotnetFormat": true
142+
},
143+
"NugetAuditOptions": {
144+
"NuGetAudit": true,
145+
"AuditMode": "all",
146+
"AuditLevel": "low"
147+
},
148+
"NuGetUpdateOptions": {
149+
"UpdateTopLevelNugetsInCsProj": true,
150+
"UpdateTopLevelNugetsNotInCsProj": true
151+
}
152+
},
153+
"NpmOptions": {
154+
"NpmBuildCommand": "publish"
155+
}
109156
}
110157
```
111158
@@ -129,7 +176,7 @@ Ignore packages inside node_modules folder:
129176

130177
## Installing Locally vs Downloading the Code
131178

132-
The tool is very opinionated. It updates all packages to the latest version, and sets some project level properties. If the tool does some things you can't use for your projects, you can download the code, make changes, and keep thay for yourself. Maybe in the future we can hide certain settings behind a flag. Feel free to file an issue and and we can discuss it.
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.
133180

134181
## Required 3rd Party Software
135182

@@ -140,13 +187,12 @@ In order to run the tool you need the following software installed on your local
140187
- PowerShell
141188
- Quick Reminder: PowerShell is cross platform, you can run it on Linux and MacOS, not just Windows
142189

143-
PowerShell is required as a workaround. The NPM executable on Windows doesn't run like other applications. It doesn't exit like a normal process. I don't know why, I never spent the time figuring it out. The workaround makes PowerShell the host application so it exits like you would expect, when the process is done. For this reason, whenever an external process must be run, it's run through PowerShell. Kind of a hack, but it works well enough.
190+
PowerShell is required as a workaround. The NPM executable on Windows doesn't run like other applications, and as a result, on Windows, it doesn't exit like a normal process. I don't know why, I never spent the time figuring it out. The workaround makes PowerShell the host application so it exits like you would expect, when the process is done. For this reason, whenever an external process must be run, it's run through PowerShell. It's a hack, but it works well enough.
144191

145192
## .NET Standard Projects
146193

147194
When updating *.csproj files to a specific `TargetFramework` version, the project is skipped if using .NET Standard. Those are usually set for a specific level of API compatibility so we don't want to mess with those.
148195

149-
150196
## Update Script Sample
151197

152198
You can create a script to make it easy to run Code Updater on a regular basis. A sample PowerShell script to do that is in the `/code-update-runner-sample` directory of this repo. It has the below files:
@@ -156,5 +202,5 @@ You can create a script to make it easy to run Code Updater on a regular basis.
156202
- `run-code-updater.ps1`
157203
- PowerShell script that runs Code Updater one directory up in the tree, using the given `code-updater-config.json` file as config
158204

159-
Feel free to use those files as a base, and modify them for your repositories as needed. For extra points, commit them to your repository too.
205+
Feel free to use those files as a base, and modify them for your repositories as needed. For extra points, commit them to your repository to make it easy to use in the future.
160206

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
{
2-
"RootDirectory": "./",
3-
"IgnorePatterns": [],
2+
"UpdatePathOptions": {
3+
"RootDirectory": "../",
4+
"IgnorePatterns": [
5+
"/samples/",
6+
"\\samples\\"
7+
]
8+
},
9+
"LoggingOptions": {
10+
"LogLevel": "Verbose",
11+
"OutputFile": "./code-updater-output.txt"
12+
},
413
"CSharpOptions": {
514
"CsProjVersioningOptions": {
615
"TreatWarningsAsErrors": true,
@@ -26,9 +35,5 @@
2635
},
2736
"NpmOptions": {
2837
"NpmBuildCommand": "publish"
29-
},
30-
"LoggingOptions": {
31-
"LogLevel": "Verbose",
32-
"OutputFile": "./code-updater-output.txt"
3338
}
3439
}
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
21
$configPath = "$PSScriptRoot/code-updater-config.json"
3-
$runLocation = "$PSScriptRoot/../"
4-
5-
$startPath = Get-Location
62

7-
# Change path so the updater runs 1 directory higher, not inside this directory
8-
Set-Location $runLocation
93
& "code-updater" --config "$configPath"
104

11-
# Go back to the original path
12-
Set-Location $startPath
13-
145
Read-Host "Press enter to exit..."

src/CodeUpdater/CodeUpdater/Options/CommandOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
namespace ProgrammerAL.Tools.CodeUpdater.Options;
1212
public class CommandOptions
1313
{
14-
[Option(shortName: 'c', longName: "config", Required = true, HelpText = "Path to the file to use for config values when updating code")]
15-
public required string ConfigFile { get; set; }
14+
[Option(shortName: 'o', longName: "options", Required = true, HelpText = "Path to the file to use for values when updating code")]
15+
public required string OptionsFile { get; set; }
1616
}

src/CodeUpdater/CodeUpdater/Options/UpdateOptions.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,10 @@ namespace ProgrammerAL.Tools.CodeUpdater;
66
public class UpdateOptions
77
{
88
/// <summary>
9-
/// Root directory to run from.
10-
/// Code Updater will search all child directories within this for projects to update.
11-
/// </summary>
12-
[Required(AllowEmptyStrings = false)]
13-
public required string RootDirectory { get; set; }
14-
15-
/// <summary>
16-
/// String to ignore within file paths when looking for projects to update.
17-
/// This is OS sensitive, so use \\ as the path separator for Windows, and / as the path separator everywhere else.
18-
/// Eg: `\my-skip-path\` will ignore all projects that have the text `\my-skip-path\` within the full path.
19-
/// Which will only happen on Windows because that uses backslashes for path separators.
9+
/// Options for path to use when updating code
2010
/// </summary>
2111
[Required]
22-
public required IEnumerable<string> IgnorePatterns { get; set; }
12+
public required UpdatePathOptions UpdatePathOptions { get; set; }
2313

2414
/// <summary>
2515
/// Options for updating C# projects and code
@@ -37,6 +27,26 @@ public class UpdateOptions
3727
public LoggingOptions? LoggingOptions { get; set; }
3828
}
3929

30+
public class UpdatePathOptions
31+
{
32+
/// <summary>
33+
/// Root directory to run from.
34+
/// Code Updater will search all child directories within this for projects to update.
35+
/// </summary>
36+
[Required(AllowEmptyStrings = false)]
37+
public required string RootDirectory { get; set; }
38+
39+
/// <summary>
40+
/// String to ignore within file paths when looking for projects to update.
41+
/// This is OS sensitive, so use \\ as the path separator for Windows, and / as the path separator everywhere else.
42+
/// Eg: `\my-skip-path\` will ignore all projects that have the text `\my-skip-path\` within the full path.
43+
/// Which will only happen on Windows because that uses backslashes for path separators.
44+
/// </summary>
45+
[Required]
46+
public required IEnumerable<string> IgnorePatterns { get; set; }
47+
48+
}
49+
4050
public class NpmOptions
4151
{
4252
/// <summary>
@@ -54,7 +64,7 @@ public class CSharpOptions
5464
public CsProjVersioningOptions? CsProjVersioningOptions { get; set; }
5565

5666
/// <summary>
57-
/// Analyzers that are set in the csproj files
67+
/// .NET Analyzer settings to set in all csproj files
5868
/// </summary>
5969
public CsProjDotNetAnalyzerOptions? CsProjDotNetAnalyzerOptions { get; set; }
6070

src/CodeUpdater/CodeUpdater/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ await Parser.Default.ParseArguments<CommandOptions>(args)
2121

2222
static async ValueTask RunAsync(CommandOptions commandOptions)
2323
{
24-
var updateOptions = await LoadUpdateOptionsAsync(commandOptions.ConfigFile);
24+
var updateOptions = await LoadUpdateOptionsAsync(commandOptions.OptionsFile);
2525
var logger = SetupLogger(updateOptions);
2626

2727
var runProcessHelper = new RunProcessHelper(logger);
@@ -31,9 +31,9 @@ static async ValueTask RunAsync(CommandOptions commandOptions)
3131
var npmUpdater = new NpmUpdater(logger, runProcessHelper);
3232
var compileRunner = new CompileRunner(logger, runProcessHelper);
3333

34-
var skipPaths = workLocator.DetermineSkipPaths(updateOptions.IgnorePatterns);
34+
var skipPaths = workLocator.DetermineSkipPaths(updateOptions.PathOptions.IgnorePatterns);
3535

36-
var updateWork = workLocator.DetermineUpdateWork(updateOptions.RootDirectory, skipPaths);
36+
var updateWork = workLocator.DetermineUpdateWork(updateOptions.PathOptions.RootDirectory, skipPaths);
3737

3838
var canRun = await validator.VerifyCanRunAsync(updateWork);
3939

src/CodeUpdater/CodeUpdater/sampleUpdateOptions.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
{
2-
"RootDirectory": "C:/my-repos/my-app-1",
3-
"IgnorePatterns": [],
2+
"UpdatePathOptions": {
3+
"RootDirectory": "C:/my-repos/my-app-1",
4+
"IgnorePatterns": [
5+
"/samples/",
6+
"\\samples\\"
7+
]
8+
},
9+
"LoggingOptions": {
10+
"LogLevel": "Verbose",
11+
"OutputFile": "./code-updater-output.txt"
12+
},
413
"CSharpOptions": {
514
"CsProjVersioningOptions": {
615
"TreatWarningsAsErrors": true,
@@ -26,9 +35,5 @@
2635
},
2736
"NpmOptions": {
2837
"NpmBuildCommand": "publish"
29-
},
30-
"LoggingOptions": {
31-
"LogLevel": "Verbose",
32-
"OutputFile": "./code-updater-output.txt"
3338
}
3439
}

0 commit comments

Comments
 (0)