There are several commercial products available that do exactly what you describe. Usually you'd have a dynohub (dynamo built into the front wheel hub) as the generator, and the charging electronics as an add-on. See Buesch & Mueller homepage
www.bumm.de for an example (E-Werk).