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
1 change: 0 additions & 1 deletion .templates/component/global.d.ts

This file was deleted.

6 changes: 6 additions & 0 deletions .templates/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"prepack": "pnpm run build",
"clean": "rm -rf node_modules dist"
},
"dependencies": {
"@radix-ui/react-slot": "catalog:",
"@sipe-team/tokens": "workspace:*",
"@vanilla-extract/recipes": "catalog:",
"clsx": "catalog:"
},
"devDependencies": {
"@testing-library/jest-dom": "catalog:",
"@testing-library/react": "catalog:",
Expand Down
16 changes: 0 additions & 16 deletions .templates/component/src/Component.stories.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions .templates/component/src/Component.tsx

This file was deleted.

14 changes: 14 additions & 0 deletions .templates/component/src/Template.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { vars } from '@sipe-team/tokens';

import { recipe } from '@vanilla-extract/recipes';

export const template = recipe({
base: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontFamily: vars.typography.fontFamily,
},
variants: {},
defaultVariants: {},
});
20 changes: 20 additions & 0 deletions .templates/component/src/Template.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Template } from './Template';

const meta = {
title: 'Components/Template',
component: Template,
parameters: {
layout: 'centered',
},
} satisfies Meta<typeof Template>;
export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {
args: {
children: 'Template',
},
};
10 changes: 10 additions & 0 deletions .templates/component/src/Template.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render, screen } from '@testing-library/react';
import { expect, test } from 'vitest';

import { Template } from './Template';

test('renders Template', () => {
render(<Template>Test</Template>);

expect(screen.getByText('Test')).toBeInTheDocument();
});
21 changes: 21 additions & 0 deletions .templates/component/src/Template.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { type ForwardedRef, forwardRef, type HTMLAttributes } from 'react';

import { Slot } from '@radix-ui/react-slot';

import { clsx as cx } from 'clsx';

import * as styles from './Template.css';

export interface TemplateProps extends HTMLAttributes<HTMLDivElement> {
asChild?: boolean;
}

export const Template = forwardRef(function Template(
{ asChild, className: _className, ...props }: TemplateProps,
ref: ForwardedRef<HTMLDivElement>,
) {
const Comp = asChild ? Slot : 'div';
const className = cx(styles.template(), _className);

return <Comp ref={ref} className={className} {...props} />;
});
2 changes: 1 addition & 1 deletion .templates/component/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './Component';
export * from './Template';
9 changes: 2 additions & 7 deletions .templates/component/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { defineConfig } from 'tsup';
import defaultConfig from '../../tsup.config';

export default defineConfig({
entry: ['src/index.ts'],
clean: true,
dts: true,
format: ['esm', 'cjs'],
});
export default defaultConfig;
22 changes: 13 additions & 9 deletions scripts/createComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ class CreateComponentCommand extends Command {
.join('');
}

private pascalToCamel(str: string): string {
return str.charAt(0).toLowerCase() + str.slice(1);
}

private replacePatterns(kebabCaseName: string, pascalCaseName: string) {
return {
Component: pascalCaseName,
'package-name': kebabCaseName,
} as const;
const camelCaseName = this.pascalToCamel(pascalCaseName);

return [
['template', camelCaseName],
['Template', pascalCaseName],
['package-name', kebabCaseName],
] as const;
}

private async validateTemplateDir(templateDir: string): Promise<void> {
Expand Down Expand Up @@ -53,17 +60,14 @@ class CreateComponentCommand extends Command {
for (const entry of entries) {
if (!this.excludePatterns.includes(entry.name)) {
const sourcePath = path.join(source, entry.name);
const newName = entry.name.replaceAll('Component', pascalCaseName);
const newName = patterns.reduce((name, [search, replace]) => name.replaceAll(search, replace), entry.name);
const targetPath = path.join(target, newName);
await this.copyRecursive(sourcePath, targetPath, kebabCaseName, pascalCaseName);
}
}
} else {
const content = await fs.readFile(source, 'utf-8');
const updatedContent = Object.entries(patterns).reduce(
(content, [search, replace]) => content.replace(new RegExp(search, 'g'), replace),
content,
);
const updatedContent = patterns.reduce((acc, [search, replace]) => acc.replaceAll(search, replace), content);

await fs.writeFile(target, updatedContent);
}
Expand Down
Loading