-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
307 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false, | ||
"useBuiltIns": false | ||
}], | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
["@babel/plugin-proposal-class-properties", { "loose": true }], | ||
"@babel/plugin-proposal-optional-chaining", | ||
"@babel/plugin-proposal-object-rest-spread" | ||
] | ||
"@babel/plugin-proposal-object-rest-spread", | ||
"@babel/plugin-proposal-export-default-from" | ||
], | ||
"env": { | ||
"module": { | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false, | ||
"useBuiltIns": false, | ||
"targets": { | ||
"esmodules": true | ||
} | ||
}] | ||
], | ||
"plugins": [ | ||
"./plugins/babel/stylus" | ||
], | ||
"ignore": [ | ||
"node_modules/**" | ||
] | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* global process */ | ||
|
||
const fs = require('fs'); | ||
const { dirname, isAbsolute, resolve } = require('path'); | ||
const postCSS = require('postcss'); | ||
const autoprefixer = require('autoprefixer'); | ||
const stylus = require('stylus'); | ||
|
||
const cleanCSS = require('../post-css/clean-css'); | ||
|
||
/* | ||
MODULE REGEX WILL RETURN STYLUS NODE_MODULE IMPORT | ||
WILL RETURN TRUE FOR | ||
* @import '~module' | ||
* @require '~another-module' | ||
WILL RETURN FALSE FOR | ||
* @require 'module.styl' | ||
* @require 'module' | ||
* div ~ input | ||
*/ | ||
|
||
const MODULE_REGEX = /(~*@).*/; | ||
|
||
const fileExists = filename => { | ||
try { | ||
const stats = fs.statSync(filename); | ||
return stats.isFile(filename); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') { | ||
return false; | ||
} else { | ||
throw Error(e); | ||
} | ||
} | ||
}; | ||
|
||
const compileStylusFile = (jsFile, stylusFile) => { | ||
// try to resolve as file path | ||
const from = resolveModulePath(jsFile); | ||
let path = resolve(from, stylusFile); | ||
if (!fileExists(path)) { | ||
// try to resolve from node modules | ||
path = resolve('./node_modules', stylusFile); | ||
} | ||
|
||
if (!fileExists(path)) { | ||
throw Error('Cannot find stylus file: ' + stylusFile); | ||
} | ||
|
||
let stylusContent = fs.readFileSync(path, 'utf8'); | ||
|
||
if (stylusContent.match(MODULE_REGEX) !== null) { | ||
const match = stylusContent.match(MODULE_REGEX); | ||
stylusContent = stylusContent | ||
.replace(MODULE_REGEX, match[0].replace('~', '')); | ||
} | ||
|
||
let parsed = stylus(stylusContent) | ||
.include(dirname(path)) | ||
.include(resolve('./node_modules')) | ||
.render(); | ||
|
||
return postCSS([ | ||
autoprefixer, | ||
cleanCSS, | ||
]).process(parsed).css; | ||
}; | ||
|
||
const resolveModulePath = (filename) => { | ||
const dir = dirname(filename); | ||
if (isAbsolute(dir)) { return dir; } | ||
if (process.env.PWD) { return resolve(process.env.PWD, dir); } | ||
return resolve(dir); | ||
}; | ||
|
||
module.exports = ({types: t}) => { | ||
return { | ||
visitor: { | ||
ImportDeclaration: (path, state) => { | ||
const node = path.node; | ||
if (node && node.source && node.source.value && | ||
node.source.type === 'StringLiteral' && | ||
node.source.value.endsWith('.styl') | ||
) { | ||
const jsFile = state.file.opts.filename; | ||
const stylusFile = node.source.value; | ||
const css = compileStylusFile(jsFile, stylusFile); | ||
|
||
const id = node.specifiers[0].local.name; | ||
path.replaceWith( | ||
t.variableDeclaration('var', [ | ||
t.variableDeclarator(t.identifier(id), t.stringLiteral(css)), | ||
]) | ||
); | ||
} | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const PostCSS = require('postcss'); | ||
const CleanCSS = require('clean-css'); | ||
|
||
module.exports = (css, res) => { | ||
const cleancss = new CleanCSS(); | ||
const minified = cleancss.minify(css.toString()); | ||
|
||
res.root = PostCSS.parse(minified.styles); | ||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import { injectStyles } from './utils'; | ||
|
||
export TextField from './TextField'; | ||
export CodeField from './CodeField'; | ||
export BreadCrumb from './BreadCrumb'; | ||
export Button from './Button'; | ||
export CheckBox from './CheckBox'; | ||
export CodeField from './CodeField'; | ||
export ColorPicker from './ColorPicker'; | ||
export DateField from './DateField'; | ||
export Dropdown from './Dropdown'; | ||
export DropdownItem from './DropdownItem'; | ||
export DropdownMenu from './DropdownMenu'; | ||
export DropdownToggle from './DropdownToggle'; | ||
export Modal from './Modal'; | ||
export SelectField from './SelectField'; | ||
export Slider from './Slider'; | ||
export Toggle from './Toggle'; | ||
export DateField from './DateField'; | ||
export Button from './Button'; | ||
export Switch from './Switch'; | ||
export Tab from './Tab'; | ||
export Tabs from './Tabs'; | ||
export TagsField from './TagsField'; | ||
export BreadCrumb from './BreadCrumb'; | ||
export TextField from './TextField'; | ||
export Toggle from './Toggle'; | ||
export Tooltip from './Tooltip'; | ||
export Tabs from './Tabs'; | ||
export Tab from './Tab'; | ||
export Modal from './Modal'; | ||
export ColorPicker from './ColorPicker'; | ||
export Switch from './Switch'; | ||
export Dropdown from './Dropdown'; | ||
export DropdownToggle from './DropdownToggle'; | ||
export DropdownMenu from './DropdownMenu'; | ||
export DropdownItem from './DropdownItem'; | ||
export { getContainerNode, omit, classNames } from './utils'; | ||
|
||
import styles from './theme/index.styl'; | ||
injectStyles(styles, { id: 'junipero-main-styles' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.