check.js 624 B

1234567891011121314151617181920212223
  1. const chalk = require('chalk');
  2. const fs = require('fs');
  3. const log = require('./log');
  4. const compile = require('./compile');
  5. module.exports = (filePath) => {
  6. log(`'${filePath}' is being checked.`);
  7. // Transform the file.
  8. compile(filePath, function check(code) {
  9. const fileName = filePath.slice(0, -7);
  10. fs.readFile(`${fileName}.js`, function read(err, data) {
  11. if (err) {
  12. log(chalk.red(err));
  13. process.exitCode = 1;
  14. return;
  15. }
  16. if (code !== data.toString()) {
  17. log(chalk.red(`'${filePath}' is not updated.`));
  18. process.exitCode = 1;
  19. }
  20. });
  21. });
  22. }