Skip to content

Commit c47dea1

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.
1 parent 339f39b commit c47dea1

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function ensure(env, options, names) {
100100

101101
if (options[v]) {
102102
env[k] = options[v];
103+
env[k + 'Cwd'] = true;
103104
}
104105
}
105106
}

src/environment.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ export default class Environment extends EventEmitter {
135135
this.dir = process.cwd();
136136
}
137137

138+
if (!this.dest) {
139+
this.dest = 'sassdoc';
140+
}
141+
142+
this.dest = this.resolve(this.dest, this.destCwd);
143+
this.displayDest = path.relative(process.cwd(), this.dest);
144+
138145
if (!this.package) {
139146
this.package = {};
140147
}
@@ -187,7 +194,10 @@ export default class Environment extends EventEmitter {
187194
return this.tryTheme(`sassdoc-theme-${this.theme}`);
188195
}
189196

190-
return this.tryTheme(this.resolve(this.theme));
197+
let theme = this.resolve(this.theme, this.themeCwd);
198+
this.displayTheme = path.relative(process.cwd(), theme);
199+
200+
return this.tryTheme(theme);
191201
}
192202

193203
/**
@@ -289,9 +299,11 @@ export default class Environment extends EventEmitter {
289299
* Resolve given file from `this.dir`.
290300
*
291301
* @param {String} file
302+
* @param {Boolean} cwd - whether it's relative to CWD (like when
303+
* defined in CLI).
292304
* @return {String}
293305
*/
294-
resolve(file) {
295-
return path.resolve(this.dir, file);
306+
resolve(file, cwd = false) {
307+
return path.resolve(cwd ? process.cwd() : this.dir, file);
296308
}
297309
}

src/sassdoc.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function sassdoc(...args) {
9898
})
9999
.then(() => mkdir(env.dest))
100100
.then(() => {
101-
env.logger.log(`Folder \`${env.dest}\` successfully refreshed.`);
101+
env.logger.log(`Folder \`${env.displayDest}\` successfully refreshed.`);
102102
})
103103
.catch(err => {
104104
// Friendly error for already existing directory.
@@ -120,8 +120,8 @@ export default function sassdoc(...args) {
120120

121121
return promise
122122
.then(() => {
123-
let themeName = env.themeName || 'anonymous';
124-
env.logger.log(`Theme \`${themeName}\` successfully rendered.`);
123+
let displayTheme = env.displayTheme || 'anonymous';
124+
env.logger.log(`Theme \`${displayTheme}\` successfully rendered.`);
125125
});
126126
}
127127

@@ -328,7 +328,6 @@ function srcEnv(documentize, stream) {
328328
env.logger.debug('cwd:', () => process.cwd());
329329

330330
env.src = src;
331-
env.dest = env.dest || 'sassdoc';
332331

333332
env.logger.debug('env:', () => {
334333
let clone = {};

0 commit comments

Comments
 (0)