|
15 | 15 | <!-- /BADGES -->
|
16 | 16 |
|
17 | 17 |
|
18 |
| -A module that takes any number of css feed streams (provided by asset-pipe sinks) and bundles them into a readable stream of css content. |
| 18 | +[](https://greenkeeper.io/) |
| 19 | + |
| 20 | +A module that takes any number of css feeds and bundles them into a css bundle. |
19 | 21 |
|
20 | 22 | This is an internal module intended for use by other modules in the [asset-pipe project](https://github.com/asset-pipe).
|
21 | 23 |
|
22 | 24 | ## Overview
|
23 | 25 |
|
24 |
| -[](https://greenkeeper.io/) |
25 |
| - |
26 |
| -Given any number of css feed streams, the reader will: |
27 |
| -1. Merge streams into a single stream |
| 26 | +Given any number of css feeds, the reader will: |
| 27 | +1. Merge feeds into a single feed |
28 | 28 | 2. Dedupe any items with identical id hashes keeping the last occurrence
|
29 |
| -3. Ensure order of streams given is preserved for the final output CSS |
| 29 | +3. Ensure order of feeds given is preserved for the final output CSS |
30 | 30 |
|
31 | 31 | ### Input data format
|
32 | 32 |
|
@@ -57,128 +57,35 @@ npm install asset-pipe-css-reader
|
57 | 57 |
|
58 | 58 | ### Require the reader
|
59 | 59 | ```js
|
60 |
| -const CssReader = require('asset-pipe-css-reader') |
| 60 | +const cssReader = require('asset-pipe-css-reader') |
61 | 61 | ```
|
62 | 62 |
|
63 | 63 | ### Instantiating the reader
|
64 | 64 |
|
65 |
| -Either pass a single stream created by an asset-pipe sink: |
66 |
| -```js |
67 |
| -const sink = new SinkFs({ |
68 |
| - path: '/path/to/css/feeds' |
69 |
| -}); |
70 |
| -const feedStream = sink.reader('feed-a.json'); |
71 |
| -const reader = new CssReader(feedStream) |
72 |
| -``` |
73 |
| - |
74 |
| -Or pass an array of streams: |
| 65 | +Pass feeds created by an asset-pipe sink: |
75 | 66 | ```js
|
76 | 67 | const sink = new SinkFs({
|
77 | 68 | path: '/path/to/css/feeds'
|
78 | 69 | });
|
79 |
| -const feedStream1 = sink.reader('feed-a.json'); |
80 |
| -const feedStream2 = sink.reader('feed-b.json'); |
81 |
| -const reader = new CssReader([feedStream1, feedStream2]) |
82 |
| -``` |
83 |
| - |
84 |
| -### Consuming content from the reader |
85 |
| - |
86 |
| -You should wait for the reader to become ready by listening for the `pipeline ready` event. |
87 |
| - |
88 |
| -The reader is a readable stream so in order to access the data you may register a data handler |
89 |
| -and listen for chunks to be passed to the handler: |
90 |
| -```js |
91 |
| -reader.on('pipeline ready', () => { |
92 |
| - reader.on('data', data => { |
93 |
| - // .. |
94 |
| - }) |
95 |
| -}) |
96 |
| -``` |
97 |
| - |
98 |
| -You might also pipe the reader into a writeable or transform stream: |
99 |
| -```js |
100 |
| -const { writeFile } = require('fs') |
101 |
| -const consumer = writeFile('/path/to/save/file') |
102 |
| - |
103 |
| -reader.on('pipeline ready', () => { |
104 |
| - reader.pipe(consumer) |
105 |
| -}) |
| 70 | +const feed1 = JSON.parse(await sink.get('feed-a.json')); |
| 71 | +const feed2 = JSON.parse(await sink.get('feed-b.json')); |
| 72 | +const bundle = await cssReader([feed1, feed2]) |
106 | 73 | ```
|
107 | 74 |
|
108 | 75 | ## API
|
109 | 76 |
|
110 |
| -### Methods |
111 |
| - |
112 |
| -#### constructor |
113 |
| - |
114 |
| -Constructor takes a single stream or array of streams. Streams should be produced with an asset-pipe sink such as: |
| 77 | +Reader takes an array of feeds. Feeds should be produced with an asset-pipe sink such as: |
115 | 78 | - [asset-pipe-sink-s3](https://github.com/asset-pipe/asset-pipe-sink-s3`)
|
116 | 79 | - [asset-pipe-sink-fs](https://github.com/asset-pipe/asset-pipe-sink-fs`)
|
117 | 80 | - [asset-pipe-sink-gcs](https://github.com/asset-pipe/asset-pipe-sink-gcs`)
|
118 | 81 | - [asset-pipe-sink-mem](https://github.com/asset-pipe/asset-pipe-sink-mem`)
|
119 | 82 |
|
120 |
| -Examples |
121 |
| -```js |
122 |
| -new CssReader(stream) |
123 |
| -``` |
124 |
| -```js |
125 |
| -new CssReader([stream, ...stream]) |
126 |
| -``` |
127 |
| - |
128 |
| -Returns: `Readable Stream` |
129 |
| - |
130 |
| -### Events |
131 |
| - |
132 |
| -#### file found |
133 |
| - |
134 |
| -Event produced whenever an underlying feed stream successfully reads its feed |
135 |
| -file from disk |
136 |
| - |
137 |
| -```js |
138 |
| -cssReader.on('file found', file => {}) |
139 |
| -``` |
140 |
| - |
141 |
| -Param: `file`, name of the file given to the feed stream to read from |
142 |
| - |
143 |
| -#### file not found |
144 |
| - |
145 |
| -Event produced whenever an underlying feed stream is unable to read its feed |
146 |
| -file from disk |
147 |
| - |
148 |
| -```js |
149 |
| -cssReader.on('file not found', file => {}) |
150 |
| -``` |
151 |
| - |
152 |
| -Param: `file`, name of the file given to the feed stream to read from |
153 |
| - |
154 |
| -#### pipeline ready |
155 |
| - |
156 |
| -Event produced once all feed file streams have been successfully merged into |
157 |
| -a pipeline |
158 |
| - |
159 |
| -```js |
160 |
| -cssReader.on('pipeline ready', () => {}) |
161 |
| -``` |
162 |
| - |
163 |
| -#### data |
164 |
| - |
165 |
| -Event that emits chunks of CSS content to a consumer |
166 |
| - |
167 |
| -```js |
168 |
| -cssReader.on('data', chunk => {}) |
169 |
| -``` |
170 |
| - |
171 |
| -Param: `chunk`, a piece of CSS text |
172 |
| - |
173 |
| -#### error |
174 |
| - |
175 |
| -Event produced whenever any of the various stages of the pipeline emit errors |
176 |
| - |
| 83 | +Example |
177 | 84 | ```js
|
178 |
| -cssReader.on('error', err => {}) |
| 85 | +cssReader([feed, ...feeds]) |
179 | 86 | ```
|
180 | 87 |
|
181 |
| -Param: `err`, Error forwarded from merged streams or otherwise emitted from the pipeline |
| 88 | +Returns: `string` |
182 | 89 |
|
183 | 90 | ## Contributing
|
184 | 91 |
|
|
0 commit comments