Skip to content

Commit

Permalink
feat(WIP): can print who's name and cast
Browse files Browse the repository at this point in the history
- [ ] Not tested yet. Need to check inheritance of who and cast.
  • Loading branch information
boan-anbo committed Nov 15, 2023
1 parent c073af0 commit e32f78c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
9 changes: 1 addition & 8 deletions packages/cantos/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "cantos",
"private": false,
"author": "Bo An",
"version": "0.0.4",
"version": "0.0.5",
"keywords": [
"User Stories",
"TDD",
Expand Down Expand Up @@ -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"
],
Expand Down
31 changes: 28 additions & 3 deletions packages/cantos/src/stories/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +46,7 @@ export class Story<CAST extends CastProfiles = typeof EmptyCast> 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;
Expand Down Expand Up @@ -81,6 +81,31 @@ export class Story<CAST extends CastProfiles = typeof EmptyCast> 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<CAST>) => printWho([who]);

getCasts = () => this.cast;

profileOfWho = (who: Who<CAST>) => {
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<StoryScript>,
Expand Down Expand Up @@ -128,7 +153,7 @@ export class Story<CAST extends CastProfiles = typeof EmptyCast> extends StorySc
* This generic type allows `ActWithMethods` to be applied to any specific implementation
* of `IActRecord`, preserving its unique structure.
*/
export type UserStory<T extends IStoryScript<CAST>, CAST extends CastProfiles > = ReadonlyDeep<T> & Story<CAST> & {
export type UserStory<T extends IStoryScript<CAST>, CAST extends CastProfiles> = ReadonlyDeep<T> & Story<CAST> & {
scenes: { [K in keyof T['scenes']]: T['scenes'][K] extends IStoryScript<CAST> ? ReadonlyDeep<UserStory<T['scenes'][K], CAST>> : never };
};

Expand Down
6 changes: 4 additions & 2 deletions packages/cantos/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -12,15 +13,16 @@ export const viteConfig: UserConfig = {
build: {
lib: {
entry: path.resolve(__dirname, './src/index.ts'),
name: 'cantos',
name: 'Cantos',
fileName: 'cantos',
},
rollupOptions: {
external: ['./tests']
}
},
plugins: [dts({
tsconfigPath: 'tsconfig.build.json'
tsconfigPath: 'tsconfig.build.json',
rollupTypes: true
}), eslintPlugin()],
test: {
include: ['**/*.test.ts'],
Expand Down

0 comments on commit e32f78c

Please sign in to comment.