Skip to content

Commit

Permalink
Use webpack for bundling, add coverage, remove gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Aug 13, 2018
1 parent 58b4c98 commit e881995
Show file tree
Hide file tree
Showing 28 changed files with 16,793 additions and 222 deletions.
26 changes: 23 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@

{
"presets": ["es2015"],
"plugins": [["add-module-exports"]]
"presets": [
["@babel/env", {
"loose": true,
"useBuiltIns": "usage",
"targets": {
"browsers": ["last 2 versions", "safari >= 7", "ie 9"],
"node": "8"
}
}]
],
"plugins": [
["module-resolver", {
"root": ["./nested_admin/static/nested_admin/src"],
"alias": {
"jquery": "./nested_admin/static/nested_admin/src/nested-admin/jquery.shim.js"
}
}]
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
28 changes: 28 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
comment:
require_changes: yes
layout: "header, diff, flags, files, footer"

coverage:
status:
project: no
patch: no
changes: no
project:
default: off
javascript:
flags: javascript
python:
flags: python

ignore:
- "nested_admin/tests/**/*.*"
- "nested_admin/tests/*"

flags:
python:
paths:
- "nested_admin/*.py"
- "nested_admin/**/*.py"
javascript:
paths:
- "nested_admin/**/*.js"
31 changes: 0 additions & 31 deletions .eslintrc

This file was deleted.

53 changes: 53 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module.exports = {
'extends': [
'airbnb-base/legacy',
],
'parserOptions': {
'sourceType': 'module',
'ecmaVersion': 2017,
},
'env': {
'node': true,
'es6': true,
},
"rules": {
// The one assertion of personal preference: no spaces before parentheses
// of anonymous functions
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
// Temporarily disabled rules
//
// no-use-before-define is a good rule, but it would make the diff for
// linting the code even more inscrutible than it already is.
'no-use-before-define': 'off',
// Relax some rules
'no-cond-assign': ['error', 'except-parens'],
'no-unused-vars': ['error', {
'args': 'none',
}],
// Disable some overly-strict airbnb style rules
'no-underscore-dangle': 'off',
'no-param-reassign': 'off',
'class-methods-use-this': 'off',
'function-paren-newline': 'off',
'no-plusplus': 'off',
'object-curly-spacing': 'off',
'no-multi-assign': 'off',
'no-else-return': 'off',
// While technically useless from the point of view of the regex parser,
// escaping characters inside character classes is more consistent. I
// would say that they make the regular expression more readable, if the
// idea of readable regular expressions wasn't absurd on its face.
'no-useless-escape': 'off',
// I'm inclined to reverse this rule to be ['error', 'always'], but not just yet
// IE 8 is a thing of the past and trailing commas are useful.
'comma-dangle': 'off',
},
'globals': {
'django': false,
'grappelli': false
},
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ pip-log.txt
*swp
.tox
node_modules
.coverage.*
/.nyc_output
/coverage/
/nested_admin/tests/static
33 changes: 18 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ matrix:
include:
- { python: 2.7, env: TOXENV=py27-dj18 }
- { python: 2.7, env: TOXENV=py27-dj18-grp }
- { python: 2.7, env: TOXENV=py27-dj18-suit }
- { python: 3.4, env: TOXENV=py34-dj18 }
- { python: 2.7, env: TOXENV=py27-dj19 }
- { python: 2.7, env: TOXENV=py27-dj19-grp }
- { python: 3.4, env: TOXENV=py34-dj19 }
- { python: 2.7, env: TOXENV=py27-dj110 }
- { python: 2.7, env: TOXENV=py27-dj110-grp }
- { python: 3.4, env: TOXENV=py34-dj110 }
- { python: 2.7, env: TOXENV=py27-dj111 }
- { python: 2.7, env: TOXENV=py27-dj111-grp }
- { python: 3.6, env: TOXENV=py36-dj111 }
Expand All @@ -32,11 +27,9 @@ addons:
env:
global:
- PATH=$HOME/bin:$PATH
# - BLINKDIFF_BIN=$TRAVIS_BUILD_DIR/node_modules/.bin/blink-diff
- PIXELMATCH_BIN=$TRAVIS_BUILD_DIR/node_modules/.bin/pixelmatch

before_script:
- if [ "$DATABASE_URL" == "postgres://[email protected]/nested_admin_test" ]; then psql -c "DROP DATABASE IF EXISTS nested_admin_test;" -U postgres; fi
- if [ "$DATABASE_URL" == "postgres://[email protected]/nested_admin_test" ]; then psql -c "create database nested_admin_test;" -U postgres; fi
- mkdir -p ~/bin
- |
if [ ! -e ~/bin/chromedriver ]; then
Expand All @@ -47,15 +40,25 @@ before_script:
chmod +x ~/bin/chromedriver
fi
# before_install:
# - nvm install node
# - nvm use node
# - npm install blink-diff
before_install:
- nvm install node
- nvm use node
- travis_retry travis_retry npm install
- travis_retry travis_retry npm install codecov
- travis_retry travis_retry npm install pixelmatch
- NODE_ENV=test npm run build

install:
- pip install tox
- pip install tox coverage codecov

script:
- travis_retry travis_retry travis_retry tox -- --verbosity=3 --selenium=chrome-headless --failfast
- |
travis_retry travis_retry travis_retry tox -- \
--selenium=chrome-headless \
--failfast
- npm run report
- npm run codecov
- coverage xml
- codecov -F python

sudo: false
10 changes: 4 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ list of the options available.
Contributing
============

This project uses `gulp <http://gulpjs.com/>`_, `babel <https://babeljs.io/>`_,
`browserify <http://browserify.org/>`_, and `scss <http://sass-lang.com/>`_ for
building its javascript and css. To install the dependencies for the build
process, run ``npm install`` from the root of the repository. You can then run
``gulp`` to rebuild the static files, or ``gulp watch`` when actively editing
these files to detect changes and rebuild automatically.
This project uses `webpack <https://webpack.js.org/>`_ for building its
javascript and css. To install the dependencies for the build process, run
``npm install`` from the root of the repository. You can then run
``npm run build`` to rebuild the static files.

License
=======
Expand Down
10 changes: 4 additions & 6 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ Contributing
Editing javascript and css
--------------------------

This project uses `gulp <http://gulpjs.com/>`_, `babel <https://babeljs.io/>`_,
`browserify <http://browserify.org/>`_, and `scss <http://sass-lang.com/>`_ for
building its javascript and css. To install the dependencies for the build
process, run ``npm install`` from the root of the repository. You can then run
``gulp`` to rebuild the static files, or ``gulp watch`` when actively editing
these files to detect changes and rebuild automatically.
This project uses `webpack <https://webpack.js.org/>`_ for building its
javascript and css. To install the dependencies for the build process, run
``npm install`` from the root of the repository. You can then run
``npm run build`` to rebuild the static files.

Running tests
-------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from 'jquery';
import './nested-admin/jquery.djangoformset';
import DJNesting from './nested-admin/utils';
const $ = require('jquery');
const DJNesting = require('./utils');
DJNesting.DjangoFormset = require('./jquery.djangoformset');

$(document).ready(function() {
// Remove the border on any empty fieldsets
Expand Down Expand Up @@ -35,3 +35,5 @@ $(document).ready(function() {
});
});
});

module.exports = DJNesting;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

import $ from 'jquery';
import regexQuote from './regexquote';
import DJNesting from './utils';
import grappelli from 'grappelli';
const $ = require('jquery');
const regexQuote = require('./regexquote');
const DJNesting = require('./utils');
const grappelli = require('grappelli');

var pluginName = 'djangoFormset';

Expand Down Expand Up @@ -488,4 +488,4 @@ $.fn[pluginName] = function() {
}
};

