, (*1)
Allows you to use Objectus seamlessly in Laravel 5 and Lumen, (*2)
, (*3)
What this does
- Combines your
.env
and config/
options with as many YAML and JSON files and directories you want to add inside config/
- Allows for functionality to share this data in any language(s) your
resources/
or public/
folders might use
Why would I want this
Most all of my projects have extended configuration, everything from style guides to site copy, this allows stylus/css and coffeescript/javascript access to this data, (*4)
Requirements
Installation
Require this package with Composer, (*5)
composer require acidjazz/larjectus
Laravel
Once Composer has installed or updated your packages you need to register Larjectus with Laravel itself. Open up config/app.php and find the providers key, towards the end of the file, and add 'Larjectus\ServiceProvider', to the end:, (*6)
'providers' => [
...
Larjectus\ServiceProvider::class,
],
Lumen
For usage with Lumen, add the service provider in bootstrap/app.php
., (*7)
$app->register(Larjectus\ServiceProvider::class);
configuration
gulpfile.js example(s)
Your gulp task is different from how Objectus works, here is an example of compiling a JSON version of your config for JavaScript access:, (*8)
🚨 Note the secure
array where i remove any secure data, like DB passwords and AWS credentials. 🚨, (*9)
exec = require('child_process').exec;
objectify = function() {
var config, secure;
config = {};
secure = ['auth', 'database'];
return exec('php artisan larjectus:config', function(error, result, stderr) {
var dim, i, len, pubconfig;
if (error) {
notify(error);
}
this.config = JSON.parse(result);
pubconfig = this.config;
for (i = 0, len = secure.length; i < len; i++) {
dim = secure[i];
delete pubconfig[dim];
}
return fs.writeFileSync('public/js/config.js', "config="+JSON.stringify(pubconfig)+";", 'utf8');
});
};
objectify();
gulp.task('larjectus', objectify);
gulp.task('watch', function() {
gulp.watch('config/**/*', ['larjectus']);
);
Here is an example of giving config access to stylus you would need the sample gulp task above :, (*10)
stylus = require('gulp-stylus');
gulp.task('stylus', function() {
return gulp.src('resources/stylus/main.styl')
.pipe(stylus({
rawDefine: {
config: config
}
}).on('error', notify.onError(function(error) {
return {
title: 'Stylus error: ' + error.name,
message: error.message,
sound: 'Pop'
};
})))
.pipe(gulp.dest('public/css/'))
.pipe(sync.stream());
}