Skip to content

Commit

Permalink
read from global config
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlytyler committed Nov 2, 2015
1 parent bc56403 commit 3547107
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .bluprintconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rootDirectory": "dummy/app",
"podsDirectory": "pods",
"blueprintsDirectory": "dummy/blueprints"
}
6 changes: 3 additions & 3 deletions dist/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ var log = (0, _chip2['default'])();
// or __root__/__podsRoot__/todos/components/List
//

function generate(args, usePods) {
function generate(args, usePods, configOptions) {
// Needs to be defined via config
var __destinationRoot__ = 'dummy/app';
var __blueprintRoot__ = 'dummy/blueprints';
var __destinationRoot__ = configOptions.rootDirectory;
var __blueprintRoot__ = configOptions.blueprintsDirectory;

// First argument is the type of blueprint we're generating
var __blueprintType__ = args[0];
Expand Down
20 changes: 13 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ var _inflection = require('inflection');

var _inflection2 = _interopRequireDefault(_inflection);

var _readConfig = require('./readConfig');

var _readConfig2 = _interopRequireDefault(_readConfig);

var _help = require('./help');

var _help2 = _interopRequireDefault(_help);
Expand Down Expand Up @@ -70,12 +74,14 @@ var anyArgs = function anyArgs() {
return !!args.length;
};

if (!anyArgs()) {
_commander2['default'].help();
} else {
if (args[0] === "generate") {
(0, _generate2['default'])((0, _lodash.drop)(args), usePods);
} else {
(0, _readConfig2['default'])(function (configOptions) {
if (!anyArgs()) {
_commander2['default'].help();
} else {
if (args[0] === "generate") {
(0, _generate2['default'])((0, _lodash.drop)(args), usePods, configOptions);
} else {
_commander2['default'].help();
}
}
}
});
35 changes: 35 additions & 0 deletions dist/readConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = readConfig;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

// Example
//
// {
// "rootDirectory": "dummy/app",
// "podsDirectory": "pods",
// "blueprintsDirectory": "dummy/pods"
// }

function readConfig(callback) {
_fs2['default'].readFile('./.bluprintconfig', 'utf8', function (err, data) {
if (err) throw err; // we'll not consider error handling for now

var options = Object.assign({
"rootDirectory": "app",
"blueprintsDirectory": "blueprints"
}, JSON.parse(data));

callback(options);
});
}

module.exports = exports['default'];
6 changes: 3 additions & 3 deletions src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const log = chip();
// or __root__/__podsRoot__/todos/components/List
//

export default function generate(args, usePods) {
export default function generate(args, usePods, configOptions) {
// Needs to be defined via config
const __destinationRoot__ = 'dummy/app';
const __blueprintRoot__ = 'dummy/blueprints';
const __destinationRoot__ = configOptions.rootDirectory;
const __blueprintRoot__ = configOptions.blueprintsDirectory;

// First argument is the type of blueprint we're generating
const __blueprintType__ = args[0];
Expand Down
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import path from 'path';
import { drop } from 'lodash';
import inflection from 'inflection';

import readConfig from './readConfig';
import help from './help';
import generate from './generate';

Expand Down Expand Up @@ -50,12 +51,14 @@ const usePods = pod || pods;

const anyArgs = () => !!args.length;

if(!anyArgs()) {
program.help();
} else {
if (args[0] === "generate") {
generate(drop(args), usePods);
} else {
readConfig(configOptions => {
if(!anyArgs()) {
program.help();
} else {
if (args[0] === "generate") {
generate(drop(args), usePods, configOptions);
} else {
program.help();
}
}
}
});
25 changes: 25 additions & 0 deletions src/readConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from 'fs';

// Example
//
// {
// "rootDirectory": "dummy/app",
// "podsDirectory": "pods",
// "blueprintsDirectory": "dummy/pods"
// }

export default function readConfig(callback) {
fs.readFile('./.bluprintconfig', 'utf8', function (err, data) {
if (err) throw err; // we'll not consider error handling for now

const options = Object.assign(
{
"rootDirectory": "app",
"blueprintsDirectory": "blueprints"
},
JSON.parse(data)
);

callback(options);
});
}

0 comments on commit 3547107

Please sign in to comment.