Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/create-rstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ npx create-rstack --dir my-project --template app-vanilla-ts --no-git

## Templates

- `app-vanilla-js` - JavaScript Vanilla application
- `app-vanilla` - JavaScript Vanilla application
- `app-vanilla-ts` - TypeScript Vanilla application
- `app-react-js` - JavaScript React application
- `app-react` - JavaScript React application
- `app-react-ts` - TypeScript React application
- `app-preact-js` - JavaScript Preact application
- `app-preact` - JavaScript Preact application
- `app-preact-ts` - TypeScript Preact application
- `app-vue-js` - JavaScript Vue application
- `app-vue` - JavaScript Vue application
- `app-vue-ts` - TypeScript Vue application
- `app-lit-js` - JavaScript Lit application
- `app-lit` - JavaScript Lit application
- `app-lit-ts` - TypeScript Lit application
- `app-svelte-js` - JavaScript Svelte application
- `app-svelte` - JavaScript Svelte application
- `app-svelte-ts` - TypeScript Svelte application
- `app-solid-js` - JavaScript Solid application
- `app-solid` - JavaScript Solid application
- `app-solid-ts` - TypeScript Solid application
- `lib-node-js` - JavaScript Node.js library
- `lib-node` - JavaScript Node.js library
- `lib-node-ts` - TypeScript Node.js library
- `lib-react-js` - JavaScript React library
- `lib-react` - JavaScript React library
- `lib-react-ts` - TypeScript React library
- `lib-vue-js` - JavaScript Vue library
- `lib-vue` - JavaScript Vue library
- `lib-vue-ts` - TypeScript Vue library
- `lib-svelte-js` - JavaScript Svelte library
- `lib-svelte` - JavaScript Svelte library
- `lib-svelte-ts` - TypeScript Svelte library
- `lib-solid-js` - JavaScript Solid library
- `lib-solid` - JavaScript Solid library
- `lib-solid-ts` - TypeScript Solid library
- `doc-basic` - Basic documentation site
- `doc` - Basic documentation site
- `doc-i18n` - Multilingual documentation site

## Documentation
Expand Down
106 changes: 49 additions & 57 deletions packages/create-rstack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,55 @@ import {
create,
select,
} from '@rstackjs/create-toolkit';
import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
import { access, appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';

const packageRoot = path.join(import.meta.dirname, '..');

const getTemplateName = async ({ template }: Argv): Promise<string> => {
if (typeof template === 'string') {
if (template === 'app' || template.startsWith('app-')) {
const [, framework = 'vanilla', language = 'js'] = template.split('-');

if (framework === 'js' || framework === 'ts') {
return `app-vanilla-${framework}`;
}

return `app-${framework}-${language}`;
}

if (template === 'lib' || template.startsWith('lib-')) {
const [, libraryType = 'node', language = 'js'] = template.split('-');

if (libraryType === 'js' || libraryType === 'ts') {
return `lib-node-${libraryType}`;
}
const templateNames = [
'app-vanilla',
'app-vanilla-ts',
'app-react',
'app-react-ts',
'app-preact',
'app-preact-ts',
'app-vue',
'app-vue-ts',
'app-lit',
'app-lit-ts',
'app-svelte',
'app-svelte-ts',
'app-solid',
'app-solid-ts',
'lib-node',
'lib-node-ts',
'lib-react',
'lib-react-ts',
'lib-vue',
'lib-vue-ts',
'lib-svelte',
'lib-svelte-ts',
'lib-solid',
'lib-solid-ts',
'doc',
'doc-i18n',
];

const resolveTemplateName = (template: string): string => {
if (!templateNames.includes(template)) {
throw new Error(`Invalid input: template "${template}" not found.`);
}

return `lib-${libraryType}-${language}`;
}
return template;
};

if (template === 'doc' || template.startsWith('doc-')) {
const [, documentationType = 'basic'] = template.split('-');
return `doc-${documentationType}`;
const getTemplateName = async ({ template }: Argv): Promise<string> => {
if (typeof template === 'string') {
if (/^(?:app|lib|doc)(?:-|$)/u.test(template)) {
return resolveTemplateName(template);
}

const [type, language = 'js'] = template.split('-');
return `${type}-${language}`;
return template;
}

const projectType = checkCancel<string>(
Expand Down Expand Up @@ -72,7 +87,7 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
}),
);

return `doc-${documentationType}`;
return resolveTemplateName(documentationType === 'basic' ? 'doc' : 'doc-i18n');
}

const templateType = checkCancel<string>(
Expand Down Expand Up @@ -109,7 +124,8 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
}),
);

