mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-27 07:26:31 -05:00
JS: Add watch support to copying flow files
This commit is contained in:
@@ -1,14 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const chokidar = require('chokidar');
|
||||
const fs = require('fs-extra');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
|
||||
function exitIfError(err) {
|
||||
// Start at 1 for the initial scan.
|
||||
let pending = 1;
|
||||
|
||||
const shouldWatch = process.argv.indexOf('-w') !== -1 ||
|
||||
process.argv.indexOf('--watch') !== -1;
|
||||
|
||||
chokidar.watch('./src')
|
||||
.on('add', copyFile)
|
||||
.on('change', copyFile)
|
||||
.on('unlink', removeFile)
|
||||
.on('ready', done);
|
||||
|
||||
function done(err) {
|
||||
pending--;
|
||||
if (err) {
|
||||
console.error(err); // eslint-disable-line
|
||||
process.exit(1);
|
||||
}
|
||||
if (pending === 0 && !shouldWatch) {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
function copyFile(f) {
|
||||
pending++;
|
||||
let nn = newName(f)
|
||||
process.stdout.write(`${f} -> ${nn}\n`);
|
||||
fs.copy(f, nn, {clobber: true}, done);
|
||||
}
|
||||
|
||||
function removeFile(f) {
|
||||
pending++;
|
||||
process.stdout.write(`${f} -> /dev/null\n`);
|
||||
fs.remove(f, done);
|
||||
}
|
||||
|
||||
function newName(f) {
|
||||
@@ -20,10 +49,3 @@ function newName(f) {
|
||||
parts[parts.length - 1] += '.flow';
|
||||
return parts.join(path.sep);
|
||||
}
|
||||
|
||||
glob('src/**/*.js', (err, files) => {
|
||||
exitIfError(err);
|
||||
for (const f of files) {
|
||||
fs.copy(f, newName(f), {clobber: true}, exitIfError);
|
||||
}
|
||||
});
|
||||
|
||||
+4
-5
@@ -20,19 +20,18 @@
|
||||
"babel-preset-es2015": "^6.3.13",
|
||||
"babel-preset-react": "^6.3.13",
|
||||
"chai": "^3.2.0",
|
||||
"chokidar": "^1.4.0",
|
||||
"eslint": "^1.9.0",
|
||||
"eslint-plugin-react": "^3.8.0",
|
||||
"flow-bin": "^0.19.1",
|
||||
"fs-extra": "^0.26.2",
|
||||
"glob": "^6.0.1",
|
||||
"mocha": "^2.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run copy-flow-files && BABEL_ENV=production babel src/ -d dist/",
|
||||
"build-dev": "npm run copy-flow-files && babel src/ -d dist/",
|
||||
"start": "node build/copy-flow-files.js -w & babel -w src/ -d dist/",
|
||||
"build": "node build/copy-flow-files.js && BABEL_ENV=production babel src/ -d dist/",
|
||||
"pretest": "eslint src/ && flow src/",
|
||||
"test": "mocha --ui tdd --reporter dot --require babel-polyfill --compilers js:babel-core/register src/",
|
||||
"copy-flow-files": "node build/copy-flow-files.js"
|
||||
"test": "mocha --ui tdd --reporter dot --require babel-polyfill --compilers js:babel-core/register src/"
|
||||
},
|
||||
"browser": {
|
||||
"./dist/fetch.js": "./dist/browser/fetch.js"
|
||||
|
||||
Reference in New Issue
Block a user