Skip to content

Commit

Permalink
fix(config): --cache-location doesn't support directory yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Dec 28, 2016
1 parent c970877 commit 325df3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/config/config.js
Expand Up @@ -2,6 +2,8 @@
"use strict";
const objectAssign = require("object-assign");
const md5 = require("md5");
const fs = require("fs");
const assert = require("assert");
const pkg = require("../../package.json");
const concat = require("unique-concat");
const path = require("path");
Expand Down Expand Up @@ -154,7 +156,8 @@ class Config {
// --cache
options.cache = cliOptions.cache !== undefined ? cliOptions.cache : defaultOptions.cache;
// --cache-location="path/to/file"
options.cacheLocation = cliOptions.cacheLocation !== undefined ? cliOptions.cacheLocation
options.cacheLocation = cliOptions.cacheLocation !== undefined
? path.resolve(process.cwd(), cliOptions.cacheLocation)
: defaultOptions.cacheLocation;
return this.initWithAutoLoading(options);
}
Expand Down Expand Up @@ -305,6 +308,23 @@ class Config {
* @type {string}
*/
this.cacheLocation = options.cacheLocation !== undefined ? options.cacheLocation : defaultOptions.cacheLocation;
this._assertCacheLocation(this.cacheLocation);
}


_assertCacheLocation(locationPath) {
let fileStats;
try {
fileStats = fs.lstatSync(locationPath);
} catch (ex) {
fileStats = null;
}
if (!fileStats) {
return;
}
// TODO: --cache-location not supported directory
// We should defined what is default name.
assert(!fileStats.isDirectory(), "--cache-location doesn't support directory");
}

/* eslint-enable complexity */
Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Expand Up @@ -133,7 +133,7 @@ export default optionator({
option: "cache-location",
type: "path::String",
description: "Path to the cache file or directory",
example: "textlint --cache docs/ --cache-location \"/Users/user/.textlintcache/\""
example: "textlint --cache --cache-location \"/Users/user/.textlintcache\" docs/"
},
{
heading: "Experimental"
Expand Down

0 comments on commit 325df3f

Please sign in to comment.