MCPcopy Index your code
hub / github.com/itwanger/toBeBetterJavaer / main

Function main

scripts/sync-sidebar.js:123–168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

121}
122
123function main() {
124 try {
125 const options = parseArgs(process.argv.slice(2));
126 if (options.help) {
127 printHelp();
128 return;
129 }
130
131 if (!fs.existsSync(options.sidebar)) {
132 throw new Error(`Sidebar file not found: ${options.sidebar}`);
133 }
134
135 let source = fs.readFileSync(options.sidebar, "utf8");
136 const originalSource = source;
137 const reports = [];
138
139 for (const target of createTargets(options)) {
140 const result = syncTarget(source, target);
141 source = result.source;
142 reports.push(result.report);
143 }
144
145 const changed = source !== originalSource;
146 for (const report of reports) {
147 if (options.verbose || report.added.length > 0 || report.removed.length > 0 || report.warnings.length > 0) {
148 printReport(report);
149 }
150 }
151
152 if (options.write && changed) {
153 fs.writeFileSync(options.sidebar, source);
154 console.log(`Updated ${path.relative(ROOT_DIR, options.sidebar)}`);
155 } else if (!changed) {
156 console.log("Sidebar is already in sync.");
157 } else {
158 console.log("Dry run only. Re-run with --write to update sidebar.ts.");
159 }
160
161 if (options.check && changed) {
162 process.exitCode = 1;
163 }
164 } catch (error) {
165 console.error(`sync-sidebar: ${error.message}`);
166 process.exitCode = 1;
167 }
168}
169
170function syncTarget(source, target) {
171 const dir = path.resolve(ROOT_DIR, target.dir);

Callers 1

sync-sidebar.jsFile · 0.70

Calls 5

createTargetsFunction · 0.85
syncTargetFunction · 0.85
printReportFunction · 0.85
parseArgsFunction · 0.70
printHelpFunction · 0.70

Tested by

no test coverage detected