export default DjangoFormset;
module.exports = DjangoFormset;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import $ from 'jquery';
const $ = require('jquery');

var prefixCache = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = window.django.jQuery;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import $ from 'jquery';
const $ = require('jquery');
/*!
* jQuery UI Sortable @VERSION
* http://jqueryui.com
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import $ from 'jquery';
import './jquery.ui.djnsortable';
const $ = require('jquery');
require('./jquery.ui.djnsortable');

/*
* jQuery UI Nested Sortable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function regexQuote(str) {
module.exports = function regexQuote(str) {
return (str+'').replace(/([\.\?\*\+\^\$\[\]\\\(\)\{\}\|\-])/g, '\\$1');
};
12 changes: 7 additions & 5 deletions nested_admin/static/nested_admin/src/nested-admin/sortable.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

import $ from 'jquery';
import regexQuote from './regexquote';
import './jquery.ui.nestedsortable';
const $ = require('jquery');
const regexQuote = require('./regexquote');
require('./jquery.ui.nestedsortable');

export function updatePositions(prefix) {
function updatePositions(prefix) {
var position = 0, // the value of the position formfield
count = 1, // The count displayed in stacked inline headers
$group = $('#' + prefix + '-group'),
Expand Down Expand Up @@ -87,7 +87,7 @@ export function updatePositions(prefix) {
});
}

export function createSortable($group) {
function createSortable($group) {
return $group.find('> .djn-items, > .djn-fieldset > .djn-items, > .tabular > .module > .djn-items').nestedSortable({
handle: [
'> h3.djn-drag-handler',
Expand Down Expand Up @@ -217,3 +217,5 @@ export function createSortable($group) {
}
});
}

module.exports = {updatePositions, createSortable};
16 changes: 7 additions & 9 deletions nested_admin/static/nested_admin/src/nested-admin/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

import $ from 'jquery';
import './jquery.djnutils.js';
import {createSortable, updatePositions} from './sortable';
import regexQuote from './regexquote';
import DateTimeShortcuts from 'django/date-time-shortcuts';
import SelectFilter from 'django/select-filter';
const $ = require('jquery');
require('./jquery.djnutils.js');
const {createSortable, updatePositions} = require('./sortable');
const regexQuote = require('./regexquote');
const DateTimeShortcuts = require('django/date-time-shortcuts');
const SelectFilter = require('django/select-filter');

var DJNesting = (typeof window.DJNesting != 'undefined')
? window.DJNesting : {};
Expand Down Expand Up @@ -209,6 +209,4 @@ DJNesting.DjangoInlines = {
}
};

window.DJNesting = DJNesting;

export default DJNesting;
module.exports = DJNesting;
7 changes: 2 additions & 5 deletions nested_admin/static/nested_admin/src/nested_admin.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import "compass";

@mixin cursor($val) {
cursor: $val;
cursor: -moz-$val;
Expand All @@ -25,7 +23,7 @@
}
.djn-group-nested .djn-items .inline-related {
border: 1px solid transparent;
@include border-radius(4px);
border-radius: 4px;

#grp-content & {
margin-bottom: 5px;
Expand Down Expand Up @@ -228,7 +226,7 @@ table.djn-table.grp-table th p > input[type="button"] {
margin: 5px;
cursor: move;
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAyCAYAAABcfPsmAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAE5JREFUeNrs0zEKACAMBEEDST6X9+Z92lpYHNgI7naBK9KMdfcch6rK9lvdeWYOJXXnESEN1d2HH9J9hhSkEFKQQkhBClKQghSkPNYSYADFZiuygfao+AAAAABJRU5ErkJggg==") no-repeat top left;
@include background-size(10px 25px);
background-size: 10px 25px;
@include cursor(grab);
}

Expand Down Expand Up @@ -259,4 +257,3 @@ table.djn-table.grp-table th p > input[type="button"] {
display: block;
}
}

Loading

0 comments on commit e881995

Please sign in to comment.