From a94020375001da4a9c106fd32541a048f288d3f3 Mon Sep 17 00:00:00 2001 From: Jiri Spac Date: Mon, 14 Nov 2016 15:12:43 +0100 Subject: [PATCH] added a build process and built version to git --- .babelrc | 3 + .editorconfig | 3 + dist/tweet-embed.js | 83 +++++++++++++++++++ package.json | 35 ++++++-- ...etEmbed_id_1_from_tweet-embed.spec.js.html | 1 + tweet-embed.js | 8 +- tweet-embed.spec.js | 8 ++ 7 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 .babelrc create mode 100644 .editorconfig create mode 100644 dist/tweet-embed.js create mode 100644 snapshots/TweetEmbed_id_1_from_tweet-embed.spec.js.html create mode 100644 tweet-embed.spec.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..facd180 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "react"] +} \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..99117d6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.js] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/dist/tweet-embed.js b/dist/tweet-embed.js new file mode 100644 index 0000000..c963389 --- /dev/null +++ b/dist/tweet-embed.js @@ -0,0 +1,83 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var callbacks = []; + +function addScript(src, cb) { + if (callbacks.length === 0) { + callbacks.push(cb); + var s = document.createElement('script'); + s.setAttribute('src', src); + s.onload = function () { + return callbacks.forEach(function (cb) { + return cb(); + }); + }; + document.body.appendChild(s); + } else { + callbacks.push(cb); + } +} + +var TweetEmbed = function (_React$Component) { + _inherits(TweetEmbed, _React$Component); + + function TweetEmbed() { + _classCallCheck(this, TweetEmbed); + + return _possibleConstructorReturn(this, (TweetEmbed.__proto__ || Object.getPrototypeOf(TweetEmbed)).apply(this, arguments)); + } + + _createClass(TweetEmbed, [{ + key: 'componentDidMount', + value: function componentDidMount() { + var _this2 = this; + + var options = this.props.options || {}; + + var renderTweet = function renderTweet() { + window.twttr.widgets.createTweetEmbed(_this2.props.id, _this2._div, options); + }; + if (!window.twttr) { + addScript('//platform.twitter.com/widgets.js', renderTweet); + } else { + renderTweet(); + } + } + }, { + key: 'render', + value: function render() { + var _this3 = this; + + return _react2.default.createElement('div', { ref: function ref(c) { + _this3._div = c; + } }); + } + }]); + + return TweetEmbed; +}(_react2.default.Component); + +TweetEmbed.propTypes = { + id: _react.PropTypes.string, + options: _react.PropTypes.object +}; + +exports.default = TweetEmbed; \ No newline at end of file diff --git a/package.json b/package.json index 609e299..b8b286a 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "react-tweet-embed", - "version": "1.0.1", + "version": "1.0.2", "description": "react component that you supply tweet id and you'll get a tweet embed back, nothing more", - "main": "tweet-embed.js", - "jspm": { - "format": "esm" - }, + "main": "dist/tweet-embed.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "BABEL_ENV=test ava", + "pretest": "standard", + "build": "babel tweet-embed.js --out-dir dist", + "clean": "rimraf dist", + "prepublish": "npm test && npm run clean && npm run build" }, "repository": { "type": "git", @@ -21,5 +22,27 @@ "homepage": "https://github.com/capaj/react-tweet-embed#readme", "dependencies": { "react": "^15.3.2" + }, + "devDependencies": { + "ava": "^0.16.0", + "babel": "^6.5.2", + "babel-cli": "^6.18.0", + "babel-preset-react-app": "^1.0.0", + "react-snappy": "^0.2.3", + "standard": "^8.5.0" + }, + "ava": { + "files": [ + "*.spec.js" + ], + "babel": "inherit", + "require": [ + "babel-register" + ] + }, + "standard": { + "ignore": [ + "dist/" + ] } } diff --git a/snapshots/TweetEmbed_id_1_from_tweet-embed.spec.js.html b/snapshots/TweetEmbed_id_1_from_tweet-embed.spec.js.html new file mode 100644 index 0000000..281c686 --- /dev/null +++ b/snapshots/TweetEmbed_id_1_from_tweet-embed.spec.js.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/tweet-embed.js b/tweet-embed.js index 7bf4967..165cc0f 100644 --- a/tweet-embed.js +++ b/tweet-embed.js @@ -1,6 +1,6 @@ import React, {PropTypes} from 'react' -var callbacks = []; +const callbacks = [] function addScript (src, cb) { if (callbacks.length === 0) { @@ -16,7 +16,7 @@ function addScript (src, cb) { class TweetEmbed extends React.Component { componentDidMount () { - const options = this.props.options || {}; + const options = this.props.options || {} const renderTweet = () => { window.twttr.widgets.createTweetEmbed(this.props.id, this._div, options) @@ -28,7 +28,9 @@ class TweetEmbed extends React.Component { } } render () { - return React.createElement('div', { ref: (c) => this._div = c }) + return
{ + this._div = c + }} /> } } diff --git a/tweet-embed.spec.js b/tweet-embed.spec.js new file mode 100644 index 0000000..2a6ed38 --- /dev/null +++ b/tweet-embed.spec.js @@ -0,0 +1,8 @@ +import test from 'ava' +import snappy from 'react-snappy' +import TweetEmbed from './tweet-embed' +import React from 'react' + +test('renders', t => { + snappy.check() +})