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