fix Windows path issues and static-file copying (#785)

- In the default template, look for the list of static file paths in the
config property `templates.default.staticFiles.include`. (You can still
use `paths` instead of `include`.)
- Handle path-normalization issues that prevented the default template
from copying user-specified static files on Windows.
- Normalize paths in `fs.toDir` so that callers get the correct path
separator on Windows.
This commit is contained in:
Jeff Williams 2014-10-30 12:06:26 -07:00
parent d2e5dd888a
commit fc2b4ad3d2
5 changed files with 24 additions and 6 deletions

View File

@ -58,6 +58,8 @@ function filepathMinusPrefix(filepath) {
var commonPrefix = path.commonPrefix(sourcePaths); var commonPrefix = path.commonPrefix(sourcePaths);
var result = ''; var result = '';
filepath = path.normalize(filepath);
if (filepath) { if (filepath) {
// always use forward slashes // always use forward slashes
result = (filepath + path.sep).replace(commonPrefix, '') result = (filepath + path.sep).replace(commonPrefix, '')

View File

@ -8,6 +8,8 @@ var wrench = require('wrench');
var toDir = exports.toDir = function(_path) { var toDir = exports.toDir = function(_path) {
var isDirectory; var isDirectory;
_path = path.normalize(_path);
try { try {
isDirectory = fs.statSync(_path).isDirectory(); isDirectory = fs.statSync(_path).isDirectory();
} }
@ -15,7 +17,7 @@ var toDir = exports.toDir = function(_path) {
isDirectory = false; isDirectory = false;
} }
if (isDirectory){ if (isDirectory) {
return _path; return _path;
} else { } else {
return path.dirname(_path); return path.dirname(_path);

View File

@ -85,7 +85,10 @@ exports.readdir = asyncify(readdirSync);
// JSDoc extension to `fs` module // JSDoc extension to `fs` module
var toDir = exports.toDir = function toDir(_path) { var toDir = exports.toDir = function toDir(_path) {
var f = new java.io.File( path.resolve(global.env.pwd, _path) ); var f;
_path = path.normalize(_path);
f = new java.io.File( path.resolve(global.env.pwd, _path) );
if ( f.isDirectory() ){ if ( f.isDirectory() ){
return _path; return _path;

View File

@ -19,7 +19,7 @@ var hasOwnProp = Object.prototype.hasOwnProperty;
var data; var data;
var view; var view;
var outdir = env.opts.destination; var outdir = path.normalize(env.opts.destination);
function find(spec) { function find(spec) {
return helper.find(data, spec); return helper.find(data, spec);
@ -426,8 +426,8 @@ exports.publish = function(taffyData, opts, tutorials) {
var conf = env.conf.templates || {}; var conf = env.conf.templates || {};
conf['default'] = conf['default'] || {}; conf['default'] = conf['default'] || {};
var templatePath = opts.template; var templatePath = path.normalize(opts.template);
view = new template.Template(templatePath + '/tmpl'); view = new template.Template( path.join(templatePath, 'tmpl') );
// claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
// doesn't try to hand them out later // doesn't try to hand them out later
@ -512,7 +512,11 @@ exports.publish = function(taffyData, opts, tutorials) {
var staticFileFilter; var staticFileFilter;
var staticFileScanner; var staticFileScanner;
if (conf['default'].staticFiles) { if (conf['default'].staticFiles) {
staticFilePaths = conf['default'].staticFiles.paths || []; // The canonical property name is `include`. We accept `paths` for backwards compatibility
// with a bug in JSDoc 3.2.x.
staticFilePaths = conf['default'].staticFiles.include ||
conf['default'].staticFiles.paths ||
[];
staticFileFilter = new (require('jsdoc/src/filter')).Filter(conf['default'].staticFiles); staticFileFilter = new (require('jsdoc/src/filter')).Filter(conf['default'].staticFiles);
staticFileScanner = new (require('jsdoc/src/scanner')).Scanner(); staticFileScanner = new (require('jsdoc/src/scanner')).Scanner();

View File

@ -48,6 +48,7 @@ describe("@overview tag", function() {
it('The name should not include the entire filepath when the source file is outside the ' + it('The name should not include the entire filepath when the source file is outside the ' +
'JSDoc directory', function() { 'JSDoc directory', function() {
var Doclet = require('jsdoc/doclet').Doclet; var Doclet = require('jsdoc/doclet').Doclet;
var os = require('os');
var doclet; var doclet;
var docletMeta; var docletMeta;
@ -60,6 +61,12 @@ describe("@overview tag", function() {
env.sourceFiles = []; env.sourceFiles = [];
env.opts._ = [fakePath]; env.opts._ = [fakePath];
// ensure that paths are resolved consistently on Windows
if (os.platform().indexOf('win') === 0) {
fakePath = 'c:' + fakePath;
env.pwd = 'c:' + env.pwd;
}
// create a doclet with a fake filepath, then add a `@file` tag // create a doclet with a fake filepath, then add a `@file` tag
docletSrc = '/** @class */'; docletSrc = '/** @class */';
docletMeta = { docletMeta = {