Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SonoIo committed Jun 22, 2016
2 parents dd258a4 + 3e6bd60 commit e59821b
Show file tree
Hide file tree
Showing 35 changed files with 1,879 additions and 60 deletions.
166 changes: 163 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,171 @@
# EVE - Command line tool

Eve is a super simple command line tool for create HTML5 applications. It compiles into a single bundle JS library and module with Browseryfy.

## Install

```
$ npm install eve
$ npm install -g node-eve
```

## Usage

```
Usage: eve [options] [command]
Commands:
init [name] Crea il template di una app
build [options] [type] [unit] Compila l'applicazione
start [options] Esegue l'applicazione
test [options] <unit> Testa l'applicazione
extract [options] Estrae le stringhe dall'applicazione e le restituisce in un file per la traduzione
prepare <section> Util for prepare a section
Options:
-h, --help output usage information
-V, --version output the version number
```


### eve init [name]

```
$ eve init myapp
```

Initialize an application structure.


### eve build [type] [unit]

```
$ eve build // Alias of ...
$ eve build dev // Compile application of type development. Also provide source map file.
$ eve build dist // Compile application of type production. The code is minified.
$ eve build pub // Compile application of type production. The code is minified and, optionally, obfuscated with jScramble.
```

### eve start

```
$ eve start
```

This comand compile the application each time a file is changed. Eve is listening folders:

- `templates`
- `locales`
- `lib`
- `test`
- `styles`

Also it starts a web server, so as to allow the application display in browser. The default port is `5000` but if you change it run the command

```
$ eve start -p 5001
```


### eve test

```
$ eve test ModuleName
```

### eve extract

```
$ eve extract -d ./myapp/ -o ./myapp/file.json
```