return `${projectType}-${templateType}-${language}`;
const templateName = `${projectType}-${templateType}${language === 'ts' ? '-ts' : ''}`;
return resolveTemplateName(templateName);
};

const getStagedConfig = (templateName: string): string => {
Expand Down Expand Up @@ -141,7 +157,10 @@ const injectStagedSetup = async ({
return;
}

const configExtension = templateName.endsWith('-js') ? 'js' : 'ts';
const configExtension = await access(path.join(distFolder, 'rstack.config.ts')).then(
() => 'ts',
() => 'js',
);
const packageJsonPath = path.join(distFolder, 'package.json');
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8')) as {
scripts: Record<string, string>;
Expand All @@ -168,34 +187,7 @@ const injectStagedSetup = async ({
await create({
root: packageRoot,
name: 'rstack',
templates: [
'app-vanilla-js',
'app-vanilla-ts',
'app-react-js',
'app-react-ts',
'app-preact-js',
'app-preact-ts',
'app-vue-js',
'app-vue-ts',
'app-lit-js',
'app-lit-ts',
'app-svelte-js',
'app-svelte-ts',
'app-solid-js',
'app-solid-ts',
'lib-node-js',
'lib-node-ts',
'lib-react-js',
'lib-react-ts',
'lib-vue-js',
'lib-vue-ts',
'lib-svelte-js',
'lib-svelte-ts',
'lib-solid-js',
'lib-solid-ts',
'doc-basic',
'doc-i18n',
],
templates: templateNames,
builtinTools: [],
getTemplateName,
onGitResolved: injectStagedSetup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-app-lit-js",
"name": "rstack-app-lit",
"version": "1.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-app-preact-js",
"name": "rstack-app-preact",
"version": "1.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-app-react-js",
"name": "rstack-app-react",
"version": "1.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-app-solid-js",
"name": "rstack-app-solid",
"version": "1.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-app-svelte-js",
"name": "rstack-app-svelte",
"version": "1.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-app-vanilla-js",
"name": "rstack-app-vanilla",
"version": "1.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-app-vue-js",
"name": "rstack-app-vue",
"version": "1.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-doc-basic",
"name": "rstack-doc",
"version": "0.0.0",
"private": true,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-lib-node-js",
"name": "rstack-lib-node",
"version": "0.0.0",
"sideEffects": false,
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-lib-react-js",
"name": "rstack-lib-react",
"version": "0.0.0",
"type": "module",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-lib-solid-js",
"name": "rstack-lib-solid",
"version": "0.0.0",
"type": "module",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-lib-svelte-js",
"name": "rstack-lib-svelte",
"version": "0.0.0",
"type": "module",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rstack-lib-vue-js",
"name": "rstack-lib-vue",
"version": "0.0.0",
"type": "module",
"exports": {
Expand Down
26 changes: 13 additions & 13 deletions packages/create-rstack/tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@ type SourceTemplate = {
};

const sourceTemplates: SourceTemplate[] = [
{ template: 'app-vanilla-js', sourceExtension: 'js', testFile: 'dom.test.js' },
{ template: 'app-vanilla', sourceExtension: 'js', testFile: 'dom.test.js' },
{ template: 'app-vanilla-ts', sourceExtension: 'ts', testFile: 'dom.test.ts' },
{ template: 'app-react-js', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'app-react', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'app-react-ts', sourceExtension: 'tsx', testFile: 'index.test.tsx' },
{ template: 'app-preact-js', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'app-preact', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'app-preact-ts', sourceExtension: 'tsx', testFile: 'index.test.tsx' },
{ template: 'app-vue-js', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'app-vue', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'app-vue-ts', sourceExtension: 'ts', testFile: 'index.test.ts' },
{ template: 'app-lit-js', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'app-lit', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'app-lit-ts', sourceExtension: 'ts', testFile: 'index.test.ts' },
{ template: 'app-svelte-js', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'app-svelte', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'app-svelte-ts', sourceExtension: 'ts', testFile: 'index.test.ts' },
{ template: 'app-solid-js', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'app-solid', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'app-solid-ts', sourceExtension: 'tsx', testFile: 'index.test.tsx' },
{ template: 'lib-node-js', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'lib-node', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'lib-node-ts', sourceExtension: 'ts', testFile: 'index.test.ts' },
{ template: 'lib-react-js', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'lib-react', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'lib-react-ts', sourceExtension: 'tsx', testFile: 'index.test.tsx' },
{ template: 'lib-vue-js', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'lib-vue', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'lib-vue-ts', sourceExtension: 'ts', testFile: 'index.test.ts' },
{ template: 'lib-svelte-js', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'lib-svelte', sourceExtension: 'js', testFile: 'index.test.js' },
{ template: 'lib-svelte-ts', sourceExtension: 'ts', testFile: 'index.test.ts' },
{ template: 'lib-solid-js', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'lib-solid', sourceExtension: 'jsx', testFile: 'index.test.jsx' },
{ template: 'lib-solid-ts', sourceExtension: 'tsx', testFile: 'index.test.tsx' },
];

const docTemplates = [
{
template: 'doc-basic',
template: 'doc',
files: [
'README.md',
'.gitignore',
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/guide/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Options:
--package-name <name> specify the package name
--template-version <ver> specify the npm template version

Available templates: app-vanilla-js, app-vanilla-ts, app-react-js, app-react-ts, app-preact-js, app-preact-ts, app-vue-js, app-vue-ts, app-lit-js, app-lit-ts, app-svelte-js, app-svelte-ts, app-solid-js, app-solid-ts, lib-node-js, lib-node-ts, lib-react-js, lib-react-ts, lib-vue-js, lib-vue-ts, lib-svelte-js, lib-svelte-ts, lib-solid-js, lib-solid-ts, doc-basic, doc-i18n
Available templates: app-vanilla, app-vanilla-ts, app-react, app-react-ts, app-preact, app-preact-ts, app-vue, app-vue-ts, app-lit, app-lit-ts, app-svelte, app-svelte-ts, app-solid, app-solid-ts, lib-node, lib-node-ts, lib-react, lib-react-ts, lib-vue, lib-vue-ts, lib-svelte, lib-svelte-ts, lib-solid, lib-solid-ts, doc, doc-i18n
```

## Install Rstack
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/guide/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Options:
--package-name <name> specify the package name
--template-version <ver> specify the npm template version

Available templates: app-vanilla-js, app-vanilla-ts, app-react-js, app-react-ts, app-preact-js, app-preact-ts, app-vue-js, app-vue-ts, app-lit-js, app-lit-ts, app-svelte-js, app-svelte-ts, app-solid-js, app-solid-ts, lib-node-js, lib-node-ts, lib-react-js, lib-react-ts, lib-vue-js, lib-vue-ts, lib-svelte-js, lib-svelte-ts, lib-solid-js, lib-solid-ts, doc-basic, doc-i18n
Available templates: app-vanilla, app-vanilla-ts, app-react, app-react-ts, app-preact, app-preact-ts, app-vue, app-vue-ts, app-lit, app-lit-ts, app-svelte, app-svelte-ts, app-solid, app-solid-ts, lib-node, lib-node-ts, lib-react, lib-react-ts, lib-vue, lib-vue-ts, lib-svelte, lib-svelte-ts, lib-solid, lib-solid-ts, doc, doc-i18n
```

## 安装 Rstack \{#install-rstack}
Expand Down