UNPKG

2.52 kBMarkdownView Raw
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
4Only process files that have changed. **Must** be used with `.clean(false)`, as
5it removes files from the build. `Metalsmith.clean(true)` will disable this plugin.
6
7Writes a json file with ctimes to your `src`-folder.
8
9
10## example
11```js
12var Metalsmith = require('metalsmith');
13var changed = require('metalsmith-changed');
14
15Metalsmith()
16 .clean(false)
17 .use(changed())
18 ... // more plugins
19 .build(function (err) {
20 if (err) throw err;
21 });
22```
23
24Which is useful when using `gulp.watch`:
25```js
26var Metalsmith = require('metalsmith');
27var changed = require('metalsmith-changed');
28var gulp = require('gulp');
29var path = require('path');
30
31function 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
42gulp.watch(path.join(__dirname, 'src', '**'), build(false));
43
44// force build of all files
45gulp.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
52Files without `stats.ctime` are always built.
53
54
55## forcePattern
56If the option `forcePattern` is defined, files matching the pattern(s) will not
57be removed from building even if the file has not changed. `forcePattern` should
58be a string or an array of strings.
59
60[micromatch](https://github.com/jonschlinkert/micromatch) is used for
61matching the files.
62
63Example:
64```js
65Metalsmith()
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
82changed({
83 force: false, // build all files
84 forcePattern: false // always build files matching these patterns
85})
86```
87
88
89## develop
90```sh
91npm build # babel
92npm test
93DEBUG=metalsmith-changed npm test # test with debug output
94```
95
96## release
97```sh
98npm version patch|minor|major
99npm publish
100```