1 | import stylusSprites from '../lib/gulp-stylus-sprites';
|
2 | import { File } from 'gulp-util';
|
3 | import { PassThrough } from 'stream';
|
4 | import { join, extname, resolve } from 'path';
|
5 | import fs from 'fs';
|
6 |
|
7 | const createFile = (path) => {
|
8 | const _path = join(__dirname, './fixtures', path);
|
9 | return new File({
|
10 | path: _path,
|
11 | contents: fs.readFileSync(_path),
|
12 | });
|
13 | };
|
14 |
|
15 | describe('gulp-stylus-sprite', () => {
|
16 |
|
17 | it('create sprite circl', (done) => {
|
18 | let _isGetAllData = false;
|
19 | const _stream = stylusSprites({
|
20 | imgSrcBase: resolve(__dirname, 'fixtures/sprite'),
|
21 | spritesmithOpts: {
|
22 | algorithm: 'top-down',
|
23 | },
|
24 | });
|
25 | _stream.on('data', (file) => {
|
26 | switch(extname(file.path)) {
|
27 | case '.png':
|
28 | console.log(file);
|
29 | fs.writeFile(`${ __dirname }/fixtures/htdocs/${ file.path }`, file.contents, 'binary', (err) => {
|
30 | if(err) console.log(err);
|
31 | });
|
32 | break;
|
33 | case '.styl':
|
34 | console.log(file.contents.toString());
|
35 | fs.writeFile(`${ __dirname }/fixtures/stylus/${ file.path }`, file.contents, 'binary', (err) => {
|
36 | if(err) console.log(err);
|
37 | });
|
38 | break;
|
39 | }
|
40 | });
|
41 | _stream.on('end', () => {
|
42 | if(_isGetAllData) {
|
43 | done();
|
44 | } else {
|
45 | _isGetAllData = true;
|
46 | }
|
47 | });
|
48 | _stream.write(createFile('sprite/images/circle/blue.png'));
|
49 | _stream.write(createFile('sprite/images/circle/green.png'));
|
50 | _stream.write(createFile('sprite/images/circle/red.png'));
|
51 | _stream.end();
|
52 | });
|
53 |
|
54 | it('create sprite square', (done) => {
|
55 | let _isGetAllData = false;
|
56 | const _stream = stylusSprites({
|
57 | imgSrcBase: resolve(__dirname, 'fixtures/sprite'),
|
58 | stylusFileName: 'test',
|
59 | });
|
60 | _stream.on('data', (file) => {
|
61 | switch(extname(file.path)) {
|
62 | case '.png':
|
63 | console.log(file);
|
64 | fs.writeFile(`${ __dirname }/fixtures/htdocs/${ file.path }`, file.contents, 'binary', (err) => {
|
65 | if(err) console.log(err);
|
66 | });
|
67 | break;
|
68 | case '.styl':
|
69 | console.log(file.contents.toString())
|
70 | fs.writeFile(`${ __dirname }/fixtures/stylus/${ file.path }`, file.contents, 'binary', (err) => {
|
71 | if(err) console.log(err);
|
72 | });
|
73 | break;
|
74 | }
|
75 | });
|
76 | _stream.on('end', () => {
|
77 | if(_isGetAllData) {
|
78 | done();
|
79 | } else {
|
80 | _isGetAllData = true;
|
81 | }
|
82 | });
|
83 | _stream.write(createFile('sprite/images/square/blue.png'));
|
84 | _stream.write(createFile('sprite/images/square/green.png'));
|
85 | _stream.write(createFile('sprite/images/square/red.png'));
|
86 | _stream.end();
|
87 | });
|
88 |
|
89 | });
|