Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.dojorc extends support with @speedy/json-extends #297

Merged
merged 3 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pin the dep please?

"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}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change related?

reject(error);
}
});
Expand Down
Loading