diff --git a/.babelrc b/.babelrc index cb910fc..7ca7f6b 100644 --- a/.babelrc +++ b/.babelrc @@ -1,16 +1,42 @@ { - "presets": ["es2015"], - "plugins": ["transform-class-properties", "transform-object-rest-spread"], - "env": { - "test": { - "plugins": [ - ["istanbul", { - "exclude": [ - "**/test/*.js", - "test-server.js" - ] - }] - ] + "env": { + "commonjs": { + "presets": [ + "es2015" + ], + "plugins": [ + "transform-runtime", + "transform-class-properties", + "transform-object-rest-spread" + ] + }, + "es": { + "presets": [ + ["es2015", { + "loose": false, + "modules": false + }] + ], + "plugins": [ + "transform-runtime", + "transform-class-properties", + "transform-object-rest-spread" + ] + }, + "test": { + "presets": [ + "es2015" + ], + "plugins": [ + "transform-class-properties", + "transform-object-rest-spread", + ["istanbul", { + "exclude": [ + "**/test/*.js", + "test-server.js" + ] + }] + ] + } } - } } diff --git a/index.js b/index.js deleted file mode 100644 index f472c54..0000000 --- a/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./src/index'); diff --git a/lib.js b/lib.js deleted file mode 100644 index f4f0e99..0000000 --- a/lib.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./dist/index'); diff --git a/package.json b/package.json index 17dc865..1d090b3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,9 @@ "name": "tg-resources", "version": "1.0.0", "description": "Abstractions on-top of `superagent` (or other Ajax libaries) for communication with REST.", - "main": "lib.js", + "main": "./dist/index.js", + "jsnext:main": "./es/index.js", + "module": "es/index.js", "files": [ "dist/", "src/", @@ -10,18 +12,17 @@ "index.js" ], "scripts": { - "clean": "rimraf dist", - "lint": "eslint src test", - "watch": "watch 'npm run build' src test", + "clean": "$(npm bin)/rimraf dist", + "lint": "$(npm bin)/eslint src test", "pretest": "npm run lint", - "test": "NODE_ENV=test nyc --require babel-register mocha -u exports test/*.js", - "coverage": "nyc report && nyc report --reporter=html", - "coveralls": "nyc report --reporter=text-lcov | coveralls", + "test": "cross-env BABEL_ENV=test $(npm bin)/nyc mocha -u exports test/*.js", + "coverage": "$(npm bin)/nyc report && $(npm bin)/nyc report --reporter=html", + "coveralls": "$(npm bin)/nyc report --reporter=text-lcov | $(npm bin)/coveralls", "prebuild": "npm run clean -s", - "build": "babel --optional runtime src -d dist", - "toc": "doctoc --github --title \"# Changelog\" CHANGELOG.md", - "prerelease": "npm run build -s", - "release": "node ./scripts/release.js" + "build": "npm run build:umd && npm run build:es", + "build:umd": "cross-env BABEL_ENV=commonjs $(npm bin)/babel src -d dist", + "build:es": "cross-env BABEL_ENV=es $(npm bin)/babel src -d es", + "toc": "$(npm bin)/doctoc --github --title \"# Changelog\" CHANGELOG.md" }, "repository": { "type": "git", @@ -46,6 +47,7 @@ "babel-plugin-istanbul": "^4.1.4", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.23.0", + "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-es2015": "^6.24.1", "babel-register": "^6.24.0", "babel-runtime": "*", @@ -53,6 +55,7 @@ "chai": "^4.1.0", "cookie-parser": "^1.4.3", "coveralls": "*", + "cross-env": "^5.0.1", "debug": "*", "doctoc": "*", "eslint": "^3.19.0", @@ -78,6 +81,9 @@ "cookie": ">=0.2.2" }, "nyc": { + "require": [ + "babel-register" + ], "sourceMap": false, "instrument": false } diff --git a/scripts/release.js b/scripts/release.js deleted file mode 100644 index cbac03b..0000000 --- a/scripts/release.js +++ /dev/null @@ -1,159 +0,0 @@ -var fs = require('fs-extra'); -var path = require('path'); -var child_process = require('child_process'); -var readline = require('readline'); -var debug = require('debug'); - -var rl = readline.createInterface(process.stdin, process.stdout); - -// Enable debug for our namespace -debug.enable('log,log:*'); - -if (process.env.NODE_ENV === 'production') { - debug('log')('log:NODE_ENV is set to production which breaks npm install in temporary dir. Exiting'); - process.exit(0); -} - -var rimraf = require('rimraf'); - - -function makeRelease(releaseType, modifiers, callback) { - var log = debug(`log:${releaseType}`); - - // Get version string from package.json - const packageData = require('../package.json'); - - // Get current time and convert it to FS safe value - const curTime = new Date().toISOString().replace(/:|\./gi, '-'); - - // Target build dir - const targetDir = path.join('.release', `${releaseType}-${curTime}`); - - // Log parameters - log(`Original: ${packageData.name}@${packageData.version}`); - log(`Release Type: ${releaseType}`); - log(`Target Dir: ${targetDir}`); - - // Modify package data with modifiers - (modifiers || []).forEach(modFn => { - // Extend packageData - Object.assign(packageData, modFn(Object.assign({}, packageData), releaseType, curTime)); - }); - - // Log new name - log(`Preparing: ${packageData.name}@${packageData.version}`); - - // Create directory - fs.mkdirpSync(targetDir); - - // Copy files to it ignoring dist & scripts - fs.copy('.', targetDir, { - filter: tPath => { - tPath = tPath.replace(path.join(__dirname, '..'), ''); - - if (tPath[0] === '/') { - tPath = tPath.substring(1); - } - - if (tPath.startsWith('.git/') || tPath === '.git') { - return false; - } - - return !(tPath.startsWith('.release') || tPath.startsWith('node_modules') || tPath.startsWith('dist') || tPath.startsWith('scripts')); - } - }, () => { - // Dump out pacakge.json - fs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageData)); - - // Link node modules - log('Directories synced'); - - log('Installing node modules'); - child_process.execSync('npm install', { - cwd: targetDir - }); - log('Installed node modules'); - - log('Building package'); - child_process.execSync('npm run build', { - cwd: targetDir - }); - log('Completed'); - - const anwserHandler = function(answer) { - answer = answer.trim().toLowerCase(); - - if (answer === 'y' || answer === 'yes' ) { - log('releasing package'); - child_process.execSync('npm publish', { - cwd: targetDir - }); - log('package released'); - } else { - log('Not releasing!'); - } - - log('Cleaning up node modules to preserve disk space'); - rimraf(`${targetDir}/node_modules`, {}, function () { - log('Done'); - - if (callback) { - callback(); - } - }); - } - - if (process.env.R_NO_PROMPT !== 'y') { - rl.question(`Release ${packageData.name}@${packageData.version} on npm? [yes]/no: `, anwserHandler); - } else { - anwserHandler('yes'); - } - }); -} - -/** - * Set correct release name - */ -function setReleaseName(packageData, releaseType, curTime) { - if (releaseType !== 'default') { - packageData.name = `${packageData.name}-${releaseType}`; - } - - return packageData; -} - -/** - * Remove browser/node specific peerDependencies from react-native release - */ - -function cleanupPeerDeps(packageData, releaseType, curTime) { - if (releaseType === 'react-native') { - delete packageData.peerDependencies['babel-runtime']; - } - - return packageData; -} - -function removeRuntimeBuild(packageData, releaseType, curTime) { - if (releaseType === 'react-native') { - packageData.scripts.build = packageData.scripts.build.replace('--optional runtime', '') - } - - return packageData; -} - -const ourModifiers = [ - setReleaseName, - cleanupPeerDeps, - removeRuntimeBuild -]; - - -// First release the default, then the react-native version -makeRelease('default', ourModifiers, () => { - makeRelease('react-native', ourModifiers, () => { - // Cleanup after readline - rl.close(); - process.stdin.destroy(); - }); -}); diff --git a/test/.eslintrc b/test/.eslintrc index 00f5c87..59a4422 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,5 +1,5 @@ { "rules": { - "no-new": 0, - }, + "no-new": 0 + } } diff --git a/test/InvalidResponseCode.js b/test/InvalidResponseCode.js index 8109974..71179f9 100644 --- a/test/InvalidResponseCode.js +++ b/test/InvalidResponseCode.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { InvalidResponseCode } from '../index'; +import { InvalidResponseCode } from '../src'; let instance = null; diff --git a/test/NetworkError.js b/test/NetworkError.js index 677481a..c94a249 100644 --- a/test/NetworkError.js +++ b/test/NetworkError.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { NetworkError } from '../index'; +import { NetworkError } from '../src'; let instance = null; diff --git a/test/ValidationError.js b/test/ValidationError.js index 335c87d..c25ac7a 100644 --- a/test/ValidationError.js +++ b/test/ValidationError.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { ValidationError } from '../index'; +import { ValidationError } from '../src'; let instance = null; diff --git a/test/exports.js b/test/exports.js index f15127f..4b239f3 100644 --- a/test/exports.js +++ b/test/exports.js @@ -1,6 +1,6 @@ import { assert, expect } from 'chai'; -import * as tgResources from '../index'; +import * as tgResources from '../src'; import { isSubClass } from '../src/typeChecks'; diff --git a/test/functional.js b/test/functional.js index f2c02f9..e18c9f6 100644 --- a/test/functional.js +++ b/test/functional.js @@ -2,7 +2,7 @@ import { assert, expect } from 'chai'; import listen from '../test-server'; -import { Resource } from '../index'; +import { Resource } from '../src'; import { isSubClass } from '../src/typeChecks'; diff --git a/test/router.js b/test/router.js index e2704f0..f971fb6 100644 --- a/test/router.js +++ b/test/router.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import Router, { Resource } from '../index'; +import Router, { Resource } from '../src'; export default {