• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build, test, and publish vanilla Web Components with a little spice

Nutmeg icon

Nutmeg logo

Build, test, and publish vanilla Web Components with a little spice

Version Status macOS Build Status Linux Build Status Windows Build Status Dependency Status

🚧 Nutmeg is in active development and it's APIs are still in flux.

👌 Overview

Nutmeg is here to help you build, test, and publish Web Components in minutes.

By default you get the following:

  • Custom Elements v1
  • Shadow DOM v1
  • TypeScript
  • lit-html
  • Karma test runner with headless browser launchers
  • Git
  • MIT license
  • Web Component best practices

🌱 Build

Generating a Nutmeg Web Component skeleton with npm init has the API <element-name> [property:type...].

npm init @nutmeg hello-world name:string

This will create a hello-world directory, stub out a base Web Component class HelloWorld that extends the Nutmeg Seed base class, and install the default dependencies. You can use either fullName or full-name for multi-word properties and full-name will be used for HTML attributes and fullName will be used in JavaScript.

Note: Yarn is not supported but may work.

🏡 Properties

Properties must be valid TypeScript types. For example string, boolean, number, string[], Element.

npm init @nutmeg grilled-cheese quantity:number pickles:boolean cheese:string[]

Properties are the public API of your Web Component and external code can set/get them.

export class GrilledCheese extends Seed {
  @property() public bread: string;
  @property() public cheese: string[];
  @property() public pickles: boolean;
  @property() public quantity: number;
  ...
}

The @property() decorator provides some nice features out of the box. There are two kinds of properties.

  • Primitive: boolean, string, and number.
  • Complex: any types that are not primitive.

✍️ Automatic rendering

Any properties decorated with @property will automatically render when set.

📟 Primitive properties are reflected to the DOM

  • boolean: grilledCheese.pickle = true; => <grilled-cheese pickle></grilled-cheese>
  • number: grilledCheese.quantity = 5; => <grilled-cheese quantity="5"></grilled-cheese>
  • string: grilledCheese.bread = 'sourdough'; => <grilled-cheese bread="sourdough"></grilled-cheese>

📱 One-time complex property loading from attributes

On instantiation of a Web Component a one-time loading and JSON parsing happens of complex properties. In the following example cheese has the type of string[]. When connected the component will have the attribute removed and the value set as a property after JSON.parse.

The following example:

<grilled-cheese cheese="[\"sharp cheddar\"]"></grilled-cheese>

Yields:

grilledCheese.cheese.includes('sharp cheddar') === true;
<grilled-cheese></grilled-cheese>

$ and $$

$ and $$ are shortcuts provided for quickly selecting elements within the shadowRoot.

  • $ is a shortcut for this.shadowRoot.querySelector.
  • $$ is a shortcut for this.shadowRoot.querySelectorAll.

🍽️ Serve

You can now serve the component for development on http://localhost:8080 by running:

npm start

With start running you can make edits to the component and see the changes take effect automatically without manually refreshing.

🧪 Test

Running the tests from within hello-world.

npm test

🔭 Continuous Integration

Components are generated with AppVeyor, CircleCI, and TravisCI pre-configured to run tests on Windows, macOS, and Linux respectively.

🗞️ Publish

Publishing to NPM is easy but make sure you are logged in first with npm login. Be sure to fill out package.json values like author and update the name in readme.md if you change it.

npm publish

📇 Dependencies

Once published, it's recommended that you set up Renovate to keep your dependencies current. Nutmeg has already setup a default renovate config for you, you just have to install the free GitHub app.

😎 Best practices

Out of the box many of the Google Web Fundamentals Custom Element Best Practices are handled automatically.

🔍 Examples

👔 License

Nutmeg is released under an MIT license.

More Repositories

1

twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
PHP
4,284
star
2

reflection

Lightweight (3K) ES Module implementation of reflect-metadata
TypeScript
251
star
3

pkg-ok

👌 Checks paths and scripts defined in package.json before you publish
TypeScript
237
star
4

birb

WIP: Instagram for birds built in Flutter
Dart
96
star
5

twitter-status

Twitter Status Web Component
TypeScript
59
star
6

chrome-extension-google-apis

