-
-
Save gnestor/5ee40cf0009e5aa037948f7c4ad6044c to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'use strict'" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function findFile(filename, dir) {\n", | |
" if (~fs.readdirSync(dir).indexOf(filename)) return path.resolve(dir, filename);\n", | |
" if (path.dirname(dir) === dir) return null;\n", | |
" return findFile(filename, path.dirname(dir));\n", | |
"}\n", | |
"\n", | |
"function getBabelConfig(filepath) {\n", | |
" if (!filepath) return null;\n", | |
" try {\n", | |
" return JSON.parse(fs.readFileSync(filepath, \"utf-8\"));\n", | |
" } catch(err) {\n", | |
" return null;\n", | |
" }\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'/Users/grant/Sites/jupyter/jp-babel/.babelrc'" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"var babelrcPath = findFile('.babelrc', process.cwd());\n", | |
"babelrcPath" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{ presets: [ 'es2015' ] }" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"var babelrc = getBabelConfig(babelrcPath);\n", | |
"babelrc" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Create a test `.babelrc`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"undefined" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"var testConfig = {\n", | |
" presets: [\"es2015\"]\n", | |
"};\n", | |
"fs.writeFileSync('.babelrc', JSON.stringify(testConfig, null, 2));" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Delete test `.babelrc`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"undefined" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"fs.unlinkSync('.babelrc');" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Babel (Node.js)", | |
"language": "babel", | |
"name": "babel" | |
}, | |
"language_info": { | |
"file_extension": ".js", | |
"mimetype": "application/javascript", | |
"name": "javascript", | |
"version": "5.12.0" | |
}, | |
"widgets": { | |
"state": {}, | |
"version": "2.0.0-dev" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment