Skip to content

Commit b72b9f7

Browse files
committed
fix: add missing source files
Added SelectionContext, script generators, hooks, themes, and assets required for build.
1 parent 0ff36b6 commit b72b9f7

File tree

10 files changed

+974
-0
lines changed

10 files changed

+974
-0
lines changed

src/App.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
transition: filter 300ms;
13+
}
14+
.logo:hover {
15+
filter: drop-shadow(0 0 2em #646cffaa);
16+
}
17+
.logo.react:hover {
18+
filter: drop-shadow(0 0 2em #61dafbaa);
19+
}
20+
21+
@keyframes logo-spin {
22+
from {
23+
transform: rotate(0deg);
24+
}
25+
to {
26+
transform: rotate(360deg);
27+
}
28+
}
29+
30+
@media (prefers-reduced-motion: no-preference) {
31+
a:nth-of-type(2) .logo {
32+
animation: logo-spin infinite 20s linear;
33+
}
34+
}
35+
36+
.card {
37+
padding: 2em;
38+
}
39+
40+
.read-the-docs {
41+
color: #888;
42+
}

src/assets/react.svg

Lines changed: 1 addition & 0 deletions
Loading

src/context/SelectionContext.jsx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { createContext, useContext, useState, useEffect } from 'react';
2+
import { softwareCatalog } from '../data/software-catalog';
3+
4+
const SelectionContext = createContext();
5+
6+
export const SelectionProvider = ({ children }) => {
7+
// State
8+
const [selectedSoftware, setSelectedSoftware] = useState([]);
9+
const [selectedConfigs, setSelectedConfigs] = useState([]);
10+
11+
// Load from localStorage on mount
12+
useEffect(() => {
13+
try {
14+
const saved = localStorage.getItem('win-installer-selections');
15+
if (saved) {
16+
const data = JSON.parse(saved);
17+
setSelectedSoftware(data.software || []);
18+
setSelectedConfigs(data.configs || []);
19+
}
20+
} catch (error) {
21+
console.error('Error loading selections from localStorage:', error);
22+
}
23+
}, []);
24+
25+
// Save to localStorage on change
26+
useEffect(() => {
27+
try {
28+
localStorage.setItem(
29+
'win-installer-selections',
30+
JSON.stringify({
31+
software: selectedSoftware,
32+
configs: selectedConfigs,
33+
})
34+
);
35+
} catch (error) {
36+
console.error('Error saving selections to localStorage:', error);
37+
}
38+
}, [selectedSoftware, selectedConfigs]);
39+
40+
// Toggle single software
41+
const toggleSoftware = (id) => {
42+
setSelectedSoftware((prev) =>
43+
prev.includes(id) ? prev.filter((s) => s !== id) : [...prev, id]
44+
);
45+
};
46+
47+
// Toggle single configuration
48+
const toggleConfig = (id) => {
49+
setSelectedConfigs((prev) =>
50+
prev.includes(id) ? prev.filter((c) => c !== id) : [...prev, id]
51+
);
52+
};
53+
54+
// Select all software in a category
55+
const selectAllInCategory = (categoryId) => {
56+
const categoryItems = softwareCatalog
57+
.filter((s) => s.category === categoryId)
58+
.map((s) => s.id);
59+
setSelectedSoftware((prev) => [...new Set([...prev, ...categoryItems])]);
60+
};
61+
62+
// Deselect all software in a category
63+
const deselectAllInCategory = (categoryId) => {
64+
const categoryItems = softwareCatalog
65+
.filter((s) => s.category === categoryId)
66+
.map((s) => s.id);
67+
setSelectedSoftware((prev) =>
68+
prev.filter((id) => !categoryItems.includes(id))
69+
);
70+
};
71+
72+
// Check if all items in category are selected
73+
const isAllCategorySelected = (categoryId) => {
74+
const categoryItems = softwareCatalog
75+
.filter((s) => s.category === categoryId)
76+
.map((s) => s.id);
77+
return categoryItems.every((id) => selectedSoftware.includes(id));
78+
};
79+
80+
// Clear all selections
81+
const clearAll = () => {
82+
setSelectedSoftware([]);
83+
setSelectedConfigs([]);
84+
};
85+
86+
// Clear only software
87+
const clearSoftware = () => {
88+
setSelectedSoftware([]);
89+
};
90+
91+
// Clear only configs
92+
const clearConfigs = () => {
93+
setSelectedConfigs([]);
94+
};
95+
96+
const value = {
97+
selectedSoftware,
98+
selectedConfigs,
99+
toggleSoftware,
100+
toggleConfig,
101+
selectAllInCategory,
102+
deselectAllInCategory,
103+
isAllCategorySelected,
104+
clearAll,
105+
clearSoftware,
106+
clearConfigs,
107+
};
108+
109+
return (
110+
<SelectionContext.Provider value={value}>
111+
{children}
112+
</SelectionContext.Provider>
113+
);
114+
};
115+
116+
// Custom hook to use the selection context
117+
export const useSelection = () => {
118+
const context = useContext(SelectionContext);
119+
if (!context) {
120+
throw new Error('useSelection must be used within SelectionProvider');
121+
}
122+
return context;
123+
};

src/generators/bat-generator.js

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import {
2+
groupSoftwareByCategory,
3+
getConfigObjects,
4+
formatWingetCommand,
5+
getDateTime,
6+
} from './script-utils';
7+
8+
/**
9+
* Generate Windows Batch (.bat) script
10+
* @param {Array} selectedSoftwareIds - Array of selected software IDs
11+
* @param {Array} selectedConfigIds - Array of selected configuration IDs
12+
* @returns {string} - Generated batch script
13+
*/
14+
export const generateBatchScript = (selectedSoftwareIds, selectedConfigIds) => {
15+
const header = generateBatchHeader();
16+
const softwareSection = generateBatchSoftwareSection(selectedSoftwareIds);
17+
const configSection = generateBatchConfigSection(selectedConfigIds);
18+
const footer = generateBatchFooter();
19+
20+
return header + softwareSection + configSection + footer;
21+
};
22+
23+
/**
24+
* Generate batch script header
25+
*/
26+
const generateBatchHeader = () => {
27+
return `@echo off
28+
chcp 65001 >nul
29+
echo ========================================
30+
echo Windows Post-Install Script (.bat)
31+
echo Generated: ${getDateTime()}
32+
echo ========================================
33+
echo.
34+
35+
:: Check for Administrator privileges
36+
net session >nul 2>&1
37+
if %errorLevel% neq 0 (
38+
echo ERROR: This script requires Administrator privileges.
39+
echo Please right-click and select "Run as administrator"
40+
echo.
41+
pause
42+
exit /b 1
43+
)
44+
45+
echo Starting installation process...
46+
echo.
47+
`;
48+
};
49+
50+
/**
51+
* Generate software installation section
52+
*/
53+
const generateBatchSoftwareSection = (selectedIds) => {
54+
if (!selectedIds || selectedIds.length === 0) {
55+
return `:: No software selected for installation\necho No software selected.\necho.\n\n`;
56+
}
57+
58+
let script = `::============================================
59+
:: SOFTWARE INSTALLATION
60+
::============================================
61+
echo.
62+
echo Installing selected software...
63+
echo This may take a while depending on your internet connection.
64+
echo.
65+
`;
66+
67+
const grouped = groupSoftwareByCategory(selectedIds);
68+
69+
Object.entries(grouped).forEach(([categoryName, softwares]) => {
70+
script += `\n:: ${categoryName}\n`;
71+
script += `echo Installing ${categoryName}...\n`;
72+
73+
softwares.forEach((software) => {
74+
script += `echo - ${software.name}\n`;
75+
script += `${formatWingetCommand(software.wingetId)} 2>>errors.log\n`;
76+
});
77+
78+
script += `echo.\n`;
79+
});
80+
81+
return script + '\n';
82+
};
83+
84+
/**
85+
* Generate configuration section
86+
*/
87+
const generateBatchConfigSection = (selectedIds) => {
88+
if (!selectedIds || selectedIds.length === 0) {
89+
return `:: No system configurations selected\necho No system configurations selected.\necho.\n\n`;
90+
}
91+
92+
let script = `::============================================
93+
:: SYSTEM CONFIGURATIONS
94+
::============================================
95+
echo.
96+
echo Applying system configurations...
97+
echo.
98+
`;
99+
100+
const configs = getConfigObjects(selectedIds);
101+
102+
configs.forEach((config) => {
103+
script += `\n:: ${config.name}\n`;
104+
script += `echo Applying: ${config.name}\n`;
105+
106+
// Add registry commands
107+
if (config.registryBat && config.registryBat.length > 0) {
108+
config.registryBat.forEach((cmd) => {
109+
script += `${cmd}\n`;
110+
});
111+
}
112+
113+
// Add regular commands
114+
if (config.commandBat && config.commandBat.length > 0) {
115+
config.commandBat.forEach((cmd) => {
116+
script += `${cmd}\n`;
117+
});
118+
}
119+
120+
script += `echo.\n`;
121+
});
122+
123+
return script + '\n';
124+
};
125+
126+
/**
127+
* Generate batch script footer
128+
*/
129+
const generateBatchFooter = () => {
130+
return `::============================================
131+
:: INSTALLATION COMPLETE
132+
::============================================
133+
echo.
134+
echo ========================================
135+
echo Installation Complete!
136+
echo ========================================
137+
echo.
138+
echo Next steps:
139+
echo 1. Restart your computer if required
140+
echo 2. Log into your installed applications
141+
echo 3. Customize your settings as needed
142+
echo.
143+
echo If any installations failed, check errors.log
144+
echo.
145+
echo Generated by Windows Post-Install Generator
146+
echo https://github.com/kaic/win-post-install
147+
echo.
148+
pause
149+
`;
150+
};

0 commit comments

Comments
 (0)