Skip to content

Commit

Permalink
Optimizes build, test and adds CDNs to package.json and README
Browse files Browse the repository at this point in the history
Build tasks use a single rollup.config.js file. It uses ENV vars to define input, output and plugins
Tests tasks uses a single karma.conf.js. It uses ENV vars to define which files to test
Adds unpkg and jsdelivr entries to package.json
Adds CDN usage instructions to README.md

adds better version verification to makefile

fixes keyword spacing rule

adds better version verification to makefile

adds better version verification to makefile
  • Loading branch information
ffflabs committed Nov 2, 2017
1 parent 8b6e7f6 commit c07f7d0
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 256 deletions.
76 changes: 46 additions & 30 deletions .eslintrc
@@ -1,27 +1,30 @@
{
"parser":"babel-eslint",
"parser": "babel-eslint",
"extends": "eslint:recommended",
"env": {
"env":
{
"browser": true,
"node": true,
"es6": true,
"jquery":true,
"amd":true
"jquery": true,
"amd": true

},
"globals":{
"google":true,
"SystemJS":true,
"globalvars":false,
"__moduleName":false,
"globalmap":false,
"expect":false,
"self":false,
"DEBUG":true
"globals":
{
"google": true,
"SystemJS": true,
"globalvars": false,
"__moduleName": false,
"globalmap": false,
"expect": false,
"self": false,
"DEBUG": true
},


"ecmaFeatures": {

"ecmaFeatures":
{
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
Expand All @@ -46,7 +49,8 @@
"jsx": true
},

"rules": {
"rules":
{

//
//Possible Errors
Expand All @@ -63,7 +67,7 @@
"no-dupe-keys": 2, // disallow duplicate keys when creating object literals
"no-duplicate-case": 2, // disallow a duplicate case label.
"no-empty": 2, // disallow empty statements

"no-ex-assign": 2, // disallow assigning to the exception in a catch block
"no-extra-boolean-cast": 2, // disallow double-negation boolean casts in a boolean context
"no-extra-parens": 0, // disallow unnecessary parentheses (off by default)
Expand Down Expand Up @@ -130,7 +134,8 @@
"no-throw-literal": 2, // restrict what can be thrown as an exception (off by default)
"no-unused-expressions": 2, // disallow usage of expressions in statement position
"no-void": 2, // disallow use of void operator (off by default)
"no-warning-comments": [0, {
"no-warning-comments": [0,
{
"terms": ["todo", "fixme"],
"location": "start"
}], // disallow usage of configurable warning terms in comments": 2, // e.g. TODO or FIXME (off by default)
Expand Down Expand Up @@ -171,7 +176,8 @@
"indent": [0, "tab"], // this option sets a specific tab width for your code (off by default)
"brace-style": 1, // enforce one true brace style (off by default)
"camelcase": 0, // require camel case names
"comma-spacing": [1, {
"comma-spacing": [1,
{
"before": false,
"after": true
}], // enforce spacing before and after comma
Expand All @@ -180,12 +186,14 @@
"eol-last": 1, // enforce newline at the end of file, with no multiple empty lines
"func-names": 0, // require function expressions to have a name (off by default)
"func-style": 0, // enforces use of function declarations or expressions (off by default)
"key-spacing": [1, {
"key-spacing": [1,
{
"beforeColon": false,
"afterColon": true
}], // enforces spacing between keys and values in object literal properties
"max-nested-callbacks": [1, 4], // specify the maximum depth callbacks can be nested (off by default)
"new-cap": [1, {
"new-cap": [1,
{
newIsCap: true,
capIsNew: false
}], // require a capital letter for constructors
Expand All @@ -195,7 +203,8 @@
"no-inline-comments": 0, // disallow comments inline after code (off by default)
"no-lonely-if": 1, // disallow if as the only statement in an else block (off by default)
"no-mixed-spaces-and-tabs": 1, // disallow mixed spaces and tabs for indentation
"no-multiple-empty-lines": [1, {
"no-multiple-empty-lines": [1,
{
"max": 2
}], // disallow multiple empty lines (off by default)
"no-nested-ternary": 1, // disallow nested ternary expressions (off by default)
Expand All @@ -210,21 +219,28 @@
"quote-props": [0, "as-needed"], // require quotes around object literal property names (off by default)
"quotes": [0, "single"], // specify whether double or single quotes should be used
"semi": [1, "always"], // require or disallow use of semicolons instead of ASI
"semi-spacing": [1, {
"semi-spacing": [1,
{
"before": false,
"after": true
}], // enforce spacing before and after semicolons
"sort-vars": 0, // sort variables within the same declaration block (off by default)
"keyword-spacing": [1, "always"], // require a space after certain keywords (off by default)
"keyword-spacing": [2,
{
"before": true,
"after": true
}], // require a space after certain keywords (off by default)
"space-before-blocks": [1, "always"], // require or disallow space before blocks (off by default)
"space-before-function-paren": [1, {
"space-before-function-paren": [1,
{
"anonymous": "always",
"named": "never"
}], // require or disallow space before function opening parenthesis (off by default)

//"space-infix-ops": [1], // require spaces around operators
//"space-return-throw-case": [1, "always"], // require a space after return, throw, and case
"space-unary-ops": [1, {
"space-unary-ops": [1,
{
"words": true,
"nonwords": false
}], // Require or disallow spaces before/after unary operators (words on by default, nonwords off by default)
Expand All @@ -250,8 +266,8 @@
"max-params": [1, 15], // limits the number of parameters that can be used in the function declaration. (off by default)
"max-statements": 0, // specify the maximum number of statement allowed in a function (off by default)
"no-bitwise": 1, // disallow use of bitwise operators (off by default)
"no-plusplus": 0,// disallow use of unary operators, ++ and -- (off by default)
"no-plusplus": 0, // disallow use of unary operators, ++ and -- (off by default)



}
}
}
73 changes: 52 additions & 21 deletions Makefile
Expand Up @@ -2,6 +2,13 @@ VERSION = $(shell cat package.json | sed -n 's/.*"version": "\([^"]*\)",/\1/p')

SHELL = /usr/bin/env bash


YELLOW=\033[0;33m
RED=\033[0;31m
WHITE=\033[0m
GREEN=\u001B[32m


default: build
.PHONY: backbone_es6 test build backbone_bundle backbone_min remove_tag

Expand All @@ -17,12 +24,12 @@ install:

test:
$$(npm bin)/karma start
$$(npm bin)/karma start karma.min.conf.js
MINIFIED=true $$(npm bin)/karma start



backbone_es6:
$$(npm bin)/rollup -c rollup.config.es6.js
ES6=true $$(npm bin)/rollup -c


backbone_bundle:
Expand All @@ -31,33 +38,25 @@ backbone_bundle:


backbone_min:
$$(npm bin)/rollup -c rollup.config.min.js
MINIFY=true $$(npm bin)/rollup -c
sed -i s/".BackboneES6"/""/g dist/backbone.min.js




update_version:
ifeq ($(shell expr "${CURRENT_MAJOR}" \> "$(NEXT_MAJOR)"),1)
$(error "v" parameter is lower than current version ${VERSION})
endif
ifeq ($(shell expr "${CURRENT_MINOR}" \> "$(NEXT_MINOR)"),1)
$(error "v" parameter is lower than current version ${VERSION})
endif
ifeq ($(shell expr "${CURRENT_HOTFIX}" \> "$(NEXT_HOTFIX)"),1)
$(error "v" parameter is lower than current version ${VERSION})
endif
@echo -e "Current version is $(GREEN) ${VERSION} $(WHITE) ";\
echo -e "Next version will be $(YELLOW) ${v} $(WHITE) ";\
sed -i s/"$(VERSION)"/"$(v)"/g package.json ;\


check_version:
ifeq ($(v),)
$(error v is undefined. You must set a tag name. e.g. make tag v=v1.0.0 or make release v=v1.0.0)
endif
ifeq (${VERSION},$(v))
$(error v is already the current version)
endif
@echo "Current version is " ${VERSION}
@echo "Next version is " $(v)
sed -i s/"$(VERSION)"/"$(v)"/g package.json

check_version:
$(eval SPLIT_VERSION = $(subst ., ,${VERSION}))
$(eval NEXT_VERSION := $(subst ., ,${v}))
$(eval CURRENT_MAJOR := $(word 1,$(SPLIT_VERSION)))
Expand All @@ -66,8 +65,39 @@ check_version:
$(eval NEXT_MAJOR := $(word 1,$(NEXT_VERSION)))
$(eval NEXT_MINOR := $(word 2,$(NEXT_VERSION)))
$(eval NEXT_HOTFIX := $(word 3,$(NEXT_VERSION)))


$(eval ERROR_HOTFIX := $(shell expr "${CURRENT_HOTFIX}" \> "$(NEXT_HOTFIX)"))
$(eval ERROR_MAJOR := $(shell expr "${CURRENT_MAJOR}" \> "$(NEXT_MAJOR)"))
$(eval ERROR_MINOR := $(shell expr "${CURRENT_MINOR}" \> "$(NEXT_MINOR)"))
$(eval SAFE_MAJOR := $(shell expr "${NEXT_MAJOR}" \> "$(CURRENT_MAJOR)"))
$(eval SAFE_MINOR := $(shell expr "${NEXT_MINOR}" \> "$(CURRENT_MINOR)"))

@if [ $(ERROR_MAJOR) == 1 ] ; then \
echo -e "$(RED)ERROR:$(WHITE) Current Major Version $(GREEN)$(CURRENT_MAJOR)$(WHITE).$(CURRENT_MINOR).$(CURRENT_HOTFIX) is higher than proposed version $(RED)$(NEXT_MAJOR)$(WHITE).$(NEXT_MINOR).$(NEXT_HOTFIX)" ;\
exit 1;\
else \
if [ $(SAFE_MAJOR) == 1 ] ; then \
${MAKE} update_version ;\
exit 1;\
else \
if [ $(ERROR_MINOR) == 1 ] ; then \
echo -e "$(RED)ERROR:$(WHITE) Current Minor Version $(CURRENT_MAJOR).$(GREEN)$(CURRENT_MINOR)$(WHITE).$(CURRENT_HOTFIX) is higher than proposed version $(NEXT_MAJOR).$(RED)$(NEXT_MINOR)$(WHITE).$(NEXT_HOTFIX)" ;\
exit 1;\
else \
if [ $(SAFE_MINOR) == 1 ] ; then \
${MAKE} update_version ;\
else \
if [ $(ERROR_HOTFIX) == 1 ] ; then \
echo -e "$(RED)ERROR:$(WHITE) Current Hotfix Version $(CURRENT_MAJOR).$(CURRENT_MINOR).$(GREEN)$(CURRENT_HOTFIX)$(WHITE) is higher than proposed version $(NEXT_MAJOR).$(NEXT_MINOR).$(RED)$(NEXT_HOTFIX)$(WHITE)" ;\
exit 1;\
else \
${MAKE} update_version ;\
fi ;\
fi ;\
fi ;\
fi ;\
fi ;\


tag_and_push:
git add --all
git commit -a -m "Tag v $(v) $(m)"
Expand All @@ -77,7 +107,7 @@ tag_and_push:

tag: build release

release: test check_version update_version tag_and_push
release: test check_version tag_and_push


remove_tag:
Expand All @@ -86,4 +116,5 @@ ifeq ($(t),)
endif
@echo "Removing tag " $(t) locally and remotely
git tag -d $(t)
git push origin :refs/tags/$(t)
git push origin :refs/tags/$(t)

53 changes: 37 additions & 16 deletions README.md
Expand Up @@ -24,6 +24,25 @@ They aren't explicitly listed as dependencies in `package.json` (for npm nor jsp

## Installation


### Including it with a script tag

Include this package in your HTML file directly with a script tag using [unpkg](https://unpkg.com/#/) or [jsdelivr](https://www.jsdelivr.com/)

```html
<script src="https://unpkg.com/backbone_es6/dist/backbone.min.js"></script>
```


**or**


```html
<script src="https://cdn.jsdelivr.net/npm/backbone_es6/dist/backbone.min.js"></script>
```



### Using npm

Install this package with npm with
Expand All @@ -41,11 +60,9 @@ jspm install npm:backbone_es6

## Can I use this as a drop-in replacement of Backbone?

Is your project already using ES6 imports?
**Yes you can**. Under the `dist` folder you can find scripts `backbone.js` and `backbone.min.js` that are in UMD format and can be used as a drop-in replacement for goold old vanilla Backbone. The minified version is listed as the `main` property in `package.json` so it's what you'll use by default.

If it isn't, don't worry. Under the `dist` folder you can find scripts `backbone.js` and `backbone.min.js` that are in UMD format and can be used as a drop-in replacement for goold old vanilla Backbone.

These scripts are also used to run the tests. Said tests are the same as the ones in the [official Backbone repo](https://github.com/jashkenas/backbone), to ensure Backbone ES6's compatibility.
These scripts are also used to run the tests. Said tests are the same as the ones in the [official Backbone repo](https://github.com/jashkenas/backbone), to ensure full Backbone ES6's compatibility with its parent framework.


### Using it with AMD
Expand All @@ -68,25 +85,20 @@ Whereas, using ES6 syntax, you would use
import {Backbone} from './node_modules/backbone_es6/dist/backbone.es6.js';
```

`package.json` already declares `dist/backbone.js` as the `main` script, while `dist/backbone.es6.js` is declared as the `jsnext:main` and `module` script properties.
`package.json` declares `dist/backbone.es6.js` as the `jsnext:main` and `module` script properties.



### Using it with [JSPM](https://github.com/jspm/jspm-cli)

If you installed Backbone ES6 with jspm, `backbone_es6` will be mapped automatically to `dist/backbone.es6.js`, so AMD usage would need you to point directly to `backbone.js`:
If you installed Backbone ES6 with jspm, `backbone_es6` will be mapped automatically to `dist/backbone.es6.js`. If you're tranpiling (using [plugin-babel](https://github.com/systemjs/plugin-babel)) you can import the module as:

```js
define([
'backbone_es6/backbone.js'
],function(Backbone) {

...your code...

});
```js
import {Backbone} from 'backbone_es6';
```

But, if you're transpiling (using [plugin-babel](https://github.com/systemjs/plugin-babel)) you could use AMD syntax as:
or you could use AMD syntax as:


```js
Expand All @@ -102,13 +114,22 @@ define([
});
```

or

If you are **not using a transpiler** and want to use the AMD build, use:


```js
import {Backbone} from 'backbone_es6';
define([
'backbone_es6/backbone.min.js'
],function(Backbone) {

...your code...

});
```



## Can I use classes?

Nope. The inner working of Backbone entities and the way they extend is kept as-is. This project is only a POC to do imports and tree shaking. No more, no less.
Expand Down

0 comments on commit c07f7d0

Please sign in to comment.