Skip to content

Commit d0225c9

Browse files
committed
Inital commit
0 parents  commit d0225c9

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
test/elm-stuff

index.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var elmCss = require('elm-css');
2+
var gutil = require('gulp-util');
3+
var path = require('path');
4+
var temp = require('temp').track();
5+
var through = require('through2');
6+
var Vinyl = require('vinyl');
7+
8+
var PluginError = gutil.PluginError;
9+
10+
const PLUGIN_NAME = 'gulp-elm-css';
11+
12+
function css(options = {}) {
13+
return through.obj(function(file, enc, cb) {
14+
var projectDir = options.projectDir || __dirname;
15+
var stylesheetsPath = path.basename(file.path);
16+
var stylesheetsModule = path.basename(file.path, path.extname(file.path));
17+
var stylesheetsPort = options.port || 'files';
18+
var pathToMake = options.pathToMake;
19+
tempDir({prefix: PLUGIN_NAME + '-tmp-'})
20+
.then(outputDir => elmCss(
21+
projectDir,
22+
stylesheetsPath,
23+
outputDir,
24+
stylesheetsModule,
25+
stylesheetsPort,
26+
pathToMake
27+
))
28+
.then(cssFiles => {
29+
cssFiles.forEach(cssFile =>
30+
this.push(new Vinyl({
31+
cwd: file.cwd,
32+
base: file.base,
33+
path: path.join(path.dirname(file.path), cssFile.filename),
34+
contents: new Buffer(cssFile.content)
35+
}))
36+
);
37+
cb();
38+
})
39+
.catch(error => cb(new gutil.PluginError(PLUGIN_NAME, error)));
40+
});
41+
}
42+
43+
function tempDir(affixes) {
44+
return new Promise((resolve, reject) =>
45+
temp.mkdir(affixes, (err, dirPath) =>
46+
(err ? reject(err) : resolve(dirPath))
47+
)
48+
);
49+
}
50+
51+
module.exports = css;

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "gulp-elm-css",
3+
"version": "0.0.1",
4+
"description": "Gulp plugin for generating CSS with elm-css",
5+
"main": "index.js",
6+
"repository": "https://github.com/TSFoster/gulp-elm-css",
7+
"author": "T.S. Foster <hi@tsf.io>",
8+
"license": "MIT",
9+
"devDependencies": {
10+
"mocha": "^3.3.0"
11+
},
12+
"dependencies": {
13+
"elm-css": "^0.6.0",
14+
"gulp-util": "^3.0.8",
15+
"temp": "^0.8.3",
16+
"through2": "^2.0.3",
17+
"vinyl": "^2.0.2"
18+
},
19+
"keywords": [
20+
"gulpplugin",
21+
"elm",
22+
"elm-css"
23+
],
24+
"scripts": {
25+
"test": "mocha ./test/main.js"
26+
}
27+
}

test/Stylesheets.elm

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
port module Stylesheets exposing (..)
2+
3+
import Css exposing (..)
4+
import Css.Elements exposing (..)
5+
import Css.File exposing (CssFileStructure, CssCompilerProgram)
6+
7+
8+
port files : CssFileStructure -> Cmd msg
9+
10+
11+
fileStructure : CssFileStructure
12+
fileStructure =
13+
Css.File.toFileStructure
14+
[ ( "main.css"
15+
, Css.File.compile
16+
[ stylesheet
17+
[ header
18+
[ backgroundColor (rgb 0 0 0)
19+
, color (rgb 255 255 255)
20+
]
21+
]
22+
]
23+
)
24+
]
25+
26+
27+
main : CssCompilerProgram
28+
main =
29+
Css.File.compiler files fileStructure

test/elm-package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.0.1",
3+
"summary": "Gulp plugin for generating CSS with elm-css",
4+
"repository": "https://github.com/TSFoster/gulp-elm-css.git",
5+
"license": "MIT",
6+
"source-directories": [
7+
"."
8+
],
9+
"exposed-modules": [],
10+
"dependencies": {
11+
"elm-lang/core": "5.1.1 <= v < 6.0.0",
12+
"elm-lang/html": "2.0.0 <= v < 3.0.0",
13+
"rtfeldman/elm-css": "8.2.0 <= v < 9.0.0"
14+
},
15+
"elm-version": "0.18.0 <= v < 0.19.0"
16+
}

test/main.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var plugin = require('..');
2+
var gutil = require('gulp-util');
3+
var assert = require('assert');
4+
var path = require('path');
5+
6+
describe('gulp-elm-css', function describeGulpElmCss() {
7+
it('should compile a real Elm file to a virtual CSS file', function itShouldCompile(done) {
8+
var gulpElmCss = plugin({projectDir: './test'});
9+
gulpElmCss.write(new gutil.File({
10+
base: __dirname,
11+
cwd: __dirname,
12+
path: path.join(__dirname, './Stylesheets.elm')
13+
}));
14+
gulpElmCss.once('data', function onceData(file) {
15+
var err;
16+
try {
17+
assert(file.isBuffer(), 'One buffer should be compiled');
18+
assert.equal(path.basename(file.path), 'main.css', 'File name should be main.css');
19+
} catch (e) {
20+
err = e;
21+
} finally {
22+
done(err);
23+
}
24+
});
25+
});
26+
});

0 commit comments

Comments
 (0)