Skip to content

Commit

Permalink
Migrate CustomVersionFilePlugin to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
JKobrynski committed Mar 8, 2024
1 parent 0141669 commit 3c29359
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions config/webpack/CustomVersionFilePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as FS from 'fs';
import type {Compiler} from 'webpack';

const fs = require('fs');
const fs = require('fs') as typeof FS;
const path = require('path');
const APP_VERSION = require('../../package.json').version;

Expand All @@ -9,27 +10,16 @@ const APP_VERSION = require('../../package.json').version;
*/
class CustomVersionFilePlugin {
apply(compiler: Compiler) {
compiler.hooks.done.tap(
this.constructor.name,
() =>
new Promise((resolve, reject) => {
const versionPath = path.join(__dirname, '/../../dist/version.json');
fs.mkdir(path.dirname(versionPath), {recursive: true}, (dirErr) => {
if (dirErr) {
reject(dirErr);
return;
}
fs.writeFile(versionPath, JSON.stringify({version: APP_VERSION}), 'utf8', (fileErr) => {
if (fileErr) {
reject(fileErr);
return;
}
resolve();
});
});
}),
);
compiler.hooks.done.tap(this.constructor.name, () => {
const versionPath = path.join(__dirname, '/../../dist/version.json');
fs.mkdir(path.dirname(versionPath), {recursive: true}, (dirErr) => {
if (dirErr) {
return;
}
fs.writeFile(versionPath, JSON.stringify({version: APP_VERSION}), {encoding: 'utf8'}, () => {});
});
});
}
}

export default CustomVersionFilePlugin;
export = CustomVersionFilePlugin;

0 comments on commit 3c29359

Please sign in to comment.