├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── lib └── index.js ├── package.json ├── src └── index.js └── test ├── index.js └── tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | # Don't publish the test directory to NPM. 30 | test 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.0" 4 | - "iojs" 5 | - "0.12" 6 | - "0.11" 7 | - "0.10" 8 | 9 | # Allow Travis tests to run in containers. 10 | sudo: false 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ben Newman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jsnext-skeleton [![Build Status](https://travis-ci.org/benjamn/jsnext-skeleton.svg?branch=master)](https://travis-ci.org/benjamn/jsnext-skeleton) 2 | 3 | Skeleton project demonstrating best practices for authoring and publishing the latest version of JavaScript to NPM. 4 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _regeneratorRuntime = require("babel-runtime/regenerator")["default"]; 4 | 5 | var _Promise = require("babel-runtime/core-js/promise")["default"]; 6 | 7 | Object.defineProperty(exports, "__esModule", { 8 | value: true 9 | }); 10 | exports.sleep = sleep; 11 | 12 | var _packageJson = require("../package.json"); 13 | 14 | Object.defineProperty(exports, "version", { 15 | enumerable: true, 16 | get: function get() { 17 | return _packageJson.version; 18 | } 19 | }); 20 | 21 | function sleep(ms) { 22 | return _regeneratorRuntime.async(function sleep$(context$1$0) { 23 | while (1) switch (context$1$0.prev = context$1$0.next) { 24 | case 0: 25 | context$1$0.next = 2; 26 | return _regeneratorRuntime.awrap(new _Promise(function (resolve) { 27 | return setTimeout(resolve, ms); 28 | })); 29 | 30 | case 2: 31 | return context$1$0.abrupt("return", ms); 32 | 33 | case 3: 34 | case "end": 35 | return context$1$0.stop(); 36 | } 37 | }, null, this); 38 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsnext-skeleton", 3 | "version": "0.1.2", 4 | "description": "Skeleton project demonstrating best practices for authoring and publishing the latest version of JavaScript to NPM.", 5 | "main": "./lib/index.js", 6 | "jsnext:main": "./src/index.js", 7 | "scripts": { 8 | "prepublish": "babel --optional runtime src/ --out-dir lib/", 9 | "test": "mocha --reporter spec --full-trace test/index.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+ssh://git@github.com/benjamn/jsnext-skeleton.git" 14 | }, 15 | "keywords": [ 16 | "ecmascript", 17 | "es2015", 18 | "jsnext", 19 | "javascript", 20 | "skeleton", 21 | "npm", 22 | "babel" 23 | ], 24 | "author": "Ben Newman ", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/benjamn/jsnext-skeleton/issues" 28 | }, 29 | "homepage": "https://github.com/benjamn/jsnext-skeleton#readme", 30 | "dependencies": { 31 | "babel-runtime": "^5.8.25" 32 | }, 33 | "devDependencies": { 34 | "babel": "^5.8.23", 35 | "mocha": "^2.3.3" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export {version} from "../package.json"; 2 | 3 | export async function sleep(ms) { 4 | await new Promise(resolve => setTimeout(resolve, ms)); 5 | return ms; 6 | } 7 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | // This file cannot be written with ECMAScript 2015 because it has to load 2 | // the Babel require hook to enable ECMAScript 2015 features! 3 | require("babel/register")({ 4 | optional: "runtime" 5 | }); 6 | 7 | // The tests, however, can and should be written with ECMAScript 2015. 8 | require("./tests.js"); 9 | -------------------------------------------------------------------------------- /test/tests.js: -------------------------------------------------------------------------------- 1 | import assert from "assert"; 2 | import {version as pkgVersion} from "../package.json"; 3 | import {version as srcVersion, sleep as srcSleep} from "../src/index.js"; 4 | import {version as libVersion, sleep as libSleep} from "../lib/index.js"; 5 | 6 | describe("jsnext-skeleton", () => { 7 | it("can be imported", () => { 8 | assert.strictEqual(pkgVersion, srcVersion); 9 | assert.strictEqual(pkgVersion, libVersion); 10 | }); 11 | 12 | it("supports async", async () => { 13 | const start = Date.now(); 14 | await Promise.all([ 15 | srcSleep(100), srcSleep(100), srcSleep(100), 16 | libSleep(100), libSleep(100), libSleep(100) 17 | ]).then(hundreds => { 18 | assert.ok(hundreds.every(n => n === 100)); 19 | assert.ok(Date.now() - start < 150); 20 | }); 21 | }); 22 | }); 23 | --------------------------------------------------------------------------------