Merge branch 'feature-using-webpack'

This commit is contained in:
Micooz 2017-08-08 14:50:14 +08:00
commit 20ae64ee40
53 changed files with 1167 additions and 84 deletions

4
.gitignore vendored

@ -19,5 +19,7 @@ coverage/
# others
blinksocks*.json
blinksocks*.js
blinksocks.client.js
blinksocks.server.js
blinksocks*.log
/build/blinksocks.js.map

@ -26,44 +26,49 @@ and [ShadowsocksR](https://github.com/shadowsocksr/shadowsocksr).
For desktop use, you can download official [blinksocks-desktop](https://github.com/blinksocks/blinksocks-desktop),
a cross-platform GUI for blinksocks.
## Quick Start
## Getting Started
### Requirements
blinksocks is built on top of [Node.js](https://nodejs.org), so please install Node.js(**greater than v6.x**) on your operating system.
### Install or Upgrade
You can get the latest pre-compiled library(including executables) of blinksocks from **yarn** or **npm**.
> NOTE: Node.js comes with npm installed so you don't have to install npm individually.
```
$ npm install -g blinksocks
```
### Without Install?
If you hate to install and want to get a even more portable version, we have one:
```
$ wget https://raw.githubusercontent.com/blinksocks/blinksocks/master/build/blinksocks.js
```
## Run blinksocks
```
$ blinksocks client -c blinksocks.client.js
```
```js
// blinksocks.client.js
module.exports = {
host: "localhost",
port: 1080,
servers: [{
enabled: true,
transport: 'tcp',
host: "bs.example.com",
port: 6858,
key: "qtPb2edK7yd7e]<K",
presets: [
{name: "ss-base", params: {}},
{name: "ss-aead-cipher", params: {method: "aes-256-gcm", info: "ss-subkey"}}
]
}],
dns: ['8.8.8.8'],
timeout: 600,
profile: false,
watch: true,
log_level: "info"
};
Or
```
$ node blinksocks.js -c blinksocks.client.js
```
## Documents
### For Users
1. [Getting Started](docs/tutorials)
2. [Usage](docs/usage)
3. [Configuration](docs/config)
4. [Presets](docs/presets)
1. [Usage](docs/usage)
2. [Configuration](docs/config)
3. [Presets](docs/presets)
### For Developers

@ -2,5 +2,5 @@ if (process.env.NODE_ENV === 'development') {
require('babel-register');
module.exports = require('../src');
} else {
module.exports = require('../lib');
module.exports = require('../build');
}

8
build/blinksocks.js Normal file

File diff suppressed because one or more lines are too long

@ -2,10 +2,9 @@
## For Users
1. [Getting Started](tutorials)
2. [Usage](usage)
3. [Configuration](config)
4. [Presets](presets)
1. [Usage](usage)
2. [Configuration](config)
3. [Presets](presets)
## For Developers

@ -160,7 +160,7 @@ npm logging levels by default, you can choose one of them demand:
## Hot reload
`--watch` is enabled by default, this means when file specified by `-c` or `--config` has been modified,
`watch` is enabled by default, this means when file specified by `-c` or `--config` has been modified,
blinksocks will hot-reload it without stop-the-world.
```

@ -1,28 +0,0 @@
# Getting Started
## Requirements
blinksocks is built on top of [Node.js](https://nodejs.org), so please install Node.js(**greater than v6.x**) properly
on your operating system.
## Install
You can get pre-compiled library(including executables) of blinksocks from **yarn** or **npm**.
> NOTE: Node.js comes with npm installed so you don't have to install npm individually.
```
$ npm install -g blinksocks
```
## Upgrade
Simply install it again then you will get the latest stable version of blinksocks:
```
$ npm install -g blinksocks
```
## Where to go next
At this point, you have successfully installed blinksocks. Now, please check out [usage](../usage).

@ -5,7 +5,7 @@
"main": "lib/index.js",
"files": [
"bin",
"lib",
"build",
"AUTHORS"
],
"bin": {
@ -38,17 +38,21 @@
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.24.1",
"babili-webpack-plugin": "^0.1.2",
"cross-env": "^5.0.4",
"eslint": "^4.3.0",
"eslint-config-babel": "^7.0.1",
"eslint-loader": "^1.9.0",
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-flowtype": "^2.35.0",
"husky": "^0.14.3",
"jest": "^20.0.4"
"jest": "^20.0.4",
"webpack": "^3.4.1"
},
"repository": {
"url": "https://github.com/blinksocks/blinksocks",

@ -1 +1,38 @@
export * from './core';
import fs from 'fs';
import path from 'path';
import * as __modules__ from './core';
// only for webpack bundle
if (global.__WEBPACK__) {
const argv = process.argv;
const usage = 'Usage: node blinksocks.js -c/--config <json_file>';
const conditions = [
argv.length !== 4,
(argv[2] !== '-c' && argv[2] !== '--config'),
!argv[3].endsWith('.json')
];
if (conditions.some((c) => c)) {
console.log(usage);
process.exit(0);
}
const file = path.resolve(process.cwd(), argv[3]);
let json = null;
try {
const jsonFile = fs.readFileSync(file);
json = JSON.parse(jsonFile);
} catch (err) {
throw Error(`fail to parse your '${file}': ${err.message}`);
}
const app = new __modules__.Hub(json);
app.on('close', () => process.exit(0));
app.run();
process.on('SIGINT', () => app.terminate());
}
module.exports = __modules__;

73
webpack.config.js Normal file

@ -0,0 +1,73 @@
const path = require('path');
const webpack = require('webpack');
const BabiliPlugin = require('babili-webpack-plugin');
const packageJson = require('./package.json');
// TODO: prevent packing src/presets/__tests__/*.test.js into blinksocks.js
// ./src/presets ^\.\/.*$ 789 bytes {0} [optional] [built]
module.exports = {
bail: true,
devtool: 'source-map',
target: 'node',
entry: {
'blinksocks': './src/index.js'
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['.js'],
modules: ['node_modules']
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: require.resolve('eslint-loader'),
include: [
path.resolve(__dirname, 'bin'),
path.resolve(__dirname, 'src')
]
},
{
test: /\.js$/,
loader: require.resolve('babel-loader')
}
]
},
performance: {
hints: false
},
plugins: [
new BabiliPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
'global.__WEBPACK__': JSON.stringify(true)
}),
new webpack.IgnorePlugin(/__mocks__/, /__tests__/),
new webpack.BannerPlugin({
banner: [
'Copyright (c) 2016-present, [name]. All rights reserved.\n',
'name: [file]',
`version: v${packageJson.version}`,
'hash: [hash]'
].join('\n'),
entryOnly: true
})
]
};

1021
yarn.lock

File diff suppressed because it is too large Load Diff