Generate file for translations strings. File oupts are `po`, `json` or `txt`. More informations read the documentation of [ets] (https://github.com/vash15/extract-translate-string).


## Packege.json of your app

```
{
"name": "{{APP_NAME}}",
"version": "1.0.0",
"description": "",
"author": "",
"license": "",
"main": "./lib/app.js",
"scripts": {
"start": "eve start"
},
"eve-language": "es6",
"eve-version": "2.0.0",
"eve-configs-developement": {},
"eve-configs-production": {},
"eve-configs": {}
}
```

### eve-language

Identify the language of the source code. Possible values: `js`, `es6` (default is `js`). [Babelify](https://github.com/babel/babelify) is used.

### eve-version (not implemented yet)

Check the version of eve required by the project.

### eve-configs-developement

Punt into object the variables for developement mode.

### eve-configs-production

Punt into object the variables for production mode.

### eve-configs

The object is generated based on the compilation mode (`development` or `production`). Into your app require this object for read the variables.


## Tips & Tricks

### File limit

If `EMFILE` file error is triggered use the command `ulimit -n 2048` to fix it.

### Set environment variables on Windows

To set environment variables in Windows use the tool from ***System in Control Panel*** (or by typing `environment` into the search box in start menu). For more details read this discussion on [Stackoverflow](http://stackoverflow.com/a/9250168).

### Set environment variables on Linux or Mac


```
`nano ~/.profile`
export JSCRAMBLER_ACCESSKEY=<MY KEY>
export JSCRAMBLER_SECRETKEY=<MY SECRET>
```

## File limit

If `EMFILE` file is triggered use the command `ulimit -n 2048` to fix it.

## LICENSE

The MIT License (MIT)

Copyright (c) 2015

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.
8 changes: 8 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Release notes

## 2.0.0

- Added support to ES6
- Added new package.json `eve-language`
- Removed `eve-components`
149 changes: 118 additions & 31 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,105 @@

var _ = require('underscore');
var exorcist = require('exorcist')
var browserify = require('browserify');
var fs = require('fs');
var path = require('path');
var UglifyJS = require('uglify-js');
var jScrambler = require('jscrambler');
var colors = require('colors');
var unzip = require('unzip');

module.exports = function(type, unit, options, done) {

module.exports = function(mode, unit, done) {
var time = process.hrtime();
var pkg = require(path.resolve('package.json'));
if ( _.isFunction(options) ){
done = options;
options = {};
}

var time = process.hrtime();
var mode = options.mode || 'mobile';
var packageJSONFile = path.resolve('package.json')
var pkg = require(packageJSONFile);

if ( !pkg['eve-configs'] )
pkg['eve-configs'] = {};

type = type || 'dev';
var configs = pkg['eve-configs'];
var language = pkg['eve-language'] || 'js';
var isForPublish = false;
var entryJsFile = path.join('lib', 'app.js');
var outputJsFile = path.join('build', 'assets', 'js', 'bundle.js');

mode = mode || 'dev';
var components = pkg['eve-components'] || [];
var entryJsFile;
var outputJsFile;
var mapFile;
var debug;

switch (mode) {
switch (type) {
case 'dist':
case 'dev':
entryJsFile = path.join('lib', 'app.js');
outputJsFile = path.join('build', 'assets', 'js', 'bundle.js');
debug = mode === 'dev';
debug = type === 'dev';
configs.env = debug ? 'development' : 'production';
break;
case 'test':
entryJsFile = path.join('test', unit, 'app.js');
entryJsFile = path.join('test', unit, 'app.js');
outputJsFile = path.join('test', unit, 'bundle.js');
debug = true;
configs.env = 'development';
break;
case 'pub':
isForPublish = true;
configs.env = 'production';
break;
default:
return done(new Error('Unknown mode ' + mode));
return done(new Error('Unknown type ' + type));
}

if ( _.isObject( pkg[ "eve-configs-" + configs.env ] ) ) {
_.extend( pkg[ "eve-configs" ], pkg[ "eve-configs-" + configs.env ] );
}

// Update new package json
fs.writeFileSync(packageJSONFile , JSON.stringify(pkg, null, 4));

mapFile = outputJsFile + '.map';

var b = browserify({ debug: debug });
b.transform('brfs', {
if (language === 'es6') {
b.transform('babelify', {
basedir: path.resolve(__dirname, "node_modules"),
presets: ['es2015'],
sourceMapsAbsolute: true,
only: ['lib']
});
}
b.transform('browserify-shim', {
basedir: path.resolve(__dirname, "node_modules")
});

components.forEach(function (aComponent) {
b.require(path.resolve(aComponent.path), aComponent.options);
b.transform('node-underscorify', {
basedir: path.resolve(__dirname, "node_modules")
});
b.transform('debowerify', {
basedir: path.resolve(__dirname, "node_modules")
});

b.require(path.resolve(entryJsFile), { entry: true } );
b.require(path.resolve(entryJsFile), { entry: true });

b.bundle(function (err, buf) {
if (err) return done(err);
done(null, beautifyTime(process.hrtime(time)), mode);
done(null, beautifyTime(process.hrtime(time)), type);
})
.on("end", function() {
if ( !debug ){
setTimeout(function(){
var src = fs.readFileSync( outputJsFile, { encoding: 'utf8'} ); // buf.toString('utf8');
var srcMinify = UglifyJS.minify(
src,
{
fromString: true
}
);
if ( !debug ) {
setTimeout(function() {
var src = fs.readFileSync( outputJsFile, { encoding: 'utf8'} );
var srcMinify = UglifyJS.minify( src, { fromString: true });

if ( srcMinify ) {
fs.writeFileSync(outputJsFile, srcMinify.code );
fs.writeFileSync(outputJsFile, srcMinify.code);

if ( isForPublish )
publisher(outputJsFile, mode, done);

} else {
done(new Error('Minify error'));
}
Expand All @@ -77,7 +114,7 @@ module.exports = function(mode, unit, done) {
.pipe(fs.createWriteStream(outputJsFile, 'utf8'));


function beautifyTime(diff) {
function beautifyTime(diff) {
var out = '';
if (diff[0] > 0) {
out += diff[0];
Expand All @@ -91,4 +128,54 @@ module.exports = function(mode, unit, done) {
};


}
function publisher(outputJsFile, mode, done){
setTimeout(function(){

// jScrambler
var accessKey = process.env.JSCRAMBLER_ACCESSKEY;
var secretKey = process.env.JSCRAMBLER_SECRETKEY;
if ( accessKey && secretKey ){

console.log(' Obfuscating code with jScrambler...'.gray);
var time = process.hrtime();
var client = new jScrambler.Client({keys: {accessKey: accessKey,secretKey: secretKey}});
jScrambler
.uploadCode(client, {
files: [ outputJsFile ],
mode: mode,
remove_comments: '%DEFAULT%',
rename_local: '%DEFAULT%',
whitespace: '%DEFAULT%',
literal_hooking: '20;50',
self_defending: '%DEFAULT%'
})
.then(function (res) {
return jScrambler.downloadCode(client, res.id);
})
.then(function (res) {
//
var zipFile = outputJsFile+'.zip';
fs.writeFileSync(zipFile, res);
fs.unlinkSync(outputJsFile);

fs.createReadStream(zipFile)
.pipe(unzip.Extract({ path: path.join('.') }))
.on('close', function(){
fs.unlinkSync(zipFile);
console.log(' Operation completed in '.gray+beautifyTime(process.hrtime(time)).green);
});

return true;
})
.catch(function (error) {
done(new Error(error && error.message ? 'jScrambler... ' + error.message : 'Error while obfuscating the code with jScrambler' ) );
});
}
else {
done(new Error('Set JSCRAMBLER_ACCESSKEY and JSCRAMBLER_SECRETKEY on your .profile'));
}

}, 1000);
}

}
Loading

0 comments on commit e59821b

Please sign in to comment.