Skip to content

Commit

Permalink
Per blueprint config
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlytyler committed Nov 2, 2015
1 parent 4f6ccd6 commit 459d913
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 50 deletions.
30 changes: 19 additions & 11 deletions dist/generate/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

Expand All @@ -23,6 +23,10 @@ var _colors = require('colors');

var _colors2 = _interopRequireDefault(_colors);

var _tasksReadBlueprintConfig = require('./tasks/read-blueprint-config');

var _tasksReadBlueprintConfig2 = _interopRequireDefault(_tasksReadBlueprintConfig);

var _tasksSerializeBlueprints = require('./tasks/serialize-blueprints');

var _tasksSerializeBlueprints2 = _interopRequireDefault(_tasksSerializeBlueprints);
Expand Down Expand Up @@ -55,16 +59,19 @@ var log = (0, _chip2['default'])();
// or __root__/__podsRoot__/todos/components/List
//

function generate(args, usePods, configOptions) {
console.log(usePods);
console.log(configOptions.podsDirectory);
// Needs to be defined via config
var __destinationRoot__ = usePods && configOptions.podsDirectory ? _path2['default'].join(configOptions.rootDirectory, configOptions.podsDirectory) : configOptions.rootDirectory;
var __blueprintRoot__ = configOptions.blueprintsDirectory;
function generate(args, podsFlag, globalConfigOptions) {
// Computed __blueprintRoot__ using config
var __blueprintRoot__ = globalConfigOptions.blueprintsDirectory;

// First argument is the type of blueprint we're generating
var __blueprintType__ = args[0];
var __blueprintTypePlur__ = __blueprintType__.plural();

(0, _tasksReadBlueprintConfig2['default'])(_path2['default'].join(__blueprintRoot__, __blueprintType__), function (blueprintConfigOptions) {
var usePods = blueprintConfigOptions.forcePods || podsFlag;

// First argument is the type of blueprint we're generating
var __blueprintType__ = args[0];
var __blueprintTypePlur__ = __blueprintType__.plural();
// Computed __destinationRoot__ using config
var __destinationRoot__ = usePods && globalConfigOptions.podsDirectory ? _path2['default'].join(globalConfigOptions.rootDirectory, globalConfigOptions.podsDirectory) : globalConfigOptions.rootDirectory;

// If using types layout the second argument is the template name
// Is using pods layout the second argument is the target directory
Expand All @@ -85,8 +92,9 @@ function generate(args, usePods, configOptions) {

// Task flow
(0, _tasksSerializeBlueprints2['default'])(__blueprintRoot__, __blueprintType__, function (blueprints) {
return (0, _tasksBuildBoilerplate2['default'])(blueprints, __destinationDirectory__, __templateDirectory__, __templateName__);
return (0, _tasksBuildBoilerplate2['default'])(blueprints, __destinationDirectory__, __templateDirectory__, __templateName__);
});
});
}

;
Expand Down
37 changes: 37 additions & 0 deletions dist/generate/tasks/read-blueprint-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'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);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

// Example
//
// {
// "forcePods": true
// }

function readConfig(__dir__, callback) {
_fs2['default'].readFile(_path2['default'].join(__dir__, 'config.json'), 'utf8', function (err, data) {
if (err) {
callback({});
} else {
var options = Object.assign({
"forcePods": false
}, JSON.parse(data));
callback(options);
}
});
}

module.exports = exports['default'];
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var _inflection = require('inflection');

var _inflection2 = _interopRequireDefault(_inflection);

var _readConfig = require('./readConfig');
var _readGlobalConfig = require('./read-global-config');

var _readConfig2 = _interopRequireDefault(_readConfig);
var _readGlobalConfig2 = _interopRequireDefault(_readGlobalConfig);

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

Expand Down Expand Up @@ -68,18 +68,18 @@ var args = _commander2['default'].args;
var pods = _commander2['default'].pods;
var pod = _commander2['default'].pod;

var usePods = pod || pods;
var podsFlag = pod || pods;

var anyArgs = function anyArgs() {
return !!args.length;
};

(0, _readConfig2['default'])(function (configOptions) {
(0, _readGlobalConfig2['default'])(function (configOptions) {
if (!anyArgs()) {
_commander2['default'].help();
} else {
if (args[0] === "generate") {
(0, _generate2['default'])((0, _lodash.drop)(args), usePods, configOptions);
(0, _generate2['default'])((0, _lodash.drop)(args), podsFlag, configOptions);
} else {
_commander2['default'].help();
}
Expand Down
35 changes: 35 additions & 0 deletions dist/read-global-config.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'];
2 changes: 1 addition & 1 deletion dummy/blueprints/component/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"enablePods": "true",
"enablePods": "true"
}
3 changes: 3 additions & 0 deletions dummy/blueprints/pod/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"forcePods": true
}
63 changes: 34 additions & 29 deletions src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import chalk from 'chalk';
import chip from 'chip';
import colors from 'colors';

import readBlueprintConfig from './tasks/read-blueprint-config';
import serializeBlueprints from './tasks/serialize-blueprints';
import buildBoilerplate from './tasks/build-boilerplate';

Expand Down Expand Up @@ -33,43 +34,47 @@ const log = chip();
// or __root__/__podsRoot__/todos/components/List
//

export default function generate(args, usePods, configOptions) {
console.log(usePods);
console.log(configOptions.podsDirectory);
// Needs to be defined via config
const __destinationRoot__ = usePods && configOptions.podsDirectory ?
path.join(configOptions.rootDirectory, configOptions.podsDirectory) :
configOptions.rootDirectory;
const __blueprintRoot__ = configOptions.blueprintsDirectory;
export default function generate(args, podsFlag, globalConfigOptions) {
// Computed __blueprintRoot__ using config
const __blueprintRoot__ = globalConfigOptions.blueprintsDirectory;

// First argument is the type of blueprint we're generating
const __blueprintType__ = args[0];
const __blueprintTypePlur__ = __blueprintType__.plural()

// If using types layout the second argument is the template name
// Is using pods layout the second argument is the target directory
readBlueprintConfig(path.join(__blueprintRoot__, __blueprintType__), blueprintConfigOptions => {
const usePods = blueprintConfigOptions.forcePods || podsFlag;

// If using pods we accept template name as the third arguments
// This allows us to create typed folders inside pods directories
// i.e. todos/components
const __templateName__ = usePods ? args[2] : args[1];
const __templateDirectory__ = usePods ? args[1] : __blueprintTypePlur__;
// Computed __destinationRoot__ using config
const __destinationRoot__ = usePods && globalConfigOptions.podsDirectory ?
path.join(globalConfigOptions.rootDirectory, globalConfigOptions.podsDirectory) :
globalConfigOptions.rootDirectory;

// If using types layout the second argument is the template name
// Is using pods layout the second argument is the target directory

// Construct the destination directory
// If using pods and supplied a template name we must include the typed
// folder name in the structure
const __destinationDirectory__ = usePods && __templateName__ ?
path.join(__destinationRoot__, __templateDirectory__, __blueprintTypePlur__) :
path.join(__destinationRoot__, __templateDirectory__);
// If using pods we accept template name as the third arguments
// This allows us to create typed folders inside pods directories
// i.e. todos/components
const __templateName__ = usePods ? args[2] : args[1];
const __templateDirectory__ = usePods ? args[1] : __blueprintTypePlur__;

const __logPath__ = usePods && __templateName__ ?
`${__templateDirectory__} ${ __templateName__}` :
__templateName__ || __templateDirectory__;
log('installing ' + chalk.white(`${__blueprintType__} ${__logPath__}`));

// Task flow
serializeBlueprints(__blueprintRoot__, __blueprintType__, (blueprints) =>
buildBoilerplate(blueprints, __destinationDirectory__, __templateDirectory__, __templateName__)
);
// Construct the destination directory
// If using pods and supplied a template name we must include the typed
// folder name in the structure
const __destinationDirectory__ = usePods && __templateName__ ?
path.join(__destinationRoot__, __templateDirectory__, __blueprintTypePlur__) :
path.join(__destinationRoot__, __templateDirectory__);

const __logPath__ = usePods && __templateName__ ?
`${__templateDirectory__} ${ __templateName__}` :
__templateName__ || __templateDirectory__;
log('installing ' + chalk.white(`${__blueprintType__} ${__logPath__}`));

// Task flow
serializeBlueprints(__blueprintRoot__, __blueprintType__, (blueprints) =>
buildBoilerplate(blueprints, __destinationDirectory__, __templateDirectory__, __templateName__)
);
});
};
24 changes: 24 additions & 0 deletions src/generate/tasks/read-blueprint-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from 'fs';
import path from 'path';

// Example
//
// {
// "forcePods": true
// }

export default function readConfig(__dir__, callback) {
fs.readFile(path.join(__dir__, 'config.json'), 'utf8', function (err, data) {
if (err) {
callback({});
} else {
const options = Object.assign(
{
"forcePods": false
},
JSON.parse(data)
);
callback(options);
}
});
}
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import { drop } from 'lodash';
import inflection from 'inflection';

import readConfig from './readConfig';
import readGlobalConfig from './read-global-config';
import help from './help';
import generate from './generate';

Expand Down Expand Up @@ -47,16 +47,16 @@ program
.parse(process.argv);

const { args, pods, pod } = program;
const usePods = pod || pods;
const podsFlag = pod || pods;

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

readConfig(configOptions => {
readGlobalConfig(configOptions => {
if(!anyArgs()) {
program.help();
} else {
if (args[0] === "generate") {
generate(drop(args), usePods, configOptions);
generate(drop(args), podsFlag, configOptions);
} else {
program.help();
}
Expand Down
File renamed without changes.

0 comments on commit 459d913

Please sign in to comment.