Add ramda and gulpfile

This commit is contained in:
Andros Fenollosa 2020-07-02 10:40:34 +02:00
parent f4f1ea6572
commit 6ad8220681
8 changed files with 4302 additions and 70 deletions

2
.gitignore vendored
View File

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

View File

@ -84,14 +84,20 @@ class:toggle('show', '#menu')
## Development ## Development
### Install
```javascript
npm i
```
### Build ### Build
```javascript ```javascript
tsc --outFile dist/ffnm.min.js src/core.ts gulp
``` ```
### Watch mode ### Watch mode
```javascript ```javascript
tsc --watch --outFile dist/ffnm.min.js src/core.ts gulp dev
``` ```

33
dist/ffnm.min.js vendored

File diff suppressed because one or more lines are too long

52
gulpfile.js Normal file
View File

@ -0,0 +1,52 @@
//===
// 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 concat = require('gulp-concat');
//===
// VARIABLES
//===
const SRC_PATH = 'src/';
const DIST_PATH = 'dist/';
const DIST_JS = 'ffnm.min.js';
const SRC_JS_VENDORS = [
'./node_modules/ramda/dist/ramda.min.js'
];
//===
// TASKS
//===
// JS concat + sourcemaps + babel + min
function js(cb) {
return src(SRC_JS_VENDORS.concat([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));
}
//===
// Commands
//===
const build = series(js);
// gulp dev
exports.dev = function () {
build();
watch(SRC_PATH + '*.js', js);
}
// gulp
exports.default = build;

4179
package-lock.json generated

File diff suppressed because it is too large Load Diff

31
package.json Normal file
View File

@ -0,0 +1,31 @@
{
"name": "ffnm",
"version": "1.0.0",
"description": "Simple plugin to avoid writing Javascript in trivial tasks.",
"main": "gulpfile.js",
"dependencies": {
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-concat": "^2.6.1",
"gulp-sourcemaps": "^2.6.5",
"gulp-uglify": "^3.0.2",
"ramda": "^0.27.0"
},
"devDependencies": {
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tanrax/FFNM.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/tanrax/FFNM/issues"
},
"homepage": "https://github.com/tanrax/FFNM#readme"
}

32
src/core.js Normal file
View File

@ -0,0 +1,32 @@
//===
// VARIABLES
//===
const EVENTS = ['i-click', 'i-scroll-up', 'i-scroll-down', 'i-hover'];
//===
// FUNCTIONS
//===
function validateSyntax() {
// Get every items from EVENTS
// Check all event syntax
return EVENTS.map((event) => {
return R.map((element) => {
console.log(element.getAttribute(event));
return /^${event}/.test(element.getAttribute(event));
}, document.querySelectorAll(`[${event}]`)).every(item => item);
}).every(event => event);
}
//===
// LINTER
//===
//===
// INIT
//===
validateSyntax();

View File

@ -1,33 +0,0 @@
//===
// VARIABLES
//===
enum EVENTS {'i-click', 'i-scroll-up', 'i-scroll-down', 'i-hover'}
//===
// FUNCTIONS
//===
function validateSyntax(): boolean {
// Get every items from EVENTS
let eventsKeys: string[] = R.filter(key => !isNaN(Number(EVENTS[key])), Object.keys(EVENTS));
// Check all event syntax
return eventsKeys.map((event) => {
return R.map((element) => {
console.log(element.getAttribute(event))
return /^${event}/.test(element.getAttribute(event))
}, document.querySelectorAll(`[${event}]`)).every(item => item)
}).every(event => event)
}
//===
// LINTER
//===
//===
// INIT
//===
validateSyntax()