├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── Makefile ├── README.md ├── index.js ├── n8-make ├── n8-make-js ├── n8-make-json ├── n8-make-jsx ├── n8-make-pug ├── package.json ├── test ├── js-async-await │ ├── index.js │ └── test.js ├── js-es6 │ ├── index.js │ └── test.js └── test.sh └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /test/*/build 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /build 3 | /test 4 | /CHANGELOG.md 5 | /README.md 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | 5 | node_js: 6 | - "0.8" 7 | - "0.10" 8 | - "0.12" 9 | - "1" 10 | - "2" 11 | - "3" 12 | - "4" 13 | - "5" 14 | 15 | install: 16 | - PATH="`npm bin`:`npm bin -g`:$PATH" 17 | # Node 0.8 comes with a too obsolete npm 18 | - if [[ "`node --version`" =~ ^v0\.8\. ]]; then npm install -g npm@1.4.28 ; fi 19 | # Install dependencies and build 20 | - npm install 21 | 22 | script: 23 | # Output useful info for debugging 24 | - node --version 25 | - npm --version 26 | # Run tests 27 | - npm test 28 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | v1.8.6 2017-12-15 2 | 3 | * [[`c2986b1c49`](https://github.com/TooTallNate/n8-make/commit/c2986b1c49)] - update deps (Nathan Rajlich) 4 | 5 | v1.8.5 2017-06-01 6 | 7 | * [[`dabca082b2`](https://github.com/TooTallNate/n8-make/commit/dabca082b2)] - redirect stderr to stdout for stat version (Nathan Rajlich) 8 | 9 | v1.8.4 2017-06-01 10 | 11 | * [[`ac8fbb949b`](https://github.com/TooTallNate/n8-make/commit/ac8fbb949b)] - moar debug (Nathan Rajlich) 12 | 13 | v1.8.3 2017-06-01 14 | 15 | * [[`d1e0902e47`](https://github.com/TooTallNate/n8-make/commit/d1e0902e47)] - fix BusyBox `stat` (Nathan Rajlich) 16 | 17 | v1.8.2 2017-01-26 18 | 19 | * [[`aad27fc219`](https://github.com/TooTallNate/n8-make/commit/aad27fc219)] - handle MacOS/BSD vs. Linux/coreutils `stat` command differences (Nathan Rajlich) 20 | 21 | v1.8.1 2017-01-24 22 | 23 | * [[`48b514eea5`](https://github.com/TooTallNate/n8-make/commit/48b514eea5)] - use more compatible `stat` command (Nathan Rajlich) 24 | 25 | v1.8.0 2016-10-24 26 | 27 | * [[`4d9c6e89c9`](https://github.com/TooTallNate/n8-make/commit/4d9c6e89c9)] - enable `transform-object-rest-spread` (Nathan Rajlich) 28 | 29 | v1.7.0 2016-10-17 30 | 31 | * [[`77b81ea877`](https://github.com/TooTallNate/n8-make/commit/77b81ea877)] - **Makefile**: chmod the output files to match the input files (Nathan Rajlich) 32 | * [[`c425db4e17`](https://github.com/TooTallNate/n8-make/commit/c425db4e17)] - **n8-make-js**: better readability (Nathan Rajlich) 33 | 34 | v1.6.2 2016-09-24 35 | 36 | * [[`d2c2b19e8e`](https://github.com/TooTallNate/n8-make/commit/d2c2b19e8e)] - **webpack**: fix source maps (Nathan Rajlich) 37 | 38 | v1.6.1 2016-09-11 39 | 40 | * [[`70e2bdc8ad`](https://github.com/TooTallNate/n8-make/commit/70e2bdc8ad)] - **Makefile**: fix webpack entry point when not a .js file (Nathan Rajlich) 41 | * [[`a93bd0b362`](https://github.com/TooTallNate/n8-make/commit/a93bd0b362)] - Release 1.6.0 (Nathan Rajlich) 42 | 43 | v1.6.0 2016-09-10 44 | 45 | * [[`0647d1347d`](https://github.com/TooTallNate/n8-make/commit/0647d1347d)] - **webpack**: fix n8-make's own deps resolving properly (Nathan Rajlich) 46 | * [[`febe71907f`](https://github.com/TooTallNate/n8-make/commit/febe71907f)] - add Webpack client-side build (Nathan Rajlich) 47 | 48 | v1.5.0 2016-06-29 49 | 50 | * [[`028a779d5f`](https://github.com/TooTallNate/n8-make/commit/028a779d5f)] - add .travis.yml file (Nathan Rajlich) 51 | * [[`48df5f05a1`](https://github.com/TooTallNate/n8-make/commit/48df5f05a1)] - add .npmignore file (Nathan Rajlich) 52 | * [[`c4a35e814e`](https://github.com/TooTallNate/n8-make/commit/c4a35e814e)] - add initial test framework (Nathan Rajlich) 53 | * [[`e2f8eb8bc9`](https://github.com/TooTallNate/n8-make/commit/e2f8eb8bc9)] - rename `make.sh` to `n8-make` (Nathan Rajlich) 54 | * [[`5d445d40be`](https://github.com/TooTallNate/n8-make/commit/5d445d40be)] - **Makefile**: use unix find `-prune` option (Nathan Rajlich) 55 | * [[`a555ebb803`](https://github.com/TooTallNate/n8-make/commit/a555ebb803)] - **Makefile**: use present tense for debug call (Nathan Rajlich) 56 | * [[`0252188d26`](https://github.com/TooTallNate/n8-make/commit/0252188d26)] - **Makefile**: make `IGNORE` augment the default list (Nathan Rajlich) 57 | * [[`e5a39cd28a`](https://github.com/TooTallNate/n8-make/commit/e5a39cd28a)] - **README**: add note about `IGNORE` env variable (Nathan Rajlich) 58 | 59 | v1.4.0 2016-06-29 60 | 61 | * [[`80a7d11d20`](https://github.com/TooTallNate/n8-make/commit/80a7d11d20)] - Rename SOURCE to ROOT (Nathan Rajlich) 62 | * [[`58a7ea8f9b`](https://github.com/TooTallNate/n8-make/commit/58a7ea8f9b)] - add `SOURCE` env (retrofox) 63 | * [[`b476b7ccb6`](https://github.com/TooTallNate/n8-make/commit/b476b7ccb6)] - **README**: add Debug instructions (Nathan Rajlich) 64 | 65 | v1.3.0 2016-06-27 66 | 67 | * [[`16b7550039`](https://github.com/TooTallNate/n8-make/commit/16b7550039)] - add `babel-plugin-add-module-exports` (Nathan Rajlich) 68 | 69 | v1.2.2 2016-06-16 70 | 71 | * [[`jb2674c0f4`](https://github.com/TooTallNate/n8-make/commit/bb2674c0f4)] - **Makefile**: add a "debug" function (Nathan Rajlich) 72 | * [[`310da36f84`](https://github.com/TooTallNate/n8-make/commit/310da36f84)] - **Makefile**: give our local bin and modules preference (Nathan Rajlich) 73 | 74 | v1.2.1 2016-06-16 75 | 76 | * [[`86b8e3d55d`](https://github.com/TooTallNate/n8-make/commit/86b8e3d55d)] - **Makefile**: filter out dangling symlinks (Nathan Rajlich) 77 | 78 | v1.2.0 2016-06-16 79 | 80 | * [[`4d0d292462`](https://github.com/TooTallNate/n8-make/commit/4d0d292462)] - **Makefile**: make ignore paths configurable with `IGNORE` var (Nathan Rajlich) 81 | * [[`60eac146c8`](https://github.com/TooTallNate/n8-make/commit/60eac146c8)] - **make**: add `--no-builtin-rules` and `--no-builtin-variables` switches (Nathan Rajlich) 82 | * [[`5d619aa92d`](https://github.com/TooTallNate/n8-make/commit/5d619aa92d)] - **package**: use `^` caret consistently (Nathan Rajlich) 83 | * [[`86e54bbaff`](https://github.com/TooTallNate/n8-make/commit/86e54bbaff)] - add README.md file (Nathan Rajlich) 84 | 85 | v1.1.0 2016-06-16 86 | 87 | * [[`8a0bae1446`](https://github.com/TooTallNate/n8-make/commit/8a0bae1446)] - add index.js file (Nathan Rajlich) 88 | * [[`6c93e2cf93`](https://github.com/TooTallNate/n8-make/commit/6c93e2cf93)] - **make**: don't export DIR (Nathan Rajlich) 89 | * [[`06a33ff1c9`](https://github.com/TooTallNate/n8-make/commit/06a33ff1c9)] - **Makefile**: make the build dir configurable (Nathan Rajlich) 90 | * [[`a27eee3778`](https://github.com/TooTallNate/n8-make/commit/a27eee3778)] - **n8-make-jsx**: use the singular `--preset` option (Nathan Rajlich) 91 | * [[`20b8eb5478`](https://github.com/TooTallNate/n8-make/commit/20b8eb5478)] - **n8-make-js**: cleaner processing of args (Nathan Rajlich) 92 | 93 | v1.0.6 2016-06-15 94 | 95 | * [[`8e156fe01e`](https://github.com/TooTallNate/n8-make/commit/8e156fe01e)] - **Makefile**: even more explicit rules (Nathan Rajlich) 96 | * [[`b749503801`](https://github.com/TooTallNate/n8-make/commit/b749503801)] - **Makefile**: dynamically define the build rules (Nathan Rajlich) 97 | 98 | v1.0.5 2016-06-08 99 | 100 | * [[`ae10be4daf`](https://github.com/TooTallNate/n8-make/commit/ae10be4daf)] - **n8-make-js**: comment out `echo` call (Nathan Rajlich) 101 | * [[`533b8e9b73`](https://github.com/TooTallNate/n8-make/commit/533b8e9b73)] - **Makefile**: add check for valid file extension (Nathan Rajlich) 102 | 103 | v1.0.4 2016-06-03 104 | 105 | * [[`b0c2cd7ba9`](https://github.com/TooTallNate/n8-make/commit/b0c2cd7ba9)] - **package**: add "pug-cli" dep (Nathan Rajlich) 106 | * [[`b8824e063b`](https://github.com/TooTallNate/n8-make/commit/b8824e063b)] - **Makefile**: add comment (Nathan Rajlich) 107 | * [[`5826101565`](https://github.com/TooTallNate/n8-make/commit/5826101565)] - **n8-make-js**: debugging... (Nathan Rajlich) 108 | 109 | v1.0.3 2016-06-03 110 | 111 | * [[`9aa13d119d`](https://github.com/TooTallNate/n8-make/commit/9aa13d119d)] - **n8-make-js**: remove multiline stuffs (Nathan Rajlich) 112 | 113 | v1.0.2 2016-06-03 114 | 115 | * [[`b5294a841f`](https://github.com/TooTallNate/n8-make/commit/b5294a841f)] - **make**: another attempt at getting dirname of script (Nathan Rajlich) 116 | 117 | v1.0.1 2016-06-03 118 | 119 | * [[`481203511a`](https://github.com/TooTallNate/n8-make/commit/481203511a)] - **make**: simpler and more portable DIR logic (Nathan Rajlich) 120 | 121 | v1.0.0 2016-06-03 122 | 123 | * [[`82b2e14899`](https://github.com/TooTallNate/n8-make/commit/82b2e14899)] - **Makefile**: include n8-make's .bin dir in NODE_PATH (Nathan Rajlich) 124 | * [[`8f70d48b82`](https://github.com/TooTallNate/n8-make/commit/8f70d48b82)] - **n8-make-js**: pass the transforms and presets in CLI (Nathan Rajlich) 125 | * [[`4c18a9cbbc`](https://github.com/TooTallNate/n8-make/commit/4c18a9cbbc)] - **Makefile**: make EXTENSIONS configurable (Nathan Rajlich) 126 | * [[`a925200f81`](https://github.com/TooTallNate/n8-make/commit/a925200f81)] - **n8-make-js**: remove `echo`, and shift out the in/out filenames from the args (Nathan Rajlich) 127 | * [[`9e38ffa265`](https://github.com/TooTallNate/n8-make/commit/9e38ffa265)] - ignore `node_modules` dir (Nathan Rajlich) 128 | * [[`6ce51cfd16`](https://github.com/TooTallNate/n8-make/commit/6ce51cfd16)] - initial commit (Nathan Rajlich) 129 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean distclean build 2 | 3 | # to enable debugging, add `DEBUG=n8-make` to the env 4 | ifneq (,$(findstring n8-make,$(DEBUG))) 5 | define debug 6 | $(info n8-make: $1) 7 | endef 8 | else 9 | define debug 10 | endef 11 | endif 12 | 13 | # get Makefile directory name: http://stackoverflow.com/a/5982798/376773 14 | THIS_MAKEFILE_PATH := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) 15 | DIR := $(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) 16 | 17 | export PATH := $(shell npm bin):$(shell cd "$(DIR)" && npm bin):$(DIR):$(PATH) 18 | export NODE_PATH := $(DIR)/node_modules:$(NODE_PATH) 19 | export NODE_ENV ?= development 20 | 21 | # Source files root directory 22 | ROOT ?= . 23 | 24 | # The directory to place the compiled .js and .json files. 25 | BUILDDIR ?= build 26 | 27 | # The client-side entry point file pattern (if a file exists 28 | # matching this pattern then the webpack client-side file is built) 29 | WEBPACK_ENTRY ?= client/index.* 30 | 31 | # The output filename for the Webpack client-side build to use. 32 | WEBPACK_BUILD ?= public/build.js 33 | 34 | # Source file extensions to process into .js files. 35 | # .json files are implicitly supported. 36 | EXTENSIONS ?= js jsx pug 37 | $(call debug,compiling extensions = $(EXTENSIONS)) 38 | 39 | # Paths to ignore for the build 40 | IGNORE_PATHS ?= $(IGNORE) $(BUILDDIR) node_modules webpack.config.js public 41 | $(call debug,ignoring paths = $(IGNORE_PATHS)) 42 | 43 | FIND_EXT_ := $(foreach EXT,$(EXTENSIONS),-o -name "*.$(EXT)") 44 | FIND_EXT := $(wordlist 2,$(words $(FIND_EXT_)),$(FIND_EXT_)) 45 | FIND_IGNORE_FILES := $(foreach IG,$(IGNORE_PATHS),! \( -path "./$(IG)" \)) 46 | FIND_IGNORE_DIRS := $(foreach IG,$(IGNORE_PATHS),! \( -path "./$(IG)" -prune \)) 47 | 48 | FIND_COMMAND := find $(ROOT) \( $(FIND_EXT) \) $(FIND_IGNORE_FILES) -exec test -e {} \; -print -o $(FIND_IGNORE_DIRS) 49 | $(call debug,$(FIND_COMMAND)) 50 | SOURCE_FILES := $(subst ./,,$(shell $(FIND_COMMAND))) 51 | 52 | JSON_SOURCE_FILES := $(subst ./,,$(shell find $(ROOT) -name "*.json" $(FIND_IGNORE_FILES) -exec test -e {} \; -print -o $(FIND_IGNORE_DIRS))) 53 | $(call debug,source files = $(SOURCE_FILES) $(JSON_SOURCE_FILES)) 54 | 55 | COMPILED_FILES := $(addprefix $(BUILDDIR)/, $(addsuffix .js,$(basename $(SOURCE_FILES))) $(JSON_SOURCE_FILES)) 56 | $(call debug,output files = $(COMPILED_FILES)) 57 | 58 | # handle BSD, coreutils, busybox, etc. `stat` command differences 59 | STAT_VERSION := $(shell stat --version 2>&1) 60 | $(call debug,stat --version: $(STAT_VERSION)) 61 | 62 | STAT_TYPE=$(shell echo "$(STAT_VERSION)" | grep -i 'coreutils\|busybox') 63 | ifeq ("$(STAT_TYPE)", "") 64 | STAT_FORMAT=-f "%p" 65 | else 66 | STAT_FORMAT=-c "%a" 67 | endif 68 | $(call debug,stat format: $(STAT_FORMAT)) 69 | 70 | WEBPACK_ENTRY_FILE := $(wildcard client/index.*) 71 | ifneq ("$(WEBPACK_ENTRY_FILE)","") 72 | DO_WEBPACK_BUILD = $(WEBPACK_BUILD) 73 | $(call debug,webpack build = $(DO_WEBPACK_BUILD)) 74 | endif 75 | 76 | build: $(COMPILED_FILES) $(DO_WEBPACK_BUILD) 77 | 78 | # Source files that need to be compiled into regular .js files. 79 | # 80 | # Optionally, a `$(BUILDDIR)/%.js.map` file may be created with 81 | # Source Map information mapping back to the source file, which may 82 | # be used by `source-map-loader` (for Webpack) 83 | # or `source-map-support` (for Node.js). 84 | define buildrule 85 | $$(BUILDDIR)/%.$(2): %.$(1) 86 | @mkdir -p $$(dir $$@) 87 | @echo $$(shell echo $(1) | tr "[a-z]" "[A-Z]") source file: "$$<" → "$$@" 88 | @n8-make-$(1) "$$<" "$$@" 89 | @chmod $$(shell stat $(STAT_FORMAT) "$$<") "$$@" 90 | endef 91 | $(foreach EXT,$(EXTENSIONS),$(eval $(call buildrule,$(EXT),js))) 92 | $(eval $(call buildrule,json,json)) 93 | 94 | # Webpack client-side build, placed at `public/build.js` by default. 95 | $(WEBPACK_BUILD): $(COMPILED_FILES) 96 | @mkdir -p $(dir $@) 97 | @echo Webpack client-side build: "$(WEBPACK_ENTRY_FILE)" → "$@" 98 | @webpack \ 99 | --config "$(DIR)/webpack.config.js" \ 100 | --entry "./$(addprefix $(BUILDDIR)/,$(addsuffix .js,$(basename $(WEBPACK_ENTRY_FILE))))" \ 101 | --output-path "$(dir $@)" \ 102 | --output-filename "$(notdir $@)" 103 | 104 | clean: 105 | @rm -rfv $(BUILDDIR) $(WEBPACK_BUILD) 106 | 107 | distclean: 108 | @rm -rfv node_modules 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | n8-make 2 | ======= 3 | ### Opinionated Makefile to build ES6 JS, JSX and Pug files 4 | 5 | `n8-make` is a wrapper around [`make`](https://www.gnu.org/software/make/) 6 | with a Makefile designed to compile JavaScript (and related) files for 7 | usage with Node.js and the web browser. 8 | 9 | By default, these file extensions get compiled into the `build` directory: 10 | 11 | * `.js` - Compiled via [Babel 6](https://babeljs.io) with support for [ES6](http://babeljs.io/docs/plugins/preset-es2015/) and [`async` functions](https://babeljs.io/docs/plugins/transform-async-to-generator/) 12 | * `.jsx` - Same as `.js`, but with the [`react`](https://www.npmjs.com/package/babel-preset-react) preset included as well 13 | * `.pug` - [Pug (a.k.a Jade) lang](http://jade-lang.com/) files get compiled into requireable template functions 14 | * `.json` - JSON files work as expected (use [`json-loader`](https://www.npmjs.com/package/json-loader) for client-side usage) 15 | 16 | 17 | Installation 18 | ------------ 19 | 20 | Install with `npm`: 21 | 22 | ``` bash 23 | $ npm install --save-dev n8-make 24 | ``` 25 | 26 | 27 | Usage 28 | ----- 29 | 30 | The `n8-make` command invokes the system's `make` with its Makefile. 31 | Any arguments you pass to `n8-make` get passed along to `make`. 32 | 33 | The Makefile has a few built-in rules: 34 | 35 | #### build (default) 36 | 37 | ``` bash 38 | $ n8-make 39 | # or 40 | $ n8-make build 41 | ``` 42 | 43 | Compiles all files matching the extensions in the current directory 44 | and nested directories. 45 | 46 | A few paths are ignored by default, and will not be compiled: 47 | 48 | * `build` (or whatever `$(BUILDDIR)` get set to) 49 | * `node_modules` 50 | * `public` 51 | * `webpack.config.js` 52 | 53 | You may override the default ignore paths by defining the `IGNORE` env variable. 54 | 55 | 56 | ### clean 57 | 58 | ``` bash 59 | $ n8-make clean 60 | ``` 61 | 62 | Deletes the `build` directory (or whatever `$(BUILDDIR)` get set to). 63 | 64 | 65 | ### distclean 66 | 67 | ``` bash 68 | $ n8-make distclean 69 | ``` 70 | 71 | Deletes the `node_modules` directory. 72 | 73 | 74 | ### Root directory 75 | 76 | The root directory that source files will be found in can be defined by 77 | setting the `ROOT` env variable: 78 | 79 | ``` bash 80 | $ n8-make build ROOT=lib 81 | ``` 82 | 83 | This would only compile source files from the `lib` directory relative to the 84 | current working directory into the `build/lib` dir. 85 | 86 | Another option is to utilize Make's `--directory`/`-C` option: 87 | 88 | ``` bash 89 | $ n8-make build --directory lib 90 | ``` 91 | 92 | This would do the same thing, but the `build` dir would end up inside of `lib`, 93 | rather then relative to your current working directory. 94 | 95 | 96 | ### Custom extensions 97 | 98 | For every file that gets compiled, a specialized executable is invoked for each 99 | file extension. For example, given the `.js` file extension, n8-make will invoke 100 | `n8-make-js inputfile.js build/outputfile.js` and the output file is generated 101 | from there. 102 | 103 | You may override the default extensions by passing `EXTENSIONS` env to n8-make. 104 | Say you wanted to use n8-make to compile `.coffee` files into js: 105 | 106 | ``` bash 107 | $ n8-make build EXTENSIONS=coffee 108 | ``` 109 | 110 | But make sure you have a `n8-make-coffee` executable in your $PATH at this 111 | point! 112 | 113 | __*HINT!*__ n8-make inherits npm's `bin` directory, so you can utilize 114 | `devDependencies` in your package.json file to include said executable. 115 | 116 | 117 | ### Extending the Makefile 118 | 119 | If you would still prefer to have your own Makefile, say to add additional rules 120 | or tweak existing variables, then you can easily extend the n8-make Makefile using 121 | the following syntax: 122 | 123 | ``` make 124 | include $(shell node -e "require('n8-make')") 125 | ``` 126 | 127 | This assumes that `n8-make` is a dependency of your project. 128 | 129 | 130 | Debug 131 | ----- 132 | 133 | To get debugging log output from `n8-make`, include "n8-make" in the `DEBUG` env 134 | variable: 135 | 136 | ``` bash 137 | $ DEBUG=n8-make n8-make build 138 | n8-make: will compile extensions = js jsx pug 139 | n8-make: ignoring paths = build node_modules webpack.config.js public 140 | n8-make: source files = j.pug r.jsx t.js package.json 141 | n8-make: output files = build/j.js build/r.js build/t.js build/package.json 142 | … 143 | ``` 144 | 145 | 146 | License 147 | ------- 148 | 149 | (The MIT License) 150 | 151 | Copyright (c) 2016 Nathan Rajlich <n@n8.io> 152 | 153 | Permission is hereby granted, free of charge, to any person obtaining 154 | a copy of this software and associated documentation files (the 155 | 'Software'), to deal in the Software without restriction, including 156 | without limitation the rights to use, copy, modify, merge, publish, 157 | distribute, sublicense, and/or sell copies of the Software, and to 158 | permit persons to whom the Software is furnished to do so, subject to 159 | the following conditions: 160 | 161 | The above copyright notice and this permission notice shall be 162 | included in all copies or substantial portions of the Software. 163 | 164 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 165 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 166 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 167 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 168 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 169 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 170 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 171 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | console.log(path.resolve(__dirname, 'Makefile')); 3 | -------------------------------------------------------------------------------- /n8-make: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # this wrapper script basically invokes `make` with the Makefile 4 | # in this directory in the context of the current working directory 5 | 6 | if [ "x$MAKE" = "x" ]; then 7 | MAKE=make 8 | fi 9 | if [ "x$NODE" = "x" ]; then 10 | NODE=node 11 | fi 12 | 13 | FILENAME=`which $0` 14 | FILENAME=`"$NODE" -pe "require('fs').realpathSync('$FILENAME')"` 15 | DIR=`dirname "$FILENAME"` 16 | 17 | "$MAKE" -f "$DIR/Makefile" --no-builtin-rules --no-builtin-variables "$@" 18 | -------------------------------------------------------------------------------- /n8-make-js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | INPUT=$1; shift 4 | OUTPUT=$1; shift 5 | 6 | ARGS= 7 | PRESETS=env 8 | PLUGINS=transform-runtime,syntax-async-functions,transform-async-to-generator,transform-dirname-filename,add-module-exports,transform-object-rest-spread 9 | 10 | while [ "x$1" != "x" ] 11 | do 12 | case "$1" in 13 | --preset) 14 | shift 15 | PRESETS="$PRESETS,$1" 16 | ;; 17 | --plugin) 18 | shift 19 | PLUGINS="$PLUGINS,$1" 20 | ;; 21 | *) 22 | ARGS="$ARGS "$1"" 23 | ;; 24 | esac 25 | shift 26 | done 27 | 28 | # compile ES6 code to ES5 compat code for Webpack / Node.js 29 | babel \ 30 | "$INPUT" \ 31 | --out-file "$OUTPUT" \ 32 | --source-maps \ 33 | --presets "$PRESETS" \ 34 | --plugins "$PLUGINS" \ 35 | $ARGS 36 | -------------------------------------------------------------------------------- /n8-make-json: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # JSON files are a special-case, just copy them over as-is: 4 | # Node.js can load them by default 5 | # Webpack can use "json-loader" 6 | cat "$1" > "$2" 7 | -------------------------------------------------------------------------------- /n8-make-jsx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # compile React.js JSX code to ES5 compat code for Webpack / Node.js 4 | n8-make-js "$@" --preset react 5 | -------------------------------------------------------------------------------- /n8-make-pug: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # compile Pug code to the template JS function 4 | # TODO: figure out Source Map support 5 | pug --client < "$1" > "$2" && 6 | echo "module.exports = template;" >> "$2" 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "n8-make", 3 | "version": "1.8.6", 4 | "description": "Opinionated Makefile to build ES6 JS, JSX and Pug files", 5 | "main": "index.js", 6 | "bin": "./n8-make", 7 | "scripts": { 8 | "test": "sh test/test.sh" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/TooTallNate/n8-make.git" 13 | }, 14 | "keywords": [ 15 | "make", 16 | "js", 17 | "jsx", 18 | "react", 19 | "pug", 20 | "build", 21 | "makefile", 22 | "es6", 23 | "babel" 24 | ], 25 | "author": "Nathan Rajlich ", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/TooTallNate/n8-make/issues" 29 | }, 30 | "homepage": "https://github.com/TooTallNate/n8-make#readme", 31 | "dependencies": { 32 | "babel-cli": "^6.7.5", 33 | "babel-core": "^6.7.2", 34 | "babel-plugin-add-module-exports": "^0.2.1", 35 | "babel-plugin-syntax-async-functions": "^6.3.13", 36 | "babel-plugin-transform-async-to-generator": "^6.4.6", 37 | "babel-plugin-transform-dirname-filename": "^1.1.0", 38 | "babel-plugin-transform-object-rest-spread": "^6.16.0", 39 | "babel-plugin-transform-runtime": "^6.6.0", 40 | "babel-preset-env": "^1.6.1", 41 | "babel-preset-react": "^6.5.0", 42 | "babel-runtime": "^6.6.1", 43 | "json-loader": "^0.5.4", 44 | "pug-cli": "^1.0.0-alpha6", 45 | "source-map-loader": "^0.2.3", 46 | "webpack": "^3.10.0" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/js-async-await/index.js: -------------------------------------------------------------------------------- 1 | function sleep (ms) { 2 | return new Promise((resolve, reject) => { 3 | setTimeout(() => resolve(), ms); 4 | }); 5 | } 6 | 7 | export default async (input) => { 8 | await sleep(100); 9 | return input * 2; 10 | } 11 | -------------------------------------------------------------------------------- /test/js-async-await/test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert'; 2 | import asyncFn from './'; 3 | 4 | function isThenable (val) { 5 | return val && 'function' === typeof val.then; 6 | } 7 | 8 | // rethrow unhandled promise errors (for assert()) 9 | process.on('unhandledRejection', (err) => { 10 | throw err; 11 | }); 12 | 13 | const promise = asyncFn(42); 14 | 15 | assert(isThenable(promise)); 16 | 17 | let called = false; 18 | promise.then((rtn) => { 19 | called = true; 20 | assert.equal(rtn, 84); 21 | }); 22 | process.on('exit', () => { 23 | assert(called); 24 | }); 25 | -------------------------------------------------------------------------------- /test/js-es6/index.js: -------------------------------------------------------------------------------- 1 | export default 'bar'; 2 | -------------------------------------------------------------------------------- /test/js-es6/test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert'; 2 | import index from './'; 3 | 4 | assert.equal(index, 'bar'); 5 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # run all the tests 4 | 5 | if [ "x$NODE" = "x" ]; then 6 | NODE=node 7 | fi 8 | 9 | RED=`tput setaf 1` 10 | GREEN=`tput setaf 2` 11 | RESET=`tput sgr0` 12 | 13 | FILENAME=`which $0` 14 | FILENAME=`"$NODE" -pe "require('fs').realpathSync('$FILENAME')"` 15 | DIR=`dirname "$FILENAME"` 16 | 17 | # expose `n8-make` to the PATH 18 | export PATH=$PATH:$DIR/.. 19 | 20 | TEST_DIRS=$(find "$DIR" -mindepth 1 -maxdepth 1 -type d) 21 | 22 | for i in $TEST_DIRS; do 23 | n8-make clean --directory "$i" 24 | done 25 | 26 | for i in $TEST_DIRS; do 27 | echo testing: $i 28 | cd "$i" 29 | n8-make clean 30 | n8-make build 31 | 32 | # allow for a `test.js` or `test.sh` file per-test 33 | if [ -f $i/build/test.js ] 34 | then 35 | "$NODE" $i/build/test.js 36 | else 37 | $i/test.sh 38 | fi 39 | 40 | cd "$DIR" 41 | 42 | # exit early if the test failed 43 | EXIT=$? 44 | if [ $EXIT = 0 ] 45 | then 46 | echo " ${GREEN}✓${RESET} Pass" 47 | else 48 | echo " ${RED}✗${RESET} Failed, bailing…" 49 | exit $EXIT 50 | fi 51 | done; 52 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | // Webpack has its own configuration for module resolution. 2 | // Let's make it mimic how `NODE_PATH` works. 3 | var modulesDirectories = process.env.NODE_PATH.split(':'); 4 | var i; 5 | while (-1 !== (i = modulesDirectories.indexOf(''))) { 6 | modulesDirectories.splice(i, 1); 7 | } 8 | if (-1 === modulesDirectories.indexOf('node_modules')) { 9 | modulesDirectories.push('node_modules'); 10 | } 11 | 12 | module.exports = { 13 | resolve: { 14 | modulesDirectories: modulesDirectories 15 | }, 16 | module: { 17 | preLoaders: [ 18 | { 19 | test: /\.js$/, 20 | loader: require.resolve('source-map-loader') 21 | } 22 | ], 23 | loaders: [ 24 | { 25 | test: /\.json/, 26 | loader: require.resolve('json-loader') 27 | } 28 | ] 29 | }, 30 | debug: true, 31 | devtool: 'source-map' 32 | }; 33 | --------------------------------------------------------------------------------