Skip to content

Commit 3c0604d

Browse files
authored
feat(create-rstack): add React library templates (#242)
1 parent ee18c63 commit 3c0604d

37 files changed

Lines changed: 538 additions & 40 deletions

‎packages/create-rstack/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ npx create-rstack -d my-project -t app-vanilla-ts
2525
- `app-vanilla-ts` - TypeScript Vanilla application
2626
- `app-react-js` - JavaScript React application
2727
- `app-react-ts` - TypeScript React application
28-
- `lib-js` - JavaScript Node.js library
29-
- `lib-ts` - TypeScript Node.js library
28+
- `lib-node-js` - JavaScript Node.js library
29+
- `lib-node-ts` - TypeScript Node.js library
30+
- `lib-react-js` - JavaScript React library
31+
- `lib-react-ts` - TypeScript React library
3032

3133
## Documentation
3234

‎packages/create-rstack/rstack.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define.lib({
66
});
77

88
define.test({
9+
include: ['./tests/**/*.test.ts'],
910
source: {
1011
tsconfigPath: './tests/tsconfig.json',
1112
},

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
1313
return `app-${framework}-${language}`;
1414
}
1515

16+
if (template === 'lib' || template.startsWith('lib-')) {
17+
const [, libraryType = 'node', language = 'js'] = template.split('-');
18+
19+
if (libraryType === 'js' || libraryType === 'ts') {
20+
return `lib-node-${libraryType}`;
21+
}
22+
23+
return `lib-${libraryType}-${language}`;
24+
}
25+
1626
const [type, language = 'js'] = template.split('-');
1727
return `${type}-${language}`;
1828
}
@@ -27,18 +37,21 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
2737
}),
2838
);
2939

30-
const framework =
31-
projectType === 'app'
32-
? checkCancel<string>(
33-
await select({
34-
message: 'Select framework',
35-
options: [
40+
const templateType = checkCancel<string>(
41+
await select({
42+
message: projectType === 'app' ? 'Select framework' : 'Select library type',
43+
options:
44+
projectType === 'app'
45+
? [
3646
{ value: 'vanilla', label: 'Vanilla' },
3747
{ value: 'react', label: 'React' },
48+
]
49+
: [
50+
{ value: 'node', label: 'Node.js' },
51+
{ value: 'react', label: 'React' },
3852
],
39-
}),
40-
)
41-
: undefined;
53+
}),
54+
);
4255

4356
const language = checkCancel<string>(
4457
await select({
@@ -50,7 +63,7 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
5063
}),
5164
);
5265

53-
return framework ? `${projectType}-${framework}-${language}` : `${projectType}-${language}`;
66+
return `${projectType}-${templateType}-${language}`;
5467
};
5568

5669
await create({
@@ -61,8 +74,10 @@ await create({
6174
'app-vanilla-ts',
6275
'app-react-js',
6376
'app-react-ts',
64-
'lib-js',
65-
'lib-ts',
77+
'lib-node-js',
78+
'lib-node-ts',
79+
'lib-react-js',
80+
'lib-react-ts',
6681
],
6782
builtinTools: [],
6883
getTemplateName,
File renamed without changes.
File renamed without changes.

packages/create-rstack/template-lib-js/package.json renamed to packages/create-rstack/template-lib-node-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "rstack-lib-js",
2+
"name": "rstack-lib-node-js",
33
"version": "0.0.0",
44
"sideEffects": false,
55
"type": "module",

packages/create-rstack/template-lib-js/rstack.config.js renamed to packages/create-rstack/template-lib-node-js/rstack.config.js

File renamed without changes.

packages/create-rstack/template-lib-js/src/index.js renamed to packages/create-rstack/template-lib-node-js/src/index.js

File renamed without changes.

packages/create-rstack/template-lib-js/tests/index.test.js renamed to packages/create-rstack/template-lib-node-js/tests/index.test.js

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)