diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..b23bee2 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,27 @@ +"use strict"; +/* eslint sort-keys: ["error", "asc"] */ + +module.exports = { + "env": { + "node": true + }, + "extends": "eslint:recommended", + "rules": { + "indent": "off", + "linebreak-style": [ + "error", + "unix", + ], + "no-console": "off", + "no-octal": "off", + "no-unused-vars": "warn", + "quotes": [ + "error", + "double", + ], + "semi": [ + "error", + "never", + ], + } +} diff --git a/.travis.yml b/.travis.yml index 2ca91f2..5947413 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,10 @@ +# Configuration +sudo: false language: node_js + node_js: - - "0.10" - - "0.8" \ No newline at end of file + - "stable" + - "lts/*" + +before_script: + - "npm run lint" diff --git a/README.md b/README.md index ff6745f..37460b5 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ since symlinks are not suitable for this purpose there. On Unix systems, you should use a symbolic link instead. -[![Build Status](https://img.shields.io/travis/ForbesLindesay/cmd-shim/master.svg)](https://travis-ci.org/ForbesLindesay/cmd-shim) -[![Dependency Status](https://img.shields.io/david/ForbesLindesay/cmd-shim.svg)](https://david-dm.org/ForbesLindesay/cmd-shim) +[![Build Status](https://img.shields.io/travis/npm/cmd-shim/master.svg)](https://travis-ci.org/npm/cmd-shim) +[![Dependency Status](https://img.shields.io/david/npm/cmd-shim.svg)](https://david-dm.org/npm/cmd-shim) [![NPM version](https://img.shields.io/npm/v/cmd-shim.svg)](https://www.npmjs.com/package/cmd-shim) ## Installation @@ -17,7 +17,7 @@ npm install cmd-shim ## API -### cmdShim(from, to, cb) +### `cmdShim(from, to, cb)` Create a cmd shim at `to` for the command line program at `from`. e.g. @@ -29,7 +29,7 @@ cmdShim(__dirname + '/cli.js', '/usr/bin/command-name', function (err) { }); ``` -### cmdShim.ifExists(from, to, cb) +### `cmdShim.ifExists(from, to, cb)` The same as above, but will just continue if the file does not exist. Source: diff --git a/index.js b/index.js index 9f22e10..a6d9fe7 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ var fs = require("graceful-fs") var mkdir = require("mkdirp") , path = require("path") - , shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/ + , shebangExpr = /^#!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/ function cmdShimIfExists (from, to, cb) { fs.stat(from, function (er) { @@ -132,12 +132,12 @@ function writeShim_ (from, to, prog, args, cb) { if (shLongProg) { sh = sh - + "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n" - + "\n" - + "case `uname` in\n" - + " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n" - + "esac\n" - + "\n" + + "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n" + + "\n" + + "case `uname` in\n" + + " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n" + + "esac\n" + + "\n" sh = sh + "if [ -x "+shLongProg+" ]; then\n" diff --git a/package.json b/package.json index 95520a9..f5b0023 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.2", "description": "Used in npm for command line application support", "scripts": { + "lint": "eslint **/*.js", "test": "tap test/*.js" }, "repository": { @@ -15,7 +16,8 @@ "mkdirp": "~0.5.0" }, "devDependencies": { - "tap": "~0.4.11", - "rimraf": "~2.2.8" + "eslint": "~4.19.1", + "rimraf": "~2.6.2", + "tap": "~12.0.1" } -} \ No newline at end of file +} diff --git a/test/00-setup.js b/test/00-setup.js index 04ec2b2..ce78626 100644 --- a/test/00-setup.js +++ b/test/00-setup.js @@ -1,30 +1,30 @@ -var test = require('tap').test -var mkdirp = require('mkdirp') -var fs = require('fs') -var path = require('path') -var fixtures = path.resolve(__dirname, 'fixtures') +var test = require("tap").test +var mkdirp = require("mkdirp") +var fs = require("fs") +var path = require("path") +var fixtures = path.resolve(__dirname, "fixtures") var froms = { - 'from.exe': 'exe', - 'from.env': '#!/usr/bin/env node\nconsole.log(/hi/)\n', - 'from.env.args': '#!/usr/bin/env node --expose_gc\ngc()\n', - 'from.sh': '#!/usr/bin/sh\necho hi\n', - 'from.sh.args': '#!/usr/bin/sh -x\necho hi\n' + "from.exe": "exe", + "from.env": "#!/usr/bin/env node\nconsole.log(/hi/)\n", + "from.env.args": "#!/usr/bin/env node --expose_gc\ngc()\n", + "from.sh": "#!/usr/bin/sh\necho hi\n", + "from.sh.args": "#!/usr/bin/sh -x\necho hi\n" } -var cmdShim = require('../') +var cmdShim = require("../") -test('create fixture', function (t) { +test("create fixture", function (t) { mkdirp(fixtures, function (er) { if (er) throw er - t.pass('made dir') + t.pass("made dir") Object.keys(froms).forEach(function (f) { - t.test('write ' + f, function (t) { + t.test("write " + f, function (t) { fs.writeFile(path.resolve(fixtures, f), froms[f], function (er) { if (er) throw er - t.pass('wrote ' + f) + t.pass("wrote " + f) t.end() }) }) diff --git a/test/basic.js b/test/basic.js index 0982315..66a598b 100755 --- a/test/basic.js +++ b/test/basic.js @@ -1,35 +1,35 @@ -var test = require('tap').test -var mkdirp = require('mkdirp') -var fs = require('fs') -var path = require('path') -var fixtures = path.resolve(__dirname, 'fixtures') +var test = require("tap").test +var mkdirp = require("mkdirp") +var fs = require("fs") +var path = require("path") +var fixtures = path.resolve(__dirname, "fixtures") -var cmdShim = require('../') +var cmdShim = require("../") -test('no shebang', function (t) { - var from = path.resolve(fixtures, 'from.exe') - var to = path.resolve(fixtures, 'exe.shim') +test("no shebang", function (t) { + var from = path.resolve(fixtures, "from.exe") + var to = path.resolve(fixtures, "exe.shim") cmdShim(from, to, function(er) { if (er) throw er - t.equal(fs.readFileSync(to, 'utf8'), + t.equal(fs.readFileSync(to, "utf8"), "\"$basedir/from.exe\" \"$@\"\nexit $?\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + t.equal(fs.readFileSync(to + ".cmd", "utf8"), "@\"%~dp0\\from.exe\" %*\r\n") t.end() }) }) -test('env shebang', function (t) { - var from = path.resolve(fixtures, 'from.env') - var to = path.resolve(fixtures, 'env.shim') +test("env shebang", function (t) { + var from = path.resolve(fixtures, "from.env") + var to = path.resolve(fixtures, "env.shim") cmdShim(from, to, function(er) { if (er) throw er - console.error('%j', fs.readFileSync(to, 'utf8')) - console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) + console.error("%j", fs.readFileSync(to, "utf8")) + console.error("%j", fs.readFileSync(to + ".cmd", "utf8")) - t.equal(fs.readFileSync(to, 'utf8'), + t.equal(fs.readFileSync(to, "utf8"), "#!/bin/sh"+ "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ "\n"+ @@ -46,7 +46,7 @@ test('env shebang', function (t) { "\nfi"+ "\nexit $ret"+ "\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + t.equal(fs.readFileSync(to + ".cmd", "utf8"), "@IF EXIST \"%~dp0\\node.exe\" (\r"+ "\n \"%~dp0\\node.exe\" \"%~dp0\\from.env\" %*\r"+ "\n) ELSE (\r"+ @@ -58,16 +58,16 @@ test('env shebang', function (t) { }) }) -test('env shebang with args', function (t) { - var from = path.resolve(fixtures, 'from.env.args') - var to = path.resolve(fixtures, 'env.args.shim') +test("env shebang with args", function (t) { + var from = path.resolve(fixtures, "from.env.args") + var to = path.resolve(fixtures, "env.args.shim") cmdShim(from, to, function(er) { if (er) throw er - console.error('%j', fs.readFileSync(to, 'utf8')) - console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) + console.error("%j", fs.readFileSync(to, "utf8")) + console.error("%j", fs.readFileSync(to + ".cmd", "utf8")) - t.equal(fs.readFileSync(to, 'utf8'), + t.equal(fs.readFileSync(to, "utf8"), "#!/bin/sh"+ "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ "\n"+ @@ -84,7 +84,7 @@ test('env shebang with args', function (t) { "\nfi"+ "\nexit $ret"+ "\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + t.equal(fs.readFileSync(to + ".cmd", "utf8"), "@IF EXIST \"%~dp0\\node.exe\" (\r"+ "\n \"%~dp0\\node.exe\" --expose_gc \"%~dp0\\from.env.args\" %*\r"+ "\n) ELSE (\r"+ @@ -96,16 +96,16 @@ test('env shebang with args', function (t) { }) }) -test('explicit shebang', function (t) { - var from = path.resolve(fixtures, 'from.sh') - var to = path.resolve(fixtures, 'sh.shim') +test("explicit shebang", function (t) { + var from = path.resolve(fixtures, "from.sh") + var to = path.resolve(fixtures, "sh.shim") cmdShim(from, to, function(er) { if (er) throw er - console.error('%j', fs.readFileSync(to, 'utf8')) - console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) + console.error("%j", fs.readFileSync(to, "utf8")) + console.error("%j", fs.readFileSync(to + ".cmd", "utf8")) - t.equal(fs.readFileSync(to, 'utf8'), + t.equal(fs.readFileSync(to, "utf8"), "#!/bin/sh" + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + "\n" + @@ -123,7 +123,7 @@ test('explicit shebang', function (t) { "\nexit $ret" + "\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + t.equal(fs.readFileSync(to + ".cmd", "utf8"), "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + "\n \"%~dp0\\/usr/bin/sh.exe\" \"%~dp0\\from.sh\" %*\r" + "\n) ELSE (\r" + @@ -135,16 +135,16 @@ test('explicit shebang', function (t) { }) }) -test('explicit shebang with args', function (t) { - var from = path.resolve(fixtures, 'from.sh.args') - var to = path.resolve(fixtures, 'sh.args.shim') +test("explicit shebang with args", function (t) { + var from = path.resolve(fixtures, "from.sh.args") + var to = path.resolve(fixtures, "sh.args.shim") cmdShim(from, to, function(er) { if (er) throw er - console.error('%j', fs.readFileSync(to, 'utf8')) - console.error('%j', fs.readFileSync(to + '.cmd', 'utf8')) + console.error("%j", fs.readFileSync(to, "utf8")) + console.error("%j", fs.readFileSync(to + ".cmd", "utf8")) - t.equal(fs.readFileSync(to, 'utf8'), + t.equal(fs.readFileSync(to, "utf8"), "#!/bin/sh" + "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + "\n" + @@ -162,7 +162,7 @@ test('explicit shebang with args', function (t) { "\nexit $ret" + "\n") - t.equal(fs.readFileSync(to + '.cmd', 'utf8'), + t.equal(fs.readFileSync(to + ".cmd", "utf8"), "@IF EXIST \"%~dp0\\/usr/bin/sh.exe\" (\r" + "\n \"%~dp0\\/usr/bin/sh.exe\" -x \"%~dp0\\from.sh.args\" %*\r" + "\n) ELSE (\r" + diff --git a/test/zz-cleanup.js b/test/zz-cleanup.js index 9425031..3d7bd4e 100644 --- a/test/zz-cleanup.js +++ b/test/zz-cleanup.js @@ -1,13 +1,13 @@ -var test = require('tap').test -var path = require('path') -var fixtures = path.resolve(__dirname, 'fixtures') -var rimraf = require('rimraf') +var test = require("tap").test +var path = require("path") +var fixtures = path.resolve(__dirname, "fixtures") +var rimraf = require("rimraf") -test('cleanup', function(t) { +test("cleanup", function(t) { rimraf(fixtures, function(er) { if (er) throw er - t.pass('cleaned up') + t.pass("cleaned up") t.end() }) })