Mercurial > hg > cmmr2012-drupal-site
comparison core/scripts/js/babel-es6-watch.js @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 /** | |
2 * @file | |
3 * | |
4 * Watch changes to *.es6.js files and compile them to ES5 during development. | |
5 * | |
6 * @internal This file is part of the core javascript build process and is only | |
7 * meant to be used in that context. | |
8 */ | |
9 | |
10 'use strict'; | |
11 | |
12 const fs = require('fs'); | |
13 const path = require('path'); | |
14 const chokidar = require('chokidar'); | |
15 | |
16 const changeOrAdded = require('./changeOrAdded'); | |
17 const log = require('./log'); | |
18 | |
19 // Match only on .es6.js files. | |
20 const fileMatch = './**/*.es6.js'; | |
21 // Ignore everything in node_modules | |
22 const watcher = chokidar.watch(fileMatch, { | |
23 ignoreInitial: true, | |
24 ignored: './node_modules/**' | |
25 }); | |
26 | |
27 const unlinkHandler = (err) => { | |
28 if (err) { | |
29 log(err); | |
30 } | |
31 }; | |
32 | |
33 // Watch for filesystem changes. | |
34 watcher | |
35 .on('add', changeOrAdded) | |
36 .on('change', changeOrAdded) | |
37 .on('unlink', (filePath) => { | |
38 const fileName = filePath.slice(0, -7); | |
39 fs.stat(`${fileName}.js`, () => { | |
40 fs.unlink(`${fileName}.js`, unlinkHandler); | |
41 }); | |
42 }) | |
43 .on('ready', () => log(`Watching '${fileMatch}' for changes.`)); |