Skip to content

Commit

Permalink
require correctly, compile correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jul 18, 2018
1 parent e6fccfb commit 21683b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/moon-mvl/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const fs = require("fs");
const path = require("path");
const Moon = require("moon");
const slash = require("./slash/slash.js");
const slash = require("./slash/slash");

const cssRE = /([@#.="':\w\s\-\[\]()]+)(\s*,|(?:{[\s\n]*(?:[\w\n]+:[\w\s\n(),]+;[\s\n]*)*}))/g;
const trailingWhitespaceRE = /\s*$/;

const addClass = (element, name) => {
const attributes = element.attributes;
const children = element.children;
let value = name;
let expression = false;
let dynamic = false;
Expand All @@ -33,6 +35,12 @@ const addClass = (element, name) => {
expression: expression,
dynamic: dynamic
});

for (let i = 0; i < children.length; i++) {
addClass(children[i], name);
}

return element;
};

module.exports = (file, contents) => {
Expand All @@ -58,7 +66,7 @@ module.exports = (file, contents) => {
if (fs.existsSync(cssPath)) {
const scope = `moon-${name}-${slash(name)}`;
view = Moon.generate(addClass(Moon.parse(contents), scope), null);
css = fs.readFileSync(css).toString().replace(cssRE, (match, selector, rule) => {
css = fs.readFileSync(cssPath).toString().replace(cssRE, (match, selector, rule) => {
return selector.replace(trailingWhitespaceRE, "") + "." + scope;
});
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/moon-mvl/slash/slash.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ const slash = (key) => {

return result.toString(36);
};

module.exports = slash;

0 comments on commit 21683b3

Please sign in to comment.