Skip to content

Commit c7a29de

Browse files
committed
roots & licenses update
roots change with set & ask for copyright name in licenses
1 parent 659de29 commit c7a29de

3 files changed

Lines changed: 106 additions & 50 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ dev <action> [typeOrName] [name] [--code] [--explorer]
5454

5555
## Commands
5656

57+
### Define roots
58+
59+
```
60+
dev set root web "path-to-ur-folder like D:/web"
61+
```
62+
5763
### Open a folder
5864

5965
```powershell
@@ -68,12 +74,6 @@ Opens a folder in VSCode and Explorer. Supports subpaths using `/`.
6874
dev create <type> <project-name>
6975
```
7076

71-
Supported types:
72-
73-
* `vite`, `web`, `python`, `home`, `discord`, `alpha-cpp`, `alpha-web`, `alpha-vite`
74-
75-
Creates the project in the appropriate root folder and opens it in VSCode and Explorer.
76-
7777
### Remove a folder
7878

7979
```powershell

dev.ps1

Lines changed: 98 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ function dev {
77

88
[string]$name,
99

10-
[bool]$code,
11-
12-
[bool]$explorer
10+
[object]$code, # changed
11+
[object]$explorer # changed
1312
)
1413

14+
1515
$DriveRoot = "D:\"
1616
$Help = @"
1717
Usage:
@@ -27,18 +27,9 @@ dev ls <web|python|home|discord|alpha-cpp|alpha-web> - List folders in specified
2727
2828
dev set --code=true/false - Open or not code by default (saves to %appdata%/SzaBee13/dev/config.json)
2929
dev set --explorer=true/false - Open or not explorer by default (saves to %appdata%/SzaBee13/dev/config.json)
30+
dev set root <root-name> <path|rm|remove> - Add root to roots (saves to %appdata%/SzaBee13/dev/roots.json) if path is rm or remove it'll remove that root from roots.json
3031
"@
3132

32-
# Change these edit add remove
33-
$roots = @{
34-
web = "D:\!_WEB"
35-
python = "D:\_python"
36-
home = "D:\_home"
37-
discord = "D:\_discord"
38-
"alpha-cpp" = "D:\_alpha\cpp"
39-
"alpha-web" = "D:\_alpha\web"
40-
}
41-
4233
function Search-Folder {
4334
param (
4435
[string]$rootPath,
@@ -49,6 +40,43 @@ dev set --explorer=true/false - Open or not explorer by default (saves to
4940
Select-Object -First 1
5041
}
5142

43+
function ConvertTo-Hashtable($object) {
44+
if ($null -eq $object) { return @{} }
45+
if ($object -is [hashtable]) { return $object }
46+
$hash = @{}
47+
$object.PSObject.Properties | ForEach-Object {
48+
$hash[$_.Name] = if ($_.Value -is [psobject]) {
49+
ConvertTo-Hashtable $_.Value
50+
}
51+
else {
52+
$_.Value
53+
}
54+
}
55+
return $hash
56+
}
57+
58+
# Load roots from "%appdata%\SzaBee13\dev\roots.json"
59+
$RootsFile = Join-Path $env:APPDATA "SzaBee13\dev\roots.json"
60+
$roots = @{}
61+
62+
if (Test-Path $RootsFile) {
63+
try {
64+
$roots = Get-Content $RootsFile | ConvertFrom-Json | ConvertTo-Hashtable
65+
66+
}
67+
catch {
68+
Write-Host "Warning: roots.json is invalid. Starting with empty roots." -ForegroundColor Yellow
69+
$roots = @{}
70+
}
71+
}
72+
else {
73+
# Create directory and file if missing
74+
$dir = Split-Path $RootsFile
75+
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
76+
'{}' | Out-File -Encoding utf8 $RootsFile
77+
Write-Host "Created new roots.json at $RootsFile" -ForegroundColor Yellow
78+
}
79+
5280
switch ($action) {
5381
"open" {
5482
# Load default config
@@ -181,14 +209,23 @@ dev set --explorer=true/false - Open or not explorer by default (saves to
181209

182210
try {
183211
$licensesJson = Invoke-RestMethod -Uri $url
184-
# Save it locally for future use
212+
213+
# Prompt user for their name to replace [name]
214+
$userName = Read-Host "Enter your name for the license copyright"
215+
216+
# Replace [name] placeholders in all license entries
217+
foreach ($key in $licensesJson.PSObject.Properties.Name) {
218+
$licensesJson[$key] = $licensesJson[$key] -replace "\[name\]", $userName
219+
}
220+
221+
# Save locally for future use
185222
$licensesJson | ConvertTo-Json -Compress | Set-Content -Path $LicensesPath
186223
$licenses = $licensesJson
187-
Write-Host "Licenses downloaded and saved to $LicensesPath" -ForegroundColor Green
224+
Write-Host "Licenses downloaded, updated with your name, and saved to $LicensesPath" -ForegroundColor Green
188225
}
189226
catch {
190227
Write-Host "Failed to download licenses JSON. Proceeding without it." -ForegroundColor Red
191-
$licenses = @{}
228+
$licenses = @{ }
192229
}
193230
}
194231

@@ -218,39 +255,58 @@ dev set --explorer=true/false - Open or not explorer by default (saves to
218255
}
219256

220257
"set" {
221-
$ConfigPath = Join-Path $env:APPDATA "SzaBee13\dev"
222-
$ConfigFile = Join-Path $ConfigPath "config.json"
258+
if ($typeOrName -eq "root") {
259+
if (-not $name) {
260+
Write-Host "Usage: dev set root <root-name> <path | remove>" -ForegroundColor Yellow
261+
return
262+
}
223263

224-
if (-not (Test-Path $ConfigPath)) {
225-
New-Item -Path $ConfigPath -ItemType Directory -Force | Out-Null
226-
}
264+
if (-not (Test-Path $RootsFile)) {
265+
$dir = Split-Path $RootsFile
266+
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
267+
'{}' | Out-File -Encoding utf8 $RootsFile
268+
}
227269

228-
# Load existing config or create default
229-
if (Test-Path $ConfigFile) {
230-
$config = Get-Content $ConfigFile | ConvertFrom-Json
231-
}
232-
else {
233-
$config = [PSCustomObject]@{
234-
code = $true
235-
explorer = $true
270+
# Load and ensure it's a hashtable
271+
$roots = if (Test-Path $RootsFile) {
272+
$json = Get-Content $RootsFile -Raw
273+
if ($json.Trim()) {
274+
try {
275+
$tmp = $json | ConvertFrom-Json
276+
if ($tmp -is [System.Collections.Hashtable]) { $tmp }
277+
else {
278+
$h = @{}
279+
foreach ($p in $tmp.PSObject.Properties) { $h[$p.Name] = $p.Value }
280+
$h
281+
}
282+
}
283+
catch { @{} }
284+
}
285+
else { @{} }
236286
}
237-
}
287+
else { @{} }
238288

239-
if ($typeOrName -match "--code=(true|false)") {
240-
$config.code = [bool]::Parse($Matches[1])
241-
Write-Host "Set 'code' to $($config.code)" -ForegroundColor Green
242-
}
243-
elseif ($typeOrName -match "--explorer=(true|false)") {
244-
$config.explorer = [bool]::Parse($Matches[1])
245-
Write-Host "Set 'explorer' to $($config.explorer)" -ForegroundColor Green
289+
# handle remove or set
290+
if ($code -eq "remove" -or $code -eq "rm") {
291+
if ($roots.ContainsKey($name)) {
292+
$roots.Remove($name)
293+
Write-Host "Root '$name' removed." -ForegroundColor Yellow
294+
}
295+
else {
296+
Write-Host "Root '$name' not found." -ForegroundColor Red
297+
}
298+
}
299+
else {
300+
$roots[$name] = $code
301+
Write-Host "Root '$name' set to path '$code'" -ForegroundColor Green
302+
}
303+
304+
# save file
305+
$roots | ConvertTo-Json | Out-File -Encoding utf8 $RootsFile
246306
}
247307
else {
248-
Write-Host "Please use --code=true/false or --explorer=true/false" -ForegroundColor Yellow
249-
return
308+
Write-Host "Unknown set type '$typeOrName'" -ForegroundColor Red
250309
}
251-
252-
# Save back to JSON
253-
$config | ConvertTo-Json | Set-Content $ConfigFile
254310
}
255311

256312
"help" { Write-Host $Help -ForegroundColor Yellow }

licenses.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mit": "MIT License\n\nCopyright (c) [yyyy] SzaBee13\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.",
2+
"mit": "MIT License\n\nCopyright (c) [yyyy] [name]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.",
33

4-
"apache2": "Copyright [yyyy] SzaBee13\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttp://www.apache.org/licenses/LICENSE-2.0 \nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License."
4+
"apache2": "Copyright [yyyy] [name]\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttp://www.apache.org/licenses/LICENSE-2.0 \nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License."
55
}

0 commit comments

Comments
 (0)