Optimize gulp
This commit is contained in:
parent
a37579c06a
commit
ec4566e023
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ test.html
|
||||
node_modules/
|
||||
dist/ffnm.min.js.map
|
||||
package-lock.json
|
||||
dist/.DS_Store
|
||||
|
@ -16,7 +16,7 @@ Simple plugin to avoid writing Javascript in trivial tasks.
|
||||
Añade a tu `<head>` la siguiente etiqueta.
|
||||
|
||||
```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
|
||||
|
2
dist/ffnm.min.js
vendored
2
dist/ffnm.min.js
vendored
File diff suppressed because one or more lines are too long
@ -2,9 +2,8 @@
|
||||
// IMPORTS
|
||||
//===
|
||||
const { series, parallel, src, dest, watch } = require('gulp');
|
||||
const babel = require('gulp-babel');
|
||||
const sourcemaps = require('gulp-sourcemaps');
|
||||
const uglify = require('gulp-uglify');
|
||||
const uglify = require('gulp-uglify-es').default;
|
||||
const concat = require('gulp-concat');
|
||||
|
||||
//===
|
||||
@ -23,9 +22,6 @@ function js(cb) {
|
||||
return src([SRC_PATH + 'core.js'])
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(concat(DIST_JS))
|
||||
.pipe(babel({
|
||||
presets: ['@babel/env']
|
||||
}))
|
||||
.pipe(uglify())
|
||||
.pipe(sourcemaps.write('.'))
|
||||
.pipe(dest(DIST_PATH));
|
||||
|
1370
package-lock.json
generated
1370
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -22,5 +22,8 @@
|
||||
"bugs": {
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
89
src/core.js
89
src/core.js
@ -1,48 +1,55 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
//===
|
||||
// VARIABLES
|
||||
//===
|
||||
const EVENTS = ['i-click', 'i-view', 'i-scroll-up', 'i-scroll-down', 'i-hover'];
|
||||
const FUNCTION_TREE = {
|
||||
'class': ['add', 'remove', 'toggle']
|
||||
};
|
||||
//===
|
||||
// VARIABLES
|
||||
//===
|
||||
const EVENTS = ['i-click', 'i-view', 'i-scroll-up', 'i-scroll-down', 'i-hover'];
|
||||
const FUNCTION_TREE = {
|
||||
'class': ['add', 'remove', 'toggle']
|
||||
};
|
||||
let elementsValidates = [];
|
||||
|
||||
//===
|
||||
// FUNCTIONS
|
||||
//===
|
||||
function validateSyntax() {
|
||||
//===
|
||||
// FUNCTIONS
|
||||
//===
|
||||
/**
|
||||
* 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
|
||||
|
||||
// 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);
|
||||
}
|
||||
function addEventClick() {
|
||||
}
|
||||
|
||||
|
||||
//===
|
||||
// LINTER
|
||||
//===
|
||||
//===
|
||||
// INIT
|
||||
//===
|
||||
validateSyntax();
|
||||
|
||||
|
||||
//===
|
||||
// INIT
|
||||
//===
|
||||
console.log("EStabien " + validateSyntax());
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user