Comparing version 1.0.2 to 1.0.3
@@ -7,18 +7,39 @@ "use strict"; | ||
var npmRoot = cp.execSync("npm -g root", { | ||
encoding: 'utf8' | ||
encoding: 'utf8' | ||
}); | ||
var isWin = /win/i.test(process.platform); | ||
fs.writeFile(path.join(npmRoot, '../dict' + (isWin ? '.cmd' : '')), fileContent(__dirname), (err) => { | ||
if (err) throw err; | ||
console.log("dict 已成为全局命令,您现在可以执行命令:"); | ||
console.log(color.green(" dict hello")); | ||
console.log("即可翻译hello"); | ||
}); | ||
var platform = { | ||
isWin: /win/i.test(process.platform), | ||
isLinux: /linux/i.test(process.platform) | ||
}; | ||
if (platform.isWin) { | ||
fs.writeFile(path.join(npmRoot, '../dict.cmd'), fileContent(__dirname), (err) => { | ||
if (err) throw err; | ||
console.log("dict 已成为全局命令,您现在可以执行命令:"); | ||
console.log(color.green(" dict hello")); | ||
console.log("即可翻译hello"); | ||
}); | ||
} else if (platform.isLinux) { | ||
let dictPath = path.join(__dirname, "bin/dict"); | ||
fs.writeFile(dictPath, fileContent(__dirname), { | ||
mode: 0o777 /// 必须具备执行的权限,否则执行 dict 时会提示没有权限 | ||
}, err => { | ||
if (err) throw err; | ||
cp.exec(`ln -s ${dictPath} ${path.join(process.argv[0],'../dict')}`, { | ||
encoding: 'utf8' | ||
}, (error, stdout, stderr) => { | ||
if (error) throw error; | ||
console.log("dict 已成为全局命令,您现在可以执行命令:"); | ||
console.log(color.green(" dict hello")); | ||
console.log("即可翻译hello"); | ||
}); | ||
}); | ||
} | ||
function fileContent(projectRoot) { | ||
projectRoot = path.join(projectRoot, 'index.js'); | ||
var s; | ||
if (isWin) { | ||
s = `@IF EXIST "%~dp0\\node.exe" ( | ||
projectRoot = path.join(projectRoot, 'index.js'); | ||
var s; | ||
if (platform.isWin) { | ||
s = `@IF EXIST "%~dp0\\node.exe" ( | ||
"%~dp0\\node.exe" "${projectRoot}" %* | ||
@@ -31,21 +52,9 @@ ) ELSE ( | ||
`; | ||
} else if (/linux/i.test(process.platform)) { | ||
s = `bin/sh | ||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") | ||
} else if (platform.isLinux) { | ||
s = `#!/usr/bin/env node | ||
case \`uname\` in | ||
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; | ||
esac | ||
if [ -x "$basedir/node" ]; then | ||
"$basedir/node" "${projectRoot}" "$@" | ||
ret=$? | ||
else | ||
node "${projectRoot}" "$@" | ||
ret=$? | ||
fi | ||
exit $ret | ||
require('${projectRoot}'); | ||
`; | ||
} | ||
return s; | ||
} | ||
return s; | ||
} |
{ | ||
"name" : "node-dict", | ||
"version" : "1.0.2", | ||
"version" : "1.0.3", | ||
"description" : "cmd dict", | ||
@@ -5,0 +5,0 @@ "bin" : { |
@@ -1,2 +0,7 @@ | ||
# 安装方法 | ||
# 自动安装 | ||
```bash | ||
npm install node-dict -g | ||
``` | ||
# 手动安装方法 | ||
1. 下载源码; | ||
@@ -6,2 +11,3 @@ 2. 安装nodejs(4.0+); | ||
4. (仍然在源码的根目录下)执行`node install.js`(此步骤是将`dict`放到全局环境) | ||
> 注意:手动安装方法只在 `Windows 10 x64` 和 `Ubuntu 16.04 x64`测试通过,建议使用npm进行安装。 | ||
@@ -8,0 +14,0 @@ # 使用方法 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5818
95
16