Skip to content

Commit d116f5f

Browse files
authored
feat(create-rstack): add Solid library templates (#250)
1 parent 3fcf1b7 commit d116f5f

24 files changed

Lines changed: 565 additions & 0 deletions

‎packages/create-rstack/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ npx create-rstack -d my-project -t app-vanilla-ts
3535
- `lib-react-ts` - TypeScript React library
3636
- `lib-vue-js` - JavaScript Vue library
3737
- `lib-vue-ts` - TypeScript Vue library
38+
- `lib-solid-js` - JavaScript Solid library
39+
- `lib-solid-ts` - TypeScript Solid library
3840

3941
## Documentation
4042

‎packages/create-rstack/src/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
5252
{ value: 'node', label: 'Node.js' },
5353
{ value: 'react', label: 'React' },
5454
{ value: 'vue', label: 'Vue' },
55+
{ value: 'solid', label: 'Solid' },
5556
],
5657
}),
5758
);
@@ -87,6 +88,8 @@ await create({
8788
'lib-react-ts',
8889
'lib-vue-js',
8990
'lib-vue-ts',
91+
'lib-solid-js',
92+
'lib-solid-ts',
9093
],
9194
builtinTools: [],
9295
getTemplateName,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AGENTS.md
2+
3+
## Commands
4+
5+
- `{{ packageManager }} run build` - Build the library for production
6+
- `{{ packageManager }} run dev` - Rebuild the library when source files change
7+
- `{{ packageManager }} run test` - Run tests
8+
- `{{ packageManager }} run test:watch` - Run tests in watch mode
9+
10+
## Docs
11+
12+
- Rslib: https://rslib.rs/llms.txt
13+
- Rspack: https://rspack.rs/llms.txt
14+
- Rstest: https://rstest.rs/llms.txt
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Rstack library
2+
3+
## Setup
4+
5+
Install the dependencies:
6+
7+
```bash
8+
{{ packageManager }} install
9+
```
10+
11+
## Get started
12+
13+
Build the library:
14+
15+
```bash
16+
{{ packageManager }} run build
17+
```
18+
19+
Build the library in watch mode:
20+
21+
```bash
22+
{{ packageManager }} run dev
23+
```
24+
25+
Run tests:
26+
27+
```bash
28+
{{ packageManager }} run test
29+
```
30+
31+
Run tests in watch mode:
32+
33+
```bash
34+
{{ packageManager }} run test:watch
35+
```
36+
37+
## Learn more
38+
39+
- [Rstack documentation](https://rstack.rs)
40+
- [Rslib documentation](https://rslib.rs)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "rstack-lib-solid-js",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"exports": {
6+
".": {
7+
"solid": "./dist/index.jsx",
8+
"default": "./dist/index.js"
9+
}
10+
},
11+
"files": [
12+
"dist",
13+
"README.md"
14+
],
15+
"scripts": {
16+
"build": "rs lib",
17+
"dev": "rs lib --watch",
18+
"format": "rs fmt",
19+
"lint": "rs lint",
20+
"test": "rs test",
21+
"test:watch": "rs test --watch"
22+
},
23+
"devDependencies": {
24+
"@rsbuild/plugin-babel": "^2.0.1",
25+
"@rsbuild/plugin-solid": "^1.2.2",
26+
"@solidjs/testing-library": "^0.8.10",
27+
"@testing-library/dom": "^10.4.1",
28+
"@testing-library/jest-dom": "^7.0.0",
29+
"happy-dom": "^20.11.1",
30+
"rstack": "^0.3.5",
31+
"solid-js": "^1.9.14"
32+
},
33+
"peerDependencies": {
34+
"solid-js": ">=1.8.0"
35+
},
36+
"publishConfig": {
37+
"access": "public"
38+
}
39+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// @ts-check
2+
// Rstack configuration guide: https://rstack.rs/config
3+
import { define } from 'rstack';
4+
5+
define.lib(async () => {
6+
const { pluginBabel } = await import('@rsbuild/plugin-babel');
7+
const { pluginSolid } = await import('@rsbuild/plugin-solid');
8+
9+
return {
10+
lib: [
11+
{
12+
id: 'compiled',
13+
bundle: false,
14+
plugins: [
15+
pluginBabel({
16+
include: /\.(?:jsx|tsx)$/,
17+
}),
18+
pluginSolid(),
19+
],
20+
},
21+
{
22+
id: 'source',
23+
bundle: false,
24+
output: {
25+
filename: {
26+
js: '[name].jsx',
27+
},
28+
},
29+
tools: {
30+
swc: {
31+
detectSyntax: 'auto',
32+
jsc: {
33+
transform: {
34+
react: {
35+
runtime: 'preserve',
36+
},
37+
},
38+
},
39+
},
40+
rspack: {
41+
module: {
42+
parser: {
43+
javascript: {
44+
jsx: true,
45+
},
46+
},
47+
},
48+
},
49+
},
50+
},
51+
],
52+
source: {
53+
entry: {
54+
index: ['./src/**'],
55+
},
56+
},
57+
output: {
58+
target: 'web',
59+
},
60+
};
61+
});
62+
63+
define.test(async () => {
64+
const { pluginBabel } = await import('@rsbuild/plugin-babel');
65+
const { pluginSolid } = await import('@rsbuild/plugin-solid');
66+
67+
return {
68+
setupFiles: ['./tests/rstest.setup.js'],
69+
plugins: [
70+
pluginBabel({
71+
include: /\.(?:jsx|tsx)$/,
72+
}),
73+
pluginSolid(),
74+
],
75+
};
76+
});
77+
78+
define.lint(async () => {
79+
const { js } = await import('rstack/lint');
80+
81+
return [js.configs.recommended];
82+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import './button.css';
2+
3+
export function Button(props) {
4+
const mode = () => (props.primary ? 'demo-button--primary' : 'demo-button--secondary');
5+
const size = () => props.size ?? 'medium';
6+
7+
return (
8+
<button
9+
type="button"
10+
class={`demo-button demo-button--${size()} ${mode()}`}
11+
style={{ 'background-color': props.backgroundColor }}
12+
onClick={props.onClick}
13+
>
14+
{props.label}
15+
</button>
16+
);
17+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.demo-button {
2+
font-weight: 700;
3+
border: 0;
4+
border-radius: 3em;
5+
cursor: pointer;
6+
display: inline-block;
7+
line-height: 1;
8+
}
9+
10+
.demo-button--primary {
11+
color: white;
12+
background-color: #1ea7fd;
13+
}
14+
15+
.demo-button--secondary {
16+
color: #333;
17+
background-color: transparent;
18+
box-shadow: rgba(0, 0, 0, 0.15) 0 0 0 1px inset;
19+
}
20+
21+
.demo-button--small {
22+
font-size: 12px;
23+
padding: 10px 16px;
24+
}
25+
26+
.demo-button--medium {
27+
font-size: 14px;
28+
padding: 11px 20px;
29+
}
30+
31+
.demo-button--large {
32+
font-size: 16px;
33+
padding: 12px 24px;
34+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Button } from './Button';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { render, screen } from '@solidjs/testing-library';
2+
import { expect, test } from 'rstack/test';
3+
import { Button } from '../src/Button';
4+
5+
test('The button should have correct background color', async () => {
6+
render(() => <Button backgroundColor="#ccc" label="Demo Button" />);
7+
const button = screen.getByText('Demo Button');
8+
expect(button).toHaveStyle({
9+
'background-color': '#ccc',
10+
});
11+
});

0 commit comments

Comments
 (0)