Skip to content
Permalink
Browse files
feat: support windows
  • Loading branch information
h13i32maru committed May 10, 2015
1 parent edd09cb commit 2d34d464f4584820450041bff2e64888b08b5aad
Showing with 25 additions and 5 deletions.
  1. +1 −0 src/Parser/CommentParser.js
  2. +24 −5 src/Util/PathResolver.js
@@ -21,6 +21,7 @@ export default class CommentParser {
let comment = commentNode.value;

// TODO: refactor
comment = comment.replace(/\r\n/gm, '\n'); // for windows
comment = comment.replace(/^\*\s?/, ''); // remove first '*'
comment = comment.replace(/ $/, ''); // remove last ' '
comment = comment.replace(/^ *\* ?/gm, ''); // remove line head '*'
@@ -1,5 +1,6 @@
import path from 'path';
import assert from 'assert';
import os from 'os';

/**
* file path resolver.
@@ -57,19 +58,22 @@ export default class PathResolver {
}

let relativeFilePath = this.filePath;
let filePath;
if (this._packageName) {
return path.normalize(`${this._packageName}${path.sep}${this._pathPrefix}${path.sep}${relativeFilePath}`);
filePath = path.normalize(`${this._packageName}${path.sep}${this._pathPrefix}${path.sep}${relativeFilePath}`);
} else {
return `./${relativeFilePath}`;
filePath = `./${relativeFilePath}`;
}

return this._slash(filePath);
}

/**
* file full path.
* @type {string}
*/
get fileFullPath() {
return this._filePath;
return this._slash(this._filePath);
}

/**
@@ -78,7 +82,7 @@ export default class PathResolver {
*/
get filePath() {
let relativeFilePath = path.relative(path.dirname(this._inDirPath), this._filePath);
return relativeFilePath;
return this._slash(relativeFilePath);
}

/**
@@ -89,6 +93,21 @@ export default class PathResolver {
let selfDirPath = path.dirname(this._filePath);
let resolvedPath = path.resolve(selfDirPath, relativePath);
let resolvedRelativePath = path.relative(path.dirname(this._inDirPath), resolvedPath);
return resolvedRelativePath;
return this._slash(resolvedRelativePath);
}

/**
* convert 'back slash' to 'slash'.
* path separator is 'back slash' if platform is windows.
* @param {string} filePath - target file path.
* @returns {string} converted path.
* @private
*/
_slash(filePath) {
if (os.platform() === 'win32') {
filePath = filePath.replace(/\\/g, '/');
}

return filePath;
}
}

0 comments on commit 2d34d46

Please sign in to comment.