es6, umd, and iife bundles are all being created properly for core and docs. Dramatically simplified (using rollup):

- js file generation
- docs js generation
- configuration and bridging to jekyll (removed a bunch of unnecessary code)
This commit is contained in:
Kevin Ross 2016-01-04 11:28:12 -06:00
parent 97c952746f
commit 3fdbbbec28
10 changed files with 56 additions and 190 deletions

View File

@ -56,55 +56,6 @@ module.exports = function (grunt) {
] ]
}); });
var moduleGenerator = require('./grunt/module-generator.js');
var configBridge = grunt.file.readJSON('./grunt/configBridge.json', {encoding: 'utf8'});
// dynamically create js file list (we do this for several different directories)
function coreFileArray(path) {
var result = []
configBridge.core.files.forEach(
function (element, index, array) {
result[index] = (path + element)
}
);
return result;
}
function fileMap(result, fileArray, destPath, sourcPath) {
fileArray.forEach(
function (element, index, array) {
result[destPath + element] = (sourcPath + element)
}
);
}
function coreFileMap(destPath, sourcePath) {
var result = {}
fileMap(result, configBridge.core.files, destPath, sourcePath)
return result;
}
function docsFileMap() {
var result = {}
var sourcePath = 'docs/assets/js/src/'
var destPath = 'docs/assets/js/dist/'
fileMap(result, configBridge.docs.files, destPath, sourcePath)
// generate core so we have local debugging
var sourcePath = 'js/src/'
var destPath = 'docs/dist/js/demoduled/'
fileMap(result, configBridge.core.files, destPath, sourcePath)
return result;
}
//Object.keys(configBridge.paths).forEach(function (key) {
// configBridge.paths[key].forEach(function (val, i, arr) {
// arr[i] = path.join('./docs/assets', val);
// });
//});
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
@ -124,31 +75,6 @@ module.exports = function (grunt) {
docs: 'docs/dist' docs: 'docs/dist'
}, },
//babel: {
// options: {
// sourceMap: true,
// presets: ['es2015'] // the following is the es2015 preset minus the commonjs requirement
// },
// core: {
// files: coreFileMap('dist/js/demoduled/', 'js/src/')
// },
// docs: {
// files: docsFileMap()
// },
// systemjs: {
// options: {
// plugins: ['transform-es2015-modules-systemjs']
// },
// files: coreFileMap('dist/js/systemjs/', 'js/src/')
// },
// umd: {
// options: {
// plugins: ['transform-es2015-modules-umd']
// },
// files: coreFileMap('dist/js/umd/', 'js/src/')
// }
//},
eslint: { eslint: {
options: { options: {
configFile: 'js/.eslintrc' configFile: 'js/.eslintrc'
@ -193,15 +119,7 @@ module.exports = function (grunt) {
// stripBanners: false, // stripBanners: false,
// sourceMap: true // sourceMap: true
// }, // },
// systemjs: {
// src: coreFileArray('dist/js/systemjs/'),
// dest: 'dist/js/system-all.js'
// },
// commonjs: {
// src: coreFileArray('dist/js/umd/'),
// dest: 'dist/js/common-all.js'
// }
//},
uglify: { uglify: {
options: { options: {
compress: { compress: {
@ -223,7 +141,6 @@ module.exports = function (grunt) {
options: { options: {
compress: false compress: false
}, },
//src: configBridge.paths.docsJs,
src: 'docs/assets/js/vendor/*.js', src: 'docs/assets/js/vendor/*.js',
//dest: 'docs/assets/js/docs.min.js' //dest: 'docs/assets/js/docs.min.js'
dest: 'docs/dist/js/docs-vendor.min.js' dest: 'docs/dist/js/docs-vendor.min.js'
@ -632,14 +549,6 @@ module.exports = function (grunt) {
// Default task. // Default task.
grunt.registerTask('default', ['clean:dist', 'test']); grunt.registerTask('default', ['clean:dist', 'test']);
grunt.registerTask('commonjs', 'Generate npm-js/commonjs entrypoint module.', function () {
moduleGenerator.commonJs(grunt, coreFileArray('./umd/'), 'dist/js/common.js');
});
grunt.registerTask('systemjs', 'Generate systemjs entrypoint module.', function () {
moduleGenerator.systemJs(grunt, coreFileArray('./systemjs/'), 'dist/js/system.js');
});
//------ //------
// Docs tasks // Docs tasks
@ -682,6 +591,6 @@ module.exports = function (grunt) {
}); });
//grunt.registerTask('debug', function () { //grunt.registerTask('debug', function () {
// console.log(coreFileArray('dist/js/demoduled/')); // console.log('');
//}); //});
}; };

View File

@ -1,10 +0,0 @@
require 'yaml'
module Bridge
class Generator < Jekyll::Generator
def generate(site)
path = File.join(site.source, "../grunt/configBridge.json")
site.data["configBridge"] = YAML.load_file(path)
end
end
end

View File

@ -2,7 +2,9 @@
import Style from './style' import Style from './style'
import Clipboard from 'clipboard' import Clipboard from 'clipboard'
import anchors from 'anchor' import anchors from 'anchor'
//import mdb from '../../../../js/src/index' // eslint-disable-line no-unused-vars
// import all the mdb code
import mdb from '../../../../js/src/index' // eslint-disable-line no-unused-vars
class Application { class Application {

View File

@ -1,22 +0,0 @@
{
"core": {
"files": [
"baseInput.js",
"baseSelection.js",
"util.js",
"ripples.js",
"autofill.js",
"text.js",
"textarea.js",
"select.js",
"checkbox.js",
"checkboxInline.js",
"switch.js",
"radio.js",
"radioInline.js",
"file.js",
"bootstrapMaterialDesign.js",
"index.js"
]
}
}

View File

@ -1,45 +0,0 @@
module.exports = (function () {
'use strict';
var fs = require('fs');
var path = require('path');
var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
var commonJs = function (grunt, srcFiles, destFilepath) {
function moduleRequireStatement(srcFilepath) {
return 'require(\'' + srcFilepath.replace(/\\/g, '/') + '\')';
}
var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(moduleRequireStatement).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
} catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
}
var SYSTEMJS_BANNER = '// This file is autogenerated via the `systemjs` Grunt task. You can import this file in a SystemJS environment.\n';
var systemJs = function (grunt, srcFiles, destFilepath) {
function moduleRequireStatement(srcFilepath) {
return 'System.import(\'' + srcFilepath.replace(/\\/g, '/') + '\')';
}
var moduleOutputJs = SYSTEMJS_BANNER + srcFiles.map(moduleRequireStatement).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
} catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
}
return {
commonJs: commonJs,
systemJs: systemJs
}
}())

42
js/src/baseFormControl.js Normal file
View File

@ -0,0 +1,42 @@
import BaseInput from './baseInput'
const BaseFormControl = (($) => {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
const Default = {
decorator: {
template: `<span class='mdb-form-control-decorator'></span>`
},
requiredClasses: ['form-control']
}
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
class BaseFormControl extends BaseInput {
constructor($element, config) {
super($element, $.extend(true, Default, config))
// Initially mark as empty
if (this.isEmpty()) {
this.removeIsFilled()
}
// Add marker div the end of the form-group
this.$element.after(this.config.decorator.template)
}
}
return BaseFormControl
})(jQuery)
export default BaseFormControl

View File

@ -9,6 +9,7 @@
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
import BaseInput from './baseInput' import BaseInput from './baseInput'
import BaseFormControl from './baseFormControl'
import BaseSelection from './baseSelection' import BaseSelection from './baseSelection'
import Util from './util' import Util from './util'
import Ripples from './ripples' import Ripples from './ripples'

View File

@ -1,3 +1,4 @@
import BaseFormControl from './baseFormControl'
import Checkbox from './checkbox' import Checkbox from './checkbox'
import File from './file' import File from './file'
import Radio from './radio' import Radio from './radio'
@ -27,7 +28,7 @@ const Select = (($) => {
* Class Definition * Class Definition
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
*/ */
class Select extends Text { class Select extends BaseFormControl {
constructor($element, config) { constructor($element, config) {
super($element, $.extend(true, {invalidComponentMatches: [Checkbox, File, Radio, Switch, Text, Textarea]}, Default, config)) super($element, $.extend(true, {invalidComponentMatches: [Checkbox, File, Radio, Switch, Text, Textarea]}, Default, config))

View File

@ -1,4 +1,4 @@
import BaseInput from './baseInput' import BaseFormControl from './baseFormControl'
import Checkbox from './checkbox' import Checkbox from './checkbox'
import File from './file' import File from './file'
import Radio from './radio' import Radio from './radio'
@ -19,30 +19,17 @@ const Text = (($) => {
const JQUERY_NAME = `mdb${NAME.charAt(0).toUpperCase() + NAME.slice(1)}` const JQUERY_NAME = `mdb${NAME.charAt(0).toUpperCase() + NAME.slice(1)}`
const JQUERY_NO_CONFLICT = $.fn[JQUERY_NAME] const JQUERY_NO_CONFLICT = $.fn[JQUERY_NAME]
const Default = { const Default = {}
decorator: {
template: `<span class='mdb-form-control-decorator'></span>`
},
requiredClasses: ['form-control']
}
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
* Class Definition * Class Definition
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
*/ */
class Text extends BaseInput { class Text extends BaseFormControl {
constructor($element, config) { constructor($element, config) {
super($element, $.extend(true, {invalidComponentMatches: [Checkbox, File, Radio, Select, Switch, Textarea]}, Default, config)) super($element, $.extend(true, {invalidComponentMatches: [Checkbox, File, Radio, Switch, Select, Textarea]}, Default, config))
// Initially mark as empty
if (this.isEmpty()) {
this.removeIsFilled()
}
// Add marker div the end of the form-group
this.$element.after(this.config.decorator.template)
} }
dispose(dataKey = DATA_KEY) { dispose(dataKey = DATA_KEY) {

View File

@ -1,3 +1,4 @@
import BaseFormControl from './baseFormControl'
import Checkbox from './checkbox' import Checkbox from './checkbox'
import File from './file' import File from './file'
import Radio from './radio' import Radio from './radio'
@ -25,7 +26,7 @@ const Textarea = (($) => {
* Class Definition * Class Definition
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
*/ */
class Textarea extends Text { class Textarea extends BaseFormControl {
constructor($element, config) { constructor($element, config) {
super($element, $.extend(true, {invalidComponentMatches: [Checkbox, File, Radio, Text, Select, Switch]}, Default, config)) super($element, $.extend(true, {invalidComponentMatches: [Checkbox, File, Radio, Text, Select, Switch]}, Default, config))