Skip to content

Commit

Permalink
[#21] fix workingDir
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed Jul 14, 2017
1 parent 8b43a4a commit bc38c92
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/reg-suit-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function init(options: CliOptions) {
core.logger.verbose(`Copied file from ${fromPath} to ${toPath}.`);
});
})).then(() => {
core.logger.info("Execute 'reg-suit' \u2B50");
core.logger.info("Execute 'reg-suit run' \u2B50");
});
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/reg-suit-core/src/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ConfigManager {

readConfig(configFileName: string = DEFAULT_CONFIG_FILE_NAME) {
const defaultCoreConfig = {
workingDir: path.join(process.cwd(), "./reg"),
workingDir: "reg",
actualDir: "actual",
expectedDir: "expected",
} as CoreConfig;
Expand Down
14 changes: 9 additions & 5 deletions packages/reg-suit-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CreateQuestionsOptions,
RegSuitConfiguration,
} from "reg-suit-interface";
import { createLogger, RegLogger, LogLevel } from "reg-suit-util";
import { createLogger, RegLogger, LogLevel, fsUtil } from "reg-suit-util";

import { ConfigManager } from "./config-manager";
import { PluginManager } from "./plugin-manager";
Expand Down Expand Up @@ -49,7 +49,8 @@ export class RegSuitCore {
...pc.config,
} : pc.config;
});
this.logger.verbose("Merged configuration: ", mergedConfig);
this.logger.info("Configuration:");
this.logger.info(JSON.stringify(mergedConfig, null, 2));
if (JSON.stringify(baseConfig) === JSON.stringify(mergedConfig)) {
// If there is no difference, exit quietly.
return Promise.resolve();
Expand All @@ -70,6 +71,7 @@ export class RegSuitCore {
const keyGenerator = this._pluginManager.initKeyGenerator();
const publisher = this._pluginManager.initPublisher();
const notifiers = this._pluginManager.initNotifiers();
const directoryInfo = this.getDirectoryInfo(configFileName);
return new RegProcessor({
coreConfig: this._config.core,
logger: this.logger,
Expand All @@ -78,6 +80,7 @@ export class RegSuitCore {
keyGenerator,
publisher,
notifiers,
directoryInfo,
},
});
}
Expand All @@ -96,8 +99,9 @@ export class RegSuitCore {

getDirectoryInfo(configFileName?: string) {
this._loadConfig(configFileName);
const actualDir = path.join(path.resolve(process.cwd(), this._config.core.workingDir), this._config.core.actualDir);
const expectedDir = path.join(path.resolve(process.cwd(), this._config.core.workingDir), this._config.core.expectedDir);
return { actualDir, expectedDir };
const workingDir = path.resolve(fsUtil.prjRootDir(), this._config.core.workingDir);
const actualDir = path.join(workingDir, this._config.core.actualDir);
const expectedDir = path.join(workingDir, this._config.core.expectedDir);
return { workingDir, actualDir, expectedDir };
}
}
19 changes: 14 additions & 5 deletions packages/reg-suit-core/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import {
PluginLogger,
ComparisonResult,
} from "reg-suit-interface";
import { fsUtil } from "reg-suit-util";

const compare = require("reg-cli");

export interface ProcessorOptions {
keyGenerator?: KeyGeneratorPlugin<any>;
publisher?: PublisherPlugin<any>;
notifiers: NotifierPlugin<any>[];
directoryInfo: {
workingDir: string;
actualDir: string;
expectedDir: string;
};
}

export interface StepResultAfterExpectedKey {
Expand All @@ -38,6 +44,7 @@ export class RegProcessor {

private _logger: PluginLogger;
private _config: CoreConfig;
private _directoryInfo: ProcessorOptions["directoryInfo"];
private _keyGenerator?: KeyGeneratorPlugin<any>;
private _publisher?: PublisherPlugin<any>;
private _notifiers: NotifierPlugin<any>[];
Expand All @@ -47,6 +54,7 @@ export class RegProcessor {
) {
this._logger = opt.logger;
this._config = opt.coreConfig;
this._directoryInfo = opt.options.directoryInfo;
this._keyGenerator = opt.options.keyGenerator;
this._publisher = opt.options.publisher;
this._notifiers = opt.options.notifiers;
Expand Down Expand Up @@ -82,12 +90,13 @@ export class RegProcessor {
}

compare(ctx: StepResultAfterExpectedKey): Promise<StepResultAfterComparison> {
const { actualDir, expectedDir, workingDir } = this._directoryInfo;
return (compare({
actualDir: path.join(this._config.workingDir, this._config.actualDir),
expectedDir: path.join(this._config.workingDir, this._config.expectedDir),
diffDir: path.join(this._config.workingDir, "diff"),
json: path.join(this._config.workingDir, "out.json"),
report: path.join(this._config.workingDir, "index.html"),
actualDir,
expectedDir,
diffDir: path.join(workingDir, "diff"),
json: path.join(workingDir, "out.json"),
report: path.join(workingDir, "index.html"),
update: false,
ignoreChange: true,
urlPrefix: "",
Expand Down
9 changes: 9 additions & 0 deletions packages/reg-suit-util/src/fs-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export class FsUtil {
return this.lookup(fileOrDirName, path.resolve(firstDir, ".."), level - 1);
}
}

prjRootDir(configFileName = "package.json") {
const c = this.lookup(configFileName);
if (c) {
return path.dirname(c);
} else {
return process.cwd();
}
}
}

export const fsUtil = new FsUtil();

0 comments on commit bc38c92

Please sign in to comment.