Skip to content

Commit

Permalink
.dojorc extends support with @speedy/json-extends (#297)
Browse files Browse the repository at this point in the history
* Add recursive extends support for deep .dojorc merging

* Use @speed/json-extends rather than custom code

* Pin dep, fix unit test
  • Loading branch information
JamesLMilner authored Sep 24, 2019
1 parent ea74415 commit fc762b3
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 40 deletions.
49 changes: 38 additions & 11 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"typings.json"
],
"dependencies": {
"@speedy/json-extends": "1.2.0",
"ajv": "6.6.2",
"chalk": "2.4.1",
"configstore": "3.1.2",
Expand Down
10 changes: 6 additions & 4 deletions src/configurationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { join } from 'path';
import { Config, ConfigurationHelper, ConfigWrapper } from './interfaces';
import * as readlineSync from 'readline-sync';
import * as detectIndent from 'detect-indent';
import { json } from '@speedy/json-extends';

const pkgDir = require('pkg-dir');

const appPath = pkgDir.sync(process.cwd());

export function getDojoRcConfigOption(): string {
Expand Down Expand Up @@ -37,18 +37,20 @@ function parseConfigs(): ConfigWrapper {
if (existsSync(dojoRcPath)) {
try {
const dojoRcFile = readFileSync(dojoRcPath, 'utf8');
const extendedConfig = json.readSync(dojoRcPath);
configWrapper.dojoRcIndent = detectIndent(dojoRcFile).indent;
configWrapper.dojoRcConfig = JSON.parse(dojoRcFile);
configWrapper.dojoRcConfig = extendedConfig;
} catch (error) {
throw Error(chalk.red(`Could not parse the .dojorc file to get config : ${error}`));
throw Error(chalk.red(`Could not parse the .dojorc file to get config: ${error}`));
}
}

if (existsSync(packageJsonPath)) {
try {
const packageJsonFile = readFileSync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonFile);
const packageJson: any = json.readSync(packageJsonPath);
configWrapper.packageJsonIndent = detectIndent(packageJsonFile).indent;

configWrapper.packageJsonConfig = packageJson.dojo;
} catch (error) {
throw Error(chalk.red(`Could not parse the package.json file to get config: ${error}`));
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function init() {

registerCommands(yargs, mergedCommands);
} catch (err) {
console.log(`Commands are not available: ${err}`);
console.log(`Commands are not available:\n ${err.message}`);
}

try {
Expand Down
3 changes: 2 additions & 1 deletion src/loadCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as globby from 'globby';
import { resolve as pathResolve, join } from 'path';
import { CliConfig, CommandWrapper, GroupMap } from './interfaces';
import configurationHelper from './configurationHelper';
import chalk from 'chalk';

export function isEjected(groupName: string, command: string): boolean {
const config: any = configurationHelper.sandbox(groupName, command).get();
Expand Down Expand Up @@ -72,7 +73,7 @@ export async function loadCommands(paths: string[], load: (path: string) => Comm
}
}
} catch (error) {
error.message = `Failed to load module ${path}\nNested error: ${error.message}`;
error.message = `${chalk.red(`Failed to load module ${path}`)}\n\nNested error:\n ${error.message}`;
reject(error);
}
});
Expand Down
Loading

0 comments on commit fc762b3

Please sign in to comment.