Skip to content

Commit

Permalink
fix(refactor-cli-issues): Fix issues remaining after refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joelcoxokc committed May 23, 2015
1 parent ba8ec8c commit 86c717b
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 238 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bower_components
.idea
.DS_STORE
*.swp
.blog
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jspm_packages
bower_components
.idea
.idea
.blog
2 changes: 2 additions & 0 deletions bin/aurelia.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CLI.create(argv,
.then(aurelia.start)

.then(aurelia.stop);

// .catch(aurelia.abort);
}
);

89 changes: 60 additions & 29 deletions dist/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var logger = _interopRequireWildcard(_libLogger);

var _libConfig = require('./lib/config');

var program = require('commander');
var program = require('./lib/program');
var Promise = require('bluebird');
var path = require('path');

Expand Down Expand Up @@ -50,18 +50,39 @@ var AureliaCLI = (function () {
_createClass(AureliaCLI, [{
key: 'config',
get: function () {
return this.store.config;
return this.env.store.config;
},
set: function (value) {
this.store.config = value;
this.env.store.config = value;
}
}, {
key: 'cwd',
get: function () {
if (!this.CWD) {
this.CWD = path.join.bind(path, this.env.cwd);
if (!this.env.CWD) {
this.env.CWD = path.join.bind(path, this.env.cwd);
}
return this.CWD;
return this.env.CWD;
}
}, {
key: 'isCmd',
value: function isCmd(cmd) {
return this.args[0] === cmd;
}
}, {
key: 'done',
value: function done(resolve) {
var self = this;
return function done(args) {
return resolve(self.env);
};
}
}, {
key: 'issue',
value: function issue(reject) {
var self = this;
return function issue(args) {
return reject(self.env);
};
}
}, {
key: 'quit',
Expand Down Expand Up @@ -93,16 +114,17 @@ var AureliaCLI = (function () {
}, {
key: 'configure',
value: function configure(env) {
this.env = env;
this.liftoff = this;
this.isLaunched = true;

this.settings.isLocal = !!env.modulePath;
this.settings.isGlobal = !this.settings.isLocal;

this.env.configName = env.configNameSearch[0];

this.store = new _libConfig.Config(env);
this.env = env;
env.argv = this.argv;
env.args = this.args;
env.lyftOff = this;
env.isLaunched = true;
env.isLocal = !!env.modulePath;
env.isGlobal = !env.isLocal;
env.configName = env.configNameSearch[0];
env.store = new _libConfig.Config(env);
env.isCmd = this.isCmd;

if (process.cwd() !== env.cwd) {
process.chdir(env.cwd);
Expand All @@ -114,27 +136,35 @@ var AureliaCLI = (function () {
}, {
key: 'initialize',
value: function initialize(env) {
var self = this;
return new Promise(function (resolve, reject) {

require(this.initFile).init.call(this);
env.done = self.done(resolve);
env.issue = self.issue(reject);

this['continue'] = true;
require(self.initFile).init.bind(self)(env);

return env;
env['continue'] = !program.isCmd(env._exec);

if (env['continue']) resolve(env);
});
}
}, {
key: 'validation',
value: function validation(env) {

if (!env.modulePath) {
if (!env['continue']) if (!env.modulePath) {

program.parse(process.argv);
logger.err('Local aurelia-cli not found in: %s', env.modulePath);
this['continue'] = false;
env['continue'] = false;
return env;
}

if (!env.configPath) {
program.parse(process.argv);
logger.err('No Aureliafile found at %s', env.configPath);
this['continue'] = false;
env['continue'] = false;
return env;
}

Expand All @@ -144,14 +174,15 @@ var AureliaCLI = (function () {
key: 'start',
value: function start(env) {
var self = this;
if (!this['continue']) return env;
this.aurelia = this.settings.isLocal ? require(env.modulePath) : require(this.base('index'));
if (!env['continue']) return env;

env.aurelia = env.isLocal ? require(env.modulePath) : require(this.base('index'));

this.configFile = require(env.configPath);
this.aureliaFile = this.configFile(this.aurelia);
this.settings.isAureliaFile = true;
env.configFile = require(env.configPath);
env.aureliaFile = env.configFile(env.aurelia);
env.isAureliaFile = true;

require(self.startFile).start.call(this);
require(env.startFile).start.bind(self)(env);

program.parse(process.argv);

Expand All @@ -160,13 +191,13 @@ var AureliaCLI = (function () {
}, {
key: 'isExec',
value: function isExec(name) {
return this._exec === name;
return this.env._exec === name;
}
}, {
key: 'execute',
value: function execute(name) {
var self = this;
this._exec = name;
this.env._exec = name;
return function () {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
Expand Down
38 changes: 27 additions & 11 deletions dist/commands/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,43 @@ var logger = _interopRequireWildcard(_libLogger);

var _libInstaller = require('../lib/installer');

var _lodash = require('lodash');

var cli = process.AURELIA;

var init = cli['import']('commands/init').action;

var templates = {
navigation: 'skeleton-navigation',
plugin: 'skeleton-plugin'
};

var prompts = [{
type: 'list',
name: 'template',
message: 'Template?',
choices: (0, _lodash.map)(templates, function (temp, key) {
return { name: key, value: temp };
})
}];

function action(cmd, options) {
var app = '';
switch (cmd.toLowerCase()) {
case 'navigation':
app = 'skeleton-navigation';
break;
case 'plugin':
app = 'skeleton-plugin';
break;
}
return cmd ? run(cmd.toLowerCase()) : this.ask(prompts).then(run);
}

function run(answers) {
var app = answers.template;

if (app === '') {
if (!app) {
logger.error('Unknown template, please type aurelia new --help to get information on available types');
return;
}

return (0, _libInstaller.installTemplate)(app).then(function (response) {
logger.log(response);
return response;
return init();
}).then(function () {
cli.done();
})['catch'](function (err) {
logger.error(err);
});
Expand Down
30 changes: 14 additions & 16 deletions dist/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,26 @@ var logger = _interopRequireWildcard(_libLogger);

var _libUtils = require('./lib/utils');

var program = require('commander');
var program = require('./lib/program');
var pjson = require('../package.json');
var cli = process.AURELIA;
var chalk = require('chalk');

function init() {
function init(env) {

if (this.argv.verbose) {
logger.log('LIFTOFF SETTINGS:', this.liftoff);
logger.log('CLI OPTIONS:', this.argv);
logger.log('CWD:', this.env.cwd);
if (env.argv.verbose) {
logger.log('LIFTOFF SETTINGS:', env.liftoff);
logger.log('CLI OPTIONS:', env.argv);
logger.log('CWD:', env.cwd);

logger.log('FOUND CONFIG AT:', this.env.configPath);
logger.log('CONFIG NAME:', this.env.configName);
logger.log('YOUR LOCAL MODULE IS LOCATED:', this.env.modulePath);
logger.log('LOCAL PACKAGE.JSON:', this.env.modulePath);
logger.log('FOUND CONFIG AT:', env.configPath);
logger.log('CONFIG NAME:', env.configName);
logger.log('YOUR LOCAL MODULE IS LOCATED:', env.modulePath);
logger.log('LOCAL PACKAGE.JSON:', env.modulePath);
logger.log('CLI PACKAGE.JSON', require('../package'));
}

program.version(pjson.version).on('--help', function () {
console.log('\n' + ' ' + chalk.bgMagenta(' ') + chalk.bgRed(' ') + chalk.bgMagenta(' ') + '\n' + ' ' + chalk.bgRed.black(' aurelia ') + '\n' + ' ' + chalk.bgMagenta(' ') + chalk.bgRed(' ') + chalk.bgMagenta(' ') + '\n');
});

program.command('new <type>').description('create a new Aurelia project').action(cli.execute('new')).on('--help', function () {
if (env.isCmd('new')) program.command('new [type]').description('create a new Aurelia project').action(cli.execute('new')).on('--help', function () {
(0, _libUtils.example)('new', {
navigation: {
flags: 'navigation',
Expand All @@ -51,7 +47,7 @@ function init() {
});
});

program.command('init').option('-e, --env', 'Initialize an aurelia project environment').description('Initialize a new Aurelia Project and creates an Aureliafile').action(cli.execute('init')).on('--help', function () {
if (env.isCmd('init')) program.command('init').option('-e, --env', 'Initialize an aurelia project environment').description('Initialize a new Aurelia Project and creates an Aureliafile').action(cli.execute('init')).on('--help', function () {
(0, _libUtils.example)('init', {
env: {
flags: '--env -e',
Expand All @@ -60,4 +56,6 @@ function init() {
}
});
});

program.parse(process.argv);
}
5 changes: 3 additions & 2 deletions dist/lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var Config = (function () {
_classCallCheck(this, Config);

cli = process.AURELIA;
this.env = env;
this.configName = basename(cli.env.configName);
this.template = __dirname + ('/template/' + cli.env.configName);
this._onready = [];
Expand All @@ -39,11 +40,11 @@ var Config = (function () {
}, {
key: 'config',
get: function () {
return cli.settings.isAureliaFile ? cli.aurelia.configuration : _defaults.defaults;
return cli.env.isAureliaFile ? cli.env.aurelia.configuration : _defaults.defaults;
},
set: function (value) {
this._config = extend(this._config, value);
cli.aurelia.configuration = this._config;
cli.env.aurelia.configuration = this._config;
}
}, {
key: 'init',
Expand Down
36 changes: 36 additions & 0 deletions dist/lib/program.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var _ask = require('./ask');

var program = require('commander');
var Promise = require('bluebird');

program.Command.prototype.ask = _ask.ask;
program.Command.prototype.loadPrompts = [];
program.Command.prototype._prompts = [];

program.Command.prototype.onHelp = function (cb) {
var self = this;
this.on('--help', function () {
cb.call(self);
});
return this;
};

program.Command.prototype.isCmd = function (name) {
var result = false;
this._cmds = this._cmds || {};

if (this._cmds[name]) return true;

this.commands.forEach((function (cmd) {
this._cmds = cmd;
if (cmd._name === name) {
result = true;
return;
}
}).bind(this));
return result;
};

module.exports = program;
2 changes: 1 addition & 1 deletion dist/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _libUtils = require('./lib/utils');
var utils = _interopRequireWildcard(_libUtils);

var cli = process.AURELIA;
var program = require('commander');
var program = require('./lib/program');
var Promise = require('bluebird');

function start() {
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// all gulp tasks are located in the ./build/tasks directory
// gulp configuration is in files in ./build directory
require('require-dir')('build/tasks');
Loading

0 comments on commit 86c717b

Please sign in to comment.