Skip to content

Commit

Permalink
Merge pull request #40 from gre/cli
Browse files Browse the repository at this point in the history
Fix use in Node and Better CLI support
  • Loading branch information
Siorki committed Feb 15, 2016
2 parents 35f05a5 + 021cc9c commit e0fff7f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 74 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ The current version works in six stages :
- *(if enabled)* variables are renamed in order to reduce character footprint and free tokens for compression.
- *(if enabled)* Initialization code is pushed inside the main loop, with conditional execution on the time variable, so that the unpacker can execute everything through ``setInterval()``
- redundancies are eliminated and replaced by tokens, as done by JS Crush (by Aivo Paas) and First Crush (by Tim Down).
- the token list is turned into a regular expression consisting in a character class.
- the token list is turned into a regular expression consisting in a character class.
- the tokens are rearranged to create a negated character class (starting with a hyphen ^ then listing nontoken characters)

The text boxes show intermediate stage results. Best one gets a green highlight :
- Preprocessed : after the first three stages. Hidden if no change was brought to the initial code.
- Crushed : after the fourth stage
- RegPack'ed : best between last two stages. Depends on how the characters present in the string are spread in the ASCII table.

--
## Usage tips
## Usage tips

- Toggle method hashing for any type of context you use. If the method renaming yields a longer code, RegPack will revert to the original one.
- "Assume global .. is a context" is for environments where the canvas is declared before your code. If entering [js1k](http://www.js1k.com), keep this on, variable is c for classic and g for webgl.
Expand All @@ -25,11 +25,20 @@ The text boxes show intermediate stage results. Best one gets a green highlight
- Some preprocessing options negatively affect the performance and should be used with caution. Always test your packed code for speed after using these.
- "Encapsulate with(Math)" get rid of all "Math." references in the code and enclose the evaluation with(Math).
- "run with setInterval()" executes the unpacked code with ``setInterval()`` instead of ``eval()`` (meaning the evaluation is performed every frame).

[Use it online](http://siorki.github.io/regPack.html) or integrate it into your Node workflow (thanks to kanaka)

## CLI usage

```
npm install # to install minimist module for command line parsing
node ./regPack.js input.js --crushGainFactor 1 --crushLengthFactor 0 --crushCopiesFactor 0 > output.js
regpack input.js > output.js
regpack input.js --crushGainFactor 1 --crushLengthFactor 0 --crushCopiesFactor 0 > output.js
```

From STDIN

```
cat input.js | regpack - > output.js
```

--
Expand All @@ -48,7 +57,7 @@ Licensed under [MIT license](http://opensource.org/licenses/mit-license.html).
Code produced by RegPack, including the hashing (if included) and unpacking routines, is not affected by the license. No restriction to its usage or redistribution arise from its compression by RegPack.

--

Any feedback or improvement suggestions appreciated. Contributions welcome.

@Siorki on Twitter
21 changes: 21 additions & 0 deletions bin/regpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env node

const cmdRegPack = require('..').cmdRegPack;
var argv = require('minimist')(process.argv.slice(2));
var input = argv._[0];

if (input != '-') {
result = cmdRegPack(require('fs').readFileSync(input, 'utf-8'), argv);
console.log(result);
} else {
process.stdin.resume();
process.stdin.setEncoding('utf8');
var buffer = '';
process.stdin.on('data', function(data) {
buffer += data;
});
process.stdin.on('end', function() {
result = cmdRegPack(buffer, argv);
console.log(result);
});
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "4.0.0",
"description": "A packer intended for use on minified Javascript code",
"main": "regPack.js",
"bin": {
"regpack": "bin/regpack"
},
"homepage": "https://github.com/Siorki/RegPack",
"dependencies": {
"minimist": "1.1.0"
Expand Down
Loading

0 comments on commit e0fff7f

Please sign in to comment.