Skip to content

Commit 25d7f3e

Browse files
committed
chore(*): clean up and documentating contributing.md
1 parent 44428c5 commit 25d7f3e

16 files changed

+90
-194
lines changed

Diff for: .eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"lit/binding-positions": 0
2222
// "jsx-quotes": [2, "prefer-single"],
2323
},
24-
"ignorePatterns": ["**/*.js", "mocks"]
24+
"ignorePatterns": ["**/*.js", "mocks", "**/*.mjs"]
2525
}

Diff for: .storybook/preview-head.html

-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@
1313
id="dev-console-gateway"
1414
src="https://assets.developer.tech.gov.sg/bundled-scripts/dev-console-gateway.bundle.js"
1515
></script>
16-
<script src="../lib/index.js"></script>

Diff for: CODE_CONVENTIONS.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
## Table of contents
44

55
- [sgds-web-components coding style guide](#typescript-coding-style-guide)
6-
- [Naming](#naming)
7-
- [Naming Conventions](#naming-conventions)
8-
- [Naming Booleans](#naming-booleans)
9-
- [Brackets](#brackets)
10-
- [Spaces](#spaces)
11-
- [Semicolons](#semicolons)
12-
- [Code Comments](#code-comments)
13-
- [Barrels](#barrels)
14-
- [Angular coding style guide](#angular-coding-style-guide)
156

16-
- [Organize imports](#organize-imports)
17-
- [Use typescript aliases](#use-typescript-aliases)
18-
- [Specify component member accessor explicitly](#specify-component-member-accessor-explicitly)
19-
- [Component structure](#component-structure)
20-
- [private Subject, public Observable pattern](#private-subject,-public-observable-pattern)
21-
- [Services inside HTML templates](#services-inside-HTML-templates)
22-
- [Manage Subscriptions Declaratively](#manage-subscriptions-declaratively)
7+
- [Events](#events)
8+
- [Typescript](#typescript)
9+
- [Jsdocs](#jsdoc)
2310

24-
### Naming
11+
### Events
2512

26-
### Typescript
13+
1. Events should be named with an action word , prefix with `sgds-`
2714

28-
All variables, properties and functions should be typed. The Tscompiler can infer the type of properties when a default value is assigned but not when none is defined. If a variable does not need to have a default variable, assign a type to it.
15+
Bad: `hide`, `show`
16+
Good: `sgds-hide, sgds-show, sgds-after-show, sgds-toggle`
2917

30-
Bad:
18+
2. Before creating a new event name, check if there are existing names for the same purposed.
19+
20+
3. Use the `emit` method of SgdsElement class to emit a custom event
21+
22+
#### variable
23+
24+
Variables should be
25+
26+
### Typescript
27+
28+
All variables, properties and functions should be typed. The Tscompiler can infer the type of properties when a default value is assigned but not when none is defined. If a variable does not need to have a default variable, assign a type to it.
29+
30+
Bad:
3131

3232
```typescript
3333
@property({ type: Boolean, reflect: true }) isLight;
@@ -90,8 +90,8 @@ export class SgdsAccordionItem extends SgdsElement {
9090
9191
4. Annotate public methods with jsdocs comments. Any methods that is meant expose for users should be marked with the "public" access modifier
9292
93-
```typescript
93+
```typescript
9494
/** Shows the accordion. */
9595
public async show() {
9696
}
97-
```
97+
```

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To run single test file, run the output javascript test file instead of the type
3030

3131
## Storybook
3232

33-
Write documentation in storybook in MDX format. Include API argstable, import instructions, at least a basic example and custom css properties table (if present)
33+
The basic storybook documentation is auto-generated from the cem metadata. Write your template examples inside `stories/templates/<Component>` folder
3434

3535
## Markdown files and README.md
3636

Diff for: index.html

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<script type="module" id="dev-console-gateway"
1010
src="https://assets.developer.tech.gov.sg/bundled-scripts/dev-console-gateway.bundle.js"></script>
1111
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
12+
<style>
1213
* {
1314
font-family: "bootstrap-icons", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
1415
}

Diff for: package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
"module": "lib/index.js",
77
"typings": "lib/index.d.ts",
88
"scripts": {
9-
"build:dev": "rm -rf lib && rollup --config rollup.dev.config.js",
10-
"build:prod": "rm -rf lib && rollup --config rollup.config.js",
9+
"build:dev": "rm -rf lib && rollup --config rollup.config.js --environment NODE_ENV:development",
10+
"build:prod": "rm -rf lib && rollup --config rollup.config.js --environment NODE_ENV:production",
1111
"build:react": "npm run cem && node ./scripts/makeReact.mjs",
1212
"build:readme": "gulp build-readme",
13-
"build:stories": "npm run cem && node ./scripts/generateStories.mjs && npm run concat:stories",
13+
"write:stories": "npm run cem && node ./scripts/generateStories.mjs && npm run concat:stories",
1414
"build:lib": "npm run build:react && npm run build:prod && npm run post:build",
1515
"build:watch": "npm run build:dev -- --watch",
1616
"post:build": "node ./scripts/frankBuild.js",
1717
"dev": "npm run build:watch & npm run serve",
1818
"serve": "wds --watch --open",
1919
"test": "rm -rf test-outdir && rollup --config rollup.test.config.js && web-test-runner",
2020
"test:scripts": "wtr scripts/__tests__/**/*.test.js --node-resolve",
21-
"storybook": "npm run build:stories && npm run build:dev && start-storybook -p 6006",
22-
"build-storybook": "rm -rf lib && npm run build:dev && npm run build:stories && build-storybook",
21+
"storybook": "npm run write:stories && npm run build:dev && start-storybook -p 6006",
22+
"build-storybook": "rm -rf lib && npm run build:dev && npm run write:stories && build-storybook",
2323
"prepare": "husky install",
2424
"concat:stories": "gulp concat-storybook-mdx",
2525
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",

Diff for: rollup.config.js

+28-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const wcPlugins = [
1212
browser: true
1313
}),
1414
replace({
15-
"process.env.NODE_ENV": JSON.stringify("production"),
15+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
1616
preventAssignment: true
1717
}),
1818
postcss({
@@ -92,25 +92,7 @@ const reactFolderBuilds = getFolders("src/react").map(folder => {
9292
plugins: reactSubFolderBuildPlugins(folder)
9393
};
9494
});
95-
export default [
96-
{
97-
input: "src/index.ts",
98-
output: [
99-
{
100-
file: packageJson.module,
101-
format: "esm",
102-
sourcemap: true
103-
},
104-
{
105-
file: packageJson.main,
106-
format: "umd",
107-
sourcemap: true,
108-
name: "index"
109-
}
110-
],
111-
plugins: wcPlugins
112-
},
113-
...wcfolderBuilds,
95+
const reactPackage = [
11496
{
11597
input: "src/react/index.ts",
11698
output: [
@@ -150,3 +132,29 @@ export default [
150132
},
151133
...reactFolderBuilds
152134
];
135+
const buildSgdsPackage = () => {
136+
const sgdsWcPackage = [
137+
{
138+
input: "src/index.ts",
139+
output: [
140+
{
141+
file: packageJson.module,
142+
format: "esm",
143+
sourcemap: true
144+
},
145+
{
146+
file: packageJson.main,
147+
format: "umd",
148+
sourcemap: true,
149+
name: "index"
150+
}
151+
],
152+
plugins: wcPlugins
153+
},
154+
...wcfolderBuilds
155+
];
156+
if (process.env.NODE_ENV === "production") return sgdsWcPackage.concat(reactPackage);
157+
return sgdsWcPackage;
158+
};
159+
160+
export default buildSgdsPackage;

Diff for: rollup.dev.config.js

-75
This file was deleted.

Diff for: scripts/generateStories.mjs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import commandLineArgs from 'command-line-args';
1+
import { deleteSync } from 'del';
22
import fs from 'fs';
3+
import groupBy from 'lodash/groupBy.js';
34
import path from 'path';
4-
import chalk from 'chalk';
5-
import { deleteSync } from 'del';
65
import prettier from 'prettier';
7-
import prettierConfig from '../prettier.config.js';
8-
import { getAllComponents, getSgdsComponents } from './shared.mjs';
96
import { makeArgTypes } from './makeArgTypes.mjs';
10-
import groupBy from 'lodash/groupBy.js';
11-
const storiesDir = path.join('stories/components');
127
import { methodsTable } from './methodsTable.mjs';
8+
import { getAllComponents, getSgdsComponents } from './shared.mjs';
9+
10+
const storiesDir = path.join('stories/components');
1311

1412
// Clear build directory
1513
deleteSync(storiesDir);

Diff for: src/Accordion/sgds-accordion-item.ts

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class SgdsAccordionItem extends SgdsElement {
3434
@property({ type: Boolean, reflect: true }) open = false;
3535
/** Title of the accordion */
3636
@property() summary: string;
37-
//TODO: disabled feature is not a supposed feature in accordion?
3837
/** Disables the accordion-item. When true, accordion-item cannot open */
3938
@property({ type: Boolean, reflect: true }) disabled = false;
4039
/** Optional for accordion item. Can be used to insert any utility classes such as `me-auto` */

Diff for: src/Accordion/sgds-accordion.ts

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class SgdsAccordion extends SgdsElement {
2121
@queryAssignedNodes()
2222
private defaultNodes!: NodeListOf<SgdsAccordionItem>;
2323

24-
//TODO: confirm if this is a public method or for internal usage only
2524
/** @internal */
2625
get items(): SgdsAccordionItem[] {
2726
return [...(this.defaultNodes || [])].filter(

Diff for: stories/templates/ActionCard/additional.mdx

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
export const TemplateType = (args) =>
1+
export const TemplateType = args =>
22
html`
3-
<div class="col">
4-
<sgds-action-card
5-
type="radio"
6-
>
7-
<span slot="card-subtitle">${args.cardSubtitleSlot}</span>
8-
<span slot="card-title">${args.cardTitleSlot}</span>
9-
<span slot="card-text">${args.cardTextSlot}</span>
10-
</sgds-action-card>
11-
<div>
12-
<div class="col">
13-
<sgds-action-card
14-
type="checkbox"
15-
>
16-
<span slot="card-subtitle">${args.cardSubtitleSlot}</span>
17-
<span slot="card-title">${args.cardTitleSlot}</span>
18-
<span slot="card-text">${args.cardTextSlot}</span>
19-
</sgds-action-card>
20-
<div>
21-
`;
3+
<div class="col">
4+
<sgds-action-card type="radio">
5+
<span slot="card-subtitle">Laptop</span>
6+
<span slot="card-title">Apple</span>
7+
<span slot="card-text">Macbook Pro M1</span>
8+
</sgds-action-card>
9+
<div>
10+
<div class="col">
11+
<sgds-action-card type="checkbox">
12+
<span slot="card-subtitle">Laptop</span>
13+
<span slot="card-title">Apple</span>
14+
<span slot="card-text">Macbook Pro M1</span>
15+
</sgds-action-card>
16+
<div></div>
17+
</div>
18+
</div>
19+
</div>
20+
`;
2221

2322
## Type
2423

2524
Use `type` prop : `radio` / `checkbox` to change the selectable card input type
2625

2726
<Canvas>
28-
<Story name='Type'>{TemplateType.bind({})}</Story>
27+
<Story name="Type">{TemplateType.bind({})}</Story>
2928
</Canvas>

Diff for: tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"module": "es2015",
55
"moduleResolution": "node",
66
"lib": ["es2017", "dom", "dom.iterable"],
7-
// "declaration": true,
8-
// "declarationDir": "lib",
7+
"declaration": true,
8+
"declarationDir": "lib",
99
"sourceMap": true,
1010
"inlineSources": true,
1111
"experimentalDecorators": true,

Diff for: tsconfig.react.json

-19
This file was deleted.

0 commit comments

Comments
 (0)