From 8f44e19412843873f7459db4a4bda8e94cae0fcc Mon Sep 17 00:00:00 2001 From: mertsincan Date: Wed, 29 May 2019 10:11:07 +0300 Subject: [PATCH] Fixed transpile issues for .js files --- build-lib.js | 25 ++++-- gulpfile.js | 2 +- package.json | 2 + src/components/utils/FilterUtils.js | 81 ------------------ src/components/utils/ObjectUtils.js | 122 +++++++++++++++++++++++----- 5 files changed, 125 insertions(+), 107 deletions(-) delete mode 100644 src/components/utils/FilterUtils.js diff --git a/build-lib.js b/build-lib.js index e7ec12148..81a6651e2 100644 --- a/build-lib.js +++ b/build-lib.js @@ -1,17 +1,32 @@ const fs = require('fs-extra'); const path = require('path'); -const {execSync} = require('child_process'); +const { execSync } = require('child_process'); const vueCliServicePath = path.resolve(__dirname, 'node_modules/@vue/cli-service/bin/vue-cli-service'); fs.readdirSync(path.resolve(__dirname, './src/components/')).forEach(folder => { fs.readdirSync(path.resolve(__dirname, './src/components/' + folder)).forEach(file => { - if (/\.vue$/.test(file) || /\.js$/.test(file)) { - let filename = file.split(/(.vue)$|(.js)$/)[0].toLowerCase(); - console.log('Building ' + filename); + let filename = file.split(/(.vue)$|(.js)$/)[0].toLowerCase(); + if (/\.vue$/.test(file)) { + console.log('Building ' + blue(filename)); execSync( `node ${vueCliServicePath} build src/components/${folder}/${file} --target lib --name ${filename} --dest components/${folder} --no-clean ` ) } + else if (/\.js$/.test(file)) { + console.log('Building ' + blue(filename)); + + execSync( + `node ${vueCliServicePath} build src/components/${folder}/${file} --target lib --name ${filename} --dest components/${folder} --no-clean ` + ) + + execSync( + `babel --no-babelrc src/components/${folder}/${file} --out-file components/${folder}/${file} --presets=es2015,stage-2 ` + ) + } }); -}); \ No newline at end of file +}); + +function blue (str) { + return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m' +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 070845279..75fc5f3cf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,7 +8,7 @@ var gulp = require('gulp'), flatten = require('gulp-flatten'); gulp.task('copy-components', function() { - return gulp.src(['src/components/**/*']) + return gulp.src(['src/components/**/*.vue']) .pipe(gulp.dest('./components')); }); diff --git a/package.json b/package.json index 7cedac829..e840e7e34 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "babel-core": "7.0.0-bridge.0", "babel-eslint": "^10.0.1", "babel-jest": "^23.6.0", + "babel-preset-es2015": "^6.24.1", + "babel-preset-stage-2": "^6.24.1", "eslint": "^5.8.0", "eslint-plugin-vue": "^5.0.0-0", "node-sass": "^4.9.0", diff --git a/src/components/utils/FilterUtils.js b/src/components/utils/FilterUtils.js deleted file mode 100644 index 71eade50f..000000000 --- a/src/components/utils/FilterUtils.js +++ /dev/null @@ -1,81 +0,0 @@ -export default class FilterUtils { - - static startsWith(value, filter) { - if(filter === undefined || filter === null || filter.trim() === '') { - return true; - } - - if(value === undefined || value === null) { - return false; - } - - let filterValue = filter.toLowerCase(); - return value.toString().toLowerCase().slice(0, filterValue.length) === filterValue; - } - - static contains(value, filter) { - if(filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { - return true; - } - - if(value === undefined || value === null) { - return false; - } - - return value.toString().toLowerCase().indexOf(filter.toLowerCase()) !== -1; - } - - static endsWith(value, filter) { - if(filter === undefined || filter === null || filter.trim() === '') { - return true; - } - - if(value === undefined || value === null) { - return false; - } - - let filterValue = filter.toString().toLowerCase(); - return value.toString().toLowerCase().indexOf(filterValue, value.toString().length - filterValue.length) !== -1; - } - - static equals(value, filter) { - if(filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { - return true; - } - - if(value === undefined || value === null) { - return false; - } - - return value.toString().toLowerCase() === filter.toString().toLowerCase(); - } - - static notEquals(value, filter) { - if(filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { - return false; - } - - if(value === undefined || value === null) { - return true; - } - - return value.toString().toLowerCase() !== filter.toString().toLowerCase(); - } - - static in(value, filter) { - if(filter === undefined || filter === null || filter.length === 0) { - return true; - } - - if(value === undefined || value === null) { - return false; - } - - for(let i = 0; i < filter.length; i++) { - if(filter[i] === value) - return true; - } - - return false; - } -} diff --git a/src/components/utils/ObjectUtils.js b/src/components/utils/ObjectUtils.js index 880013c6a..29c76126d 100644 --- a/src/components/utils/ObjectUtils.js +++ b/src/components/utils/ObjectUtils.js @@ -1,7 +1,7 @@ export default class ObjectUtils { - + static equals(obj1, obj2, field) { - if(field) + if (field) return (this.resolveFieldData(obj1, field) === this.resolveFieldData(obj2, field)); else return this.deepEquals(obj1, obj2); @@ -56,16 +56,16 @@ export default class ObjectUtils { return a !== a && b !== b; } - + static resolveFieldData(data, field) { - if(data && field) { - if(field.indexOf('.') === -1) { + if (data && field) { + if (field.indexOf('.') === -1) { return data[field]; } else { let fields = field.split('.'); let value = data; - for(var i = 0, len = fields.length; i < len; ++i) { + for (var i = 0, len = fields.length; i < len; ++i) { value = value[fields[i]]; } return value; @@ -76,12 +76,12 @@ export default class ObjectUtils { } } static filter(value, fields, filterValue) { - var filteredItems=[]; + var filteredItems = []; - if(value) { - for(let item of value) { - for(let field of fields) { - if(String(this.resolveFieldData(item, field)).toLowerCase().indexOf(filterValue.toLowerCase()) > -1) { + if (value) { + for (let item of value) { + for (let field of fields) { + if (String(this.resolveFieldData(item, field)).toLowerCase().indexOf(filterValue.toLowerCase()) > -1) { filteredItems.push(item); break; } @@ -94,29 +94,29 @@ export default class ObjectUtils { static reorderArray(value, from, to) { let target; - if(value && (from !== to)) { - if(to >= value.length) { + if (value && (from !== to)) { + if (to >= value.length) { target = to - value.length; - while((target--) + 1) { + while ((target--) + 1) { value.push(undefined); } } value.splice(to, 0, value.splice(from, 1)[0]); } } - + static findIndexInList(value, list) { let index = -1; - - if(list) { - for(let i = 0; i < list.length; i++) { - if(list[i] === value) { + + if (list) { + for (let i = 0; i < list.length; i++) { + if (list[i] === value) { index = i; break; } } } - + return index; } @@ -130,4 +130,86 @@ export default class ObjectUtils { return false; } + + static filterConstraints = { + + startsWith(value, filter) { + if (filter === undefined || filter === null || filter.trim() === '') { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + let filterValue = filter.toLowerCase(); + return value.toString().toLowerCase().slice(0, filterValue.length) === filterValue; + }, + + contains(value, filter) { + if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + return value.toString().toLowerCase().indexOf(filter.toLowerCase()) !== -1; + }, + + endsWith(value, filter) { + if (filter === undefined || filter === null || filter.trim() === '') { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + let filterValue = filter.toString().toLowerCase(); + return value.toString().toLowerCase().indexOf(filterValue, value.toString().length - filterValue.length) !== -1; + }, + + equals(value, filter) { + if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + return value.toString().toLowerCase() === filter.toString().toLowerCase(); + }, + + notEquals(value, filter) { + if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { + return false; + } + + if (value === undefined || value === null) { + return true; + } + + return value.toString().toLowerCase() !== filter.toString().toLowerCase(); + }, + + in(value, filter) { + if (filter === undefined || filter === null || filter.length === 0) { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + for (let i = 0; i < filter.length; i++) { + if (filter[i] === value) + return true; + } + + return false; + } + } } \ No newline at end of file