diff --git a/packages/cantos/package.json b/packages/cantos/package.json index 3b8b129..bc55d88 100644 --- a/packages/cantos/package.json +++ b/packages/cantos/package.json @@ -1,8 +1,7 @@ { "name": "cantos", - "private": false, "author": "Bo An", - "version": "0.0.4", + "version": "0.0.5", "keywords": [ "User Stories", "TDD", @@ -30,12 +29,6 @@ "main": "./dist/cantos.umd.cjs", "module": "./dist/cantos.js", "types": "./dist/index.d.ts", - "exports": { - ".": { - "import": "./dist/cantos.js", - "require": "./dist/cantos.umd.cjs" - } - }, "files": [ "dist" ], diff --git a/packages/cantos/src/stories/stories.ts b/packages/cantos/src/stories/stories.ts index 9bba923..0f5b396 100644 --- a/packages/cantos/src/stories/stories.ts +++ b/packages/cantos/src/stories/stories.ts @@ -6,14 +6,13 @@ import {CastProfiles, EmptyCast, IStory, IStoryScript, Test, Who} from "@src/sto import {Genres} from "@src/stories/story-kinds.ts"; import {getPath, populateActPath} from "@src/stories/utils.ts"; import {TestKind} from "@src/stories/test-kinds.ts"; -import {printTag, printTestTags, tellStory} from "@src/stories/storyteller.ts"; +import {printTag, printTestTags, printWho, tellStory} from "@src/stories/storyteller.ts"; import {IStoryScripts} from "@src/stories/story-types.ts"; import {NameList} from "@src/util-types.ts"; import {StoryOptions, StoryVersion} from "@src/stories/story-options.ts"; import {StoryStatus} from "@src/stories/status.ts"; - class StoryScript implements IStoryScript { story: string = STORY_DEFAULTS.DEFAULT_NARRATIVE; parentPath?: string | undefined; @@ -47,6 +46,7 @@ export class Story extends StorySc status?: StoryStatus | string; priority?: number; + cast?: CAST; path = () => getPath(this.story, this.parentPath) // get a getter to get test id testId = this.path; @@ -81,6 +81,31 @@ export class Story extends StorySc // Get the next act according to the priority and the implementation status of the act. + /** + * get all the names of the who + */ + namesOfWho = () => printWho(this.who); + + /** + * get the name of a cast member in the who + * @param who + */ + nameOfWho = (who: Who) => printWho([who]); + + getCasts = () => this.cast; + + profileOfWho = (who: Who) => { + if (this.cast) { + try { + + return this.cast[who]; + } catch (e) { + throw new Error(`Cast ${who} not found in ${this.cast}. Check if you had ${who} in the cast profiles.`) + } + } + throw new Error(`You did not provide a cast for this story.`) + } + constructor( entity: PartialDeep, @@ -128,7 +153,7 @@ export class Story extends StorySc * This generic type allows `ActWithMethods` to be applied to any specific implementation * of `IActRecord`, preserving its unique structure. */ -export type UserStory, CAST extends CastProfiles > = ReadonlyDeep & Story & { +export type UserStory, CAST extends CastProfiles> = ReadonlyDeep & Story & { scenes: { [K in keyof T['scenes']]: T['scenes'][K] extends IStoryScript ? ReadonlyDeep> : never }; }; diff --git a/packages/cantos/vite.config.ts b/packages/cantos/vite.config.ts index 8202b51..5cdfbea 100644 --- a/packages/cantos/vite.config.ts +++ b/packages/cantos/vite.config.ts @@ -2,6 +2,7 @@ import {defineConfig, UserConfig} from "vitest/config"; import * as path from "path"; import dts from 'vite-plugin-dts'; import eslintPlugin from "vite-plugin-eslint"; + export const viteConfig: UserConfig = { resolve: { alias: { @@ -12,7 +13,7 @@ export const viteConfig: UserConfig = { build: { lib: { entry: path.resolve(__dirname, './src/index.ts'), - name: 'cantos', + name: 'Cantos', fileName: 'cantos', }, rollupOptions: { @@ -20,7 +21,8 @@ export const viteConfig: UserConfig = { } }, plugins: [dts({ - tsconfigPath: 'tsconfig.build.json' + tsconfigPath: 'tsconfig.build.json', + rollupTypes: true }), eslintPlugin()], test: { include: ['**/*.test.ts'],