-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_component_files.js
179 lines (168 loc) · 4.6 KB
/
create_component_files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Convert __filename and __dirname to ESM equivalent
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Define the root directory for the components
const rootDir = path.join(__dirname, 'src', 'components');
// Function to convert algorithm names to Title format (e.g., "LinearSearchAlgo" to "Linear Search Algo")
const toTitleCase = (str) => {
return str.replace(/([A-Z])/g, ' $1').trim();
};
// Define the structure based on the list
const structure = {
"1_Beginner_Algos": [
"LinearSearchAlgo",
"BubbleSortAlgo",
"BinarySearchAlgo",
"SelectionSortAlgo",
"InsertionSortAlgo",
"FibonacciSequenceIterativeAlgo",
"CountingSortAlgo",
"EuclideanAlgorithmAlgo",
"GcdLcmAlgo",
"RodCuttingAlgo"
],
"2_Intermediate_Algos": [
"MergeSortAlgo",
"QuickSortAlgo",
"DfsAlgo",
"BfsAlgo",
"KruskalAlgorithmAlgo",
"PrimAlgorithmAlgo",
"DijkstraAlgorithmAlgo",
"MatrixChainMultiplicationAlgo",
"LongestCommonSubsequenceAlgo",
"FloydWarshallAlgo",
"KmpAlgorithmAlgo",
"RabinKarpAlgorithmAlgo",
"SuffixTreeConstructionAlgo",
"TrieOperationsAlgo",
"BinarySearchTreeAlgo",
"NQueensAlgo",
"SudokuSolverAlgo",
"BellmanFordAlgo",
"AStarSearchAlgo",
"EditDistanceAlgo",
"HeapSortAlgo",
"ActivitySelectionAlgo",
"JobSequencingAlgo",
"CoinChangeAlgo",
"KnapsackAlgo",
"HamiltonianPathAlgo",
"KnightsTourAlgo",
"ZAlgorithmAlgo",
"ModularExponentiationAlgo",
"LevenshteinDistanceAlgo"
],
"3_Advanced_Algos": [
"SuffixArrayConstructionAlgo",
"AvlTreeRotationsAlgo",
"RedBlackTreeAlgo",
"KruskalDisjointSetAlgo",
"MinimumSpanningTreeAlgo",
"KMeansClusteringAlgo",
"PagerankAlgorithmAlgo",
"DijkstraPriorityQueueAlgo",
"ManachersAlgorithmAlgo",
"ChineseRemainderTheoremAlgo",
"MillerRabinAlgo",
"FermatsTheoremAlgo",
"SieveOfEratosthenesAlgo",
"SegmentTreeAlgo",
"FenwickTreeAlgo",
"LowestCommonAncestorAlgo",
"SplayTreeAlgo",
"TarjanAlgorithmAlgo",
"KosarajuAlgorithmAlgo",
"JohnsonsAlgorithmAlgo",
"LongestIncreasingSubsequenceAlgo",
"FftAlgo",
"KaratsubaAlgorithmAlgo",
"SubsetSumAlgo",
"IntervalSchedulingMaximizationAlgo",
"CombinationSumAlgo",
"PermutationGenerationAlgo"
],
"4_10x_Dev_Algos": [
"NeuralNetworkBackpropagationAlgo",
"GeneticAlgorithmAlgo",
"SvmAlgo",
"RandomForestAlgo",
"PcaAlgo",
"DecisionTreeAlgo",
"NaiveBayesAlgo",
"PagerankAdvancedAlgo",
"SpfaAlgorithmAlgo",
"TarjanSccAlgo",
"AhoCorasickAlgo",
"UkkonenSuffixTreeAlgo",
"BoyerMooreAlgo",
"KmpAdvancedAlgo",
"RabinKarpHashingAlgo",
"ZAlgorithmAdvancedAlgo",
"ManachersAdvancedAlgo",
"HamiltonianPathBacktrackingAlgo",
"NQueensBacktrackingAlgo",
"SudokuSolverBacktrackingAlgo",
"RatInAMazeAlgo",
"WordBreakDpAlgo",
"EggDroppingPuzzleAlgo",
"MinimaxAlgo",
"AlphaBetaPruningAlgo",
"ConvexHullAlgo",
"GrahamScanAlgo",
"JarvisMarchAlgo",
"VoronoiDiagramsAlgo",
"FortuneAlgorithmAlgo",
"LineIntersectionAlgo",
"SimpsonsRuleAlgo",
"RungeKuttaAlgo"
]
};
// Function to generate boilerplate code
const generateBoilerplate = (algoName) => {
const algoTitleName = toTitleCase(algoName);
return `import {
Container,
CardContainer,
Title,
AlgoVisualizer,
CodeBlock
} from "../../Styled Components/styledComponents";
import React from "react";
import useStore from "../../ZustandStore";
const ${algoName} = () => {
return (
<Container>
<CardContainer>
<Title>${algoTitleName}</Title>
<AlgoVisualizer>
</AlgoVisualizer>
<CodeBlock>
{ \` \` }
</CodeBlock>
</CardContainer>
</Container>
);
};
export default ${algoName};`;
};
// Create the folders and files with boilerplate content
Object.keys(structure).forEach(folder => {
const folderPath = path.join(rootDir, folder);
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true });
console.log(`Created folder: ${folderPath}`);
}
structure[folder].forEach(algoName => {
const filePath = path.join(folderPath, `${algoName}.jsx`);
if (!fs.existsSync(filePath)) {
const boilerplate = generateBoilerplate(algoName);
fs.writeFileSync(filePath, boilerplate);
console.log(`Created file: ${filePath} with boilerplate content`);
}
});
});
console.log('Folders and files with boilerplate created successfully.');