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,3 +1,4 @@
document.addEventListener('DOMContentLoaded', () => {
//=== //===
// VARIABLES // VARIABLES
@ -6,14 +7,17 @@ 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
//=== //===
/**
* Method that validates syntax and reports.
* return - Bool
*/
function validateSyntax() { function validateSyntax() {
elementsValidates = [];
// Get every items from EVENTS
// Check all event syntax // Check all event syntax
return EVENTS.map((event) => { return EVENTS.map((event) => {
// Check element FUNCTION_TREE // Check element FUNCTION_TREE
@ -25,24 +29,27 @@ function validateSyntax() {
return RegExp(`^${key}:${method}\\('\\w+', *'[#,.,a-zA-Z]\\w*'\\)$`).test(element.getAttribute(event)); return RegExp(`^${key}:${method}\\('\\w+', *'[#,.,a-zA-Z]\\w*'\\)$`).test(element.getAttribute(event));
}).some(method => method); }).some(method => method);
}).every(key => key); }).every(key => key);
if(checked) {
// Save element validate
elementsValidates.push(element);
} else {
// Notify error // Notify error
if(!checked) {
console.error('FFNM: Bad syntax'); console.error('FFNM: Bad syntax');
console.error(element); console.error(element);
} }
return checked; return checked;
}).every(item => item); }).every(item => item);
}).every(event => event); }).every(event => event);
} }
function addEventClick() {
//=== }
// LINTER
//===
//=== //===
// INIT // INIT
//=== //===
console.log("EStabien " + validateSyntax()); validateSyntax();
});