1 | [![npm version](https://badge.fury.io/js/metalsmith-changed.svg)](https://badge.fury.io/js/metalsmith-changed) [![Build Status](https://travis-ci.org/arve0/metalsmith-changed.svg?branch=master)](https://travis-ci.org/arve0/metalsmith-changed)
|
2 |
|
3 | # metalsmith-changed
|
4 | Only process files that have changed. **Must** be used with `.clean(false)`, as
|
5 | it removes files from the build. `Metalsmith.clean(true)` will disable this plugin.
|
6 |
|
7 | Writes a json file with ctimes to your `src`-folder.
|
8 |
|
9 |
|
10 | ## example
|
11 | ```js
|
12 | var Metalsmith = require('metalsmith');
|
13 | var changed = require('metalsmith-changed');
|
14 |
|
15 | Metalsmith()
|
16 | .clean(false)
|
17 | .use(changed())
|
18 | ... // more plugins
|
19 | .build(function (err) {
|
20 | if (err) throw err;
|
21 | });
|
22 | ```
|
23 |
|
24 | Which is useful when using `gulp.watch`:
|
25 | ```js
|
26 | var Metalsmith = require('metalsmith');
|
27 | var changed = require('metalsmith-changed');
|
28 | var gulp = require('gulp');
|
29 | var path = require('path');
|
30 |
|
31 | function build (force) {
|
32 | return function (cb) {
|
33 | Metalsmith()
|
34 | .clean(force) // forces build even if files has not changed
|
35 | .use(changed())
|
36 | ... // more plugins
|
37 | .build(cb);
|
38 | }
|
39 | }
|
40 |
|
41 | // only build changed files
|
42 | gulp.watch(path.join(__dirname, 'src', '**'), build(false));
|
43 |
|
44 | // force build of all files
|
45 | gulp.watch(path.join(__dirname, 'templates', '**'), build(true));
|
46 | ```
|
47 |
|
48 |
|
49 | ## metalsmith-changed-ctimes.json
|
50 | `metalsmith-changed-ctimes.json` is written to your `src` folder upon every build. `metalsmith-changed` takes ctimes from `files[n].stats.ctime`, so if your plugin creates files with `.stats.ctime`, `metalsmith-changed` can be used with it.
|
51 |
|
52 | Files without `stats.ctime` are always built.
|
53 |
|
54 |
|
55 | ## forcePattern
|
56 | If the option `forcePattern` is defined, files matching the pattern(s) will not
|
57 | be removed from building even if the file has not changed. `forcePattern` should
|
58 | be a string or an array of strings.
|
59 |
|
60 | [micromatch](https://github.com/jonschlinkert/micromatch) is used for
|
61 | matching the files.
|
62 |
|
63 | Example:
|
64 | ```js
|
65 | Metalsmith()
|
66 | .clean(false)
|
67 | .use(changed({
|
68 | forcePattern: [
|
69 | '**/index.md', // always build index files
|
70 | ... // more patterns
|
71 | ]
|
72 | }))
|
73 | ... // more plugins
|
74 | .build(function(err){
|
75 | if (err) throw err;
|
76 | });
|
77 | ```
|
78 |
|
79 |
|
80 | ## default options
|
81 | ```js
|
82 | changed({
|
83 | force: false, // build all files
|
84 | forcePattern: false // always build files matching these patterns
|
85 | })
|
86 | ```
|
87 |
|
88 |
|
89 | ## develop
|
90 | ```sh
|
91 | npm build # babel
|
92 | npm test
|
93 | DEBUG=metalsmith-changed npm test # test with debug output
|
94 | ```
|
95 |
|
96 | ## release
|
97 | ```sh
|
98 | npm version patch|minor|major
|
99 | npm publish
|
100 | ```
|