Skip to content

Commit f56950b

Browse files
author
Davide Perozzi
committed
chore(quality): added unit test + readme
1 parent 6c5263a commit f56950b

File tree

12 files changed

+3395
-51
lines changed

12 files changed

+3395
-51
lines changed

.circleci/config.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: 2.1
2+
3+
general:
4+
branches:
5+
only:
6+
- master
7+
- develop
8+
- /feature/.*/
9+
10+
references:
11+
defaults: &defaults
12+
working_directory: ~
13+
docker:
14+
- image: circleci/node:11.10.1-browsers
15+
update_npm: &update_npm
16+
run:
17+
name: "Update npm"
18+
command: 'sudo npm install -g npm@latest'
19+
install_node_modules: &install_node_modules
20+
run:
21+
name: "Install node modules"
22+
command: 'npm install'
23+
build: &build
24+
run:
25+
name: "Build module"
26+
command: "npm run build"
27+
test: &test
28+
run:
29+
name: "Test module"
30+
command: "npm run test"
31+
32+
jobs:
33+
build_test:
34+
<<: *defaults
35+
steps:
36+
- checkout
37+
- *update_npm
38+
- *install_node_modules
39+
- *build
40+
- *test
41+
42+
workflows:
43+
build_test:
44+
jobs:
45+
- build_test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
dist
33
.DS_Store
4+
.cache

README.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
11
# gulp-map-transform
22

3-
Easily transform virtual paths in any file to real paths
3+
[![Version](https://flat.badgen.net/npm/v/gulp-map-transform/scroller)](https://www.npmjs.com/package/gulp-map-transform)
4+
[![CircleCI](https://flat.badgen.net/circleci/github/davideperozzi/gulp-map-transform/master)](https://circleci.com/gh/davideperozzi/gulp-map-transform/tree/master)
5+
[![License](https://flat.badgen.net/badge/license/MIT/blue)](./LICENSE)
6+
7+
Easily transform virtual paths inside any file to real paths
8+
9+
## Install
10+
11+
Install via npm:
12+
```sh
13+
npm install --save-dev gulp-map-transform
14+
```
15+
16+
## Usage
17+
18+
### Transforming scss paths to compiled css paths
19+
20+
Given this section of a html file:
21+
22+
```html
23+
...
24+
<head>
25+
<link rel="stylesheet" href="@styles/test.css" />
26+
</head>
27+
...
28+
```
29+
30+
And this configuration inside your gulpfile
31+
32+
```js
33+
const { src, dest } = require('gulp');
34+
const sass = require('gulp-sass');
35+
const mapTransform = require('gulp-map-transform');
36+
37+
const OUT_PATH = '/dist/folder';
38+
39+
src('/html/files/**/*.html')
40+
.pipe(
41+
mapTransform({
42+
search: /href="@styles\/(.*?).scss"/gi,
43+
replace: /"(.*?)"/i,
44+
rootPath: OUT_PATH,
45+
rewrite: (path) => path.replace('@styles', 'css/files'),
46+
transform: (stream) => stream
47+
.pipe(sass())
48+
.pipe(dest(path.join(OUT_PATH, 'css')))
49+
})
50+
)
51+
.pipe(dest(OUT_PATH))
52+
```
53+
54+
This will generate the following html file after compiling the css file:
55+
```html
56+
...
57+
<head>
58+
<link rel="stylesheet" href="/css/files/test.css" />
59+
</head>
60+
...
61+
```
62+
63+
## Options
64+
| Name | Type | Required | Description
65+
| -- | -- | -- | --
66+
| search | `RegExp` | yes | This expression is used to identify in which location you want to execute a transformation of the content
67+
| replace | `RegExp` | yes | This is used to replace the path of the file inside a result of the search matches
68+
| rewrite | Function | yes | Use this to tell what and how to replace the path inside the string found by the replace expression
69+
| transform | Function | yes | In this callback you get a separate stream to handle all your files already present with the real path
70+
| rootPath | string | no | The root path to which the transfomed file paths will be appended (with `path.relative()`)
71+
72+
## License
73+
See the [LICENSE](./LICENSE) file for license rights and limitations (MIT).

jest.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"transform": {
3+
"^.+\\.tsx?$": "ts-jest"
4+
}
5+
}

0 commit comments

Comments
 (0)