npm package: @staffbase/create-widget
Description: initializer for staffbase widgets
Author: Staffbase
Latest version: 2.7.1


![Staffbase Logo](https://staffbase.com/wp-content/themes/staffbase-theme/img/logo-blau.svg)

# Staffbase Create-Widget

## Description

The "Create Widget" repository is an utility to kick start the development of a custom element, used in the employee application. It generates the file and folder structure, a first 
small example widget and the toolbelt to run the development cycle and build the final script. 

The widgets are based on the web component standard and leverage the lifecycle methods of it. Read more about web components in the [documentation](https://developer.mozilla.org/en-US/docs/Web/Web_Components).

## File structure

The root folder contains the configuration files and package manager description. For Webpack the config differentiate between development and production environments for more clarity. 

``` 
.
├── README.md
├── favicon.png
├── index.html
├── package.json
├── src
│   ├── bootstrap.ts
│   ├── config.tsx
│   ├── configuration-schema.ts
│   ├── dummy-widget.tsx
│   └── index.tsx
├── tsconfig.json
├── webpack.common.js
├── webpack.dev.js
└── webpack.prod.js

```

### Source files


#### bootstrap.ts

A mocked implementation of the registration methods used in the real application. It is needed to preview the widget in development.

#### config.tsx

The configuration form which is rendered from the configuration schema in the widget. It is also used in the preview to alter the component.

#### configuration-schema.ts

A simple schema to define custom settings for the widget. For more information, please refer to the documentation of [RJFS](https://rjsf-team.github.io/react-jsonschema-form/docs/).

#### widget.tsx

The naming of this file should reflect the chosen widget name. This file contains the logic of the widget. It is rendered within the render method of the index.tsx file.

#### index.tsx

Bootstrap the widget here to be used inside the target platform. Also the block definition is set here.


# Usage:
```
npx @staffbase/create-widget
``` 

Read more about custom-element naming conventions [here](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name).

## cli-options:

`--packageManager=[npm|yarn]`

`--org=[orgName]`

`--name=[widgetName]`

## Running Locally
To run the generator from a local copy of the source code, first install dependencies:
```
npm install
```
then build the generator:
```
npm run build
```
and finally, start the generator using:
```
node bin/index.js
```
The generated widget code will reside in the current directory.

## Release a new version

The releases are managed by **semantic-release**, which uses the commit messages to determine the consumer impact of changes in the codebase.
Following formalized conventions for commit messages, **semantic-release** automatically determines the next [semantic version](https://semver.org) number, generates a changelog and publishes the release.


The table below shows which commit message gets you which release type when `semantic-release` runs (using the default configuration):

| Commit message                                                                                                                                                                                   | Release type                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
| `fix(pencil): stop graphite breaking when too much pressure applied`                                                                                                                             | Fix Release                                                                                           |
| `feat(pencil): add 'graphiteWidth' option`                                                                                                                                                       | Feature Release                                                                                       |
| `perf(pencil): remove graphiteWidth option`<br><br>`BREAKING CHANGE: The graphiteWidth option has been removed.`<br>`The default graphite width of 10mm is always used for performance reasons.` | Breaking Release <br /> (Note that the `BREAKING CHANGE: ` token must be in the footer of the commit) |