Skip to content

Commit

Permalink
#7 Minor improvements to index.js
Browse files Browse the repository at this point in the history
+ Changed from [component] to [keyword] due to it actually being called keywords in dever.json
  • Loading branch information
czprz committed Dec 12, 2021
1 parent 216addd commit 49d5235
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 91 deletions.
34 changes: 17 additions & 17 deletions bin/environments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ module.exports = new class {
await this.#startOrStop(args);
break;
case args.config:
this.#showConfig(args.component);
this.#showConfig(args.keyword);
break;
case args.list:
this.#listAllComponents();
break;
case args.location:
this.#showLocation(args.component);
this.#showLocation(args.keyword);
break;
default:
this.#showHelp(yargs);
Expand All @@ -59,7 +59,7 @@ module.exports = new class {
* @returns {Promise<void>}
*/
async #startOrStop(args) {
const keyword = args.component != null ? args.component.toLowerCase() : null;
const keyword = args.keyword != null ? args.keyword.toLowerCase() : null;

if (keyword == null) {
console.error(`Must have a component keyword. Please attempt with ${chalk.blue('dever env [component]')}`);
Expand All @@ -73,7 +73,7 @@ module.exports = new class {

const component = components_handler.getComponent(keyword);
if (component == null) {
console.log('Could not find component');
console.error(chalk.redBright('Could not find component with keyword'));
return;
}

Expand Down Expand Up @@ -131,13 +131,13 @@ module.exports = new class {
*/
#showLocation(keyword) {
if (keyword == null) {
console.error(`Missing [component]. Please try again with ${chalk.green('dever env [component] --location')}`);
console.error(`Missing [keyword]. Please try again with ${chalk.green('dever env [keyword] --location')}`);
return;
}

const component = components_handler.getComponent(keyword);
if (component == null) {
console.error('Could not find component');
console.error(chalk.redBright('Could not find component with keyword'));
return;
}

Expand All @@ -158,7 +158,7 @@ module.exports = new class {
}

if (config == null) {
console.error(chalk.redBright(keyword == null ? 'Could not find dever configuration' : 'Could not find component'));
console.error(chalk.redBright(keyword == null ? 'Could not find dever configuration' : 'Could not find component with keyword'));
return;
}

Expand All @@ -171,7 +171,7 @@ module.exports = new class {
#listAllComponents() {
const components = components_handler.getAllComponents();
if (components == null || components.length === 0) {
console.error(`could not find any components. Please try running ${chalk.green('dever init')}`);
console.error(`Could not find any components. Please try running ${chalk.green('dever init')}`);
return;
}

Expand All @@ -198,7 +198,7 @@ module.exports = new class {
*/
#optionsWithoutComponent(yargs) {
return yargs
.positional('component', {
.positional('keyword', {
describe: 'Keyword for component',
type: 'string'
})
Expand All @@ -219,14 +219,9 @@ module.exports = new class {
* @returns {object}
*/
#optionsWithComponent(yargs, keyword) {
const component = components_handler.getComponent(keyword);
if (component == null) {
return null;
}

const options = yargs
.positional('component', {
describe: 'Name of component to start or stop',
.positional('keyword', {
describe: 'Keyword for component',
type: 'string'
})
.option('start', {
Expand All @@ -250,6 +245,11 @@ module.exports = new class {
describe: 'Show component configuration'
});

const component = components_handler.getComponent(keyword);
if (component == null) {
return options;
}

const customOptions = this.#getCustomOptions(component.dependencies);
return customOption.addOptionsToYargs(options, customOptions);
}
Expand Down Expand Up @@ -417,7 +417,7 @@ class Args {
* Component
* @var {string}
*/
component;
keyword;

/**
* How component location
Expand Down
3 changes: 1 addition & 2 deletions bin/fix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module.exports = new class {
* @returns {Promise<void>}
*/
async handler(yargs, args) {
// Todo: Missing handling of fixes

switch (true) {
case args.list:
this.#showListOfProblems();
Expand All @@ -34,6 +32,7 @@ module.exports = new class {
*/
getOptions(yargs) {
const keyword = this.#getKeywordFromArgv(yargs.argv);
// Todo: How to handle .argv causing javascript execution not being able to continue when using --help
return keyword == null ?
this.#optionsWithoutComponent(yargs) :
this.#optionsWithComponent(yargs, keyword);
Expand Down
53 changes: 23 additions & 30 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,38 @@
const yargs = require("yargs")(process.argv.slice(2));

const env = require('./environments');
const install = require('./install');
const init = require('./init');
const fix = require('./fix');

const usage = "\nUsage: dever <command> <option>";
yargs
.usage(usage)
.command('init', 'Initialize dever', yargs => {
return yargs;
}, argv => {
init.init(argv);
})
.command('install', 'Install necessary dependencies for web and backend development', (yargs) => {
return yargs
.option('all', {
describe: 'Flag for installing both backend and web development dependencies'
})
.option('web', {
describe: 'Flag for only installing web development dependencies'
})
.option('backend', {
describe: 'Flag for only installing backend development dependencies'
});
}, (argv) => {
install.install(argv);
.usage('\nUsage: $0 <command> [keyword]')
.command({
command: 'init',
desc: 'Initializes dever and searches for dever.json files',
handler: (argv) => {
init.init(argv).catch(console.error);
}
})
.command('fix', 'Fix common possibly repeatable issues')
.command('fix [problem]', 'Fix common possibly repeatable issues', (yargs) => {
return fix.getOptions(yargs);
}, (argv) => {
fix.handler(yargs, argv).catch(console.error);
.command({
command: 'fix [problem]',
desc: 'Fix common possibly repeatable issues',
builder: (yargs) => fix.getOptions(yargs),
handler: (argv) => {
fix.handler(yargs, argv).catch(console.error);
}
})
.command('env', 'Development environment organizer')
.command('env [component]', 'Development environment organizer', (yargs) => {
return env.getOptions(yargs);
}, (argv) => {
env.handler(yargs, argv).catch(console.error);
.command({
command: 'env [keyword]',
desc: 'Development environment organizer',
builder: (yargs) => env.getOptions(yargs),
handler: (argv) => {
env.handler(yargs, argv).catch(console.error);
}
})
.scriptName("dever");
.scriptName("dever")
.wrap(100);

if (yargs.argv._.length === 0) {
yargs.showHelp();
Expand Down
4 changes: 4 additions & 0 deletions bin/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module.exports = new class {
async init() {
const file = path.join(path.dirname(fs.realpathSync(__filename)), 'common/find_all_dever_json_files.ps1');

console.log('Initialization has started.. Please wait..');

componentHandler.clearComponents();

const raw = await powershell.executeFileSync(file);
Expand All @@ -16,6 +18,8 @@ module.exports = new class {
for (const path of paths) {
this.#getConfigFiles(path);
}

console.log('Initialization has been completed!');
}

#getConfigFiles(filePath) {
Expand Down
81 changes: 40 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 49d5235

Please sign in to comment.