Don’t try to reinvent the wheel, I’ve already done it the perfect example has been already made (the manager itself uses it for Javascript based Lexicon entries). I’ve modified it to suite my needs and to be extended.
The template for the config file:
var cmbConfig = function() { return {structure: %s, config: %s, post: %s, get: %s, auth: %s} };
In a custom initializer from my main class, I’ve built the following:
$config = file_get_contents($this->structure['model'].'callmeback/config.template.php');
$config = sprintf($config, json_encode($this->structure), json_encode($this->config), json_encode($_POST), json_encode($_GET), (string) '"'.trim($this->modx->site_id).'"');
The first line simply fetches the config template, and using sprintf I replace all that I need. Reasigning it to the $config variable saves time, space and memory. Next, I return it (sort of a dump, since I "echo" the initializer class, which this is in).
As so:
echo $modx->cmb->initialize('javascript:config');
Action: javascript
Method: config
All the examples on how to initialize a config core/connector core, is already in the connectors/index.php file.
Good luck!