Skip to content

Commit 661a810

Browse files
author
Tom Maton
committed
Fixedd issue: dom-module not appending to the document
1 parent 8646db6 commit 661a810

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

.eslintrc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"parser": "babel-eslint",
3+
"parserOptions": {
4+
"ecmaVersion": 9,
5+
"sourceType": "module"
6+
},
7+
"extends": "airbnb-base",
8+
"rules": {
9+
"comma-dangle" : 0,
10+
"semi": "error",
11+
"no-console": "warn",
12+
"indent": [
13+
"error",
14+
4,
15+
{
16+
"SwitchCase": 1
17+
}
18+
],
19+
"class-methods-use-this": "off",
20+
"import/prefer-default-export": "off",
21+
"no-underscore-dangle": "off",
22+
"prefer-destructuring": ["error", {
23+
"AssignmentExpression": {
24+
"array": false,
25+
"object": true
26+
}
27+
}],
28+
"import/no-extraneous-dependencies": "off"
29+
},
30+
"globals": {
31+
"props": true
32+
},
33+
"env": {
34+
"browser": true,
35+
"es6": true,
36+
"node": true
37+
}
38+
}

index.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
'use strict';
2-
31
const through = require('through2');
42
const path = require('path');
53
const gutil = require('gulp-util');
6-
const PLUGIN_NAME = 'gulp-css-to-polymer';
74

8-
module.exports = (opts) => {
5+
const PLUGIN_NAME = 'gulp-css-to-polymer';
96

10-
return through.obj(function (file, enc, cb) {
7+
function generateModuleName(options, file) {
8+
return `${options.prefix}${path.basename(file.path, path.extname(file.path))}${options.suffix}`;
9+
}
1110

12-
if (file.isStream()) {
13-
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
14-
}
15-
if (file.isNull()) {
16-
return cb(null, file);
17-
}
11+
module.exports = opts => through.obj((file, enc, cb) => {
12+
const fileObj = file;
1813

19-
const moduleId = generateModuleName(opts, file);
20-
const dirname = path.dirname(file.path);
14+
if (file.isStream()) {
15+
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
16+
}
17+
if (file.isNull()) {
18+
return cb(null, file);
19+
}
2120

22-
const res = `import '@polymer/polymer/polymer-element.js';
21+
const moduleId = generateModuleName(opts, file);
22+
const dirname = path.dirname(file.path);
2323

24-
const $_documentContainer = document.createElement('template');
25-
$_documentContainer.innerHTML = \`<dom-module id=${moduleId}><template><style>${file.contents.toString('utf8')}</style></template></dom-module>\` `;
24+
const res = `import '@polymer/polymer/polymer-element';
2625
27-
file.contents = new Buffer(res);
28-
file.path = path.join(dirname, moduleId) + '.js';
26+
const $_documentContainer = document.createElement('template');
27+
$_documentContainer.innerHTML = \`<dom-module id=${moduleId}>
28+
<template>
29+
<style>
30+
${file.contents.toString('utf8')}
31+
</style>
32+
</template>
33+
</dom-module>\`;
2934
30-
return cb(null, file);
31-
});
35+
document.head.appendChild($_documentContainer.content);`;
3236

33-
};
37+
fileObj.contents = Buffer.from(res);
38+
fileObj.path = `${path.join(dirname, moduleId)}.js`;
3439

35-
function generateModuleName (options, file) {
36-
return `${options.prefix}${path.basename(file.path, path.extname(file.path))}${options.suffix}`;
37-
}
40+
return cb(null, file);
41+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-css-to-polymer",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Converting CSS to a ES6 Module for Polymer V3.x.x",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)