Skip to content

Commit

Permalink
add story
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-peruzzo committed Nov 28, 2024
1 parent 91b864c commit 321ab0c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
"keycloakify-svelte",
"!keycloakify-svelte/**/*.test.*",
"!keycloakify-svelte/**/*.spec.*",
"stories",
"src",
"!src/**/*.test.*",
"!src/**/*.spec.*",
Expand Down
3 changes: 3 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ run('cp package.json dist/package.json && cp LICENSE dist/LICENSE && cp README.m
run('cp -r src dist/src', {
cwd: getThisCodebaseRootDirPath(),
});
run('cp -r stories dist/stories', {
cwd: getThisCodebaseRootDirPath(),
});
run('npx publint', {
cwd: join(getThisCodebaseRootDirPath(), 'dist'),
});
Expand Down
23 changes: 9 additions & 14 deletions src/bin/add-story.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import chalk from 'chalk';
import cliSelect from 'cli-select';
import * as fs from 'fs';
import { dirname as pathDirname, join as pathJoin, relative as pathRelative } from 'path';
import { assert, Equals } from 'tsafe/assert';
import { capitalize } from 'tsafe/capitalize';
import {
ACCOUNT_THEME_PAGE_IDS,
type AccountThemePageId,
Expand All @@ -27,8 +27,9 @@ export async function command(params: { buildContext: BuildContext }) {
return buildContext.implementedThemeTypes.account.isImplemented;
case 'login':
return buildContext.implementedThemeTypes.login.isImplemented;
case 'admin':
return false;
}
// @ts-ignore
assert<Equals<typeof themeType, never>>(false);
});

Expand Down Expand Up @@ -58,8 +59,9 @@ export async function command(params: { buildContext: BuildContext }) {
return [...LOGIN_THEME_PAGE_IDS];
case 'account':
return [...ACCOUNT_THEME_PAGE_IDS];
case 'admin':
return [];
}
// @ts-ignore
assert<Equals<typeof themeType, never>>(false);
})(),
}).catch(() => {
Expand All @@ -68,15 +70,9 @@ export async function command(params: { buildContext: BuildContext }) {

console.log(`→ ${pageId}`);

const componentBasename = pageId.replace(/ftl$/, 'stories.ts');
const componentBasename = capitalize(pageId.replace(/ftl$/, '')) + 'stories.svelte';

const targetFilePath = pathJoin(
buildContext.themeSrcDirPath,
themeType,
'pages',
pageId.replace(/\.ftl$/, ''),
componentBasename,
);
const targetFilePath = pathJoin(buildContext.themeSrcDirPath, themeType, 'pages', componentBasename);

if (fs.existsSync(targetFilePath)) {
console.log(`${pathRelative(process.cwd(), targetFilePath)} already exists`);
Expand All @@ -86,8 +82,7 @@ export async function command(params: { buildContext: BuildContext }) {

let sourceCode = fs
.readFileSync(pathJoin(getThisCodebaseRootDirPath(), 'stories', themeType, 'pages', componentBasename))
.toString('utf8')
.replace(/["']\.\.\/KcPageStory["']/, "'../../KcPageStory'");
.toString('utf8');

run_prettier: {
if (!(await getIsPrettierAvailable())) {
Expand Down Expand Up @@ -115,7 +110,7 @@ export async function command(params: { buildContext: BuildContext }) {
`${chalk.green('✓')} ${chalk.bold(
pathJoin('.', pathRelative(process.cwd(), targetFilePath)),
)} copy pasted from the Keycloakify source code into your project`,
`You can start storybook with ${chalk.bold('npm run storybook')}`,
`You can start storybook with ${chalk.bold('yarn run storybook')}`,
].join('\n'),
);
}

0 comments on commit 321ab0c

Please sign in to comment.