Skip to content

Commit

Permalink
chore: refactor imports
Browse files Browse the repository at this point in the history
  • Loading branch information
janschoenherr committed Dec 9, 2019
1 parent 792a25a commit 87d51ad
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 2,712 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module.exports = {
"sourceType": "module"
},
"globals": {
"BUNDLED": true,
"VERSION": true,
"ICONS": true
"ICONS": true,
"NAME": true
},
"rules": {
"arrow-parens": ["error", "as-needed"],
Expand Down
10 changes: 5 additions & 5 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ const minify = !(argv.debug || argv.nominify || argv.d);
// -----

// map component build jobs
const components = glob.sync('src/js/components/*.js').reduce((components, file) => {
const components = glob.sync('src/js/components/!(index).js').reduce((components, file) => {

const name = path.basename(file, '.js');

components[name] = () =>
util.compile(`${__dirname}/componentWrapper.js`, `dist/${file.substring(4, file.length - 3)}`, {
util.compile(`${__dirname}/wrapper/component.js`, `dist/js/components/${name}`, {
name,
minify,
external: ['uikit', 'uikit-util'],
globals: {uikit: 'UIkit', 'uikit-util': 'UIkit.util'},
aliases: {component: path.join(__dirname, '..', file.substr(0, file.length - 3))},
aliases: {component: path.resolve(__dirname, '../src/js/components', name)},
replaces: {NAME: `'${camelize(name)}'`}
});

Expand All @@ -38,8 +38,8 @@ const components = glob.sync('src/js/components/*.js').reduce((components, file)
const steps = {

core: () => util.compile('src/js/uikit-core.js', 'dist/js/uikit-core', {minify}),
uikit: () => util.compile('src/js/uikit.js', 'dist/js/uikit', {minify, bundled: true}),
icons: () => util.icons('{src/images,custom}/icons/*.svg').then(ICONS => util.compile('src/js/icons.js', 'dist/js/uikit-icons', {
uikit: () => util.compile('src/js/uikit.js', 'dist/js/uikit', {minify}),
icons: () => util.icons('{src/images,custom}/icons/*.svg').then(ICONS => util.compile('build/wrapper/icons.js', 'dist/js/uikit-icons', {
minify,
name: 'icons',
replaces: {ICONS}
Expand Down
3 changes: 1 addition & 2 deletions build/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ exports.renderLess = async function (data, options) {
.css;
};

exports.compile = async function (file, dest, {external, globals, name, aliases, bundled, replaces, minify = true}) {
exports.compile = async function (file, dest, {external, globals, name, aliases, replaces, minify = true}) {

name = (name || '').replace(/[^\w]/g, '_');

Expand All @@ -106,7 +106,6 @@ exports.compile = async function (file, dest, {external, globals, name, aliases,
input: `${resolve(dirname(file), basename(file, '.js'))}.js`,
plugins: [
replace(Object.assign({
BUNDLED: bundled || false,
VERSION: `'${version}'`
}, replaces)),
alias({
Expand Down
1 change: 0 additions & 1 deletion build/componentWrapper.js → build/wrapper/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global UIkit, NAME */
import Component from 'component';

if (typeof window !== 'undefined' && window.UIkit) {
Expand Down
File renamed without changes.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"archiver": "3.1.1",
"buble": "^0.19.8",
"buble-loader": "^0.5.0",
"camelcase": "^5.3.1",
"circular-dependency-plugin": "^5.2.0",
"clean-css": "^4.1.11",
"dateformat": "^3.0.3",
Expand All @@ -60,11 +59,7 @@
"semver": "^6.3.0",
"shortid": "^2.2.15",
"svgo": "^1.3.2",
"uglify-js": "^3.6.7",
"uglifyjs-webpack-plugin": "2.2.0",
"webpack": "^4.41.2",
"webpack-cli": "3.3.10",
"webpack-dev-server": "^3.9.0"
"uglify-js": "^3.7.1"
},
"watch": {
"compile-js": "src/js/**/*.js",
Expand Down
5 changes: 4 additions & 1 deletion src/js/api/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default function (UIkit) {

UIkit.component = function (name, options) {

const id = hyphenate(name);

name = camelize(id);

if (!options) {

if (isPlainObject(components[name])) {
Expand Down Expand Up @@ -53,7 +57,6 @@ export default function (UIkit) {
}

if (UIkit._initialized && !opt.functional) {
const id = hyphenate(name);
fastdom.read(() => UIkit[name](`[uk-${id}],[data-uk-${id}]`));
}

Expand Down
1 change: 1 addition & 0 deletions src/js/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ UIkit.util = util;
UIkit.data = '__uikit__';
UIkit.prefix = 'uk-';
UIkit.options = {};
UIkit.version = VERSION;

globalAPI(UIkit);
hooksAPI(UIkit);
Expand Down
13 changes: 13 additions & 0 deletions src/js/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export {default as Countdown} from './countdown';
export {default as Filter} from './filter';
export {default as Lightbox} from './lightbox';
export {default as LightboxPanel} from './lightbox-panel';
export {default as Notification} from './notification';
export {default as Parallax} from './parallax';
export {default as Slider} from './slider';
export {default as SliderParallax} from './slider-parallax';
export {default as Slideshow} from './slideshow';
export {default as SlideshowParallax} from './slideshow-parallax';
export {default as Sortable} from './sortable';
export {default as Tooltip} from './tooltip';
export {default as Upload} from './upload';
121 changes: 41 additions & 80 deletions src/js/core/index.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,42 @@
import Accordion from './accordion';
import Alert from './alert';
import Core from './core';
import Cover from './cover';
import Drop from './drop';
import Dropdown from './dropdown';
import FormCustom from './form-custom';
import Gif from './gif';
import Grid from './grid';
import HeightMatch from './height-match';
import HeightViewport from './height-viewport';
import Icon, {IconComponent, Slidenav, Search, Close, Spinner} from './icon';
import Img from './img';
import Leader from './leader';
import Margin from './margin';
import Modal from './modal';
import Nav from './nav';
import Navbar from './navbar';
import Offcanvas from './offcanvas';
import OverflowAuto from './overflow-auto';
import Responsive from './responsive';
import Scroll from './scroll';
import Scrollspy from './scrollspy';
import ScrollspyNav from './scrollspy-nav';
import Sticky from './sticky';
import Svg from './svg';
import Switcher from './switcher';
import Tab from './tab';
import Toggle from './toggle';
import Video from './video';
export {default as Accordion} from './accordion';
export {default as Alert} from './alert';
export {default as Cover} from './cover';
export {default as Drop} from './drop';
export {default as Dropdown} from './dropdown';
export {default as FormCustom} from './form-custom';
export {default as Gif} from './gif';
export {default as Grid} from './grid';
export {default as HeightMatch} from './height-match';
export {default as HeightViewport} from './height-viewport';
export {default as Icon} from './icon';
export {default as Img} from './img';
export {default as Leader} from './leader';
export {default as Margin} from './margin';
export {default as Modal} from './modal';
export {default as Nav} from './nav';
export {default as Navbar} from './navbar';
export {default as Offcanvas} from './offcanvas';
export {default as OverflowAuto} from './overflow-auto';
export {default as Responsive} from './responsive';
export {default as Scroll} from './scroll';
export {default as Scrollspy} from './scrollspy';
export {default as ScrollspyNav} from './scrollspy-nav';
export {default as Sticky} from './sticky';
export {default as Svg} from './svg';
export {default as Switcher} from './switcher';
export {default as Tab} from './tab';
export {default as Toggle} from './toggle';
export {default as Video} from './video';

export default function (UIkit) {

// core components
UIkit.component('accordion', Accordion);
UIkit.component('alert', Alert);
UIkit.component('cover', Cover);
UIkit.component('drop', Drop);
UIkit.component('dropdown', Dropdown);
UIkit.component('formCustom', FormCustom);
UIkit.component('gif', Gif);
UIkit.component('grid', Grid);
UIkit.component('heightMatch', HeightMatch);
UIkit.component('heightViewport', HeightViewport);
UIkit.component('icon', Icon);
UIkit.component('img', Img);
UIkit.component('leader', Leader);
UIkit.component('margin', Margin);
UIkit.component('modal', Modal);
UIkit.component('nav', Nav);
UIkit.component('navbar', Navbar);
UIkit.component('offcanvas', Offcanvas);
UIkit.component('overflowAuto', OverflowAuto);
UIkit.component('responsive', Responsive);
UIkit.component('scroll', Scroll);
UIkit.component('scrollspy', Scrollspy);
UIkit.component('scrollspyNav', ScrollspyNav);
UIkit.component('sticky', Sticky);
UIkit.component('svg', Svg);
UIkit.component('switcher', Switcher);
UIkit.component('tab', Tab);
UIkit.component('toggle', Toggle);
UIkit.component('video', Video);

// Icon components
UIkit.component('close', Close);
UIkit.component('marker', IconComponent);
UIkit.component('navbarToggleIcon', IconComponent);
UIkit.component('overlayIcon', IconComponent);
UIkit.component('paginationNext', IconComponent);
UIkit.component('paginationPrevious', IconComponent);
UIkit.component('searchIcon', Search);
UIkit.component('slidenavNext', Slidenav);
UIkit.component('slidenavPrevious', Slidenav);
UIkit.component('spinner', Spinner);
UIkit.component('totop', IconComponent);

// core functionality
UIkit.use(Core);

}
// Icon components
export {Close} from './icon';
export {Spinner} from './icon';
export {Slidenav as SlidenavNext} from './icon';
export {Slidenav as SlidenavPrevious} from './icon';
export {Search as SearchIcon} from './icon';
export {IconComponent as Marker} from './icon';
export {IconComponent as NavbarToggleIcon} from './icon';
export {IconComponent as OverlayIcon} from './icon';
export {IconComponent as PaginationNext} from './icon';
export {IconComponent as PaginationPrevious} from './icon';
export {IconComponent as Totop} from './icon';
16 changes: 10 additions & 6 deletions src/js/uikit-core.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import UIkit from './api/index';
import core from './core/index';
import Core from './core/core';
import boot from './api/boot';
import * as components from './core/index';
import {each} from './util/lang';

UIkit.version = VERSION;
// register components
each(components, (component, name) =>
UIkit.component(name, component)
);

core(UIkit);
// core functionality
UIkit.use(Core);

if (!BUNDLED) {
boot(UIkit);
}
boot(UIkit);

export default UIkit;
46 changes: 16 additions & 30 deletions src/js/uikit.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
import UIkit from './api/index';
import Core from './core/core';
import boot from './api/boot';
import UIkit from './uikit-core';
import Countdown from './components/countdown';
import Filter from './components/filter';
import Lightbox from './components/lightbox';
import lightboxPanel from './components/lightbox-panel';
import Notification from './components/notification';
import Parallax from './components/parallax';
import Slider from './components/slider';
import SliderParallax from './components/slider-parallax';
import Slideshow from './components/slideshow';
import SlideshowParallax from './components/slideshow-parallax';
import Sortable from './components/sortable';
import Tooltip from './components/tooltip';
import Upload from './components/upload';
import * as coreComponents from './core/index';
import * as components from './components/index';
import {each} from './util/lang';

UIkit.component('countdown', Countdown);
UIkit.component('filter', Filter);
UIkit.component('lightbox', Lightbox);
UIkit.component('lightboxPanel', lightboxPanel);
UIkit.component('notification', Notification);
UIkit.component('parallax', Parallax);
UIkit.component('slider', Slider);
UIkit.component('sliderParallax', SliderParallax);
UIkit.component('slideshow', Slideshow);
UIkit.component('slideshowParallax', SlideshowParallax);
UIkit.component('sortable', Sortable);
UIkit.component('tooltip', Tooltip);
UIkit.component('upload', Upload);
// register components
each(coreComponents, register);
each(components, register);

if (BUNDLED) {
boot(UIkit);
}
// core functionality
UIkit.use(Core);

boot(UIkit);

export default UIkit;

function register(component, name) {
UIkit.component(name, component);
}

0 comments on commit 87d51ad

Please sign in to comment.