Skip to content

Commit

Permalink
Adding gulp plugin for pumascript
Browse files Browse the repository at this point in the history
  • Loading branch information
albertinad committed Nov 29, 2016
1 parent 8a6f81f commit 4d87885
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"rules": {
"curly": 2,
"eqeqeq": 2,
"no-caller": 2,
"no-empty": 0,
"no-new": 2,
"no-invalid-regexp": 2,
"no-control-regex": 2,
"no-regex-spaces": 2,
"no-undef": 2,
"strict": 2,
"no-unused-vars": [0, {
"vars": "all",
"args": "none"
}],
"semi": 2,
"no-new-object": 2,
"indent": [0, 4],
"valid-jsdoc": 2,
"no-trailing-spaces": 2,
"eol-last": 0,
"max-len": [1, 120]
},
"globals": {
"require": false,
"console": false,
"module": false
}
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Dependencies and configuration files
**/node_modules/
npm-debug.log
.idea
.DS_Store

# Auto-generated folders
dest/
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Test folder
tests/

# Configuration and tasks files
.eslintrc.json
.travis.yml
gulpfile.js

# Auto-generated folder
dest/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 - present UTN-LIS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# gulp-puma
# gulp-puma

Grunt plugin that runs PumaScript on any JavaScript file.
12 changes: 12 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2016 - present UTN-LIS

'use strict';

var gulp = require('gulp'),
puma = require('./');

gulp.task('default', function () {
return gulp.src('tests/files/*')
.pipe(puma('test.zip'))
.pipe(gulp.dest('dest/output.js'));
});
45 changes: 45 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2016 - present UTN-LIS

'use strict';

var path = require('path'),
gulpUtil = require('gulp-util'),
through = require('through2'),
puma = require('pumascript');

module.exports = function (fileName) {
if (!fileName) {
throw new gulpUtil.PluginError('gulp-puma', gulpUtil.colors.green('fileName') + ' required');
}

var firstFile,
content = '';

return through.obj(function (file, enc, cb) {
if (!firstFile) {
firstFile = file;
}

content += file.contents.toString();

cb();
}, function (cb) {
if (!firstFile) {
cb();
return;
}

var result = puma.evalPuma(content);

gulpUtil.log('PumaScript run successful');

this.push(new gulpUtil.File({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, 'result.js'),
contents: new Buffer(result.output)
}));

cb();
});
};
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "gulp-puma",
"version": "0.0.1",
"description": "Gulp plugin that runs PumaScript on any JavaScript file",
"repository": {
"type": "git",
"url": "pumascript/gulp-puma.git"
},
"bugs": {
"url": "https://github.com/pumascript/gulp-puma/issues"
},
"author": {
"name": "PumaScript Team",
"url": "http://github.com/pumascript/gulp-puma"
},
"keywords": [
"gulp",
"gulpplugin",
"gulp task",
"task",
"optimization",
"meta-programming",
"metaprogramming",
"ecma",
"ecmascript",
"javascript",
"puma",
"pumascript"
],
"main": "index.js",
"engines": {
"node": ">= 0.8.0"
},
"license": "MIT",
"dependencies": {
"pumascript": "^0.1.0",
"gulp-util": "^3.0.0",
"through2": "^2.0.0"
},
"devDependencies": {
"gulp": "^3.9.1"
}
}
44 changes: 44 additions & 0 deletions tests/files/puma-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2016 - present UTN-LIS

var PUMA_FORCE_REWRITE = true;

/* @meta */
function $(valueExp) {
//Regular Expression for ID
var regex = /^#\b[a-zA-Z0-9_]+\b$/;
var copy = {};
var ast = {};

//Evaluation if not a literal
if (valueExp !== "Literal") {
copy = evalPumaAst(valueExp).value;
}

if (regex.test(copy) && PUMA_FORCE_REWRITE) {
return pumaAst($(getElementById($valueExp)));
} else if (regex.test(valueExp.value)) {
valueExp.value = valueExp.value.substring(1);
return pumaAst($(getElementById($valueExp)));
}
return null;
}

// Tests

//Add a class in runtime so it does not need to re-write
var t = " .pepe";

//Context evaluation
var a = function () {
var name = "puma";
$("#" + name + t);
}();

//Re-write because it returns a string
var j = "ma";

//Context evaluation
var b = function () {
var name = "pu";
$("#" + name + j);
}();
44 changes: 44 additions & 0 deletions tests/files/puma-test2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2016 - present UTN-LIS

var PUMA_FORCE_REWRITE = true;

/* @meta */
function $(valueExp) {
//Regular Expression for ID
var regex = /^#\b[a-zA-Z0-9_]+\b$/;
var copy = {};
var ast = {};

//Evaluation if not a literal
if (valueExp !== "Literal") {
copy = evalPumaAst(valueExp).value;
}

if (regex.test(copy) && PUMA_FORCE_REWRITE) {
return pumaAst($(getElementById($valueExp)));
} else if (regex.test(valueExp.value)) {
valueExp.value = valueExp.value.substring(1);
return pumaAst($(getElementById($valueExp)));
}
return null;
}

// Tests

//Add a class in runtime so it does not need to re-write
var t = " .paco";

//Context evaluation
var a = function () {
var name = "puma";
$("#" + name + t);
}();

//Re-write because it returns a string
var j = "ma";

//Context evaluation
var b = function () {
var name = "pu";
$("#" + name + j);
}();

0 comments on commit 4d87885

Please sign in to comment.