Skip to content

Commit 9babe8a

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # setup.py
2 parents a7f69f5 + 59a61d8 commit 9babe8a

File tree

15 files changed

+167
-49
lines changed

15 files changed

+167
-49
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ python:
33
- 2.7
44
- 3.4
55
before_install:
6-
- nvm install 4.0
7-
- npm install -g node-sass postcss-cli autoprefixer
8-
- npm install -g browserify babelify babel-preset-es2015
6+
- nvm install 6.0
7+
- npm install
98
install:
109
- pip install -e .[test]
1110
script:
12-
- py.test
11+
- py.test tests/unit_tests tests/integration_tests

README.md

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ $title-size: 30px;
7171

7272
You need `node-sass`, `postcss-cli` and `autoprefixer` to be installed. Quick install:
7373

74+
```sh
75+
npm install node-sass postcss-cli autoprefixer
76+
```
77+
78+
Or you can install them globally (you need to set `COMPRESS_LOCAL_NPM_INSTALL = False`):
79+
7480
```sh
7581
npm install -g node-sass postcss-cli autoprefixer
7682
```
@@ -136,55 +142,89 @@ export default class {
136142

137143
You need `browserify`, `babelify` and `babel-preset-es2015` to be installed. Quick install:
138144

145+
```sh
146+
npm install browserify babelify babel-preset-es2015
147+
```
148+
149+
Or you can install them globally (you need to set `COMPRESS_LOCAL_NPM_INSTALL = False`):
150+
139151
```sh
140152
npm install -g browserify babelify babel-preset-es2015
141153
```
142154

143155
## Django settings
144156

157+
### `COMPRESS_LOCAL_NPM_INSTALL`
158+
159+
Whether you install required NPM packages _locally_.
160+
161+
Default: `True`.
162+
145163
### `COMPRESS_NODE_MODULES`
146164

147-
Path to `node_modules` where `browserify`, `babelify`, `autoprefixer`, etc, are installed.
165+
Path to `node_modules` where `babelify`, `autoprefixer`, etc, libs are installed.
166+
167+
Default: `./node_modules` if `COMPRESS_LOCAL_NPM_INSTALL` else `/usr/lib/node_modules`.
168+
169+
### `COMPRESS_NODE_SASS_BIN`
170+
171+
`node-sass` executable. It may be just the executable name (if it's on `PATH`) or the executable path.
172+
173+
Default: `./node_modules/.bin/node-sass` if `COMPRESS_LOCAL_NPM_INSTALL` else `node-sass`.
148174

149-
Default: `/usr/lib/node_modules`
175+
### `COMPRESS_POSTCSS_BIN`
176+
177+
`postcss` executable. It may be just the executable name (if it's on `PATH`) or the executable path.
178+
179+
Default: `./node_modules/.bin/postcss` if `COMPRESS_LOCAL_NPM_INSTALL` else `postcss`.
180+
181+
### `COMPRESS_AUTOPREFIXER_BROWSERS`
182+
183+
Browser versions config for Autoprefixer.
184+
185+
Default: `ie >= 9, > 5%`.
150186

151187
### `COMPRESS_SCSS_COMPILER_CMD`
152188

153189
Command that will be executed to transform SCSS into CSS code.
154190

155191
Default:
156192

157-
```sh
158-
node-sass --output-style expanded {paths} "{infile}" "{outfile}" &&
159-
postcss --use "{node_modules}/autoprefixer" --autoprefixer.browsers "{autoprefixer_browsers}" -r "{outfile}"
193+
```py
194+
'{node_sass_bin} --output-style expanded {paths} "{infile}" "{outfile}" && '
195+
'{postcss_bin} --use "{node_modules}/autoprefixer" --autoprefixer.browsers "{autoprefixer_browsers}" -r "{outfile}"'
160196
```
161197

162-
Placeholders:
198+
Placeholders (i.e. they **can be re-used** in custom `COMPRESS_SCSS_COMPILER_CMD` string):
199+
- `{node_sass_bin}` - value from `COMPRESS_NODE_SASS_BIN`
200+
- `{postcss_bin}` - value from `COMPRESS_POSTCSS_BIN`
163201
- `{infile}` - input file path
164202
- `{outfile}` - output file path
165203
- `{paths}` - specially for `node-sass`, include all Django app static folders:
166204
`--include-path=/path/to/app-1/static/ --include-path=/path/to/app-2/static/ ...`
167205
- `{node_modules}` - see `COMPRESS_NODE_MODULES` setting
168-
- `{autoprefixer_browsers}` - see `COMPRESS_AUTOPREFIXER_BROWSERS` setting
206+
- `{autoprefixer_browsers}` - value from `COMPRESS_AUTOPREFIXER_BROWSERS`
169207

170-
### `COMPRESS_AUTOPREFIXER_BROWSERS`
208+
### `COMPRESS_BROWSERIFY_BIN`
171209

172-
Browser versions config for Autoprefixer.
210+
`browserify` executable. It may be just the executable name (if it's on `PATH`) or the executable path.
173211

174-
Default: `ie >= 9, > 5%`
212+
Default: `./node_modules/.bin/browserify` if `COMPRESS_LOCAL_NPM_INSTALL` else `browserify`.
175213

176214
### `COMPRESS_ES6_COMPILER_CMD`
177215

178216
Command that will be executed to transform ES6 into ES5 code.
179217

180218
Default:
181219

182-
```sh
183-
export NODE_PATH="{paths}" && browserify "{infile}" -o "{outfile}" --no-bundle-external --node
184-
-t [ "{node_modules}/babelify" --presets="{node_modules}/babel-preset-es2015" ]
220+
```py
221+
'export NODE_PATH="{paths}" && '
222+
'{browserify_bin} "{infile}" -o "{outfile}" --no-bundle-external --node '
223+
'-t [ "{node_modules}/babelify" --presets="{node_modules}/babel-preset-es2015" ]'
185224
```
186225

187226
Placeholders:
227+
- `{browserify_bin}` - value from `COMPRESS_BROWSERIFY_BIN`
188228
- `{infile}` - input file path
189229
- `{outfile}` - output file path
190230
- `{paths}` - specially for `browserify`, include all Django app static folders:
@@ -197,5 +237,6 @@ Placeholders:
197237
git clone https://github.com/kottenator/django-compressor-toolkit.git
198238
cd django-compressor-toolkit
199239
pip install -e '.[test]'
240+
npm install
200241
py.test
201242
```

compressor_toolkit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# PEP 440 - version number format
2-
VERSION = (0, 5, 1, 'dev0')
2+
VERSION = (0, 6, 0, 'dev0')
33

44
# PEP 396 - module version variable
55
__version__ = '.'.join(map(str, VERSION))

compressor_toolkit/apps.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,55 @@
1+
import os
2+
13
from django.apps.config import AppConfig
24
from django.conf import settings
35

46

57
class CompressorToolkitConfig(AppConfig):
68
name = 'compressor_toolkit'
79

10+
LOCAL_NPM_INSTALL = getattr(settings, 'COMPRESS_LOCAL_NPM_INSTALL', True)
11+
812
# Path to 'node_modules' where browserify, babelify, autoprefixer, etc, are installed
9-
NODE_MODULES = getattr(settings, 'COMPRESS_NODE_MODULES', None) or '/usr/lib/node_modules'
13+
NODE_MODULES = getattr(
14+
settings,
15+
'COMPRESS_NODE_MODULES',
16+
os.path.abspath('node_modules') if LOCAL_NPM_INSTALL else '/usr/lib/node_modules'
17+
)
1018

11-
# Custom SCSS transpiler command
12-
SCSS_COMPILER_CMD = getattr(settings, 'COMPRESS_SCSS_COMPILER_CMD', None) or (
13-
'node-sass --output-style expanded {paths} "{infile}" "{outfile}" && '
14-
'postcss --use "{node_modules}/autoprefixer" '
15-
'--autoprefixer.browsers "{autoprefixer_browsers}" -r "{outfile}"'
19+
# node-sass executable
20+
NODE_SASS_BIN = getattr(
21+
settings,
22+
'COMPRESS_NODE_SASS_BIN',
23+
'node_modules/.bin/node-sass' if LOCAL_NPM_INSTALL else 'node-sass'
24+
)
25+
26+
# postcss executable
27+
POSTCSS_BIN = getattr(
28+
settings,
29+
'COMPRESS_POSTCSS_BIN',
30+
'node_modules/.bin/node-sass' if LOCAL_NPM_INSTALL else 'postcss'
1631
)
1732

1833
# Browser versions config for Autoprefixer
19-
AUTOPREFIXER_BROWSERS = getattr(settings, 'COMPRESS_AUTOPREFIXER_BROWSERS', None) or (
20-
'ie >= 9, > 5%'
34+
AUTOPREFIXER_BROWSERS = getattr(settings, 'COMPRESS_AUTOPREFIXER_BROWSERS', 'ie >= 9, > 5%')
35+
36+
# Custom SCSS transpiler command
37+
SCSS_COMPILER_CMD = getattr(settings, 'COMPRESS_SCSS_COMPILER_CMD', (
38+
'{node_sass_bin} --output-style expanded {paths} "{infile}" > "{outfile}" && '
39+
'{postcss_bin} --use "{node_modules}/autoprefixer" '
40+
'--autoprefixer.browsers "{autoprefixer_browsers}" -r "{outfile}"'
41+
))
42+
43+
# browserify executable
44+
BROWSERIFY_BIN = getattr(
45+
settings,
46+
'COMPRESS_BROWSERIFY_BIN',
47+
'node_modules/.bin/browserify' if LOCAL_NPM_INSTALL else 'browserify'
2148
)
2249

2350
# Custom ES6 transpiler command
24-
ES6_COMPILER_CMD = getattr(settings, 'COMPRESS_ES6_COMPILER_CMD', None) or (
51+
ES6_COMPILER_CMD = getattr(settings, 'COMPRESS_ES6_COMPILER_CMD', (
2552
'export NODE_PATH="{paths}" && '
26-
'browserify "{infile}" -o "{outfile}" --no-bundle-external --node '
53+
'{browserify_bin} "{infile}" -o "{outfile}" '
2754
'-t [ "{node_modules}/babelify" --presets="{node_modules}/babel-preset-es2015" ]'
28-
)
55+
))

compressor_toolkit/precompilers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class SCSSCompiler(BaseCompiler):
7777
"""
7878
command = app_config.SCSS_COMPILER_CMD
7979
options = (
80+
('node_sass_bin', app_config.NODE_SASS_BIN),
81+
('postcss_bin', app_config.POSTCSS_BIN),
8082
('paths', ' '.join(['--include-path {}'.format(s) for s in get_all_static()])),
8183
('node_modules', app_config.NODE_MODULES),
8284
('autoprefixer_browsers', app_config.AUTOPREFIXER_BROWSERS),
@@ -103,6 +105,7 @@ class ES6Compiler(BaseCompiler):
103105
"""
104106
command = app_config.ES6_COMPILER_CMD
105107
options = (
108+
('browserify_bin', app_config.BROWSERIFY_BIN),
106109
('paths', os.pathsep.join(get_all_static())),
107110
('node_modules', app_config.NODE_MODULES)
108111
)

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"private": true,
3+
"devDependencies": {
4+
"node-sass": "~3.10",
5+
"postcss-cli": "~2.6",
6+
"autoprefixer": "~6.5",
7+
"browserify": "~13.1",
8+
"babelify": "~7.3",
9+
"babel-preset-es2015": "~6.16"
10+
}
11+
}

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
[pytest]
1+
[tool:pytest]
22
python_paths = tests/test_project
33
testpaths = tests/unit_tests tests/integration_tests
44
addopts =
55
--ds test_project.settings
66
--cov compressor_toolkit
7-
--cov-report term
7+
--cov-report term-missing
88
--cov-report html
99
--cov-report xml

setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
license='MIT',
1919
packages=find_packages(exclude=['tests', 'tests.*']),
2020
include_package_data=True,
21-
setup_requires=[
22-
'setuptools-git'
23-
],
2421
install_requires=[
25-
'django-compressor~=1.5'
22+
'django-compressor>=1.5'
2623
],
2724
extras_require={
2825
'test': [
29-
'django>=1.8',
26+
'django~=1.8',
3027
'pytest~=3.0',
3128
'pytest-django~=3.0',
3229
'pytest-cov~=2.4',

tests/__init__.py

Whitespace-only changes.

tests/integration_tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)