Skip to content

Commit

Permalink
Merge 36f5f75 into f657f8d
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Sep 5, 2017
2 parents f657f8d + 36f5f75 commit 02cfd5b
Show file tree
Hide file tree
Showing 26 changed files with 772 additions and 445 deletions.
35 changes: 3 additions & 32 deletions .babelrc
@@ -1,34 +1,5 @@
{
"env": {
"webpack": {
"presets": [
["env", {
"targets": {
"node": "4.7",
"browsers": [
"last 3 versions",
"ie >= 11"
]
},
"modules": false
}]
],
"plugins": ["transform-object-assign"]
},
"test": {
"presets": [
["env", {
"targets": {
"node": "4.7",
"browsers": [
"last 3 versions",
"ie >= 11"
]
}
}]
],
"plugins": ["rewire", "transform-object-assign"],
"sourceMaps": "inline"
}
}
"presets": [
"./.babelrc.js"
]
}
106 changes: 106 additions & 0 deletions .babelrc.js
@@ -0,0 +1,106 @@
// About this file:
// Babel 7 introduces .babelrc.js files. The .babelrc file can be removed when Babel 7 is released. (https://github.com/babel/babel/pull/4892)

// Babel 7 will also remove the 'env' option --> https://github.com/babel/babel/issues/4539#issuecomment-284870486
var env = process.env.BABEL_ENV || process.env.NODE_ENV

var defaultBabelPresetEnvConfig = {
// No module transformation, webpack will take care of this if necessary.
'modules': false
}

// Latest browsers
var browserBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': {
'browsers': [
'last 2 versions',
'not ie < 13',
'not android < 50'
]
}
})

// Legacy browsers
var legacyBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': {
'browsers': [
'last 5 versions',
'not ie < 10'
]
}
})

// Node
var nodeBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': {
'node': '4.7'
}
})

// Combined node and browser environment for es6 modules version and tests
var modulesBabelPresetEnvConfig = Object.assign({}, defaultBabelPresetEnvConfig, {
'targets': Object.assign(legacyBabelPresetEnvConfig.targets, nodeBabelPresetEnvConfig.targets)
})

var testBabelPresetEnvConfig = Object.assign({}, modulesBabelPresetEnvConfig, {
// Tests need to transform modules
'modules': 'commonjs'
})

var plugins = [
'transform-object-rest-spread',
'lodash',
['inline-replace-variables', {
// Inject version number into code
'__VERSION__': require('./package.json').version
}]
]

var babelConfig = {
plugins
}

if (env === 'browser') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', browserBabelPresetEnvConfig]
]
})
}

if (env === 'legacy') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', legacyBabelPresetEnvConfig]
]
})
}

if (env === 'modules') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', modulesBabelPresetEnvConfig]
]
})
}

if (env === 'node') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', nodeBabelPresetEnvConfig]
]
})
}

if (env === 'test') {
babelConfig = Object.assign(babelConfig, {
'presets': [
['env', testBabelPresetEnvConfig]
],
'plugins': babelConfig.plugins.concat([
'rewire'
])
})
}

