diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..fef12663 --- /dev/null +++ b/.babelrc @@ -0,0 +1,10 @@ +{ + "presets": [ + ["env", { + "targets": { + "node": "6" + } + }] + ], + "plugins": ["transform-object-rest-spread"] +} diff --git a/.gitignore b/.gitignore index fd4f2b06..da592f8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules .DS_Store +dist diff --git a/.travis.yml b/.travis.yml index 245900f1..813ea903 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ language: node_js +script: + - npm run build + - npm test node_js: - - 8 + - "8" + - "6" diff --git a/index.js b/index.js new file mode 100644 index 00000000..82323087 --- /dev/null +++ b/index.js @@ -0,0 +1,4 @@ +module.exports = + parseInt(process.versions.node, 10) < 8 + ? require('./dist/index.js') + : require('./lib/index.js'); diff --git a/package.json b/package.json index 359b1cd4..01564134 100644 --- a/package.json +++ b/package.json @@ -4,17 +4,20 @@ "description": "Lightweight, beautiful and user-friendly prompts", "homepage": "https://github.com/terkelg/prompts", "repository": "terkelg/prompts", - "main": "lib/index.js", + "main": "index.js", "author": { "name": "Terkel Gjervig", "email": "terkel@terkel.com", "url": "https://terkel.com" }, "files": [ - "lib" + "lib", + "dist", + "index.js" ], "scripts": { "start": "node lib/index.js", + "build": "babel lib -d dist", "test": "tape test/*.js | tap-spec" }, "keywords": [ @@ -31,10 +34,13 @@ "sisteransi": "^0.1.0" }, "devDependencies": { + "babel-cli": "^6.26.0", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-env": "^1.7.0", "tap-spec": "^4.1.1", "tape": "^4.8.0" }, "engines": { - "node": ">= 8" + "node": ">= 6" } } diff --git a/readme.md b/readme.md index 0684fef0..d639a5a6 100755 --- a/readme.md +++ b/readme.md @@ -43,7 +43,7 @@ $ npm install --save prompts ``` -> This package uses async/await and requires Node.js 7.6 +> This package supports Node 6 and above ![split](https://github.com/terkelg/prompts/raw/master/media/split.png) diff --git a/test/prompts.js b/test/prompts.js index a49ad337..f72215d2 100644 --- a/test/prompts.js +++ b/test/prompts.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('tape'); -const prompt = require('../lib'); +const prompt = require('../'); const { prompts } = prompt; test('basics', t => { @@ -36,18 +36,21 @@ test('prompts', t => { t.equal(Object.keys(prompts).length, types.length, 'all prompts are exported'); }); -test('injects', async t => { +test('injects', t => { let obj = { a:1, b:2, c:3 }; prompt.inject(obj); t.same(prompt._map, obj, 'injects key:val object of answers'); - let foo = await prompt({ name:'a' }); - t.same(foo, { a:1 }, 'immediately returns object with injected answer'); - t.same(prompt._map, { b:2, c:3 }, 'deletes the `a` key from internal map'); - - let bar = await prompt([{ name:'b' }, { name:'c' }]); - t.same(bar, { b:2, c:3 }, 'immediately handles two prompts at once'); - t.same(prompt._map, {}, 'leaves behind empty internal mapping when exhausted'); - - t.end(); + prompt({ name:'a' }) + .then(foo => { + t.same(foo, { a:1 }, 'immediately returns object with injected answer'); + t.same(prompt._map, { b:2, c:3 }, 'deletes the `a` key from internal map'); + + prompt([{ name:'b' }, { name:'c' }]) + .then(bar => { + t.same(bar, { b:2, c:3 }, 'immediately handles two prompts at once'); + t.same(prompt._map, {}, 'leaves behind empty internal mapping when exhausted'); + t.end(); + }) + }) })