Skip to content

Commit

Permalink
兼容Mac OS和Linux的文件(夹)路径
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoXuanZhi committed Jan 24, 2017
1 parent 491f866 commit a8c3ee6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
35 changes: 19 additions & 16 deletions lib/export.github.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module.exports = {
copyFolder(pathFrom + '../assets/', pathTo + '/images/');
}
},

/**
* @desc 检查文件列表是否存在重名文件
* @param[in] fileList 待检查的文件列表
Expand Down Expand Up @@ -171,7 +171,7 @@ module.exports = {
checkExist(fileName);
}
},

/**
* @desc 导出普通文档
* @param[in] list 待导出的普通文件列表
Expand Down Expand Up @@ -208,13 +208,13 @@ module.exports = {
}
},

/**
* @desc 开始导出
* @param[in] pathFrom 原来的文件路径
* @param[in] pathTo 处理后的所在文件路径
* @param[in] fileList 待处理的文件列表
* @param[in] duplicates 重复文件列表
*/
/**
* @desc 开始导出
* @param[in] pathFrom 原来的文件路径
* @param[in] pathTo 处理后的所在文件路径
* @param[in] fileList 待处理的文件列表
* @param[in] duplicates 重复文件列表
*/
_toExport: function (pathFrom, pathTo, fileList, duplicates) {
var fileList2 = [];
var duplicate2 = [];
Expand Down Expand Up @@ -242,7 +242,7 @@ module.exports = {
this._exportHome(pathFrom, pathTo);
this._exportNavigation(fileList2, duplicate2, pathFrom, pathTo);
},

/**
* @desc 导出准备
* @param[in] pathFrom 原来的文件路径
Expand All @@ -252,7 +252,8 @@ module.exports = {
_toPrepare: function (pathFrom, pathTo) {
var that = this;
var fileList = [];
pathFrom += pathFrom.substr(pathFrom.length - 1, 1) == '\\' ? 'library\\' : '\\library\\';
pathFrom.replace(/\\/g, '/');
pathFrom += pathFrom.substr(pathFrom.length - 1, 1) == '/' ? 'library/' : '/library/';
//读取文件夹
directories.readLibraryDir(pathFrom, function (err, tree, files) {
if (err) {
Expand All @@ -275,8 +276,8 @@ module.exports = {
var dups = [];
var message = '以下文件脱离文件夹偏平化时将会重名:\n\n';
for (var j = 0, dup; dup = duplicate[j]; j++) {
message += dup[0][0].replace(/\//g, '\\') + '\n' +
dup[1][0].replace(/\//g, '\\') + '\n\n';
message += dup[0][0].replace(/\//g, '/') + '\n' +
dup[1][0].replace(/\//g, '/') + '\n\n';
dups.push(dup[0][0], dup[1][0]);
}
message += '点击确认将自动处理(追加额外空格)并继续导出;\n' +
Expand Down Expand Up @@ -317,7 +318,7 @@ module.exports = {
}
return '/' + urlArr[1] + '/' + urlArr[2] + '/';
},

/**
* @desc 导出文库为github wiki
*/
Expand All @@ -331,7 +332,7 @@ module.exports = {
//检测是否为 amWiki 项目
amWikiPath = directories.isAmWiki(amWikiPath);
if (!amWikiPath) {
vscode.window.showWarningMessage('导出失败!\n只能对一个 amWiki 项目进行导出!');
vscode.window.showWarningMessage('导出失败!注意,只能对一个 amWiki 项目进行导出!');
return;
}
//检测 GitHub 项目地址
Expand All @@ -341,11 +342,13 @@ module.exports = {
}

//选中保存github wiki的文件夹信息
vscode.window.showInputBox({ placeHolder: '请输入存放github wiki的文件夹路径,如C:\\XXX\\Test', ignoreFocusOut: true }).then(function (msg) {
vscode.window.showInputBox({ placeHolder: '请输入存放github wiki的文件夹路径', ignoreFocusOut: true }).then(function (msg) {
console.log('当前输入的路径为:' + msg);
if (msg !== 'undefined') {
if (fs.existsSync(msg)) {
that._toPrepare(amWikiPath, msg);
} else {
vscode.window.showWarningMessage('此文件夹路径并不存在!');
}
}
});
Expand Down
10 changes: 5 additions & 5 deletions lib/pasterImg.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class pasterImg {
//判断当前文件夹名称是否为library和此父文件夹下是否有config.json为判断依据
if (path.basename(e) === 'library') {
var parentDir = path.dirname(e);
var configPath = parentDir + '\\config.json';
var configPath = parentDir + '/config.json';
console.log(configPath);
if (fs.existsSync(configPath)) {
console.log('当前文件夹已经匹配');
Expand All @@ -48,7 +48,7 @@ class pasterImg {
});

if (libraryPath) {
var assertPath = path.dirname(libraryPath) + '\\assets';
var assertPath = path.dirname(libraryPath) + '/assets';
//假设没有assets文件夹则创建它
if (!fs.existsSync(assertPath)) {
fs.mkdirSync(assertPath);
Expand All @@ -57,7 +57,7 @@ class pasterImg {
var ncount = subList.length;
for (var i = 0; i < ncount; i++) {
var temp = subList[ncount - i - 1];
assertPath += '\\' + temp;
assertPath += '/' + temp;
if (!fs.existsSync(assertPath)) {
fs.mkdirSync(assertPath);
}
Expand All @@ -75,7 +75,7 @@ class pasterImg {
//假设ID并不是数字,那么直接将其名称视为ID
fileID = path.basename(filePath).split(path.extname(filePath))[0];
}
var imageFilePath = assertPath + '\\' + fileID + '-' + imageFileName;
var imageFilePath = assertPath + '/' + fileID + '-' + imageFileName;
return imageFilePath;
}
return null;
Expand Down Expand Up @@ -172,7 +172,7 @@ class pasterImg {
editoBuilder.delete(editor.selection);
}).then(function () {
editor.edit(function (editoBuilder) {
var relativePath = imagePath.split('\\assets\\');
var relativePath = imagePath.split('/assets/');
var tempImgPath = '![](assets/' + relativePath[relativePath.length - 1] + ')';
tempImgPath = tempImgPath.replace(/\\/g, '/')
editoBuilder.insert(editor.selection.start, tempImgPath);
Expand Down

0 comments on commit a8c3ee6

Please sign in to comment.