1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | const path = require('path-posix');
|
25 | const CachingWriter = require('broccoli-caching-writer');
|
26 | const {
|
27 | readFile, svgDataFor, toPosixPath, saveToFile, relativePathFor
|
28 | } = require('./utils');
|
29 |
|
30 | class InlinePacker extends CachingWriter {
|
31 | constructor(inputNode, opts) {
|
32 | super([inputNode], { name: 'InlinePacker' });
|
33 | this.options = opts;
|
34 | }
|
35 |
|
36 | build() {
|
37 | let inputPath = toPosixPath(this.inputPaths[0]);
|
38 | let outputPath = path.join(toPosixPath(this.outputPath), 'inlined');
|
39 | let { makeAssetID } = this.options;
|
40 |
|
41 | this.listFiles()
|
42 | .forEach((_filePath) => {
|
43 | let filePath = toPosixPath(_filePath);
|
44 | let relativePath = relativePathFor(filePath, inputPath);
|
45 | let modulePath = path.join(outputPath, `${makeAssetID(relativePath)}.js`);
|
46 | let svgData = svgDataFor(readFile(filePath));
|
47 |
|
48 | saveToFile(modulePath, `export default ${JSON.stringify(svgData)}`);
|
49 | });
|
50 | }
|
51 | }
|
52 |
|
53 | module.exports = InlinePacker;
|