Sample Google Chrome extension that demonstrates using the Chrome Identity API to authorize Google API access
JavaScript
55
star
7

twitter-d

TypeScript types for Twitter API objects
TypeScript
54
star
8

twitter-user

Twitter User Web Component
TypeScript
40
star
9

github-anywhere

An experimental JavaScript platform for adding follow, watch, and fork widgets to any site with a simple HTML snippet.
JavaScript
40
star
10

omnitweet

An experimental minimalist Twitter Client for Google Chrome.
JavaScript
38
star
11

twitteroauth-com

Documentation site for using the TwitterOAuth library.
HTML
36
star
12

node-package

Node Package Web Component
TypeScript
21
star
13

sprinkle

Example PWA that demonstrates an offline web app using the Unsplash REST API.
JavaScript
16
star
14

github-repository

GitHub Repository Web Component
TypeScript
15
star
15

chargify

Example code for integrating a PHP application with the Chargify billing service
PHP
15
star
16

remotedata

Maintain your remote data state with confidence
TypeScript
15
star
17

succynct

Minimalist App.net client for Google Chrome
JavaScript
11
star
18

getting-started-with-webpack

Getting started with Webpack
JavaScript
8
star
19

slides-today

Slides.today is a site dedicated to the presentations @abraham and @pearlbea give at conferences and meetups.
TypeScript
7
star
20

sign-in-with-twitter

Lightweight Sign in with Twitter Drupal module.
PHP
7
star
21

life

Conway's Game of Life in 3D
JavaScript
6
star
22

php-twitter

A minimalist PHP Twitter API.
PHP
6
star
23

end-of-day

Slack bot for collecting a summary of your team's activity for the day
TypeScript
6
star
24

pwa-ng

Progressive Web Apps made ridiculously easy with Angular
HTML
5
star
25

gde-social

Tweets from GDEs
TypeScript
5
star
26

intersect

Source code for Intersect.
JavaScript
5
star
27

google-chrome-extensions

Various Google Chrome extension
JavaScript
5
star
28

nutmeg-hello-world

Example Web Component started with Nutmeg
TypeScript
5
star
29

poseurhttp

PHP library for making HTTP connections with cURL
PHP
4
star
30

audio-rpg

Play an audio based RPG simple by calling a phone number.
4
star
31

social-backup

Some scripts to backup personal social activities using Heorku
Python
4
star
32

intersect-api

An API to get common friends, followers, and friends following from two Twitter accounts
JavaScript
4
star
33

tasks-codelab

Join me for a live codelab where I will run through building a JavaScript based web app powered by a REST API
JavaScript
4
star
34

matciphone

Code samples from my MATCiPhone Class
3
star
35

abraham

TypeScript
2
star
36

engager

Turn off native retweets for everyone you follow on Twitter
Python
2
star
37

intersect.labs.abrah.am

An API to get common friends, followers, and friends following from two Twitter accounts.
2
star
38

twibes

Google Chrome extension that adds http://www.twibes.com links to Twitter profiles
JavaScript
1
star
39

quark

Quark Clicker: Rails ActionCable sample application
Ruby
1
star
40

test-push-wiki

1
star
41

civility

The easiest way to manage your Civ5 hotseat games hosted by GMR
Ruby
1
star
42

flutter-sandbox

Sandbox for playing with
Dart
1
star
43

material-rocks

A collection of Material Design animations to take your app to the next level
HTML
1
star
44

timely-for-chrome

Adds a Timely schedule button to twitter.com
JavaScript
1
star
45

firebase-hosting-sitemap

Sample Firebase Hosting project with sitemap.xml
HTML
1
star
46

daily-cat

WIP
JavaScript
1
star
47

adn-widgets

JavaScript widgets for App.net
JavaScript
1
star
48

abraham-ror

Ruby
1
star
49

thank-you

Thank You aims to encourage positive action by recognizing people on Twitter for their good deeds.
Ruby
1
star
50

movie-maven

JavaScript
1
star
51

pwa-today

HTML
1
star
52

development

Simple script for keeping projects updated
Shell
1
star
53

hackernews-extension

An experimental extension to augment your Hacker News experience.
JavaScript
1
star