Optimize gulp

This commit is contained in:
Andros Fenollosa 2020-07-04 16:57:28 +02:00
parent a37579c06a
commit ec4566e023
7 changed files with 118 additions and 1357 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ test.html
node_modules/ node_modules/
dist/ffnm.min.js.map dist/ffnm.min.js.map
package-lock.json package-lock.json
dist/.DS_Store

View File

@ -16,7 +16,7 @@ Simple plugin to avoid writing Javascript in trivial tasks.
Añade a tu `<head>` la siguiente etiqueta. Añade a tu `<head>` la siguiente etiqueta.
```html ```html
<script defer src="https://cdn.jsdelivr.net/gh/tanrax/FFNM@v1.0.0/ffnm.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/tanrax/FFNM@v1.0.0/ffnm.min.js"></script>
``` ```
### Ejemplos de uso ### Ejemplos de uso

2
dist/ffnm.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -2,9 +2,8 @@
// IMPORTS // IMPORTS
//=== //===
const { series, parallel, src, dest, watch } = require('gulp'); const { series, parallel, src, dest, watch } = require('gulp');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps'); const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify'); const uglify = require('gulp-uglify-es').default;
const concat = require('gulp-concat'); const concat = require('gulp-concat');
//=== //===
@ -23,9 +22,6 @@ function js(cb) {
return src([SRC_PATH + 'core.js']) return src([SRC_PATH + 'core.js'])
.pipe(sourcemaps.init()) .pipe(sourcemaps.init())
.pipe(concat(DIST_JS)) .pipe(concat(DIST_JS))
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify()) .pipe(uglify())
.pipe(sourcemaps.write('.')) .pipe(sourcemaps.write('.'))
.pipe(dest(DIST_PATH)); .pipe(dest(DIST_PATH));

1370
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -22,5 +22,8 @@
"bugs": { "bugs": {
"url": "https://github.com/tanrax/FFNM/issues" "url": "https://github.com/tanrax/FFNM/issues"
}, },
"homepage": "https://github.com/tanrax/FFNM#readme" "homepage": "https://github.com/tanrax/FFNM#readme",
"devDependencies": {
"gulp-uglify-es": "^2.0.0"
}
} }

View File

@ -1,48 +1,55 @@
document.addEventListener('DOMContentLoaded', () => {
//=== //===
// VARIABLES // VARIABLES
//=== //===
const EVENTS = ['i-click', 'i-view', 'i-scroll-up', 'i-scroll-down', 'i-hover']; const EVENTS = ['i-click', 'i-view', 'i-scroll-up', 'i-scroll-down', 'i-hover'];
const FUNCTION_TREE = { const FUNCTION_TREE = {
'class': ['add', 'remove', 'toggle'] 'class': ['add', 'remove', 'toggle']
}; };
let elementsValidates = [];
//=== //===
// FUNCTIONS // FUNCTIONS
//=== //===
function validateSyntax() { /**
* Method that validates syntax and reports.
* return - Bool
*/
function validateSyntax() {
elementsValidates = [];
// Check all event syntax
return EVENTS.map((event) => {
// Check element FUNCTION_TREE
return [...document.querySelectorAll(`[${event}]`)].map((element) => {
// Check KEY FUNCTION_TREE
let checked = Object.keys(FUNCTION_TREE).map((key) => {
// Check METHODS FUNCTION_TREE
return FUNCTION_TREE[key].map((method) => {
return RegExp(`^${key}:${method}\\('\\w+', *'[#,.,a-zA-Z]\\w*'\\)$`).test(element.getAttribute(event));
}).some(method => method);
}).every(key => key);
if(checked) {
// Save element validate
elementsValidates.push(element);
} else {
// Notify error
console.error('FFNM: Bad syntax');
console.error(element);
}
return checked;
}).every(item => item);
}).every(event => event);
}
// Get every items from EVENTS function addEventClick() {
}
// Check all event syntax
return EVENTS.map((event) => {
// Check element FUNCTION_TREE
return [...document.querySelectorAll(`[${event}]`)].map((element) => {
// Check KEY FUNCTION_TREE
let checked = Object.keys(FUNCTION_TREE).map((key) => {
// Check METHODS FUNCTION_TREE
return FUNCTION_TREE[key].map((method) => {
return RegExp(`^${key}:${method}\\('\\w+', *'[#,.,a-zA-Z]\\w*'\\)$`).test(element.getAttribute(event));
}).some(method => method);
}).every(key => key);
// Notify error
if(!checked) {
console.error('FFNM: Bad syntax');
console.error(element);
}
return checked;
}).every(item => item);
}).every(event => event);
}
//=== //===
// LINTER // INIT
//=== //===
validateSyntax();
//=== });
// INIT
//===
console.log("EStabien " + validateSyntax());