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
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
Promise.all([stat(`${__dirname}/../../yarn.lock`), stat(`${__dirname}/../../dll/vendor.json`)])
|
|
|
|
.then(([lockFileStats, dllFileStats]) => {
|
|
|
|
const lockFile = new Date(lockFileStats.mtime);
|
|
|
|
const dll = new Date(dllFileStats.mtime);
|
|
|
|
|
|
|
|
if (dll < lockFile) {
|
|
|
|
return Promise.reject({
|
|
|
|
code: 'OUTDATED',
|
|
|
|
});
|
|
|
|
}
|
2016-11-29 11:42:20 +05:30
|
|
|
|
2020-05-24 04:38:24 +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
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
console.log('Rebuilding dlls...');
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
compiler.run((err, stats) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
logResult(chalk.green('Dll was successfully build in %s ms'), stats.endTime! - stats.startTime!);
|
2016-11-30 12:44:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
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 {
|
2020-05-24 04:38:24 +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> {
|
2020-05-24 04:38:24 +05:30
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
fs.stat(path, (err, stats) => {
|
|
|
|
err ? reject(err) : resolve(stats);
|
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-11-30 12:44:08 +05:30
|
|
|
}
|