Permalink
Browse files

Graceful relative paths in CLI and config file

Before this, `dest` was always relative to CWD even when set from config
file, and if a config file was defined, `theme` was always relative to
it even when set via CLI.

Now for all CLI-passed environment properties, a "friend" `*Cli` prperty
is set to `true` (`themeCli`, `destCli`), so the environment loader can
determine whether it's relative to CWD or config file.

Also paths are now stored absolute, but are always displayed relative to
the CWD for coherent CLI output. If you set `theme: ../../theme` in
`foo/config.yml`, the displayed theme in CLI output will be `../theme`.

This fixes #362.
  • Loading branch information...
valeriangalliat committed Feb 9, 2015
1 parent 339f39b commit c47dea149771e995b1782fd917e48bec37df48f6
Showing with 19 additions and 7 deletions.
  1. +1 −0 src/cli.js
  2. +15 −3 src/environment.js
  3. +3 −4 src/sassdoc.js
View
@@ -100,6 +100,7 @@ function ensure(env, options, names) {
if (options[v]) {
env[k] = options[v];
env[k + 'Cwd'] = true;
}
}
}
View
@@ -135,6 +135,13 @@ export default class Environment extends EventEmitter {
this.dir = process.cwd();
}
if (!this.dest) {
this.dest = 'sassdoc';
}
this.dest = this.resolve(this.dest, this.destCwd);
this.displayDest = path.relative(process.cwd(), this.dest);
if (!this.package) {
this.package = {};
}
@@ -187,7 +194,10 @@ export default class Environment extends EventEmitter {
return this.tryTheme(`sassdoc-theme-${this.theme}`);
}
return this.tryTheme(this.resolve(this.theme));
let theme = this.resolve(this.theme, this.themeCwd);
this.displayTheme = path.relative(process.cwd(), theme);
return this.tryTheme(theme);
}
/**
@@ -289,9 +299,11 @@ export default class Environment extends EventEmitter {
* Resolve given file from `this.dir`.
*
* @param {String} file
* @param {Boolean} cwd - whether it's relative to CWD (like when
* defined in CLI).
* @return {String}
*/
resolve(file) {
return path.resolve(this.dir, file);
resolve(file, cwd = false) {
return path.resolve(cwd ? process.cwd() : this.dir, file);
}
}
View
@@ -98,7 +98,7 @@ export default function sassdoc(...args) {
})
.then(() => mkdir(env.dest))
.then(() => {
env.logger.log(`Folder \`${env.dest}\` successfully refreshed.`);
env.logger.log(`Folder \`${env.displayDest}\` successfully refreshed.`);
})
.catch(err => {
// Friendly error for already existing directory.
@@ -120,8 +120,8 @@ export default function sassdoc(...args) {
return promise
.then(() => {
let themeName = env.themeName || 'anonymous';
env.logger.log(`Theme \`${themeName}\` successfully rendered.`);
let displayTheme = env.displayTheme || 'anonymous';
env.logger.log(`Theme \`${displayTheme}\` successfully rendered.`);
});
}
@@ -328,7 +328,6 @@ function srcEnv(documentize, stream) {
env.logger.debug('cwd:', () => process.cwd());
env.src = src;
env.dest = env.dest || 'sassdoc';
env.logger.debug('env:', () => {
let clone = {};

0 comments on commit c47dea1

Please sign in to comment.