【发布时间】:2016-09-23 10:32:09
【问题描述】:
所以我有以下代码块:
#!/usr/bin/env node
const path = require('path');
const yargs = require('yargs').argv;
const ghpages = require('gh-pages');
const randomstring = require("randomstring");
const dirName = randomstring.generate({
length: 12,
charset: 'alphabetic'
});
console.log(__dirname, dirName, process.cwd(), yargs.directory, yargs.branch);
ghpages.publish(path.join(process.cwd(), yargs.directory), {
branch: yargs.branch,
clone: `../../../../tmp/${dirName}`
}, () => {
console.log('removing');
});
这需要clone 位置的绝对路径。
显然,我目前已对其进行硬编码以进行测试,但我想做的是从process.cwd() 获取到/tmp/ 的绝对路径。
所以基本上我想要的是如果我在/home/otis 中运行脚本../../../../tmp/${dirName} 会变成../../tmp/${dirName} 所以我需要根据process.cwd() 生成路径
有什么想法吗?
干杯/
【问题讨论】:
标签: node.js process relative-path absolute-path