Skip to content

Commit

Permalink
Updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
osztenkurden committed Mar 12, 2021
1 parent b23d713 commit 2218e73
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 947 deletions.
49 changes: 49 additions & 0 deletions OpenBrowserPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const open = require('open');

module.exports = class OpenBrowser {
constructor(options) {
if (typeof options === 'string') {
this.options = Object.assign(
{
hasOpen: false
},
{
url: options
}
);
} else {
this.options = Object.assign(
{
port: 8080,
host: 'localhost',
protocol: 'http:',
hasOpen: false
},
options
);
}
}

apply(compiler) {
const options = this.options;
let url;
let hasOpen = options.hasOpen;
if (options.protocol && !options.protocol.endsWith(':')) options.protocol += ':';
if (options.url) url = options.url;
else url = `${options.protocol}//${options.host}:${options.port}`;
if (compiler.hooks) {
compiler.hooks.afterEmit.tap('openBrowser', () => {
if (!hasOpen) open(url);
hasOpen = true;
this.options.hasOpen = true;
});
} else {
compiler.plugin('after-emit', (c, cb) => {
if (!hasOpen) open(url);
hasOpen = true;
this.options.hasOpen = true;
return cb();
});
}
}
};
2 changes: 1 addition & 1 deletion craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const fs = require('fs');
const homedir = require('os').homedir();
const internalIp = require('internal-ip');
const OpenBrowserPlugin = require('open-browser-plugin')
const OpenBrowserPlugin = require('./OpenBrowserPlugin');

const pathToConfig = path.join(process.env.APPDATA || path.join(homedir, '.config'), 'hud-manager', 'databases', 'config');
let port = 1349;
Expand Down
Loading

0 comments on commit 2218e73

Please sign in to comment.