2019-12-07 16:58:52 +05:30
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2016-11-29 11:42:20 +05:30
|
|
|
/* eslint-env node */
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
import fs, { Stats } from 'fs';
|
|
|
|
import webpack, { MultiCompiler } from 'webpack';
|
|
|
|
import chalk from 'chalk';
|
2016-11-29 11:42:20 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
import webpackConfig from './../../webpack.dll.config';
|
2016-11-29 11:42:20 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
// @ts-ignore
|
|
|
|
const compiler: MultiCompiler = webpack(webpackConfig);
|
2016-11-29 11:42:20 +05:30
|
|
|
|
2016-11-30 12:44:08 +05:30
|
|
|
Promise.all([
|
2019-12-08 00:32:00 +05:30
|
|
|
stat(`${__dirname}/../../yarn.lock`),
|
|
|
|
stat(`${__dirname}/../../dll/vendor.json`),
|
2016-11-30 12:44:08 +05:30
|
|
|
])
|
2020-01-18 02:07:52 +05:30
|
|
|
.then(([lockFileStats, dllFileStats]) => {
|
|
|
|
const lockFile = new Date(lockFileStats.mtime);
|
|
|
|
const dll = new Date(dllFileStats.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!'));
|
|
|
|
})
|
2020-05-20 22:05:52 +05:30
|
|
|
.catch((err) => {
|
2019-11-27 14:33:32 +05:30
|
|
|
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'),
|
2020-01-18 02:07:52 +05:30
|
|
|
stats.endTime! - stats.startTime!,
|
2019-11-27 14:33:32 +05:30
|
|
|
);
|
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
|
|
|
})
|
2020-05-20 22:05:52 +05:30
|
|
|
.catch((err) => {
|
2019-11-27 14:33:32 +05:30
|
|
|
logResult(chalk.red('Unexpected error checking dll state'), err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
function logResult(...args: any[]): void {
|
2019-11-27 14:33:32 +05:30
|
|
|
console.log('\n');
|
|
|
|
console.log(...args);
|
|
|
|
console.log('\n');
|
2016-11-30 12:44:08 +05:30
|
|
|
}
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
function stat(path: string): Promise<Stats> {
|
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
|
|
|
}
|