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