├── .gitattributes ├── index.js ├── .travis.yml ├── test ├── fixtures │ └── main.js └── test.js ├── lib ├── index.js └── bundle.js ├── .eslintrc ├── .editorconfig ├── LICENSE ├── bin └── cli.js ├── package.json ├── README.md └── .gitignore /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/'); 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'stable' 5 | - '4.2.1' 6 | -------------------------------------------------------------------------------- /test/fixtures/main.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | 3 | /* eslint no-console: 0 */ 4 | console.log('bla', chalk); 5 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | var mkdirp = require('mkdirp'); 2 | var bundle = require('./bundle'); 3 | 4 | module.exports = function esnow(o) { 5 | mkdirp(o.outputPath, bundle(o)); 6 | }; 7 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb/base", 3 | "rules": { 4 | "no-var": 0, 5 | "no-console": 0, 6 | "strict": [2, "global"], 7 | "func-names": 0, 8 | "one-var": 0 9 | }, 10 | "env": { 11 | "node": true, 12 | "browser": false 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var test = require('tape'); 4 | var spawn = require('child_process').spawn; 5 | var isThere = require('is-there'); 6 | var testCompile = spawn('npm', ['run', 'test-compile']); 7 | 8 | var paths = ['test/fixtures/out/main.js', 'test/fixtures/out/main.js.map']; 9 | 10 | test('should generate main.js and main.js.map', function(t) { 11 | t.plan(2); 12 | 13 | testCompile.on('close', function(code) { 14 | paths.forEach(function(p) { 15 | t.equal(isThere(p), true); 16 | }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is Awesome: http://editorconfig.org 2 | 3 | # Top-most EditorConfig file. 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file. 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | indent_style = space 12 | indent_size = 2 13 | trim_trailing_whitespace = true 14 | 15 | # Indent HTML with 4 spaces for better readability. 16 | [*.html] 17 | indent_style = 4 18 | 19 | # Don't trim whitespace in Markdown in order to be able 20 | # to do two spaces for line breaks. 21 | [*.md] 22 | trim_trailing_whitespace = false 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kahlil Lechelt (kahlil.info) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var opts; 3 | var path = require('path'); 4 | var chalk = require('chalk'); 5 | var argv = require('minimist')(process.argv.slice(2)); 6 | var esnow = require('../lib/'); 7 | 8 | // Parse command line options. 9 | var entryFile = argv.entryFile || argv.e || false; 10 | 11 | if (entryFile === false) { 12 | console.error('Please specify your', chalk.green('--entryFile') + '.'); 13 | process.exit(1); 14 | } 15 | 16 | /* eslint vars-on-top:0 */ 17 | var outputFileName = argv.outputFileName || argv.f || path.basename(entryFile); 18 | var outputPath = argv.outputPath || argv.o || false; 19 | 20 | if (outputPath === false) { 21 | console.error('Please specify your', chalk.green('--outputPath') + '.'); 22 | process.exit(1); 23 | } 24 | 25 | var outputFile = path.join(process.cwd(), outputPath, outputFileName); 26 | var prod = argv.prod || argv.p || false; 27 | var watch = argv.watch || argv.w || false; 28 | 29 | opts = { 30 | outputFileName: outputFileName, 31 | outputPath: path.join(process.cwd(), outputPath), 32 | entryFile: path.join(process.cwd(), entryFile), 33 | outputFile: outputFile, 34 | mapFile: outputFile + '.map', 35 | prod: prod, 36 | watch: watch, 37 | }; 38 | 39 | esnow(opts); 40 | -------------------------------------------------------------------------------- /lib/bundle.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var browserify = require('browserify'); 3 | var watchify = require('watchify'); 4 | var babelify = require('babelify'); 5 | var uglifyify = require('uglifyify'); 6 | var exorcist = require('exorcist'); 7 | 8 | module.exports = function(o) { 9 | return function(err) { 10 | var b, w; 11 | var options = { debug: true }; 12 | 13 | // Return if there was an error. 14 | if (err) { 15 | console.error(err); 16 | process.exit(1); 17 | } 18 | 19 | if (o.watch) { 20 | options.cache = {}; 21 | options.packageCache = {}; 22 | } 23 | 24 | // Bundle the JavaScript 25 | b = browserify(o.entryFile, options); 26 | 27 | if (o.prod) { 28 | b.transform(babelify); 29 | b.transform({ global: true }, uglifyify); 30 | } else { 31 | b.transform(babelify, { 32 | sourceMap: true, 33 | sourceMapRelative: process.cwd(), 34 | }); 35 | } 36 | 37 | function bundleUp(bundler) { 38 | bundler 39 | .bundle() 40 | .pipe(exorcist(o.mapFile, null, null, o.outputPath)) 41 | .pipe(fs.createWriteStream(o.outputFile, 'utf8')); 42 | } 43 | 44 | if (o.watch) { 45 | w = watchify(b); 46 | 47 | bundleUp(w); 48 | 49 | w.on('update', function() { bundleUp(w); }); 50 | w.on('log', function(msg) { console.log(msg); }); 51 | } else { 52 | bundleUp(b); 53 | } 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "esnow", 3 | "version": "2.0.1", 4 | "description": "Write ES2015 for the browser, import Node packages with the ES2015 module syntax and generate separate source maps.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "tape test/*.js | faucet && trash test/fixtures/out", 8 | "test-compile": "node bin/cli.js -e test/fixtures/main.js -o test/fixtures/out", 9 | "test-compile-w": "node bin/cli.js -w -e test/fixtures/main.js -o test/fixtures/out", 10 | "test-compile-p": "node bin/cli.js -e test/fixtures/main.js -o test/fixtures/out -p", 11 | "test-compile-simple": "node bin/cli.js -e test/fixtures/main.js", 12 | "clean": "trash test/fixtures/out" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/kahlil/esnow.git" 17 | }, 18 | "keywords": [ 19 | "es6", 20 | "es7", 21 | "es2015", 22 | "es2016", 23 | "babel", 24 | "browserify", 25 | "sourcemaps", 26 | "uglify" 27 | ], 28 | "author": "Kahlil Lechelt", 29 | "license": "MIT", 30 | "bin": { 31 | "esnow": "bin/cli.js" 32 | }, 33 | "dependencies": { 34 | "babelify": "^6.1.3", 35 | "browserify": "^11.0.1", 36 | "chalk": "^1.1.1", 37 | "exorcist": "^0.4.0", 38 | "minimist": "^1.1.3", 39 | "mkdirp": "^0.5.1", 40 | "uglifyify": "^3.0.1", 41 | "watchify": "^3.3.1" 42 | }, 43 | "devDependencies": { 44 | "babel-eslint": "^4.0.10", 45 | "eslint": "^1.2.1", 46 | "eslint-config-airbnb": "0.0.8", 47 | "faucet": "0.0.1", 48 | "is-there": "^4.0.0", 49 | "serve": "^1.4.0", 50 | "tape": "^4.2.2", 51 | "trash": "^2.0.0" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esnow - DEPRECATED 2 | 3 | _**This repo is not being maintained. I recommend you use [budo](http://npm.im/budo) instead.**_ 4 | 5 | Write ES2015 for the browser, import Node packages with the ES2015 module syntax and generate separate source maps. 6 | 7 | `esnow` is a Node package that preconfigures Browserify including the Babelify and Uglifyify transforms. It generates 8 | separate source map files using Exorcist. 9 | 10 | For watching and compiling changed files esnow uses [`watchify`](https://www.npmjs.com/package/watchify). Watchify increases compile speed after the first compile because it uses caching. 11 | 12 | It is very easy to use. 13 | 14 | ## Usage 15 | 16 | Install `esnow` with npm. 17 | 18 | ```sh 19 | npm install esnow --save-dev 20 | ``` 21 | 22 | Add an `esnow` call it to your package.json `scripts` field. Specify your entryfile with the `-e` option and the output folder with the `-o` option. `esnow` will produce an `main.js` and an `main.js.map` in your output folder. 23 | 24 | ```js 25 | "scripts": { 26 | "js": "esnow -e js/main.js -o out/js" 27 | } 28 | ``` 29 | 30 | If you want to use Watchify just add `-w`. 31 | 32 | ```js 33 | "scripts": { 34 | "jsw": "esnow -e js/main.js -o out/js -w" 35 | } 36 | ``` 37 | 38 | Execute it with npm. 39 | 40 | ```sh 41 | npm run js 42 | ``` 43 | 44 | or 45 | 46 | ```sh 47 | npm run jsw 48 | ``` 49 | 50 | ### Using Node Packages 51 | 52 | Because we are using Browserify you can install and use node packages in your program of course. 53 | 54 | Install a package as a devDependency: 55 | 56 | ```sh 57 | npm install --save-dev some-cool-package 58 | ``` 59 | 60 | Then go ahead and import it in your program with the ES2015 module syntax: 61 | 62 | ```js 63 | import someCoolPackage from 'some-cool-package'; 64 | ``` 65 | 66 | Then use it! 67 | 68 | ```js 69 | someCoolPackage(); 70 | ``` 71 | 72 | The Babelify transform transpiles this to a CommonJS `require` statement and passes it on to Browserify to bundle it up with your program. 73 | 74 | ## Global Install 75 | 76 | You can also install and use it globally. 77 | 78 | ```sh 79 | npm install -g esnow 80 | ``` 81 | 82 | Then just use it anywhere you want with the `esnow` command. 83 | 84 | ```sh 85 | esnow -e js/main.js -o out/js 86 | ``` 87 | 88 | or 89 | 90 | ```sh 91 | esnow -e js/main.js -o out/js -w 92 | ``` 93 | 94 | Enjoy writing **ESXXXX** code with Node packages and debugging it easily via source maps. 95 | 96 | ## Options 97 | 98 | ``` 99 | --outputPath, -o Pass the output path (required). 100 | --entryFile, -e Path to the entry file (required). 101 | --watch, -w Watch and compile your files with watchify. 102 | --prod, -p Production mode (minifies the code). 103 | --outputFileName, -f Name of the output file defaults to the basename of `--entryFile`. 104 | ``` 105 | 106 | ## Todo 107 | 108 | - write better tests 109 | - add better cli with help with [`commander`](https://www.npmjs.com/package/commander) 110 | - use `package.json` for Browserify transforms 111 | - refactor this package to es6 112 | 113 | ## Changelog 114 | 115 | ### v2.0.0 116 | * The output filename does not default to "app.js" anymore. It defaults to the filename of your entryfile. Feature added by @andreruffert. 117 | 118 | # License 119 | 120 | MIT © [Kahlil Lechelt](http://kahlil.info) 121 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | test/fixtures/out 2 | 3 | # Created by https://www.gitignore.io 4 | 5 | ### OSX ### 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | 10 | # Icon must end with two \r 11 | Icon 12 | 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | 25 | # Directories potentially created on remote AFP share 26 | .AppleDB 27 | .AppleDesktop 28 | Network Trash Folder 29 | Temporary Items 30 | .apdisk 31 | 32 | 33 | ### Node ### 34 | # Logs 35 | logs 36 | *.log 37 | 38 | # Runtime data 39 | pids 40 | *.pid 41 | *.seed 42 | 43 | # Directory for instrumented libs generated by jscoverage/JSCover 44 | lib-cov 45 | 46 | # Coverage directory used by tools like istanbul 47 | coverage 48 | 49 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 50 | .grunt 51 | 52 | # node-waf configuration 53 | .lock-wscript 54 | 55 | # Compiled binary addons (http://nodejs.org/api/addons.html) 56 | build/Release 57 | 58 | # Dependency directory 59 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 60 | node_modules 61 | 62 | 63 | ### Windows ### 64 | # Windows image file caches 65 | Thumbs.db 66 | ehthumbs.db 67 | 68 | # Folder config file 69 | Desktop.ini 70 | 71 | # Recycle Bin used on file shares 72 | $RECYCLE.BIN/ 73 | 74 | # Windows Installer files 75 | *.cab 76 | *.msi 77 | *.msm 78 | *.msp 79 | 80 | # Windows shortcuts 81 | *.lnk 82 | 83 | 84 | ### Linux ### 85 | *~ 86 | 87 | # KDE directory preferences 88 | .directory 89 | 90 | # Linux trash folder which might appear on any partition or disk 91 | .Trash-* 92 | 93 | 94 | ### Sass ### 95 | .sass-cache 96 | *.css.map 97 | 98 | 99 | ### WebStorm ### 100 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 101 | 102 | *.iml 103 | 104 | ## Directory-based project format: 105 | .idea/ 106 | # if you remove the above rule, at least ignore the following: 107 | 108 | # User-specific stuff: 109 | # .idea/workspace.xml 110 | # .idea/tasks.xml 111 | # .idea/dictionaries 112 | 113 | # Sensitive or high-churn files: 114 | # .idea/dataSources.ids 115 | # .idea/dataSources.xml 116 | # .idea/sqlDataSources.xml 117 | # .idea/dynamic.xml 118 | # .idea/uiDesigner.xml 119 | 120 | # Gradle: 121 | # .idea/gradle.xml 122 | # .idea/libraries 123 | 124 | # Mongo Explorer plugin: 125 | # .idea/mongoSettings.xml 126 | 127 | ## File-based project format: 128 | *.ipr 129 | *.iws 130 | 131 | ## Plugin-specific files: 132 | 133 | # IntelliJ 134 | /out/ 135 | 136 | # mpeltonen/sbt-idea plugin 137 | .idea_modules/ 138 | 139 | # JIRA plugin 140 | atlassian-ide-plugin.xml 141 | 142 | # Crashlytics plugin (for Android Studio and IntelliJ) 143 | com_crashlytics_export_strings.xml 144 | crashlytics.properties 145 | crashlytics-build.properties 146 | 147 | 148 | ### PhpStorm ### 149 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 150 | 151 | *.iml 152 | 153 | ## Directory-based project format: 154 | .idea/ 155 | # if you remove the above rule, at least ignore the following: 156 | 157 | # User-specific stuff: 158 | # .idea/workspace.xml 159 | # .idea/tasks.xml 160 | # .idea/dictionaries 161 | 162 | # Sensitive or high-churn files: 163 | # .idea/dataSources.ids 164 | # .idea/dataSources.xml 165 | # .idea/sqlDataSources.xml 166 | # .idea/dynamic.xml 167 | # .idea/uiDesigner.xml 168 | 169 | # Gradle: 170 | # .idea/gradle.xml 171 | # .idea/libraries 172 | 173 | # Mongo Explorer plugin: 174 | # .idea/mongoSettings.xml 175 | 176 | ## File-based project format: 177 | *.ipr 178 | *.iws 179 | 180 | ## Plugin-specific files: 181 | 182 | # IntelliJ 183 | /out/ 184 | 185 | # mpeltonen/sbt-idea plugin 186 | .idea_modules/ 187 | 188 | # JIRA plugin 189 | atlassian-ide-plugin.xml 190 | 191 | # Crashlytics plugin (for Android Studio and IntelliJ) 192 | com_crashlytics_export_strings.xml 193 | crashlytics.properties 194 | crashlytics-build.properties 195 | 196 | 197 | ### SublimeText ### 198 | # cache files for sublime text 199 | *.tmlanguage.cache 200 | *.tmPreferences.cache 201 | *.stTheme.cache 202 | 203 | # workspace files are user-specific 204 | *.sublime-workspace 205 | 206 | # project files should be checked into the repository, unless a significant 207 | # proportion of contributors will probably not be using SublimeText 208 | # *.sublime-project 209 | 210 | # sftp configuration file 211 | sftp-config.json 212 | 213 | 214 | ### Bower ### 215 | bower_components 216 | .bower-cache 217 | .bower-registry 218 | .bower-tmp 219 | 220 | 221 | ### grunt ### 222 | # Grunt usually compiles files inside this directory 223 | dist/ 224 | 225 | # Grunt usually preprocesses files such as coffeescript, compass... inside the .tmp directory 226 | .tmp/ 227 | 228 | 229 | ### Vim ### 230 | [._]*.s[a-w][a-z] 231 | [._]s[a-w][a-z] 232 | *.un~ 233 | Session.vim 234 | .netrwhist 235 | *~ 236 | 237 | npm-debug.log.* 238 | --------------------------------------------------------------------------------