-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
55 changed files
with
1,015 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes
File renamed without changes
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('./')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
Oops, something went wrong.