0.4.3 • Published 11 months ago

brinejs v0.4.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

brine

Brine is a set of tools for creating web components by wrapping applications written in popular frameworks.

It enables developers to write components in their favourite framework and use them in any other project, regardless of what framework is used there.

More on the power of web components here

Currently, brine supports the following frameworks

  • React
  • Vue
  • Svelte
  • Solid

Install

npm install --save brinejs

Usage

brine consists of 2 separate layers and a meta object

  • the wrapper, this is th web component that wraps around the framework code
  • the options object, the internals that contain the framework specific code
  • the meta object, contains metadata required to create thw component

Examples

react

import { define } from 'brinejs/react'
import App from './App'

define(App, {
    emits: ["change"],
    attributes: ["text", "header"],
    style: `.dummy-style{}`,
    tag: 'my-react-app',
})

vue

import {createOptions} from 'brinejs/vue'
import App from './App.vue'

svelte

import {createOptions} from 'brinejs/svelte'
import App from './App.svelte'

solid js

import {createOptions} from 'brinejs/solid'
import App from './App'

Build tools

Brine contains some helper functions that makes building and bundling simpler.

hot component transplant

Hot component transplant server is a websocket server that allows developers to automatically transplant components during development or debugging.

// build script
import {startHotComponentTransplantServer} from 'brinejs/build'

const hotTransplant = startHotComponentTransplantServer()
const build = () => {
    // ... some build code
    hotTransplant(['path/to/some/file/that/changed.js'])
}
// in browser
new WebSocket('ws://localhost:8080').onmessage = 
    async (ev) => {import(ev.data+'?t='+Date.now())}

boilerplate generation

Brine has two code generation methods, 'writeMetaFile' and 'writeIndexFile'. They can be used to generate boilerplate code, specifically the meta object that describes the component.

meta file

// Generate meta file
import {writeMetaFile} from '/brine'

await writeMetaFile('App.tsx', 'my') // (filePath, prefix or filename)
// output
// App.meta.ts
export const meta = {
    emits: ["my-click"],
    attributes: ["count", "text", "obj"],
    style: `.dummy-style{}`,
    tag: 'my-app',
}

index file

// Generate meta file
import {writeIndexFile} from '/brine'

await writeIndexFile('App.tsx', 'my') // (filePath, prefix or filename)
// output
// index.ts
import { define } from 'brinejs/react'
import App from './SolidApp.js'

define(App, {
    emits: [] as string[],
    attributes: ["count"] as string[],
    style: `.dummy-style{}` as string,
    tag: 'my-solid-app' as string,
})

css injection

Most builders produce separate js and css files as build output. Since the styling needs to be in the code, this styling must be injected into the code somehow.

Brine has a helper method that can modify a bundled js file and inject css into it. It also updates and adjusts the source map to match the new content.

import {writeJsMapCssGroup, groupJsMapCssFiles} from '/brine'

const groupedFiles = groupJsMapCssFiles(['./dist/App.js'])
await writeJsMapCssGroup(groupedFiles)

type documentation

Type documentation can be extracted and generated for the components

import {
  generateTypes,
  writeTypesFile,
  writeVsCodeTypes,
  writeWebTypes
} from 'brine'

const types = await generateTypes(['src/App.tsx'], 'my')
// json file with serialized typing
await writeTypesFile(types, 'dist')

// vscode.html-custom-data.json (VsCode)
await writeVsCodeTypes(types, 'dist')

// web-types.json (JetBrains, IntelliJ/WebStorm)
await writeWebTypes(types, 'dist', {
  name: 'example',
  version: '1.0.0',
})

// react wrappers
await writeReactWrappersFile(types, 'dist/wrapper')
0.4.3

11 months ago

0.4.1-beta-036

1 year ago

0.4.2

1 year ago

0.3.4-beta-028

1 year ago

0.3.4-beta-027

1 year ago

0.3.4-beta-029

1 year ago

0.3.4

1 year ago

0.3.4-beta-031

1 year ago

0.3.4-beta-030

1 year ago

0.3.4-beta-033

1 year ago

0.3.4-beta-032

1 year ago

0.3.4-beta-034

1 year ago

0.4.1

1 year ago

0.4.1-beta-035

1 year ago

0.4.0

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0-beta-026

1 year ago

0.3.0

1 year ago

0.2.7-beta-025

1 year ago

0.2.7-beta-024

1 year ago

0.2.7

1 year ago

0.2.6-beta-023

1 year ago

0.2.6

1 year ago

0.2.5-beta-022

1 year ago

0.2.5-beta-021

1 year ago

0.2.5-beta-020

1 year ago

0.2.5-beta-019

1 year ago

0.2.5-beta-018

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2-beta-017

1 year ago

0.2.2

1 year ago

0.2.1-beta-016

1 year ago

0.2.1-beta-015

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.6-beta-014

1 year ago

0.1.6-beta-013

1 year ago

0.1.6-beta-012

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4-beta-011

1 year ago

0.1.4

1 year ago

0.1.3-beta-010

1 year ago

0.1.3-beta-009

1 year ago

0.1.3-beta-008

1 year ago

0.1.3

1 year ago

0.1.2-beta-007

1 year ago

0.1.2-beta-006

1 year ago

0.1.2-beta-005

1 year ago

0.1.2-beta-004

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0-beta-003

1 year ago

0.1.0-beta-002

1 year ago

0.1.0-beta001

1 year ago

0.1.0

1 year ago