They made money on publishing and then invested that in the Witcher 1, which sales helped financing the Witcher 2. Which part of it you don't understand?
The sotry I read some time ago on some Polish website went somehow like this: CDP was founded in the first half of the nineties and soon became one of the biggest game distributors in Poland. That didn't account for much as the market was heavily piracy ridden. One of their ideas on how to make Poles buy original games was to fully localise them with the voiceover made by famous actors: they did it with Baldurs Gate and managed to sold almost 20,000 copies which was considered a great success at that time. They made friends with Bioware and Interplay and continued to make money by preparing rich, fully voiced local editions of games like BG2, Planescape and Icewind Dale. In 2001 though, Interplay decided to consolise themselves and didn't release Baldur's Gate: Dark Alliance on PCs. CDP wen Kodex-furious with "What the fuck is that supposed to mean whot are you even thinking. Don't you know that in Poland there is no console and there won't be no potato for us. Do this new shit for PCs we demand you faggots" for which they replied "oh, silly Pollacks, don't you know that the new shit is to be streamlined to the consoles only? Stop bitchig idiots, if you want this on a PC then do it yourself, lol" and then CD Projekt felt their potato pride being spit on and said "Oh, fuck you Interplay, you thinks we can't do that? Don't understimate the potato, we'd port the fucking game so that the better people can play it to, douchebags". What finally happened though is that Interplay went into financial and legal troubles and CDP could do BG no more. But they already saw the future of decline very clearly and knew if they didn't start to make their own games, there'd be no games to sell to the elitists PC potato consumers any more and henceforth they realized they had to produce something on their own.
That's right, bitches, the early signs of consolisation spotted in 2001 were directly responsible for the fact that you are playing The Witcher 2 today. How'bout that, huh?
So, in early 2002 (yeah, it took them 5 years+ to make a goddammit game and it was still in a beta stage when they released it) they set up a games development studio in Warsaw with an aim to produce quality RPGs for the local and foreign audiences and fed them potato all that time as, as you might not know in Pakistan, potatoes grow out of another potatoes. The rest is history.
That be a potato history in a nutshell.