Browse Source

Add babel build

zhixin 7 years ago
parent
commit
5b818f18bc

+ 16 - 0
.babelrc

@@ -0,0 +1,16 @@
+{
+  "presets": [
+    ["env", {
+      "modules": "umd",
+      "targets": {
+        "browsers": ["last 2 versions"]
+      }
+    }],
+    "stage-0",
+  ],
+  "env": {
+    "production": {
+      "presets": ["babili"]
+    }
+  }
+}

+ 0 - 126
Gruntfile.js

@@ -1,126 +0,0 @@
-'use strict';
-
-var fs = require('fs');
-
-module.exports = function(grunt) {
-
-    // Project configuration.
-    grunt.initConfig({
-        // Metadata.
-        pkg: grunt.file.readJSON('bootstrap-table.jquery.json'),
-        banner: '/*\n' +
-                '* <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
-                '<%= pkg.homepage ? "* " + pkg.homepage : "" %>\n' +
-                '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>\n' +
-                '* Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
-                '*/\n',
-        // Task configuration.
-        clean: ['dist', 'docs/dist'],
-        concat: {
-            //basic_target: {
-            //    src: ['src/<%= pkg.name %>.js', 'src/extensions/**/*.js'],
-            //    dest: 'dist/<%= pkg.name %>-all.js'
-            //},
-            locale_target: {
-                src: ['src/locale/**/*.js'],
-                dest: 'dist/<%= pkg.name %>-locale-all.js'
-            }
-        },
-        uglify: {
-            options: {
-                banner: '<%= banner %>'
-            },
-            basic_target: {
-                files: {
-                    'dist/<%= pkg.name %>.min.js': ['src/<%=pkg.name %>.js'],
-                    //'dist/<%= pkg.name %>-all.min.js': ['dist/<%=pkg.name %>-all.js'],
-                    'dist/<%= pkg.name %>-locale-all.min.js': ['dist/<%=pkg.name %>-locale-all.js']
-                }
-            },
-            locale_target: {
-                files: [{
-                    expand: true,
-                    cwd: 'src/locale',
-                    src: '**/*.js',
-                    dest: 'dist/locale',
-                    ext: '.min.js' // replace .js to .min.js
-                }]
-            },
-            extensions_target: {
-                files: [{
-                    expand: true,
-                    cwd: 'src/extensions',
-                    src: '**/*.js',
-                    dest: 'dist/extensions',
-                    ext: '.min.js' // replace .js to .min.js
-                }]
-            }
-        },
-        cssmin: {
-            add_banner: {
-                options: {
-                    banner: '<%= banner %>'
-                },
-                files: {
-                    'dist/<%= pkg.name %>.min.css': ['src/<%=pkg.name %>.css']
-                }
-            }
-        },
-        copy: {
-            source: {
-                cwd: 'src',                     // set working folder / root to copy
-                src: ['**/*.js', '**/*.css'],   // copy all files and subfolders
-                dest: 'dist',                   // destination folder
-                expand: true                    // required when using cwd
-            }
-        },
-        release: {
-            options: {
-                additionalFiles: ['bootstrap-table.jquery.json'],
-                beforeRelease: ['docs', 'default']
-            }
-        }
-    });
-
-    var bumpVersion = function (path, version, startWith) {
-        var lines = fs.readFileSync(path, 'utf8').split('\n');
-        lines.forEach(function (line, i) {
-            if (line.indexOf(startWith) === 0) {
-                lines[i] = startWith + version;
-            }
-        });
-        fs.writeFileSync(path, lines.join('\n'), 'utf8');
-
-        grunt.log.ok('bumped version of ' + path + ' to ' + version);
-    };
-
-    grunt.registerTask('docs', 'build the docs', function () {
-        var version = require('./package.json').version;
-        bumpVersion('./_config.yml', version, 'current_version: ');
-        bumpVersion('./src/bootstrap-table.js', version, ' * version: ');
-        bumpVersion('./src/bootstrap-table.css', version, ' * version: ');
-
-        var changeLog = fs.readFileSync('./CHANGELOG.md', 'utf8');
-        var latestLogs = changeLog.split('### ')[1];
-        var date = new Date();
-
-        var lines = [
-            '### Latest release (' +
-            [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-') + ')',
-            '',
-            '#### v' + latestLogs
-        ];
-        fs.writeFileSync('./docs/_includes/latest-release.md', lines.join('\n'), 'utf8');
-
-        grunt.log.ok('updated the latest-release.md to ' + version);
-    });
-
-    grunt.loadNpmTasks('grunt-contrib-clean');
-    grunt.loadNpmTasks('grunt-contrib-concat');
-    grunt.loadNpmTasks('grunt-contrib-uglify');
-    grunt.loadNpmTasks('grunt-contrib-cssmin');
-    grunt.loadNpmTasks('grunt-contrib-copy');
-    grunt.loadNpmTasks('grunt-release');
-
-    grunt.registerTask('default', ['clean', 'concat', 'uglify', 'cssmin', 'copy']);
-};

