From b64ed1a021c258e212e99a5b39d120a7f6592f96 Mon Sep 17 00:00:00 2001 From: Ritesh Kumar Date: Thu, 23 Feb 2017 19:54:56 +0530 Subject: [PATCH 1/2] refactor(eslint): added eslint-standard --- .eslintrc | 30 +-- package.json | 7 +- src/js/helpers/applyPlyr.js | 10 +- src/js/helpers/applyVideoJS.js | 22 +-- src/js/helpers/asyncEmbed.js | 126 +++++++------ src/js/helpers/baseEmbed.js | 4 +- src/js/helpers/destroyVideos.js | 8 +- src/js/helpers/embed.js | 62 +++--- src/js/helpers/getDetailsTemplate.js | 10 +- src/js/helpers/index.js | 17 +- src/js/helpers/playVideo.js | 20 +- src/js/helpers/template.js | 4 +- src/js/modules/base.js | 24 +-- src/js/modules/github.js | 65 ++++--- src/js/modules/hashtag.js | 12 +- src/js/modules/markdown.js | 50 ++--- src/js/modules/mentions.js | 12 +- src/js/modules/openGraph.js | 52 ++--- src/js/modules/regex.js | 62 +++--- src/js/modules/template.js | 272 +++++++++++++-------------- src/js/modules/url.js | 18 +- src/js/modules/utils.js | 136 +++++++------- 22 files changed, 504 insertions(+), 519 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0d46eb5..7c59f2e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,29 +1,9 @@ { - "env": { - "node": true, - "es6": true, - "browser": true - }, - "parser": "babel-eslint", - "extends": "eslint:recommended", + "extends": "standard", "rules": { - "no-multi-spaces": 0, - "key-spacing": 0, - "no-return-assign": 0, - "consistent-return": 0, - "no-shadow": 0, - "comma-dangle": 0, - "no-use-before-define": 0, - "no-empty": 0, - "new-parens": 0, - "no-cond-assign": 0, - "no-fallthrough": 0, - "new-cap": 0, - "no-loop-func": 0, - "no-unreachable": 0, - "no-labels": 0, - "no-process-exit": 0, - "camelcase": 0, - "no-console": 0 + "one-var": "off", + "no-tabs": "off", + "no-useless-escape": "off", + "no-new-func": "off" } } diff --git a/package.json b/package.json index 496e1c5..d64c16f 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,10 @@ "cssnano": "^3.4.0", "cz-conventional-changelog": "^1.1.6", "es6-promise": "^3.0.2", - "eslint": "^2.5.1", + "eslint": "^3.16.1", + "eslint-config-standard": "^6.2.1", + "eslint-plugin-promise": "^3.4.2", + "eslint-plugin-standard": "^2.0.1", "fetch-jsonp": "^1.0.0", "grunt": "^0.4.5", "grunt-bump": "^0.7.0", @@ -87,6 +90,8 @@ }, "scripts": { "commit": "git-cz", + "lint": "eslint src/js/**/*.js", + "lintfix": "eslint --fix src/js/**/*.js", "test": "ava test/**/*.test.js --require babel-register" }, "config": { diff --git a/src/js/helpers/applyPlyr.js b/src/js/helpers/applyPlyr.js index 754b8f9..b935cd0 100644 --- a/src/js/helpers/applyPlyr.js +++ b/src/js/helpers/applyPlyr.js @@ -4,9 +4,9 @@ * @return {null} */ export default function (options) { - if (options.plyr) { - if (!options.plugins.plyr) throw new ReferenceError("You have enabled plyr but you haven't loaded the library.Find it at https://plyr.io/"); - let plyr = options.plugins.plyr; - plyr.setup('.ejs-plyr', options.plyrOptions); - } + if (options.plyr) { + if (!options.plugins.plyr) throw new ReferenceError("You have enabled plyr but you haven't loaded the library.Find it at https://plyr.io/") + let plyr = options.plugins.plyr + plyr.setup('.ejs-plyr', options.plyrOptions) + } } diff --git a/src/js/helpers/applyVideoJS.js b/src/js/helpers/applyVideoJS.js index 987b1c3..6cbb6a5 100644 --- a/src/js/helpers/applyVideoJS.js +++ b/src/js/helpers/applyVideoJS.js @@ -3,15 +3,15 @@ * @param {object} options Options object * @return {null} */ -export default function applyVideoJS(options) { - options.videojsOptions.width = options.videoWidth; - options.videojsOptions.height = options.videoHeight; - if (options.videoJS) { - if (!options.plugins.videojs) throw new ReferenceError("You have enabled videojs but you haven't loaded the library.Find it at http://videojs.com/"); - let VideoJS = options.plugins.videojs; - let elements = options.input.getElementsByClassName('ejs-video-js'); - for (let i = 0; i < elements.length; i++) { - VideoJS(elements[i], options.videojsOptions, () => options.videojsCallback()); - } - } +export default function applyVideoJS (options) { + options.videojsOptions.width = options.videoWidth + options.videojsOptions.height = options.videoHeight + if (options.videoJS) { + if (!options.plugins.videojs) throw new ReferenceError("You have enabled videojs but you haven't loaded the library.Find it at http://videojs.com/") + let VideoJS = options.plugins.videojs + let elements = options.input.getElementsByClassName('ejs-video-js') + for (let i = 0; i < elements.length; i++) { + VideoJS(elements[i], options.videojsOptions, () => options.videojsCallback()) + } + } } diff --git a/src/js/helpers/asyncEmbed.js b/src/js/helpers/asyncEmbed.js index 1f3867b..cf8ab39 100644 --- a/src/js/helpers/asyncEmbed.js +++ b/src/js/helpers/asyncEmbed.js @@ -8,17 +8,17 @@ import { matches, ifInline } from '../modules/utils' * @param {object} match object containing info of matching string * @return {Promise} resolves to the text */ -function getInlineData(_, urlToText, match) { - let url = (_.options.link ? match[0].slice(0, -4) : match[0]) || match[1]; - if (_.options.served.indexOf(url) >= 0) return Promise.resolve(null); +function getInlineData (_, urlToText, match) { + let url = (_.options.link ? match[0].slice(0, -4) : match[0]) || match[1] + if (_.options.served.indexOf(url) >= 0) return Promise.resolve(null) - return new Promise((resolve) => { - urlToText(_, match, url).then((text) => { - if (!text) return resolve(); - _.options.served.push(url); - resolve(text); - }) - }) + return new Promise((resolve) => { + urlToText(_, match, url).then((text) => { + if (!text) return resolve() + _.options.served.push(url) + resolve(text) + }) + }) } /** @@ -27,46 +27,48 @@ function getInlineData(_, urlToText, match) { * @param urlToText * @returns Promise */ -function inlineAsyncEmbed(_, urlToText) { - let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gi') : new RegExp(`([^\\s]*${_.regex.source})`, 'gi'); - let match, promises = []; +function inlineAsyncEmbed (_, urlToText) { + let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gi') : new RegExp(`([^\\s]*${_.regex.source})`, 'gi') + let match, promises = [] - while ((match = matches(regexInline, _.output)) !== null) - promises.push(getInlineData(_, urlToText, match)); + while ((match = matches(regexInline, _.output)) !== null) { + promises.push(getInlineData(_, urlToText, match)) + } - return new Promise((resolve) => { - if (promises.length) - Promise.all(promises).then((data) => { - let i = 0; - _.output = _.output.replace(regexInline, (matched) => { - if (_.options.link) - return !_.options.inlineText ? data[i++] + '' : matched + data[i++]; - else - return !_.options.inlineText ? data[i++] : matched + data[i++]; - }); - resolve(_.output) - }); - else - resolve(_.output) - }) + return new Promise((resolve) => { + if (promises.length) { + Promise.all(promises).then((data) => { + let i = 0 + _.output = _.output.replace(regexInline, (matched) => { + if (_.options.link) { + return !_.options.inlineText ? data[i++] + '' : matched + data[i++] + } else { + return !_.options.inlineText ? data[i++] : matched + data[i++] + } + }) + resolve(_.output) + }) + } else { + resolve(_.output) + } + }) } +function getNormalData (_, urlToText, match) { + let url = match[0] + if (_.options.served.indexOf(url) >= 0) return -function getNormalData(_, urlToText, match) { - let url = match[0]; - if (_.options.served.indexOf(url) >= 0) return; - - return new Promise((resolve) => { - urlToText(_, match, url, true).then(function (text) { - if (!text) resolve(); - _.options.served.push(url); - _.embeds.push({ - text : text, - index: match.index - }); - resolve() - }) - }) + return new Promise((resolve) => { + urlToText(_, match, url, true).then(function (text) { + if (!text) resolve() + _.options.served.push(url) + _.embeds.push({ + text: text, + index: match.index + }) + resolve() + }) + }) } /** @@ -75,22 +77,24 @@ function getNormalData(_, urlToText, match) { * @param {function} urlToText * @return {Promise} */ -function normalAsyncEmbed(_, urlToText) { - let match, promises = []; - while ((match = matches(_.regex, _.input)) !== null) - promises.push(getNormalData(_, urlToText, match)); - return new Promise(function (resolve) { - Promise.all(promises).then(function () { - resolve(_.embeds) - }); - }) +function normalAsyncEmbed (_, urlToText) { + let match, promises = [] + while ((match = matches(_.regex, _.input)) !== null) { + promises.push(getNormalData(_, urlToText, match)) + } + return new Promise(function (resolve) { + Promise.all(promises).then(function () { + resolve(_.embeds) + }) + }) } -export default function asyncEmbed(_, urlToText) { - return new Promise(function (resolve) { - if (ifInline(_.options, _.service)) - inlineAsyncEmbed(_, urlToText).then((output) => resolve([output, _.embeds])); - else - normalAsyncEmbed(_, urlToText).then((embeds) => resolve([_.output, embeds])) - }) +export default function asyncEmbed (_, urlToText) { + return new Promise(function (resolve) { + if (ifInline(_.options, _.service)) { + inlineAsyncEmbed(_, urlToText).then((output) => resolve([output, _.embeds])) + } else { + normalAsyncEmbed(_, urlToText).then((embeds) => resolve([_.output, embeds])) + } + }) } diff --git a/src/js/helpers/baseEmbed.js b/src/js/helpers/baseEmbed.js index fb5ca49..7c05f2b 100644 --- a/src/js/helpers/baseEmbed.js +++ b/src/js/helpers/baseEmbed.js @@ -1,6 +1,6 @@ import { ifEmbed } from '../modules/utils' import base from '../modules/base' -export default function baseEmbed(input, output, embeds, options, regex, service, flag){ - return ifEmbed(options, service) || (ifEmbed(options, service) && flag) ? base(input, output, embeds, options, regex, service) : [output, embeds] +export default function baseEmbed (input, output, embeds, options, regex, service, flag) { + return ifEmbed(options, service) || (ifEmbed(options, service) && flag) ? base(input, output, embeds, options, regex, service) : [output, embeds] } diff --git a/src/js/helpers/destroyVideos.js b/src/js/helpers/destroyVideos.js index 7007fdb..8dcf1da 100644 --- a/src/js/helpers/destroyVideos.js +++ b/src/js/helpers/destroyVideos.js @@ -4,8 +4,8 @@ * @return {null} */ export default function (className) { - const classes = document.getElementsByClassName(className); - for (let i = 0; i < classes.length; i++) { - classes[i].onclick = null - } + const classes = document.getElementsByClassName(className) + for (let i = 0; i < classes.length; i++) { + classes[i].onclick = null + } } diff --git a/src/js/helpers/embed.js b/src/js/helpers/embed.js index 6a1d19b..becd05a 100644 --- a/src/js/helpers/embed.js +++ b/src/js/helpers/embed.js @@ -1,38 +1,38 @@ import { ifInline, matches } from '../modules/utils' -function inlineEmbed(_){ - let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gm') : new RegExp(`([^\\s]*${_.regex.source})`, 'gm'); - _.output = _.output.replace(regexInline, function(match) { - let url = _.options.link ? match.slice(0, -4) : match; - if (_.options.served.indexOf(url) === -1) { - _.options.served.push(url); - if (_.options.link) { - return !_.options.inlineText ? _.template(match.slice(0, -4)) + '' : match + _.template(match.slice(0, -4)) - } else { - return !_.options.inlineText ? _.template(match) : match + _.template(match) - } - } else { - return match; //TODO : check whether this should be `match` - } - }); - return [_.output, _.embeds]; +function inlineEmbed (_) { + let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gm') : new RegExp(`([^\\s]*${_.regex.source})`, 'gm') + _.output = _.output.replace(regexInline, function (match) { + let url = _.options.link ? match.slice(0, -4) : match + if (_.options.served.indexOf(url) === -1) { + _.options.served.push(url) + if (_.options.link) { + return !_.options.inlineText ? _.template(match.slice(0, -4)) + '' : match + _.template(match.slice(0, -4)) + } else { + return !_.options.inlineText ? _.template(match) : match + _.template(match) + } + } else { + return match // TODO : check whether this should be `match` + } + }) + return [_.output, _.embeds] } -function normalEmbed(_){ - let match; - while ((match = matches(_.regex, _.input)) !== null) { - let url = match[0]; - if (!(_.options.served.indexOf(url) === -1) || (_.options.served.length && _.options.singleEmbed)) continue; - _.options.served.push(url); - let text = _.template(url); - _.embeds.push({ - text : text, - index: match.index - }) - } - return [_.output, _.embeds]; +function normalEmbed (_) { + let match + while ((match = matches(_.regex, _.input)) !== null) { + let url = match[0] + if (!(_.options.served.indexOf(url) === -1) || (_.options.served.length && _.options.singleEmbed)) continue + _.options.served.push(url) + let text = _.template(url) + _.embeds.push({ + text: text, + index: match.index + }) + } + return [_.output, _.embeds] } -export default function embed(_){ - return (ifInline(_.options, _.service)) ? inlineEmbed(_) : normalEmbed(_) +export default function embed (_) { + return (ifInline(_.options, _.service)) ? inlineEmbed(_) : normalEmbed(_) } diff --git a/src/js/helpers/getDetailsTemplate.js b/src/js/helpers/getDetailsTemplate.js index 0133cf1..daebe27 100644 --- a/src/js/helpers/getDetailsTemplate.js +++ b/src/js/helpers/getDetailsTemplate.js @@ -1,7 +1,7 @@ export default function (data, fullData, embedUrl, options) { - if (data.host === 'vimeo') { - return options.template.detailsVimeo(data, fullData, embedUrl, options) - } else if (data.host === 'youtube') { - return options.template.detailsYoutube(data, fullData, embedUrl, options) - } + if (data.host === 'vimeo') { + return options.template.detailsVimeo(data, fullData, embedUrl, options) + } else if (data.host === 'youtube') { + return options.template.detailsYoutube(data, fullData, embedUrl, options) + } } diff --git a/src/js/helpers/index.js b/src/js/helpers/index.js index 4a3dd2b..6f7910a 100644 --- a/src/js/helpers/index.js +++ b/src/js/helpers/index.js @@ -1,12 +1,11 @@ -import playVideo from './playVideo' +import playVideo from './playVideo' import getDetailsTemplate from './getDetailsTemplate' -import applyPlyr from './applyPlyr' -import applyVideoJS from './applyVideoJS'; -import destroyVideos from './destroyVideos' -import embed from './embed' -import template from './template' -import baseEmbed from './baseEmbed' -import asyncEmbed from './asyncEmbed' - +import applyPlyr from './applyPlyr' +import applyVideoJS from './applyVideoJS' +import destroyVideos from './destroyVideos' +import embed from './embed' +import template from './template' +import baseEmbed from './baseEmbed' +import asyncEmbed from './asyncEmbed' export {playVideo, getDetailsTemplate, applyPlyr, applyVideoJS, destroyVideos, embed, template, baseEmbed, asyncEmbed} diff --git a/src/js/helpers/playVideo.js b/src/js/helpers/playVideo.js index fd36d7b..287eb59 100644 --- a/src/js/helpers/playVideo.js +++ b/src/js/helpers/playVideo.js @@ -5,16 +5,16 @@ import template from './template' * @param {object} options Options object * @return {null} */ -export default function playVideo(options) { +export default function playVideo (options) { /** Execute the customVideoClickHandler if the user wants to handle it on his own. */ - if (options.customVideoClickHandler) return options.videoClickHandler(options, template); + if (options.customVideoClickHandler) return options.videoClickHandler(options, template) - let classes = document.getElementsByClassName(options.videoClickClass); - for (let i = 0; i < classes.length; i++) { - classes[i].onclick = function () { - options.onVideoShow(); - let url = this.getAttribute('data-ejs-url') + "?autoplay=true"; - this.parentNode.parentNode.innerHTML = template(url, options); - }; - } + let classes = document.getElementsByClassName(options.videoClickClass) + for (let i = 0; i < classes.length; i++) { + classes[i].onclick = function () { + options.onVideoShow() + let url = this.getAttribute('data-ejs-url') + '?autoplay=true' + this.parentNode.parentNode.innerHTML = template(url, options) + } + } } diff --git a/src/js/helpers/template.js b/src/js/helpers/template.js index c324b88..b50bea0 100644 --- a/src/js/helpers/template.js +++ b/src/js/helpers/template.js @@ -4,6 +4,6 @@ * @param {object} options Options object * @return {string} compiled template with variables replaced */ -export default function template(url, options) { - return options.template.vimeo(url, options) || options.template.youtube(url, options) +export default function template (url, options) { + return options.template.vimeo(url, options) || options.template.youtube(url, options) } diff --git a/src/js/modules/base.js b/src/js/modules/base.js index 4d57bde..f803b53 100644 --- a/src/js/modules/base.js +++ b/src/js/modules/base.js @@ -1,17 +1,17 @@ import { embed } from '../helpers' export default function (input, output, embeds, options, regex, service) { - const args = { - input, - output, - options, - embeds, - regex, - service, - template(match){ - return this.options.template[this.service](match, this.options); - } - }; + const args = { + input, + output, + options, + embeds, + regex, + service, + template (match) { + return this.options.template[this.service](match, this.options) + } + } - return embed(args); + return embed(args) } diff --git a/src/js/modules/github.js b/src/js/modules/github.js index 47e106e..e27b120 100644 --- a/src/js/modules/github.js +++ b/src/js/modules/github.js @@ -1,48 +1,47 @@ -import {asyncEmbed} from '../helpers' +import { asyncEmbed } from '../helpers' import regex from './regex' import fetch from 'unfetch' -function template(data, options) { - return options.template.github(data, options); +function template (data, options) { + return options.template.github(data, options) } -function fetchRepo(data) { - let api = `https://api.github.com/repos/${data.user}/${data.repo}`; - return new Promise((resolve) => { +function fetchRepo (data) { + let api = `https://api.github.com/repos/${data.user}/${data.repo}` + return new Promise((resolve) => fetch(api) - .then(function (data) { - return data.json() - }) - .then(function (json) { - return resolve(json) - }) - }) + .then(data => data.json()) + .then(json => resolve(json)) + ) } -function urlToText(_this, match, url, normalEmbed) { - let data = !normalEmbed ? ({ - user: match[2], - repo: match[3] - }) : ({ - user: match[1], - repo: match[2] - }); +function urlToText (_this, match, url, normalEmbed) { + let data = !normalEmbed ? ({ + user: match[2], + repo: match[3] + }) : ({ + user: match[1], + repo: match[2] + }) - if (!data.repo) return; - return new Promise(function (resolve) { - fetchRepo(data) + if (!data.repo) return + return new Promise(function (resolve) { + fetchRepo(data) .then(function (response) { - return resolve(template(response, _this.options)) - }) - }) + return resolve(template(response, _this.options)) +}) + }) } export default function (input, output, options, embeds) { - const args = { - input, output, options, embeds, - service: 'github', - regex : regex.github - }; + const args = { + input, + output, + options, + embeds, + service: 'github', + regex: regex.github + } - return new Promise((resolve) => asyncEmbed(args, urlToText).then((data) => resolve(data))) + return new Promise((resolve) => asyncEmbed(args, urlToText).then((data) => resolve(data))) } diff --git a/src/js/modules/hashtag.js b/src/js/modules/hashtag.js index 7cfb8e0..93de45e 100644 --- a/src/js/modules/hashtag.js +++ b/src/js/modules/hashtag.js @@ -1,9 +1,9 @@ -import regex from './regex'; +import regex from './regex' export default function (input, options) { - const hRegex = regex.hashtag; - return input.replace(hRegex,(match, $1, $2)=>{ - const username = $2.split('#')[1]; - return $1 + options.hashtagUrl(username); - }) + const hRegex = regex.hashtag + return input.replace(hRegex, (match, $1, $2) => { + const username = $2.split('#')[1] + return $1 + options.hashtagUrl(username) + }) } diff --git a/src/js/modules/markdown.js b/src/js/modules/markdown.js index df2b47a..646af40 100644 --- a/src/js/modules/markdown.js +++ b/src/js/modules/markdown.js @@ -1,33 +1,33 @@ export default function (output, options) { - if (!options.plugins.marked) throw new ReferenceError(`marked.js is not loaded.`); + if (!options.plugins.marked) throw new ReferenceError(`marked.js is not loaded.`) - const Marked = options.plugins.marked; - const renderer = new Marked.Renderer(); + const Marked = options.plugins.marked + const renderer = new Marked.Renderer() - renderer.link = (href, title, text) => { - if (href.indexOf('</a') === -1) return href; - if (href.match(/>(.+)<\/a/gi)) { - if (!title) title = ''; - return `${text}` - } - }; + renderer.link = (href, title, text) => { + if (href.indexOf('</a') === -1) return href + if (href.match(/>(.+)<\/a/gi)) { + if (!title) title = '' + return `${text}` + } + } - renderer.image = (href, title, text) => { - if (href.match(/>(.+)<\/a/gi)) { - if (!title) title = ''; - return `
${text}
` - } - return `
${text}
` - }; + renderer.image = (href, title, text) => { + if (href.match(/>(.+)<\/a/gi)) { + if (!title) title = '' + return `
${text}
` + } + return `
${text}
` + } - renderer.paragraph = (text) => `

${text}

`; //for font smiley in end. + renderer.paragraph = (text) => `

${text}

` // for font smiley in end. - //Fix for heading that should be actually present in marked.js - //if gfm is true the `## Heading` is acceptable but `##Heading` is not - Marked.Lexer.rules.gfm.heading = Marked.Lexer.rules.normal.heading; - Marked.Lexer.rules.tables.heading = Marked.Lexer.rules.normal.heading; + // Fix for heading that should be actually present in marked.js + // if gfm is true the `## Heading` is acceptable but `##Heading` is not + Marked.Lexer.rules.gfm.heading = Marked.Lexer.rules.normal.heading + Marked.Lexer.rules.tables.heading = Marked.Lexer.rules.normal.heading - options.markedOptions.renderer = renderer; - options.markedOptions.highlight = false; - return Marked(output, options.markedOptions) + options.markedOptions.renderer = renderer + options.markedOptions.highlight = false + return Marked(output, options.markedOptions) } diff --git a/src/js/modules/mentions.js b/src/js/modules/mentions.js index ca5cb9e..e31b9b7 100644 --- a/src/js/modules/mentions.js +++ b/src/js/modules/mentions.js @@ -1,9 +1,9 @@ -import regex from './regex'; +import regex from './regex' export default function (input, options) { - const mRegex = regex.mentions; - return input.replace(mRegex,(match, $1, $2) => { - const username = $2.split('@')[1]; - return $1 + options.mentionsUrl(username); - }) + const mRegex = regex.mentions + return input.replace(mRegex, (match, $1, $2) => { + const username = $2.split('@')[1] + return $1 + options.mentionsUrl(username) + }) } diff --git a/src/js/modules/openGraph.js b/src/js/modules/openGraph.js index 9126da7..6f60839 100644 --- a/src/js/modules/openGraph.js +++ b/src/js/modules/openGraph.js @@ -2,37 +2,37 @@ import { urlRegex } from './utils' import { asyncEmbed } from '../helpers' import fetch from 'unfetch' -function fetchData(url, _) { - url = encodeURIComponent(url); - let api = new Function('url', 'return `' + _.options.openGraphEndpoint + '`')(url); - return new Promise((resolve) => { - fetch(api) - .then((res)=>res.json()) - .then((json)=>resolve(_.options.onOpenGraphFetch(json) || json)) - }) +function fetchData (url, _) { + url = encodeURIComponent(url) + let api = new Function('url', 'return `' + _.options.openGraphEndpoint + '`')(url) + return new Promise((resolve) => { + fetch(api) + .then((res) => res.json()) + .then((json) => resolve(_.options.onOpenGraphFetch(json) || json)) + }) } -function urlToText(_, match, url) { - if (url.match(_.excludeRegex)) return Promise.resolve(); +function urlToText (_, match, url) { + if (url.match(_.excludeRegex)) return Promise.resolve() - return new Promise((resolve) => { - fetchData(url, _).then((data) => resolve(data && data.success ? _.template(data) : '')) - }) + return new Promise((resolve) => { + fetchData(url, _).then((data) => resolve(data && data.success ? _.template(data) : '')) + }) } export default function (input, output, options, embeds) { - const args = { - input, - output, - options, - embeds, - service : 'opengraph', - regex : urlRegex(), - excludeRegex: new RegExp(['.mp4|.mp3|.gif|.pdf|.doc|.ppt|.docx|.jpg|.jpeg|.ogg'].concat(options.openGraphExclude).join('|'), 'gi'), - template(data) { - return this.options.template.openGraph(data, this.options) - } - }; + const args = { + input, + output, + options, + embeds, + service: 'opengraph', + regex: urlRegex(), + excludeRegex: new RegExp(['.mp4|.mp3|.gif|.pdf|.doc|.ppt|.docx|.jpg|.jpeg|.ogg'].concat(options.openGraphExclude).join('|'), 'gi'), + template (data) { + return this.options.template.openGraph(data, this.options) + } + } - return new Promise((resolve) => asyncEmbed(args, urlToText).then((data) => resolve(data))) + return new Promise((resolve) => asyncEmbed(args, urlToText).then((data) => resolve(data))) } diff --git a/src/js/modules/regex.js b/src/js/modules/regex.js index 2dc7233..c74d13a 100644 --- a/src/js/modules/regex.js +++ b/src/js/modules/regex.js @@ -1,33 +1,33 @@ const regex = { - mentions : /(^|\s)(@[a-z0-9_-]+)/gi, - hashtag : /(^|\s)(#[a-z\d-]+)/gi, - basicAudio : /((?:https?):\/\/\S*\.(?:wav|mp3|ogg))/gi, - soundCloud : /(soundcloud.com)\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+/gi, - spotify : /spotify.com\/track\/[a-zA-Z0-9_]+/gi, - codepen : /http:\/\/codepen.io\/([A-Za-z0-9_]+)\/pen\/([A-Za-z0-9_]+)/gi, - gist : /gist.github.com\/[a-zA-Z0-9_-]+\/([a-zA-Z0-9]+)/gi, - highlightCode: /(`{3})(\s|[a-z]+)\s*([\s\S]*?[^`])\s*\1(?!`)/gm, - inlineCode : /(`)\s*([\s\S]*?[^`])\s*\1(?!`)/gm, - ideone : /ideone.com\/[a-zA-Z0-9]{6}/gi, - jsbin : /jsbin.com\/[a-zA-Z0-9_]+\/[0-9_]+/gi, - jsfiddle : /jsfiddle.net\/[a-zA-Z0-9_]+\/[a-zA-Z0-9_\/]+/gi, - plunker : /plnkr.co\/edit\/[a-zA-Z0-9\?=]+/gi, - basicImage : /((?:https?):\/\/\S*\.(?:gif|jpg|jpeg|tiff|png|svg|webp))/gi, - flickr : /flickr.com\/[a-z]+\/[a-zA-Z@_$!\d\-\]+\/[\d]+/gi, - instagram : /instagram.com\/p\/[a-zA-Z0-9_\/\?\-\=]+/gi, - slideShare : /slideshare.net\/[a-zA-Z0-9_-]*\/[a-zA-Z0-9_-]*/gi, - github : /[^\.]github.com\/([\w\.\-]+)\/([\w\.\-]+)/gi, - basicVideo : /(?:https?):\/\/\S*\.(?:ogv|webm|mp4)/gi, - dailymotion : /dailymotion.com\/video\/[a-zA-Z0-9-_]+/gi, - liveleak : /liveleak.com\/view\?i=[a-zA-Z0-9_]+/gi, - ted : /ted.com\/talks\/[a-zA-Z0-9_]+/gi, - ustream : /ustream.tv\/[a-z\/0-9]*/gi, - vimeo : /https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)*/gi, - vine : /vine.co\/v\/[a-zA-Z0-9]+/gi, - youtube : /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[?=&+%\w-]*/gi, - gmap : /@\((.+)\)/gi, - twitter : /https:\/\/twitter\.com\/\w+\/\w+\/\d+/gi, - smileys : /:[a-zA-Z0-9-_+]+:(:skin-tone-[2-6]:)?/gi -}; + mentions: /(^|\s)(@[a-z0-9_-]+)/gi, + hashtag: /(^|\s)(#[a-z\d-]+)/gi, + basicAudio: /((?:https?):\/\/\S*\.(?:wav|mp3|ogg))/gi, + soundCloud: /(soundcloud.com)\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+/gi, + spotify: /spotify.com\/track\/[a-zA-Z0-9_]+/gi, + codepen: /http:\/\/codepen.io\/([A-Za-z0-9_]+)\/pen\/([A-Za-z0-9_]+)/gi, + gist: /gist.github.com\/[a-zA-Z0-9_-]+\/([a-zA-Z0-9]+)/gi, + highlightCode: /(`{3})(\s|[a-z]+)\s*([\s\S]*?[^`])\s*\1(?!`)/gm, + inlineCode: /(`)\s*([\s\S]*?[^`])\s*\1(?!`)/gm, + ideone: /ideone.com\/[a-zA-Z0-9]{6}/gi, + jsbin: /jsbin.com\/[a-zA-Z0-9_]+\/[0-9_]+/gi, + jsfiddle: /jsfiddle.net\/[a-zA-Z0-9_]+\/[a-zA-Z0-9_\/]+/gi, + plunker: /plnkr.co\/edit\/[a-zA-Z0-9\?=]+/gi, + basicImage: /((?:https?):\/\/\S*\.(?:gif|jpg|jpeg|tiff|png|svg|webp))/gi, + flickr: /flickr.com\/[a-z]+\/[a-zA-Z@_$!\d\-\]+\/[\d]+/gi, + instagram: /instagram.com\/p\/[a-zA-Z0-9_\/\?\-\=]+/gi, + slideShare: /slideshare.net\/[a-zA-Z0-9_-]*\/[a-zA-Z0-9_-]*/gi, + github: /[^\.]github.com\/([\w\.\-]+)\/([\w\.\-]+)/gi, + basicVideo: /(?:https?):\/\/\S*\.(?:ogv|webm|mp4)/gi, + dailymotion: /dailymotion.com\/video\/[a-zA-Z0-9-_]+/gi, + liveleak: /liveleak.com\/view\?i=[a-zA-Z0-9_]+/gi, + ted: /ted.com\/talks\/[a-zA-Z0-9_]+/gi, + ustream: /ustream.tv\/[a-z\/0-9]*/gi, + vimeo: /https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)*/gi, + vine: /vine.co\/v\/[a-zA-Z0-9]+/gi, + youtube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[?=&+%\w-]*/gi, + gmap: /@\((.+)\)/gi, + twitter: /https:\/\/twitter\.com\/\w+\/\w+\/\d+/gi, + smileys: /:[a-zA-Z0-9-_+]+:(:skin-tone-[2-6]:)?/gi +} -export default regex; +export default regex diff --git a/src/js/modules/template.js b/src/js/modules/template.js index f26e9de..65db884 100644 --- a/src/js/modules/template.js +++ b/src/js/modules/template.js @@ -1,143 +1,143 @@ import { toUrl, lastElement } from './utils' export default { - url(match, options){ - let config = options.linkOptions; - return `${match}`; - }, - - smiley(text, pre, code) { - return `${pre}${code}`; - }, - - emoji(text){ - return ``; - }, - - audio(match){ - return `
` - }, - - soundcloud(match, options){ - let config = options.soundCloudOptions; - return `
+ url (match, options) { + let config = options.linkOptions + return `${match}` + }, + + smiley (text, pre, code) { + return `${pre}${code}` + }, + + emoji (text) { + return `` + }, + + audio (match) { + return `
` + }, + + soundcloud (match, options) { + let config = options.soundCloudOptions + return `
` - }, - - spotify(match){ - let id = lastElement(match.split('/')); - return `
` - }, - - codepen(id, options){ - return `
` - }, - - ideone(match, options){ - return `
` - }, - - jsbin(id, options){ - return `
` - }, - - jsfiddle(id, options){ - id = lastElement(id) == '/' ? id.slice(0, - 1) : id; - id = (id.indexOf('//') !== -1) ? id : `//${id}`; - return `
` - }, - - plunker(id, options){ - return `
` - }, - - image(match){ - return `
` - }, - - flickr(match, options){ - return `
` - }, - - instagram(match, options){ - return `
`; - }, - - slideShare(html){ - return `
${html}
`; - }, - - video(match){ - return `
` - }, - - dailymotion(match, options){ - const id = lastElement(match.split('/')); - return `
` - }, - - liveleak(match, options){ - return `
` - }, - - ted(match, options){ - let a = match.split('/'); - const id = a[a.length - 1]; - return `
` - }, - - ustream(match, options){ - let id = match.split('/'); + }, + + spotify (match) { + let id = lastElement(match.split('/')) + return `
` + }, + + codepen (id, options) { + return `
` + }, + + ideone (match, options) { + return `
` + }, + + jsbin (id, options) { + return `
` + }, + + jsfiddle (id, options) { + id = lastElement(id) === '/' ? id.slice(0, -1) : id + id = (id.indexOf('//') !== -1) ? id : `//${id}` + return `
` + }, + + plunker (id, options) { + return `
` + }, + + image (match) { + return `
` + }, + + flickr (match, options) { + return `
` + }, + + instagram (match, options) { + return `
` + }, + + slideShare (html) { + return `
${html}
` + }, + + video (match) { + return `
` + }, + + dailymotion (match, options) { + const id = lastElement(match.split('/')) + return `
` + }, + + liveleak (match, options) { + return `
` + }, + + ted (match, options) { + let a = match.split('/') + const id = a[a.length - 1] + return `
` + }, + + ustream (match, options) { + let id = match.split('/') // only add embed if it is not already in the link - if( match.indexOf('/embed/') < 0 ) { - id.splice(1, 0, 'embed'); - } - return `
` - }, - - detailsVimeo(data, fullData, embedUrl){ - return `
${data.description}
${data.views}${data.likes}
` - }, - - detailsYoutube(data, fullData, embedUrl){ - return `
${data.description}
${data.views}${data.likes}
` - }, - - vine(match, options){ - const id = lastElement(match.split('/')); - const config = options.vineOptions; - return `
` - }, - - vimeo(url, options){ - return options.plyr ? - `
` : - `
` - }, - - youtube(url, options){ - return options.plyr ? - `
` : - `
` - }, - - openGraph(data, options){ - return `
${data.description}
` - }, - - github(data, options){ - return `
${data.description}
${data.stargazers_count}${data.network_count}
` - }, - - gmap(latitude, longitude, location, options){ - const config = options.mapOptions; - if (config.mode === 'place') { - return `
`; - } else if (config.mode === 'streetview') { - return `
`; - } else if (config.mode === 'view') { - return `
` - } - } + if (match.indexOf('/embed/') < 0) { + id.splice(1, 0, 'embed') + } + return `
` + }, + + detailsVimeo (data, fullData, embedUrl) { + return `
${data.description}
${data.views}${data.likes}
` + }, + + detailsYoutube (data, fullData, embedUrl) { + return `
${data.description}
${data.views}${data.likes}
` + }, + + vine (match, options) { + const id = lastElement(match.split('/')) + const config = options.vineOptions + return `
` + }, + + vimeo (url, options) { + return options.plyr + ? `
` + : `
` + }, + + youtube (url, options) { + return options.plyr + ? `
` + : `
` + }, + + openGraph (data, options) { + return `
${data.description}
` + }, + + github (data, options) { + return `
${data.description}
${data.stargazers_count}${data.network_count}
` + }, + + gmap (latitude, longitude, location, options) { + const config = options.mapOptions + if (config.mode === 'place') { + return `
` + } else if (config.mode === 'streetview') { + return `
` + } else if (config.mode === 'view') { + return `
` + } + } } diff --git a/src/js/modules/url.js b/src/js/modules/url.js index b8a8864..4b97350 100644 --- a/src/js/modules/url.js +++ b/src/js/modules/url.js @@ -1,14 +1,12 @@ import {urlRegex, lastElement} from './utils' export default function (input, options) { - const config = options.linkOptions; - return input.replace(urlRegex(), function(match) { - if(lastElement(match) === ')') return match; //hack for markdown image - let extension = lastElement(match.split('.')); - if ((lastElement(match) === '/')) - match = match.slice(0, -1); - if (config.exclude.indexOf(extension) === -1) - return options.template.url(match, options); - return match; - }); + const config = options.linkOptions + return input.replace(urlRegex(), function (match) { + if (lastElement(match) === ')') return match // hack for markdown image + let extension = lastElement(match.split('.')) + if ((lastElement(match) === '/')) { match = match.slice(0, -1) } + if (config.exclude.indexOf(extension) === -1) { return options.template.url(match, options) } + return match + }) } diff --git a/src/js/modules/utils.js b/src/js/modules/utils.js index 37e796d..44fbb50 100644 --- a/src/js/modules/utils.js +++ b/src/js/modules/utils.js @@ -4,8 +4,8 @@ * @param n Length to which it should be truncated * @returns {string} The truncated string */ -export function truncate(string, n) { - return string.substr(0, n - 1) + (string.length > n ? '...' : ''); +export function truncate (string, n) { + return string.substr(0, n - 1) + (string.length > n ? '...' : '') } /** @@ -13,25 +13,25 @@ export function truncate(string, n) { * @param array The array containing the duplicates * @returns {Array} Array with unique values. */ -export function getUnique(array) { - var u = {}, - a = []; - - array.forEach((value) => { - if (!u.hasOwnProperty(value)) { - a.push(value); - u[value] = 1; - } - }); - return a; +export function getUnique (array) { + var u = {}, + a = [] + + array.forEach((value) => { + if (!u.hasOwnProperty(value)) { + a.push(value) + u[value] = 1 + } + }) + return a } /** * Converts a string into legitimate url. * @param string */ -export function toUrl(string) { - return (string.indexOf('//') === -1) ? ('//' + string) : string +export function toUrl (string) { + return (string.indexOf('//') === -1) ? ('//' + string) : string } /** @@ -40,20 +40,20 @@ export function toUrl(string) { * @param source * @returns {*} */ -export function deepExtend(destination, source) { - for (var property in source) { - if (source.hasOwnProperty(property) && source[property] && source[property].constructor === Object) { - destination[property] = destination[property] || {}; - deepExtend(destination[property], source[property]); - } else { - destination[property] = source[property]; - } +export function deepExtend (destination, source) { + for (var property in source) { + if (source.hasOwnProperty(property) && source[property] && source[property].constructor === Object) { + destination[property] = destination[property] || {} + deepExtend(destination[property], source[property]) + } else { + destination[property] = source[property] } - return destination; + } + return destination } -export function escapeRegExp(str) { - return str.replace(/[\-\[\]\/\{}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); +export function escapeRegExp (str) { + return str.replace(/[\-\[\]\/\{}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') } /** @@ -61,8 +61,8 @@ export function escapeRegExp(str) { * @param {Array} arr Array to be sorted * @return {Array} Sorted array */ -function sortObject(arr) { - return arr.sort((a, b) => (a.index - b.index)); +function sortObject (arr) { + return arr.sort((a, b) => (a.index - b.index)) } /** @@ -71,12 +71,12 @@ function sortObject(arr) { * @param {object} embeds Sorted array of iframe html * @return {string} String to be rendered */ -export function createText(str, embeds) { - let sortedEmbeds = sortObject(embeds); - for (let i = 0; i < sortedEmbeds.length; i++) { - str += ` ${sortedEmbeds[i].text}`; - } - return str; +export function createText (str, embeds) { + let sortedEmbeds = sortObject(embeds) + for (let i = 0; i < sortedEmbeds.length; i++) { + str += ` ${sortedEmbeds[i].text}` + } + return str } /** @@ -85,8 +85,8 @@ export function createText(str, embeds) { * @param {string} input The string to be analyzed * @return {object} Returns the matched substring with their corresponding positions */ -export function matches(regex, input) { - return regex.exec(input); +export function matches (regex, input) { + return regex.exec(input) } /** @@ -96,13 +96,13 @@ export function matches(regex, input) { * @param {string} service Name of the service for which the condition is to be analyzed * @return {boolean} True if it should be embedded */ -export function ifEmbed(options, service) { - if (options.singleEmbed && options.served.length) return; - return ((options.excludeEmbed.indexOf(service) == -1) && !(options.excludeEmbed === 'all')); +export function ifEmbed (options, service) { + if (options.singleEmbed && options.served.length) return + return ((options.excludeEmbed.indexOf(service) === -1) && !(options.excludeEmbed === 'all')) } -export function ifInline(options, service) { - return ((options.inlineEmbed.indexOf(service) >= 0) || (options.inlineEmbed === 'all')); +export function ifInline (options, service) { + return ((options.inlineEmbed.indexOf(service) >= 0) || (options.inlineEmbed === 'all')) } /** @@ -110,10 +110,10 @@ export function ifInline(options, service) { * @param {object} options Plugin options * @return {object} The width and height of the elements */ -function setDimensions(options) { - options.videoWidth = options.videoWidth || ((options.videoHeight) / 3) * 4 || 800; - options.videoHeight = options.videoHeight || ((options.videoWidth) / 4) * 3 || 600; - return options; +function setDimensions (options) { + options.videoWidth = options.videoWidth || ((options.videoHeight) / 3) * 4 || 800 + options.videoHeight = options.videoHeight || ((options.videoWidth) / 4) * 3 || 600 + return options } /** @@ -121,26 +121,26 @@ function setDimensions(options) { * @param {object} obj * @return {object} cloned object */ -export function cloneObject(obj) { - if (obj === null || typeof obj !== 'object') return obj; - var temp = obj.constructor(); // give temp the original obj's constructor - for (var key in obj) { - temp[key] = cloneObject(obj[key]) - } - return temp +export function cloneObject (obj) { + if (obj === null || typeof obj !== 'object') return obj + var temp = obj.constructor() // give temp the original obj's constructor + for (var key in obj) { + temp[key] = cloneObject(obj[key]) + } + return temp } -export function urlRegex() { - return /((href|src)=["']|)(\b(https?|ftp|file):\/\/[^,.\s]+[^\s]*[^,.\s]+)|(?:https?:\/\/)?(?:(?:0rz\.tw)|(?:1link\.in)|(?:1url\.com)|(?:2\.gp)|(?:2big\.at)|(?:2tu\.us)|(?:3\.ly)|(?:307\.to)|(?:4ms\.me)|(?:4sq\.com)|(?:4url\.cc)|(?:6url\.com)|(?:7\.ly)|(?:a\.gg)|(?:a\.nf)|(?:aa\.cx)|(?:abcurl\.net)|(?:ad\.vu)|(?:adf\.ly)|(?:adjix\.com)|(?:afx\.cc)|(?:all\.fuseurl.com)|(?:alturl\.com)|(?:amzn\.to)|(?:ar\.gy)|(?:arst\.ch)|(?:atu\.ca)|(?:azc\.cc)|(?:b23\.ru)|(?:b2l\.me)|(?:bacn\.me)|(?:bcool\.bz)|(?:binged\.it)|(?:bit\.ly)|(?:buff\.ly)|(?:bizj\.us)|(?:bloat\.me)|(?:bravo\.ly)|(?:bsa\.ly)|(?:budurl\.com)|(?:canurl\.com)|(?:chilp\.it)|(?:chzb\.gr)|(?:cl\.lk)|(?:cl\.ly)|(?:clck\.ru)|(?:cli\.gs)|(?:cliccami\.info)|(?:clickthru\.ca)|(?:clop\.in)|(?:conta\.cc)|(?:cort\.as)|(?:cot\.ag)|(?:crks\.me)|(?:ctvr\.us)|(?:cutt\.us)|(?:dai\.ly)|(?:decenturl\.com)|(?:dfl8\.me)|(?:digbig\.com)|(?:digg\.com)|(?:disq\.us)|(?:dld\.bz)|(?:dlvr\.it)|(?:do\.my)|(?:doiop\.com)|(?:dopen\.us)|(?:easyuri\.com)|(?:easyurl\.net)|(?:eepurl\.com)|(?:eweri\.com)|(?:fa\.by)|(?:fav\.me)|(?:fb\.me)|(?:fbshare\.me)|(?:ff\.im)|(?:fff\.to)|(?:fire\.to)|(?:firsturl\.de)|(?:firsturl\.net)|(?:flic\.kr)|(?:flq\.us)|(?:fly2\.ws)|(?:fon\.gs)|(?:freak\.to)|(?:fuseurl\.com)|(?:fuzzy\.to)|(?:fwd4\.me)|(?:fwib\.net)|(?:g\.ro.lt)|(?:gizmo\.do)|(?:gl\.am)|(?:go\.9nl.com)|(?:go\.ign.com)|(?:go\.usa.gov)|(?:goo\.gl)|(?:goshrink\.com)|(?:gurl\.es)|(?:hex\.io)|(?:hiderefer\.com)|(?:hmm\.ph)|(?:href\.in)|(?:hsblinks\.com)|(?:htxt\.it)|(?:huff\.to)|(?:hulu\.com)|(?:hurl\.me)|(?:hurl\.ws)|(?:icanhaz\.com)|(?:idek\.net)|(?:ilix\.in)|(?:is\.gd)|(?:its\.my)|(?:ix\.lt)|(?:j\.mp)|(?:jijr\.com)|(?:kl\.am)|(?:klck\.me)|(?:korta\.nu)|(?:krunchd\.com)|(?:l9k\.net)|(?:lat\.ms)|(?:liip\.to)|(?:liltext\.com)|(?:linkbee\.com)|(?:linkbun\.ch)|(?:liurl\.cn)|(?:ln-s\.net)|(?:ln-s\.ru)|(?:lnk\.gd)|(?:lnk\.ms)|(?:lnkd\.in)|(?:lnkurl\.com)|(?:lru\.jp)|(?:lt\.tl)|(?:lurl\.no)|(?:macte\.ch)|(?:mash\.to)|(?:merky\.de)|(?:migre\.me)|(?:miniurl\.com)|(?:minurl\.fr)|(?:mke\.me)|(?:moby\.to)|(?:moourl\.com)|(?:mrte\.ch)|(?:myloc\.me)|(?:myurl\.in)|(?:n\.pr)|(?:nbc\.co)|(?:nblo\.gs)|(?:nn\.nf)|(?:not\.my)|(?:notlong\.com)|(?:nsfw\.in)|(?:nutshellurl\.com)|(?:nxy\.in)|(?:nyti\.ms)|(?:o-x\.fr)|(?:oc1\.us)|(?:om\.ly)|(?:omf\.gd)|(?:omoikane\.net)|(?:on\.cnn.com)|(?:on\.mktw.net)|(?:onforb\.es)|(?:orz\.se)|(?:ow\.ly)|(?:ping\.fm)|(?:pli\.gs)|(?:pnt\.me)|(?:politi\.co)|(?:post\.ly)|(?:pp\.gg)|(?:profile\.to)|(?:ptiturl\.com)|(?:pub\.vitrue.com)|(?:qlnk\.net)|(?:qte\.me)|(?:qu\.tc)|(?:qy\.fi)|(?:r\.im)|(?:rb6\.me)|(?:read\.bi)|(?:readthis\.ca)|(?:reallytinyurl\.com)|(?:redir\.ec)|(?:redirects\.ca)|(?:redirx\.com)|(?:retwt\.me)|(?:ri\.ms)|(?:rickroll\.it)|(?:riz\.gd)|(?:rt\.nu)|(?:ru\.ly)|(?:rubyurl\.com)|(?:rurl\.org)|(?:rww\.tw)|(?:s4c\.in)|(?:s7y\.us)|(?:safe\.mn)|(?:sameurl\.com)|(?:sdut\.us)|(?:shar\.es)|(?:shink\.de)|(?:shorl\.com)|(?:short\.ie)|(?:short\.to)|(?:shortlinks\.co.uk)|(?:shorturl\.com)|(?:shout\.to)|(?:show\.my)|(?:shrinkify\.com)|(?:shrinkr\.com)|(?:shrt\.fr)|(?:shrt\.st)|(?:shrten\.com)|(?:shrunkin\.com)|(?:simurl\.com)|(?:slate\.me)|(?:smallr\.com)|(?:smsh\.me)|(?:smurl\.name)|(?:sn\.im)|(?:snipr\.com)|(?:snipurl\.com)|(?:snurl\.com)|(?:sp2\.ro)|(?:spedr\.com)|(?:srnk\.net)|(?:srs\.li)|(?:starturl\.com)|(?:su\.pr)|(?:surl\.co.uk)|(?:surl\.hu)|(?:t\.cn)|(?:t\.co)|(?:t\.lh.com)|(?:ta\.gd)|(?:tbd\.ly)|(?:tcrn\.ch)|(?:tgr\.me)|(?:tgr\.ph)|(?:tighturl\.com)|(?:tiniuri\.com)|(?:tiny\.cc)|(?:tiny\.ly)|(?:tiny\.pl)|(?:tinylink\.in)|(?:tinyuri\.ca)|(?:tinyurl\.com)|(?:tl\.gd)|(?:tmi\.me)|(?:tnij\.org)|(?:tnw\.to)|(?:tny\.com)|(?:to\.ly)|(?:togoto\.us)|(?:totc\.us)|(?:toysr\.us)|(?:tpm\.ly)|(?:tr\.im)|(?:tra\.kz)|(?:trunc\.it)|(?:twhub\.com)|(?:twirl\.at)|(?:twitclicks\.com)|(?:twitterurl\.net)|(?:twitterurl\.org)|(?:twiturl\.de)|(?:twurl\.cc)|(?:twurl\.nl)|(?:u\.mavrev.com)|(?:u\.nu)|(?:u76\.org)|(?:ub0\.cc)|(?:ulu\.lu)|(?:updating\.me)|(?:ur1\.ca)|(?:url\.az)|(?:url\.co.uk)|(?:url\.ie)|(?:url360\.me)|(?:url4\.eu)|(?:urlborg\.com)|(?:urlbrief\.com)|(?:urlcover\.com)|(?:urlcut\.com)|(?:urlenco\.de)|(?:urli\.nl)|(?:urls\.im)|(?:urlshorteningservicefortwitter\.com)|(?:urlx\.ie)|(?:urlzen\.com)|(?:usat\.ly)|(?:use\.my)|(?:vb\.ly)|(?:vgn\.am)|(?:vl\.am)|(?:vm\.lc)|(?:w55\.de)|(?:wapo\.st)|(?:wapurl\.co.uk)|(?:wipi\.es)|(?:wp\.me)|(?:x\.vu)|(?:xr\.com)|(?:xrl\.in)|(?:xrl\.us)|(?:xurl\.es)|(?:xurl\.jp)|(?:y\.ahoo.it)|(?:yatuc\.com)|(?:ye\.pe)|(?:yep\.it)|(?:yfrog\.com)|(?:yhoo\.it)|(?:yiyd\.com)|(?:youtu\.be)|(?:yuarel\.com)|(?:z0p\.de)|(?:zi\.ma)|(?:zi\.mu)|(?:zipmyurl\.com)|(?:zud\.me)|(?:zurl\.ws)|(?:zz\.gd)|(?:zzang\.kr)|(?:›\.ws)|(?:✩\.ws)|(?:✿\.ws)|(?:❥\.ws)|(?:➔\.ws)|(?:➞\.ws)|(?:➡\.ws)|(?:➨\.ws)|(?:➯\.ws)|(?:➹\.ws)|(?:➽\.ws))\/[a-z0-9]*/gi; +export function urlRegex () { + return /((href|src)=["']|)(\b(https?|ftp|file):\/\/[^,.\s]+[^\s]*[^,.\s]+)|(?:https?:\/\/)?(?:(?:0rz\.tw)|(?:1link\.in)|(?:1url\.com)|(?:2\.gp)|(?:2big\.at)|(?:2tu\.us)|(?:3\.ly)|(?:307\.to)|(?:4ms\.me)|(?:4sq\.com)|(?:4url\.cc)|(?:6url\.com)|(?:7\.ly)|(?:a\.gg)|(?:a\.nf)|(?:aa\.cx)|(?:abcurl\.net)|(?:ad\.vu)|(?:adf\.ly)|(?:adjix\.com)|(?:afx\.cc)|(?:all\.fuseurl.com)|(?:alturl\.com)|(?:amzn\.to)|(?:ar\.gy)|(?:arst\.ch)|(?:atu\.ca)|(?:azc\.cc)|(?:b23\.ru)|(?:b2l\.me)|(?:bacn\.me)|(?:bcool\.bz)|(?:binged\.it)|(?:bit\.ly)|(?:buff\.ly)|(?:bizj\.us)|(?:bloat\.me)|(?:bravo\.ly)|(?:bsa\.ly)|(?:budurl\.com)|(?:canurl\.com)|(?:chilp\.it)|(?:chzb\.gr)|(?:cl\.lk)|(?:cl\.ly)|(?:clck\.ru)|(?:cli\.gs)|(?:cliccami\.info)|(?:clickthru\.ca)|(?:clop\.in)|(?:conta\.cc)|(?:cort\.as)|(?:cot\.ag)|(?:crks\.me)|(?:ctvr\.us)|(?:cutt\.us)|(?:dai\.ly)|(?:decenturl\.com)|(?:dfl8\.me)|(?:digbig\.com)|(?:digg\.com)|(?:disq\.us)|(?:dld\.bz)|(?:dlvr\.it)|(?:do\.my)|(?:doiop\.com)|(?:dopen\.us)|(?:easyuri\.com)|(?:easyurl\.net)|(?:eepurl\.com)|(?:eweri\.com)|(?:fa\.by)|(?:fav\.me)|(?:fb\.me)|(?:fbshare\.me)|(?:ff\.im)|(?:fff\.to)|(?:fire\.to)|(?:firsturl\.de)|(?:firsturl\.net)|(?:flic\.kr)|(?:flq\.us)|(?:fly2\.ws)|(?:fon\.gs)|(?:freak\.to)|(?:fuseurl\.com)|(?:fuzzy\.to)|(?:fwd4\.me)|(?:fwib\.net)|(?:g\.ro.lt)|(?:gizmo\.do)|(?:gl\.am)|(?:go\.9nl.com)|(?:go\.ign.com)|(?:go\.usa.gov)|(?:goo\.gl)|(?:goshrink\.com)|(?:gurl\.es)|(?:hex\.io)|(?:hiderefer\.com)|(?:hmm\.ph)|(?:href\.in)|(?:hsblinks\.com)|(?:htxt\.it)|(?:huff\.to)|(?:hulu\.com)|(?:hurl\.me)|(?:hurl\.ws)|(?:icanhaz\.com)|(?:idek\.net)|(?:ilix\.in)|(?:is\.gd)|(?:its\.my)|(?:ix\.lt)|(?:j\.mp)|(?:jijr\.com)|(?:kl\.am)|(?:klck\.me)|(?:korta\.nu)|(?:krunchd\.com)|(?:l9k\.net)|(?:lat\.ms)|(?:liip\.to)|(?:liltext\.com)|(?:linkbee\.com)|(?:linkbun\.ch)|(?:liurl\.cn)|(?:ln-s\.net)|(?:ln-s\.ru)|(?:lnk\.gd)|(?:lnk\.ms)|(?:lnkd\.in)|(?:lnkurl\.com)|(?:lru\.jp)|(?:lt\.tl)|(?:lurl\.no)|(?:macte\.ch)|(?:mash\.to)|(?:merky\.de)|(?:migre\.me)|(?:miniurl\.com)|(?:minurl\.fr)|(?:mke\.me)|(?:moby\.to)|(?:moourl\.com)|(?:mrte\.ch)|(?:myloc\.me)|(?:myurl\.in)|(?:n\.pr)|(?:nbc\.co)|(?:nblo\.gs)|(?:nn\.nf)|(?:not\.my)|(?:notlong\.com)|(?:nsfw\.in)|(?:nutshellurl\.com)|(?:nxy\.in)|(?:nyti\.ms)|(?:o-x\.fr)|(?:oc1\.us)|(?:om\.ly)|(?:omf\.gd)|(?:omoikane\.net)|(?:on\.cnn.com)|(?:on\.mktw.net)|(?:onforb\.es)|(?:orz\.se)|(?:ow\.ly)|(?:ping\.fm)|(?:pli\.gs)|(?:pnt\.me)|(?:politi\.co)|(?:post\.ly)|(?:pp\.gg)|(?:profile\.to)|(?:ptiturl\.com)|(?:pub\.vitrue.com)|(?:qlnk\.net)|(?:qte\.me)|(?:qu\.tc)|(?:qy\.fi)|(?:r\.im)|(?:rb6\.me)|(?:read\.bi)|(?:readthis\.ca)|(?:reallytinyurl\.com)|(?:redir\.ec)|(?:redirects\.ca)|(?:redirx\.com)|(?:retwt\.me)|(?:ri\.ms)|(?:rickroll\.it)|(?:riz\.gd)|(?:rt\.nu)|(?:ru\.ly)|(?:rubyurl\.com)|(?:rurl\.org)|(?:rww\.tw)|(?:s4c\.in)|(?:s7y\.us)|(?:safe\.mn)|(?:sameurl\.com)|(?:sdut\.us)|(?:shar\.es)|(?:shink\.de)|(?:shorl\.com)|(?:short\.ie)|(?:short\.to)|(?:shortlinks\.co.uk)|(?:shorturl\.com)|(?:shout\.to)|(?:show\.my)|(?:shrinkify\.com)|(?:shrinkr\.com)|(?:shrt\.fr)|(?:shrt\.st)|(?:shrten\.com)|(?:shrunkin\.com)|(?:simurl\.com)|(?:slate\.me)|(?:smallr\.com)|(?:smsh\.me)|(?:smurl\.name)|(?:sn\.im)|(?:snipr\.com)|(?:snipurl\.com)|(?:snurl\.com)|(?:sp2\.ro)|(?:spedr\.com)|(?:srnk\.net)|(?:srs\.li)|(?:starturl\.com)|(?:su\.pr)|(?:surl\.co.uk)|(?:surl\.hu)|(?:t\.cn)|(?:t\.co)|(?:t\.lh.com)|(?:ta\.gd)|(?:tbd\.ly)|(?:tcrn\.ch)|(?:tgr\.me)|(?:tgr\.ph)|(?:tighturl\.com)|(?:tiniuri\.com)|(?:tiny\.cc)|(?:tiny\.ly)|(?:tiny\.pl)|(?:tinylink\.in)|(?:tinyuri\.ca)|(?:tinyurl\.com)|(?:tl\.gd)|(?:tmi\.me)|(?:tnij\.org)|(?:tnw\.to)|(?:tny\.com)|(?:to\.ly)|(?:togoto\.us)|(?:totc\.us)|(?:toysr\.us)|(?:tpm\.ly)|(?:tr\.im)|(?:tra\.kz)|(?:trunc\.it)|(?:twhub\.com)|(?:twirl\.at)|(?:twitclicks\.com)|(?:twitterurl\.net)|(?:twitterurl\.org)|(?:twiturl\.de)|(?:twurl\.cc)|(?:twurl\.nl)|(?:u\.mavrev.com)|(?:u\.nu)|(?:u76\.org)|(?:ub0\.cc)|(?:ulu\.lu)|(?:updating\.me)|(?:ur1\.ca)|(?:url\.az)|(?:url\.co.uk)|(?:url\.ie)|(?:url360\.me)|(?:url4\.eu)|(?:urlborg\.com)|(?:urlbrief\.com)|(?:urlcover\.com)|(?:urlcut\.com)|(?:urlenco\.de)|(?:urli\.nl)|(?:urls\.im)|(?:urlshorteningservicefortwitter\.com)|(?:urlx\.ie)|(?:urlzen\.com)|(?:usat\.ly)|(?:use\.my)|(?:vb\.ly)|(?:vgn\.am)|(?:vl\.am)|(?:vm\.lc)|(?:w55\.de)|(?:wapo\.st)|(?:wapurl\.co.uk)|(?:wipi\.es)|(?:wp\.me)|(?:x\.vu)|(?:xr\.com)|(?:xrl\.in)|(?:xrl\.us)|(?:xurl\.es)|(?:xurl\.jp)|(?:y\.ahoo.it)|(?:yatuc\.com)|(?:ye\.pe)|(?:yep\.it)|(?:yfrog\.com)|(?:yhoo\.it)|(?:yiyd\.com)|(?:youtu\.be)|(?:yuarel\.com)|(?:z0p\.de)|(?:zi\.ma)|(?:zi\.mu)|(?:zipmyurl\.com)|(?:zud\.me)|(?:zurl\.ws)|(?:zz\.gd)|(?:zzang\.kr)|(?:›\.ws)|(?:✩\.ws)|(?:✿\.ws)|(?:❥\.ws)|(?:➔\.ws)|(?:➞\.ws)|(?:➡\.ws)|(?:➨\.ws)|(?:➯\.ws)|(?:➹\.ws)|(?:➽\.ws))\/[a-z0-9]*/gi } -function arrayLowercase(options, property){ - if(typeof options[property] !== 'string'){ - options[property] = options[property].map(function(elem){ - return elem.toLowerCase(); - }) - } - return options; +function arrayLowercase (options, property) { + if (typeof options[property] !== 'string') { + options[property] = options[property].map(function (elem) { + return elem.toLowerCase() + }) + } + return options } /** @@ -148,11 +148,11 @@ function arrayLowercase(options, property){ * @param options * @returns {Object|*} */ -export function processOptions(options){ - options = setDimensions(options); - options = arrayLowercase(options, 'excludeEmbed'); - options = arrayLowercase(options, 'inlineEmbed'); - return arrayLowercase(options, 'openGraphExclude'); +export function processOptions (options) { + options = setDimensions(options) + options = arrayLowercase(options, 'excludeEmbed') + options = arrayLowercase(options, 'inlineEmbed') + return arrayLowercase(options, 'openGraphExclude') } /** @@ -160,6 +160,6 @@ export function processOptions(options){ * @param elem [String|Array] * @returns last element of the Array or String */ -export function lastElement(elem){ - return elem[elem.length - 1]; +export function lastElement (elem) { + return elem[elem.length - 1] } From 9e8f4c55aedd75a40aff17f3c21be48fe873705f Mon Sep 17 00:00:00 2001 From: Ritesh Kumar Date: Sat, 25 Feb 2017 00:11:57 +0530 Subject: [PATCH 2/2] build(rollup): replace babel with buble --- Gruntfile.js | 100 +++++++++++++++++++--------------------- package.json | 16 +++---- rollup.es2015.config.js | 48 ++++++++++--------- rollup.umd.config.js | 31 ++++++------- 4 files changed, 95 insertions(+), 100 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 24b7ce3..97cbde1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -24,11 +24,11 @@ module.exports = function (grunt) { options: { livereload: true }, - css : { + css: { files: ['src/css/**/*.scss'], tasks: ['sass', 'postcss'] }, - js : { + js: { files: ['src/js/**/*.js', 'build.json'], tasks: ['eslint', 'shell:rollup', 'uglify'] } @@ -36,15 +36,15 @@ module.exports = function (grunt) { postcss: { options: { - map : false, + map: false, processors: [ require('cssnano')({ convertValues: false }) ] }, - dist : { - src : 'dist/embed.css', + dist: { + src: 'dist/embed.css', dest: 'dist/embed.min.css' } }, @@ -53,13 +53,13 @@ module.exports = function (grunt) { 'sprite': { all: { - src : './assets/images/ejs_emojis/*.png', - dest : './assets/images/emojis.png', - retinaSrcFilter : './assets/images/ejs_emojis/*@2x.png', - destCss : 'src/css/_emojis.scss', - retinaDest : './assets/images/emojis@2x.png', - cssFormat : 'css', - cssTemplate : 'sprite.handlebars', + src: './assets/images/ejs_emojis/*.png', + dest: './assets/images/emojis.png', + retinaSrcFilter: './assets/images/ejs_emojis/*@2x.png', + destCss: 'src/css/_emojis.scss', + retinaDest: './assets/images/emojis@2x.png', + cssFormat: 'css', + cssTemplate: 'sprite.handlebars', cssHandlebarsHelpers: { escape: function (name) { var x = ['+', '-', '/', '*']; @@ -81,11 +81,11 @@ module.exports = function (grunt) { } } }, - files : { + files: { expand: true, - cwd : 'assets/images/emojis', - src : ['*.png'], - dest : 'assets/images/ejs_emojis/' + cwd: 'assets/images/emojis', + src: ['*.png'], + dest: 'assets/images/ejs_emojis/' } }, @@ -94,7 +94,7 @@ module.exports = function (grunt) { options: { style: 'expanded' }, - files : { + files: { 'dist/embed.css': 'src/css/embed.scss' } } @@ -102,36 +102,36 @@ module.exports = function (grunt) { 'uglify': { options: { - banner : "<%= meta.banner %>", - mangle : true, + banner: "<%= meta.banner %>", + mangle: true, compress: { - sequences : true, - dead_code : true, + sequences: true, + dead_code: true, conditionals: true, - booleans : true, - unused : true, - if_return : true, - join_vars : true, + booleans: true, + unused: true, + if_return: true, + join_vars: true, drop_console: true } }, - build : { + build: { files: { 'dist/embed.min.js': 'dist/embed.js' } } }, - connect : { + connect: { server: { options: { - port : 8000, + port: 8000, livereload: true, - open : true, - keepAlive : true, - base : { - path : './', + open: true, + keepAlive: true, + base: { + path: './', options: { - index : 'demo/index.html', + index: 'demo/index.html', maxAge: 300000 } } @@ -139,24 +139,20 @@ module.exports = function (grunt) { } }, - eslint: { - target: ['src/js/**/*.js'] - }, - 'string-replace': { dist: { - files : { + files: { '.tmp/embed.css': 'dist/embed.css' }, options: { replacements: [{ - pattern : /..\/assets\/images\/loader.svg/g, + pattern: /..\/assets\/images\/loader.svg/g, replacement: 'assets/images' }, { - pattern : /..\/.\/assets\/images\/emojis/g, + pattern: /..\/.\/assets\/images\/emojis/g, replacement: 'assets/images/emojis' }, { - pattern : /..\/assets\/fonts/g, + pattern: /..\/assets\/fonts/g, replacement: 'assets/fonts' }] } @@ -167,12 +163,12 @@ module.exports = function (grunt) { dist: { files: [{ expand: true, - src : 'assets/fonts/*', - dest : 'dist/' + src: 'assets/fonts/*', + dest: 'dist/' }, { expand: true, - src : 'assets/images/*', - dest : 'dist/', + src: 'assets/images/*', + dest: 'dist/', filter: 'isFile' }] } @@ -180,9 +176,9 @@ module.exports = function (grunt) { bump: { options: { - files : ['package.json'], - commitFiles : ['-a'], - pushTo : 'origin', + files: ['package.json'], + commitFiles: ['-a'], + pushTo: 'origin', updateConfigs: ['pkg'] } }, @@ -204,7 +200,7 @@ module.exports = function (grunt) { publish: { command: 'npm publish' }, - rollup : { + rollup: { command: 'rollup -c rollup.umd.config.js && rollup -c rollup.es2015.config.js' } } @@ -212,10 +208,10 @@ module.exports = function (grunt) { require('load-grunt-tasks')(grunt); - grunt.registerTask("default", ["eslint", "shell:rollup", "sass", "connect", "watch"]); - grunt.registerTask("build", ["clean", "build-emoji", "eslint", "shell:rollup", "sass", "uglify", "string-replace", "postcss", "copy"]); + grunt.registerTask("default", ["shell:rollup", "sass", "connect", "watch"]); + grunt.registerTask("build", ["clean", "build-emoji", "shell:rollup", "sass", "uglify", "string-replace", "postcss", "copy"]); grunt.registerTask("build-emoji", ["retinafy", "sprite", "sass"]); - grunt.registerTask("dist", ["clean", "eslint", "shell:rollup", "sass", "uglify", "string-replace", "postcss", "copy"]); + grunt.registerTask("dist", ["clean", "shell:rollup", "sass", "uglify", "string-replace", "postcss", "copy"]); grunt.registerTask("release", function (option) { grunt.task.run(["bump-only:" + option, "dist", "conventionalChangelog", "bump-commit", "shell:publish"]); diff --git a/package.json b/package.json index d64c16f..3b2428a 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,6 @@ "grunt-contrib-uglify": "^1.0.1", "grunt-contrib-watch": "^1.0.0", "grunt-conventional-changelog": "^6.1.0", - "grunt-eslint": "^18.0.0", "grunt-postcss": "^0.8.0", "grunt-retinafy": "^0.1.5", "grunt-shell": "^1.1.2", @@ -81,18 +80,19 @@ "grunt-string-replace": "^1.2.1", "load-grunt-tasks": "^3.4.0", "phantomjs": "^2.1.3", - "rollup": "^0.31.2", - "rollup-plugin-babel": "2.4.0", - "rollup-plugin-commonjs": "^2.2.1", - "rollup-plugin-filesize": "^0.2.1", - "rollup-plugin-npm": "^1.4.0", - "rollup-plugin-uglify": "^0.3.1" + "rollup": "^0.41.4", + "rollup-plugin-buble": "^0.15.0", + "rollup-plugin-commonjs": "^7.0.0", + "rollup-plugin-filesize": "^1.0.1", + "rollup-plugin-node-resolve": "^2.0.0", + "rollup-plugin-uglify": "^1.0.1" }, "scripts": { "commit": "git-cz", "lint": "eslint src/js/**/*.js", "lintfix": "eslint --fix src/js/**/*.js", - "test": "ava test/**/*.test.js --require babel-register" + "test": "ava test/**/*.test.js --require babel-register", + "build": "rollup -c rollup.umd.config.js && rollup.es2015.config.js" }, "config": { "commitizen": { diff --git a/rollup.es2015.config.js b/rollup.es2015.config.js index 0a83570..c370cdc 100644 --- a/rollup.es2015.config.js +++ b/rollup.es2015.config.js @@ -1,32 +1,34 @@ var commonjs = require('rollup-plugin-commonjs'); -var npm = require('rollup-plugin-npm'); -var pkg = require('./package.json'); +var nodeResolve = require('rollup-plugin-node-resolve'); +var pkg = require('./package.json'); +var filesize = require('rollup-plugin-filesize'); var banner = "/*\n" + - " * " + pkg.name + " - v"+ pkg.version +"\n" + - " * " + pkg.description +"\n" + - " * " + pkg.homepage +"\n" + - " *\n" + - " * Made by "+ pkg.author.name +"\n" + - " * Under "+ pkg.license +" License\n" + - " */\n"; + " * " + pkg.name + " - v" + pkg.version + "\n" + + " * " + pkg.description + "\n" + + " * " + pkg.homepage + "\n" + + " *\n" + + " * Made by " + pkg.author.name + "\n" + + " * Under " + pkg.license + " License\n" + + " */\n"; var config = { - entry : 'src/js/main.js', - dest : 'dist/embed.es2015.js', - format : 'es', - banner : banner, - sourceMap : true, - plugins: [ - npm({ - jsnext : true, - main : true - }), - commonjs({ - include: 'node_modules/**' - }) - ] + entry: 'src/js/main.js', + dest: 'dist/embed.es2015.js', + format: 'es', + banner: banner, + sourceMap: true, + plugins: [ + nodeResolve({ + jsnext: true, + main: true + }), + commonjs({ + include: 'node_modules/**' + }), + filesize() + ] }; module.exports = config; diff --git a/rollup.umd.config.js b/rollup.umd.config.js index a0be72e..4987a8b 100644 --- a/rollup.umd.config.js +++ b/rollup.umd.config.js @@ -1,8 +1,8 @@ -var babel = require('rollup-plugin-babel'); var commonjs = require('rollup-plugin-commonjs'); -var npm = require('rollup-plugin-npm'); -var pkg = require('./package.json'); -var filesize = require('rollup-plugin-filesize'); +var nodeResolve = require('rollup-plugin-node-resolve'); +var pkg = require('./package.json'); +var filesize = require('rollup-plugin-filesize'); +var buble = require('rollup-plugin-buble') var banner = "/*\n" + " * " + pkg.name + " - v" + pkg.version + "\n" + @@ -14,24 +14,21 @@ var banner = "/*\n" + " */\n"; var config = { - entry : 'src/js/main.js', - dest : 'dist/embed.js', - format : 'umd', - banner : banner, - sourceMap : true, - moduleName : 'EmbedJS', - plugins : [ - npm({ + entry: 'src/js/main.js', + dest: 'dist/embed.js', + format: 'umd', + banner: banner, + sourceMap: true, + moduleName: 'EmbedJS', + plugins: [ + nodeResolve({ jsnext: true, - main : true + main: true }), commonjs({ include: 'node_modules/**' }), - babel({ - babelrc:false, - presets:['es2015-rollup'] - }), + buble(), filesize() ] };