Skip to content

Commit adce41f

Browse files
committed
♻️ REFACTOR: re-worked
1 parent 7c03f90 commit adce41f

File tree

19 files changed

+689
-82
lines changed

19 files changed

+689
-82
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
ignore=E203,W503

.github/workflows/tests.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: continuous-integration
2+
3+
on:
4+
push:
5+
branches: [master]
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
10+
jobs:
11+
12+
pre-commit:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python 3.8
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.8
22+
- uses: pre-commit/[email protected]
23+
24+
tests:
25+
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
python-version: [3.6, 3.7, 3.8]
30+
31+
steps:
32+
- uses: actions/checkout@v2
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v2
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
38+
- name: Install Python dependencies
39+
run: |
40+
python -m pip install --upgrade pip
41+
pip install wheel
42+
pip install .[testing]
43+
44+
- name: Run pytest
45+
run: pytest
46+
47+
publish:
48+
49+
name: Publish to PyPi
50+
needs: [pre-commit, tests]
51+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Checkout source
55+
uses: actions/checkout@v2
56+
- name: Set up Python 3.7
57+
uses: actions/setup-python@v1
58+
with:
59+
python-version: 3.7
60+
- name: Build package
61+
run: |
62+
pip install wheel
63+
python setup.py sdist bdist_wheel
64+
- name: Publish
65+
uses: pypa/[email protected]
66+
with:
67+
user: __token__
68+
password: ${{ secrets.PYPI_KEY }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
.vscode/
131+
.vscode/

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
9+
- repo: https://github.com/psf/black
10+
rev: 20.8b1
11+
hooks:
12+
- id: black
13+
14+
- repo: https://github.com/mgedmin/check-manifest
15+
rev: "0.39"
16+
hooks:
17+
- id: check-manifest
18+
19+
- repo: https://gitlab.com/pycqa/flake8
20+
rev: 3.7.9
21+
hooks:
22+
- id: flake8

.pre-commit-hooks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
- id: compile-sass
1+
- id: scss-compile
22
name: Compile SCSS
33
description: This hook compiles SCSS to CSS.
4-
entry: compile-scss
4+
entry: scss-compile
55
language: python
66
types: [scss]

.scss-compile.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

MANIFEST.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
exclude tests
2+
recursive-exclude tests *
3+
exclude .github
4+
recursive-exclude .github *
5+
6+
exclude .pre-commit-config.yaml
7+
exclude .readthedocs.yml
8+
exclude .flake8
9+
exclude tox.ini
10+
exclude scss-compile-config.yml
11+
12+
include LICENSE
13+
include README.md
14+
include .pre-commit-hooks.yaml

README.md

Lines changed: 209 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,211 @@
1-
# pre-commit-scss [IN-DEVELOPMENT]
1+
# scss-compile [IN-DEVELOPMENT]
22

3-
A pre-commit hook for compiling SCSS files to CSS.
3+
A CLI for compiling SCSS files to CSS, and associated pre-commit hook.
44

5-
It utilises [libsass-python](https://github.com/sass/libsass-python), with code also adapted from [boussole](https://github.com/sveetch/boussole).
5+
This CLI is a small wrapper around [libsass-python](https://github.com/sass/libsass-python),
6+
which also aims to be compatible with [pre-commit](https://pre-commit.com/),
7+
and provide a pre-commit hook.
8+
9+
## Installation
10+
11+
To use directly as CLI:
12+
13+
```console
14+
pip install scss-compile
15+
scss-compile --help
16+
```
17+
18+
To use *via* pre-commit:
19+
20+
Add to your `.pre-commit-config.yaml`
21+
22+
```yaml
23+
- repo: https://github.com/executablebooks/scss-compile
24+
rev: v0.1.0
25+
hooks:
26+
- id: scss-compile
27+
args: [--config=config.yml] # optional
28+
```
29+
30+
## Configuration
31+
32+
You can can configure the compilation directly *via* the CLI or using a configuration file
33+
(simply replace `-` with `_`):
34+
35+
```console
36+
$ scss-compile --help
37+
Usage: scss-compile [OPTIONS] [PATHS]...
38+
39+
Compile all SCSS files in the paths provided.
40+
41+
For directories; include all non-partial SCSS files, and for files; if
42+
partial, include all adjacent, non-partial, SCSS files.
43+
44+
Options:
45+
--recurse / --no-recurse For directories, include files in sub-
46+
folders. [default: True]
47+
48+
-d, --partial-depth INTEGER For partial files (starting '_') include all
49+
SCSS files up 'n' parent folders [default:
50+
0]
51+
52+
-s, --stop-on-error Stop on the first compilation error.
53+
-e, --encoding TEXT [default: utf8]
54+
-f, --output-format [nested|expanded|compact|compressed]
55+
[default: compressed]
56+
-m, --sourcemap Output source map.
57+
-h, --hash-filenames Add the content hash to filenames:
58+
<filename>#<hash>.css (old hashes will be
59+
removed).
60+
61+
-t, --translate TEXT Source to output path translations, e.g.
62+
'src/scss:dist/css' (can be used multiple
63+
times)
64+
65+
-p, --precision INTEGER precision for numbers. [default: 5]
66+
-q, --quiet Remove stdout logging.
67+
-v, --verbose Increase stdout logging.
68+
--test-run Do not delete/create any files.
69+
--config FILE Read default configuration from a file
70+
(allowed extensions: .json, .toml, .yml,
71+
.yaml.)
72+
73+
--help Show this message and exit.
74+
```
75+
76+
`--config` can point to any of three file-formats:
77+
78+
`config.json`:
79+
80+
```json
81+
{
82+
"scss-compile": {
83+
"precision": 5,
84+
"sourcemap": true,
85+
"hash_filenames": true,
86+
"output_format": "compressed",
87+
"partial_depth": 1,
88+
"translate": ["tests/example_sass:tests/output_css"]
89+
}
90+
}
91+
```
92+
93+
`config.toml`:
94+
95+
```toml
96+
[scss-compile]
97+
precision = 5
98+
sourcemap = true
99+
hash_filenames = true
100+
output_format = "compressed"
101+
partial_depth = 1
102+
translate = ["tests/example_sass:tests/output_css"]
103+
```
104+
105+
`config.yml`/`config.yaml`:
106+
107+
```yaml
108+
scss-compile:
109+
precision: 5
110+
sourcemap: true
111+
hash_filenames: true
112+
output_format: compressed
113+
partial_depth: 1
114+
translate: [tests/example_sass:tests/output_css]
115+
```
116+
117+
## Usage
118+
119+
If you simply specify a normal SCSS file, then the CSS file will be output in the same folder:
120+
121+
```console
122+
$ scss-compile scss/file.scss
123+
```
124+
125+
```
126+
scss/
127+
file.scss
128+
file.css
129+
```
130+
131+
If you use the `sourcemap` option, then a sourcemap will also be output,
132+
and a `sourceMappingURL` comment added to the CSS:
133+
134+
```console
135+
$ scss-compile scss/file.scss --sourcemap
136+
```
137+
138+
```
139+
scss/
140+
file.scss
141+
file.css
142+
file.scss.map.json
143+
```
144+
145+
If you use the `hash_filenames` option, then the CSS filename will include the content hash (and any existing file with a different hash will be removed):
146+
147+
```console
148+
$ scss-compile scss/file.scss -- hash-filenames
149+
```
150+
151+
```
152+
scss/
153+
file.scss
154+
file#beabd761a3703567b4ce06c9a6adde55.css
155+
```
156+
157+
If you specify a partial file, i.e. ones beginning `_` used *via* `@import` and `@use`,
158+
then all "normal" SCSS files in that folder will be compiled.
159+
If you also use the `partial-depth` option, then files in parent folders will also be compiled.
160+
161+
```console
162+
$ scss-compile scss/imports/_partial.scss -- partial-depth=1
163+
```
164+
165+
```
166+
scss
167+
/imports
168+
_partial.scss
169+
file.scss
170+
file.css
171+
```
172+
173+
If you set the `--translate` option, then the output files will be "translated" to the specified output path
174+
(which will be created if it does not yet exist):
175+
176+
```console
177+
$ scss-compile scss/file.scss --translate "src/scss:dist/css" --sourcemap
178+
```
179+
180+
```
181+
src/scss/
182+
file.scss
183+
dist/css/
184+
file.css
185+
file.scss.map.json
186+
```
187+
188+
If you specify a directory, then it will first find all SCSS files in that directory,
189+
and recursive sub-folders (unless `--no-recurse` is used), then treat each individual file as above.
190+
191+
## Development
192+
193+
To run the tests:
194+
195+
```console
196+
pip install tox
197+
tox
198+
```
199+
200+
To test out the CLI:
201+
202+
```console
203+
tox -e py37-cli -- --help
204+
```
205+
206+
For code style:
207+
208+
```console
209+
pip install pre-commit
210+
pre-commit run --all
211+
```

0 commit comments

Comments
 (0)