Skip to content

Commit

Permalink
feature(#1): enable() / disable()
Browse files Browse the repository at this point in the history
  • Loading branch information
talss89 committed Sep 21, 2023
1 parent a5c26c6 commit a93971e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/extension.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { __decorate } from "tslib";
import { Bud } from '@roots/bud-framework';
import { Extension } from '@roots/bud-framework/extension';
import { bind, label } from '@roots/bud-framework/extension/decorators';
import { bind, label, expose } from '@roots/bud-framework/extension/decorators';
import localtunnel from 'localtunnel/localtunnel.js';
let BudLocaltunnel = class BudLocaltunnel extends Extension {
#devTunnel;
async configAfter(bud) {
if (bud.isDevelopment) {
if (bud.isDevelopment && this.enabled) {
this.#devTunnel = await localtunnel({ subdomain: bud.context.label.length > 3 ? bud.context.label : undefined, local_host: bud.server?.url.hostname, port: bud.server?.url.port });
const tunnelUrl = new URL(this.#devTunnel.url);
bud.setPublicUrl(tunnelUrl);
Expand All @@ -23,6 +23,7 @@ __decorate([
bind
], BudLocaltunnel.prototype, "configAfter", null);
BudLocaltunnel = __decorate([
label(`bud-localtunnel`)
label(`bud-localtunnel`),
expose(`localtunnel`)
], BudLocaltunnel);
export default BudLocaltunnel;
3 changes: 3 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ declare module '@roots/bud-framework' {
interface Modules {
'bud-localtunnel': BudLocaltunnel;
}
interface Bud {
localtunnel: BudLocaltunnel;
}
}
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import {Bud} from '@roots/bud-framework'
import {Extension} from '@roots/bud-framework/extension'
import type {WebpackPluginInstance} from '@roots/bud-framework/config'

import {bind, label} from '@roots/bud-framework/extension/decorators'
import {bind, label, expose} from '@roots/bud-framework/extension/decorators'

import localtunnel from 'localtunnel/localtunnel.js'

interface Options {}

@label(`bud-localtunnel`)
@expose(`localtunnel`)
export default class BudLocaltunnel extends Extension<
Options,
WebpackPluginInstance
Expand All @@ -19,7 +20,7 @@ export default class BudLocaltunnel extends Extension<

@bind
public override async configAfter(bud: Bud) {
if(bud.isDevelopment) {
if(bud.isDevelopment && this.enabled) {
this.#devTunnel = await localtunnel({ subdomain: bud.context.label.length > 3 ? bud.context.label : undefined, local_host: bud.server?.url.hostname, port: bud.server?.url.port })

const tunnelUrl = new URL(this.#devTunnel.url);
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ declare module '@roots/bud-framework' {
interface Modules {
'bud-localtunnel': BudLocaltunnel
}

interface Bud {
localtunnel: BudLocaltunnel
}
}

0 comments on commit a93971e

Please sign in to comment.