Skip to content

Commit

Permalink
Step 1 of moving to ES6 (#1149)
Browse files Browse the repository at this point in the history
* First draft of babel+eslint+rollup

* Moved to gulp 4, improved some logging output during builds.

* Tweaks to the build process.

* Fixing the versioning task.

* Created separate copies of the .eslintrc files, one for each package.
  • Loading branch information
dacarley authored and frozeman committed Nov 13, 2017
1 parent fdb40ab commit 9d04d24
Show file tree
Hide file tree
Showing 55 changed files with 1,015 additions and 373 deletions.
15 changes: 15 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"presets": [
"env"
],
"plugins": [
"lodash",
"transform-class-properties",
[
"transform-runtime",
{
"polyfill": false
}
]
]
}
5 changes: 0 additions & 5 deletions .bowerrc

This file was deleted.

1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.js
65 changes: 65 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"root": true,
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"extends": "airbnb-base",
"plugins": [],
"rules": {
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"newline-before-return": "error",
"no-multiple-empty-lines": [
"error",
{
"max": 1,
"maxEOF": 0
}
],
"no-use-before-define": [
"error",
{
"functions": false,
"classes": true
}
],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}
],
"import/extensions": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"gulpfile.babel.js",
"gulp/**/*.js"
]
}
],
"comma-dangle": [
"error",
"never"
]
},
"globals": {}
}
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ npm-debug.log
/coverage
/tmp
node_modules
bower_components
/bower
.idea/
.npm/
.vscode/
/packages/**/lib/*
.vscode/
2 changes: 0 additions & 2 deletions .jshintignore

This file was deleted.

7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@ before_script:
install:
- npm install
script:
- npm run-script build
- npm run-script test-coveralls
after_script:
- cd test/node && npm install && node app.js

- npm run build
- npm run test-coveralls
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**PREVIEW RELEASE** This is a beta preview release with breaking changes! The current stable version is 0.20.0

<img src="https://github.com/ethereum/web3.js/raw/1.0/web3js.jpg" width=200 />
<img src="./assets/web3js.jpg" width=200 />

# web3.js - Ethereum JavaScript API

Expand Down Expand Up @@ -44,7 +44,7 @@ Use the prebuild ``dist/web3.min.js``, or
build using the [web3.js][repo] repository:

```bash
npm run-script build
npm run build
```

Then include `dist/web3.js` in your html file.
Expand Down Expand Up @@ -104,13 +104,13 @@ sudo apt-get install npm
Build only the web3.js package

```bash
npm run-script build
npm run build
```

Or build all sub packages as well

```bash
npm run-script build-all
npm run build-all
```

This will put all the browser build files into the `dist` folder.
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
75 changes: 0 additions & 75 deletions bower.json

This file was deleted.

3 changes: 0 additions & 3 deletions circle.yml

This file was deleted.

107 changes: 107 additions & 0 deletions gulp/buildUmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import path from 'path';
import gutil from 'gulp-util';
import { rollup } from 'rollup';
import rollupBabelrc from 'babelrc-rollup';
import rollupReplace from 'rollup-plugin-replace';
import rollupBabel from 'rollup-plugin-babel';
import rollupProgress from 'rollup-plugin-progress';
import rollupResolve from 'rollup-plugin-node-resolve';
import rollupJson from 'rollup-plugin-json';
import rollupCommonjs from 'rollup-plugin-commonjs';
import rollupUglify from 'rollup-plugin-uglify';
import rollupGlobals from 'rollup-plugin-node-globals';
import rollupBuiltins from 'rollup-plugin-node-builtins';

import moduleNameMappings from './moduleNameMappings.js';
import config from './config.js';

export default buildUmd;

function log(msg, color = 'green') {
if (!msg) {
// eslint-disable-next-line no-console
console.log(); // Blank line

return;
}

gutil.log(gutil.colors[color](msg));
}

async function buildUmd(p, minify = false) {
const rbc = rollupBabelrc();
rbc.runtimeHelpers = true;
rbc.exclude = 'node_modules/**';

try {
log(`Compiling ${p} (minified: ${minify})...`);

const bundle = await rollup({
input: path.resolve(config.PACKAGES_DIR, p, 'src/index.js'),
external: [
'websocket'
],
plugins: [
rollupProgress(),
rollupResolve({
preferBuiltins: false,
browser: true
}),
rollupJson(),
rollupCommonjs(),
rollupGlobals(),
rollupBuiltins({ crypto: true }),
rollupBabel(rbc),
rollupReplace({
exclude: `./packages/${p}/node_modules/**`,
ENV: JSON.stringify(process.env.NODE_ENV || 'production')
}),
minify ? rollupUglify() : {}
],
onwarn
});

const baseFilename = `${p}${minify ? '.min' : ''}.js`;
const file = path.resolve(config.DIST, baseFilename);
log();
log(`Saving compiled module to ${baseFilename}...`);

await bundle.write({
file,
name: getModuleName(p),
format: 'umd',
sourcemap: minify,
globals: {
websocket: 'WebSocket'
}
});

log('Done.');
} catch (err) {
log();
log(err, 'red');
}
}

function onwarn(warning, warn) {
switch (warning.code) {
case 'EVAL':
return;

case 'NON_EXISTENT_EXPORT':
throw new Error(warning.message);

default:
warn(warning);
}
}

function getModuleName(p) {
const moduleName = moduleNameMappings[p];

if (!moduleName) {
throw new Error(`Could not find a module name for the package: ${p}`);
}

return moduleName;
}
20 changes: 20 additions & 0 deletions gulp/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import path from 'path';
import glob from 'glob';
import root from 'root-path';

const PACKAGES_DIR = root('packages');
const packages = glob.sync(`${PACKAGES_DIR}/*`).map(d => path.basename(d));
const scripts = './packages/*/src/**/*.js';

export default {
DIST: root('dist/'),
PACKAGES_DIR,
packages,
scripts,
lintableFiles: [
scripts,
'./*.js',
'./gulp/**/*.js',
'./test/**/*.js'
]
};
22 changes: 22 additions & 0 deletions gulp/fixFileVersions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import gulp from 'gulp';
import replace from 'gulp-replace';

import { version } from '../lerna.json';

export default () => {
if (!version) {
throw new Error('version property is missing from lerna.json');
}

const jsonPattern = /"version": "[.0-9\-a-z]*"/;
const jsPattern = /version: '[.0-9\-a-z]*'/;
const files = [
'./package.json',
'./package.js'
];

gulp.src(files, { base: './' })
.pipe(replace(jsonPattern, `"version": "${version}"`))
.pipe(replace(jsPattern, `version: '${version}'`))
.pipe(gulp.dest('./'));
};
16 changes: 16 additions & 0 deletions gulp/lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import gulp from 'gulp';
import eslint from 'gulp-eslint';

import config from './config.js';

export default (failOnError) => {
let stream = gulp.src(config.lintableFiles)
.pipe(eslint())
.pipe(eslint.format());

if (failOnError) {
stream = stream.pipe(eslint.failAfterError());
}

return stream;
};
Loading

0 comments on commit 9d04d24

Please sign in to comment.