module.exports = babelConfig
5 changes: 4 additions & 1 deletion .eslintrc.js
Expand Up @@ -3,5 +3,8 @@ module.exports = {
'plugins': [
'standard',
'promise'
]
],
'globals': {
'__VERSION__': true
}
}
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,7 @@ language: node_js
node_js:
- "6.9"
- "4.7"
script: npm run test:ci
script: npm run test
after_success:
- curl -Lo travis_after_all.py https://raw.githubusercontent.com/contentful/travis_after_all/master/travis_after_all.py
- python travis_after_all.py
Expand Down
47 changes: 40 additions & 7 deletions README.md
Expand Up @@ -11,6 +11,8 @@
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![npm downloads](https://img.shields.io/npm/dm/contentful.svg)](http://npm-stat.com/charts.html?package=contentful)
[![gzip bundle size](http://img.badgesize.io/https://unpkg.com/contentful/dist/contentful.browser.min.js?compression=gzip
)](https://unpkg.com/contentful/dist/contentful.browser.min.js)

[Contentful](https://www.contentful.com) is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via a powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.

Expand All @@ -26,7 +28,7 @@ Browsers and Node.js:
- Chrome
- Firefox
- Edge
- IE11 (with [es6-promise](https://github.com/stefanpenner/es6-promise) polyfill applied)
- IE11 (with [legacy version](#legacy-browsers) of the library)
- Safari
- node.js (4.x, 6.x)

Expand All @@ -44,30 +46,47 @@ In order to get started with the Contentful JS SDK you'll need not only to insta
- [Advanced features](#advanced-features)
- [Troubleshooting](#troubleshooting)
- [Documentation/References](#documentationreferences)

## Installation

In node, using [npm](http://npmjs.org):
### Node:

Using [npm](http://npmjs.org):

``` sh
npm install contentful
```

Or, if you'd like to use a standalone built file you can use the following script tag or just download it from [unpkg](https://unpkg.com), under the `dist` directory:
Using [yarn](https://yarnpkg.com/lang/en/):

``` sh
yarn add contentful
```

### Browser:

If you'd like to use a standalone built file you can use the following script tag or download it from [unpkg](https://unpkg.com), under the `dist` directory:

``` html
<script src="https://unpkg.com/contentful@latest/dist/contentful.min.js"></script>
<script src="https://unpkg.com/contentful@latest/dist/contentful.browser.min.js"></script>
```
**It is not recommended to use the above URL for production.**
**It's not recommended to use the above URL for production.**

Using `contentful@latest` will always get you the latest version, but you can also specify a specific version number:

``` html
<script src="https://unpkg.com/contentful@4.1.1/dist/contentful.min.js"></script>
<script src="https://unpkg.com/contentful@4.1.1/dist/contentful.browser.min.js"></script>
```

The Contentful Delivery SDK will be accessible via the `contentful` global variable.

Check the [releases](https://github.com/contentful/contentful.js/releases) page to know which versions are available.

### Legacy browsers:

This library also comes with a legacy version to support Internet Explorer 11 and other older browsers. It already contains a polyfill for Promises.

To support legacy browsers in your application, use `contentful.legacy.min.js` instead of `contentful.browser.min.js`

## Authentication

To get content from Contentful, an app should authenticate with an OAuth bearer token.
Expand Down Expand Up @@ -259,19 +278,27 @@ This path gets appended to the host to allow request urls like `https://gateway.
#### httpAgent (default: `undefined`)
Custom agent to perform HTTP requests. Find further information in the [axios request config documentation](https://github.com/mzabriskie/axios#request-config).

#### httpsAgent (default: `undefined`)
Custom agent to perform HTTPS requests. Find further information in the [axios request config documentation](https://github.com/mzabriskie/axios#request-config).

#### headers (default: `[]`)
Additional headers to attach to the requests. We add/overwrite the following headers:

* Content-Type: `application/vnd.contentful.management.v1+json`
* X-Contentful-User-Agent: `sdk contentful.js/1.2.3; platform node.js/1.2.3; os macOS/1.2.3`
(Automatically generated)

#### proxy (default: `undefined`)
Axios proxy configuration. See the [axios request config documentation](https://github.com/mzabriskie/axios#request-config) for further information about the supported values.

#### resolveLinks (default: `true`)
Turn off to disable link resolving.

#### retryOnError (default: `true`)
By default, this SDK is retrying requests which resulted in a 500 server error and 429 rate limit response. Set this to `false` to disable this behavior.

#### logHandler (default: `function (level, data) {}`)
Errors and warnings will be logged by default to the node or browser console. Pass your own log handler to intercept here and handle errors, warnings and info on your own.

### Reference documentation

Expand Down Expand Up @@ -303,6 +330,12 @@ This means that new versions are released automatically as fixes, features or br

You can check the changelog on the [releases](https://github.com/contentful/contentful.js/releases) page.

## Migration from contentful.js 4.x

The bundle for browsers is now called `contentful.browser.min.js` to mark it clearly as browser only bundle. If you need to support IE 11 or other old browsers, you may use the `contentful.legacy.min.js`. Node will automatically use the `contentful.node.min.js` while bundlers like Webpack will resolve to the new ES-modules version of the library.

No changes to the API of the library were made.

## Migration from contentful.js 3.x

From version 4.0.0 and up contentful.js is exported as a single `umd` bundle the cdn distribution has changed, there is no more `browser-dist`. the new link format is https://unpkg.com/contentful@version/dist/contentful.min.js instead of https://unpkg.com/contentful@version/browser-dist/contentful.min.js. to access version 3 you can still use https://unpkg.com/contentful@3.0.0/browser-dist/contentful.min.js
Expand Down
8 changes: 1 addition & 7 deletions SETUP.md
Expand Up @@ -8,10 +8,4 @@ Details and notes about the build process and setup
"prepublish": "in-publish && npm run build || not-in-publish",
```

See https://www.npmjs.com/package/in-publish and https://medium.com/greenkeeper-blog/what-is-npm-s-prepublish-and-why-is-it-so-confusing-a948373e6be1#.u5ht8hn77

## Vendored axios

`index.js` is the entry point for the node.js package, and it requires a vendored version of Axios from the [contentful-sdk-core](https://github.com/contentful/contentful-sdk-core) package.

`browser.js` is the entry point for the CommonJS package when required from a browser aware environment (webpack or browserify) and for the standalone `browser-dist` build which is generated with webpack. This version requires a different vendored version of Axios which contains no code that isn't necessary for browsers.
See https://www.npmjs.com/package/in-publish and https://medium.com/greenkeeper-blog/what-is-npm-s-prepublish-and-why-is-it-so-confusing-a948373e6be1#.u5ht8hn77
20 changes: 17 additions & 3 deletions karma.base.conf.js
@@ -1,8 +1,9 @@
// This file is just a base configuration for karma and not directly usable
// Use karma.conf.local.js for local tests
// Use karma.conf.saucelabs.js for saucelabs tests
var _ = require('lodash')
var webpackConfig = _.cloneDeep(require('./webpack.config.js')[0])

const cloneDeep = require('lodash/cloneDeep')
const webpackConfig = cloneDeep(require('./webpack.config.js')[1])
delete webpackConfig.entry
delete webpackConfig.output
webpackConfig.devtool = 'inline-source-map'
Expand All @@ -13,6 +14,16 @@ webpackConfig.node = {
fs: 'empty'
}

webpackConfig.module.loaders = webpackConfig.module.loaders.map((loader) => {
if (loader.loader === 'babel-loader') {
loader.options.forceEnv = 'test'
}
return loader
})

console.log('Karma webpack config:')
console.log(JSON.stringify(webpackConfig, null, 2))

module.exports = {
plugins: [
require('karma-tap'),
Expand All @@ -31,7 +42,10 @@ module.exports = {
},

webpack: webpackConfig,

browserDisconnectTolerance: 5,
browserNoActivityTimeout: 4 * 60 * 1000,
browserDisconnectTimeout: 10000,
captureTimeout: 4 * 60 * 1000,
reporters: [ 'dots' ],
port: 9876,
colors: true,
Expand Down
3 changes: 2 additions & 1 deletion karma.conf.local.js
Expand Up @@ -2,7 +2,8 @@ var karmaBaseConf = require('./karma.base.conf')

module.exports = function (config) {
karmaBaseConf.plugins.push(require('karma-chrome-launcher'))
karmaBaseConf.browsers = ['Chrome']
karmaBaseConf.plugins.push(require('karma-firefox-launcher'))
karmaBaseConf.browsers = ['Chrome', 'Firefox']
karmaBaseConf.logLevel = config.LOG_DEBUG

config.set(karmaBaseConf)
Expand Down
27 changes: 14 additions & 13 deletions karma.conf.saucelabs.js
@@ -1,23 +1,26 @@
var karmaBaseConf = require('./karma.base.conf')

var browsers = {
'SL_Chrome': {
sl_chrome: {
base: 'SauceLabs',
platform: 'OS X 10.11',
browserName: 'chrome',
customData: {
awesome: true
}
platform: 'Linux'
},
'SL_Firefox': {
sl_firefox: {
base: 'SauceLabs',
platform: 'OS X 10.11',
browserName: 'firefox'
browserName: 'firefox',
platform: 'Linux'
},
'SL_Edge': {
sl_ie_11: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 10',
browserName: 'microsoftedge'
version: '11.103'
},
sl_edge: {
base: 'SauceLabs',
browserName: 'MicrosoftEdge',
platform: 'Windows 10'
}
}

Expand All @@ -26,9 +29,7 @@ module.exports = function (config) {
karmaBaseConf.reporters.push('saucelabs')
karmaBaseConf.logLevel = config.LOG_DEBUG
karmaBaseConf.customLaunchers = browsers
karmaBaseConf.captureTimeout = 200000
karmaBaseConf.browserDisconnectTolerance = 5
karmaBaseConf.concurrency = 5
karmaBaseConf.concurrency = 2
karmaBaseConf.browsers = Object.keys(browsers)
karmaBaseConf.sauceLabs = {
// Should be false for running on travis, as travis already starts its own
Expand Down

0 comments on commit 02cfd5b

Please sign in to comment.