2016-11-29 11:42:20 +05:30
|
|
|
/* eslint-env node */
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2016-11-30 12:44:08 +05:30
|
|
|
const fs = require('fs');
|
|
|
|
|
2016-11-29 11:42:20 +05:30
|
|
|
const webpack = require('webpack');
|
|
|
|
const chalk = require('chalk');
|
|
|
|
|
|
|
|
const webpackConfig = require('../webpack.dll.config.js');
|
|
|
|
|
|
|
|
const compiler = webpack(webpackConfig);
|
|
|
|
|
2016-11-30 12:44:08 +05:30
|
|
|
Promise.all([
|
2019-11-27 14:33:32 +05:30
|
|
|
stat(`${__dirname}/../yarn.lock`),
|
|
|
|
stat(`${__dirname}/../dll/vendor.json`),
|
2016-11-30 12:44:08 +05:30
|
|
|
])
|
2019-11-27 14:33:32 +05:30
|
|
|
.then(stats => {
|
|
|
|
const lockFile = new Date(stats[0].mtime);
|
|
|
|
const dll = new Date(stats[1].mtime);
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
if (dll < lockFile) {
|
|
|
|
return Promise.reject({
|
|
|
|
code: 'OUTDATED',
|
|
|
|
});
|
|
|
|
}
|
2016-11-29 11:42:20 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
logResult(chalk.green('Current dlls are up to date!'));
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
if (err.code !== 'ENOENT' && err.code !== 'OUTDATED') {
|
|
|
|
return Promise.reject(err);
|
|
|
|
}
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
console.log('Rebuilding dlls...');
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
compiler.run((err, stats) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
logResult(
|
|
|
|
chalk.green('Dll was successfully build in %s ms'),
|
|
|
|
stats.endTime - stats.startTime,
|
|
|
|
);
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
resolve();
|
|
|
|
});
|
2016-11-30 12:44:08 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
logResult(chalk.red('Unexpected error checking dll state'), err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
function logResult(...args) {
|
|
|
|
console.log('\n');
|
|
|
|
console.log(...args);
|
|
|
|
console.log('\n');
|
2016-11-30 12:44:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function stat(path) {
|
2019-11-27 14:33:32 +05:30
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
fs.stat(path, (err, stats) => {
|
|
|
|
err ? reject(err) : resolve(stats);
|
|
|
|
});
|
|
|
|
});
|
2016-11-30 12:44:08 +05:30
|
|
|
}
|