+ 21 - 12
package.json

@@ -7,27 +7,36 @@
     "doc": "docs"
   },
   "devDependencies": {
+    "babel-cli": "^6.26.0",
+    "babel-preset-babili": "^0.1.4",
+    "babel-preset-env": "^1.7.0",
+    "babel-preset-stage-0": "^6.24.1",
+    "cssmin-cli": "^0.0.5",
     "eslint": "^4.19.1",
     "eslint-config-standard": "^11.0.0",
     "eslint-plugin-import": "^2.9.0",
     "eslint-plugin-node": "^6.0.1",
     "eslint-plugin-promise": "^3.7.0",
     "eslint-plugin-standard": "^3.0.1",
-    "grunt": "^0.4.5",
-    "grunt-cli": "^1.2.0",
-    "grunt-contrib-clean": "^0.6.0",
-    "grunt-contrib-concat": "^0.5.1",
-    "grunt-contrib-copy": "^0.8.0",
-    "grunt-contrib-cssmin": "^0.12.2",
-    "grunt-contrib-jshint": "^0.10.0",
-    "grunt-contrib-uglify": "^0.8.0",
-    "grunt-release": "^0.13.0",
+    "headr": "^0.0.4",
+    "npm-run-all": "^4.1.5",
     "opencollective": "^1.0.3"
   },
   "scripts": {
-    "grunt": "grunt",
     "postinstall": "opencollective postinstall || exit 0",
-    "lint": "eslint src/bootstrap-table.js src/extensions/export/bootstrap-table-export.js src/extensions/toolbar/bootstrap-table-toolbar.js"
+    "lint:js": "eslint src/bootstrap-table.js src/extensions/export/bootstrap-table-export.js src/extensions/toolbar/bootstrap-table-toolbar.js",
+    "lint": "run-p lint:*",
+    "js:build:min": "NODE_ENV=production babel src -d dist -q && find dist -name '*.js' | sed -e 'p;s/.js/.min.js/' | xargs -n2 mv",
+    "js:build:base": "babel src -d dist -q",
+    "js:build:concat": "babel src/locale -o dist/bootstrap-table-locale-all.js && NODE_ENV=production babel src/locale -o dist/bootstrap-table-locale-all.min.js",
+    "js:build:banner": "find dist -name '*.min.js' -exec headr {} -o {} --version --homepage --author --license \\;",
+    "js:build": "run-s js:build:*",
+    "css:build:base": "find src -name '*.css' | sed -e 'p;s/src/dist/' | xargs -n2 cp",
+    "css:build:min": "find dist -name '*.css' | sed -e 'p;s/.css/.min.css/' | xargs -n2 cssmin",
+    "css:build:banner": "find dist -name '*.min.css' -exec headr {} -o {} --version --homepage --author --license \\;",
+    "css:build": "run-s css:build:*",
+    "clean": "rm -rf dist",
+    "build": "run-s clean *:build"
   },
   "repository": {
     "type": "git",
@@ -47,7 +56,7 @@
   "bugs": {
     "url": "https://github.com/wenzhixin/bootstrap-table/issues"
   },
-  "homepage": "https://github.com/wenzhixin/bootstrap-table",
+  "homepage": "http://bootstrap-table.wenzhixin.net.cn",
   "config": {
     "commitizen": {
       "path": "./node_modules/cz-conventional-changelog"

+ 2 - 2
src/bootstrap-table.js

@@ -1783,7 +1783,7 @@
           type = column.radio ? 'radio' : type
 
           const c = column['class'] || ''
-          const isChecked = value === true || (value_ || value && value.checked)
+          const isChecked = value === true || (value_ || (value && value.checked))
           const isDisabled = !column.checkboxEnabled || (value && value.disabled)
 
           text = [
@@ -1855,7 +1855,7 @@
         const tr = this.initRow(item, i, data, trFragments)
         hasTr = hasTr || !!tr
         if (tr && typeof tr === 'string') {
-            trFragments.append(tr)
+          trFragments.append(tr)
         }
       }
 

+ 3 - 3
src/extensions/export/bootstrap-table-export.js

@@ -109,15 +109,15 @@
       $menu.find('>li, >a').click(e => {
         const type = $(e.currentTarget).data('type')
         const exportOptions = {
-            type: type,
-            escape: false
+          type: type,
+          escape: false
         }
 
         this.exportTable(exportOptions)
       })
     }
 
-    exportTable(options) {
+    exportTable (options) {
       const o = this.options
 
       const doExport = () => {

+ 4 - 1
src/extensions/toolbar/bootstrap-table-toolbar.js

@@ -75,7 +75,10 @@
     initToolbar () {
       const o = this.options
 
-      this.showToolbar = this.showToolbar || o.search && o.advancedSearch && o.idTable
+      this.showToolbar = this.showToolbar ||
+        (o.search &&
+        o.advancedSearch &&
+        o.idTable)
 
       super.initToolbar()