Skip to content

Commit

Permalink
Tweak Build script
Browse files Browse the repository at this point in the history
  • Loading branch information
alxjrvs committed Dec 4, 2024
1 parent c09a464 commit a1d7ae1
Show file tree
Hide file tree
Showing 29 changed files with 60 additions and 25 deletions.
22 changes: 19 additions & 3 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import dts from 'bun-plugin-dts'

await Bun.build({
entrypoints: ['./src/index.ts'],
const results = await Bun.build({
entrypoints: [
'./src/dice/index.ts',
'./src/faces/index.ts',
'./src/notation/index.ts',
'./src/tower/index.ts',
'./src/types.ts'
],
outdir: './dist',
target: 'node',
splitting: true,
sourcemap: 'inline',
plugins: [dts()]
})

if (results.success == false) {
console.error('Build failed')
for (const message of results.logs) {
console.error(message)
}
} else {
console.log('Compiled ' + results.outputs.length + ' javascript files...')
}

export {}
4 changes: 2 additions & 2 deletions src/dice/D.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RollConfig } from '~src/core/types'
import { coreRandom } from '~src/core/utils/coreRandom'
import { coreRandom } from '~src/utils/coreRandom'
import { RollConfig } from '~types'

export class D {
constructor(public sides: number) {
Expand Down
2 changes: 2 additions & 0 deletions src/dice/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { D } from './D'
export * from './dice'
8 changes: 8 additions & 0 deletions src/faces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from './types'
export * from './guards'
export * from './patterns'

export * from './customFacesD'
export * from './customFacesDice'
export { rollCustomFaces } from './rollCustomFaces'
export { validateCustomFacesNotation } from './validateCustomFacesNotation'
2 changes: 1 addition & 1 deletion src/faces/rollCustomFaces.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { v4 as uuid } from 'uuid'

import { rollDicePools } from '~src/core/utils/rollDicePools'
import type {
CustomFacesRollResult,
CustomFacesRollArgument,
CustomFacesDicePools
} from './types'
import { argumentToCustomFacesRollParameters } from './utils/argumentToCustomFacesRollParameters'
import { rollDicePools } from '~src/utils/rollDicePools'

export function rollCustomFaces(
...args: CustomFacesRollArgument[]
Expand Down
2 changes: 1 addition & 1 deletion src/faces/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~src/core/types'
import { RollConfig } from '~types'
import { NotationValidationResult } from '~src/notation/types'
import { RollArgument } from '~src/tower/types'
import type { CustomFacesD } from './customFacesD'
Expand Down
2 changes: 1 addition & 1 deletion src/faces/utils/customFacesConfigToDescription.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatCoreDescriptions } from '~src/core/utils/configToDescription'
import { formatCoreDescriptions } from '~src/utils/configToDescription'
import type { CustomFacesRollConfig } from '../types'

export function customFacesConfigToDescriptions({
Expand Down
5 changes: 5 additions & 0 deletions src/notation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './types'
export * from './guards'
export * from './patterns'

export { validateNotation } from './validateNotation'
2 changes: 1 addition & 1 deletion src/notation/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~src/core/types'
import { RollConfig } from '~types'

export interface NotationValidationResult<V = boolean> {
valid: V
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/configToNotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
formatModifierNotation
} from './notationFormatters'
import type { DiceNotation } from '../../types'
import { RollConfig } from '~src/core/types'
import { RollConfig } from '~types'

export function configToNotation(options: RollConfig): DiceNotation {
return `${formatCoreNotation(options)}${formatModifierNotation(options)}`
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/configToNotation/notationFormatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RerollOptions,
UniqueOptions,
RollConfig
} from '~src/core/types'
} from '~types'
import { DiceNotation } from '~src/notation/types'

function capNotation(cap: GreaterLessOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/notationToRollConfig/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseCoreNotation, parseModifiers } from './optionsParsers'
import { coreNotationPattern } from '../../patterns'
import { RollConfig } from '~src/core/types'
import { RollConfig } from '~types'
import { DiceNotation } from '~src/notation/types'

export function notationToRollConfig(notationString: DiceNotation): RollConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/notationToRollConfig/optionsParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Modifiers,
RequiredCoreDiceParameters,
RerollOptions
} from '~src/core/types'
} from '~types'
import {
dropHighestPattern,
dropLowestPattern,
Expand Down
2 changes: 1 addition & 1 deletion src/notation/validateNotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isDiceNotation } from './guards'
import { NotationValidationResult } from './types'
import { notationToRollConfig } from './utils/notationToRollConfig'
import { configToNotation } from './utils/configToNotation'
import { configToDescription } from '~src/core/utils/configToDescription'
import { configToDescription } from '~src/utils/configToDescription'

function validateNotation(arg: string): NotationValidationResult {
if (!isDiceNotation(arg)) {
Expand Down
2 changes: 1 addition & 1 deletion src/tower/__tests__/utils/applyModifiers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, spyOn, test } from 'bun:test'
import { Modifiers } from '~src/core/types'
import { Modifiers } from '~types'
import { D } from '~src/dice/D'
import { RollParameters } from '~src/tower/types'
import {
Expand Down
4 changes: 4 additions & 0 deletions src/tower/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './types'
export * from './guards'

export { roll } from './roll'
2 changes: 1 addition & 1 deletion src/tower/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { v4 as uuid } from 'uuid'

import type { DicePools, RollArgument, RollResult } from './types'
import { applyModifiers, calculateTotal } from './utils/applyModifiers'
import { rollDicePools } from '~src/core/utils/rollDicePools'
import { argumentToRollParameters } from './utils/argumentToRollParameters'
import { rollDicePools } from '~src/utils/rollDicePools'

export function roll(...args: RollArgument[]): RollResult {
const dicePools = args.reduce(
Expand Down
2 changes: 1 addition & 1 deletion src/tower/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~src/core/types'
import { RollConfig } from '~types'
import { D } from '~src/dice/D'
import { DiceNotation } from '~src/notation/types'

Expand Down
2 changes: 1 addition & 1 deletion src/tower/utils/applyModifiers/modifierApplicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ReplaceOptions,
RequiredCoreDiceParameters,
RerollOptions
} from '~src/core/types'
} from '~types'

export class InvalidUniqueError extends Error {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/tower/utils/argumentToRollConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~src/core/types'
import { RollConfig } from '~types'
import { isRollConfigArgument, isD } from '../guards'
import type { RollArgument } from '../types'
import { isDiceNotation } from '~src/notation/guards'
Expand Down
2 changes: 1 addition & 1 deletion src/tower/utils/argumentToRollParameters.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { configToDescription } from '~src/core/utils/configToDescription'
import { D } from '~src/dice/D'
import { isD } from '../guards'
import type { RollArgument, RollParameters } from '../types'
import { argumentToRollConfig } from './argumentToRollConfig'
import { configToNotation } from '~src/notation/utils/configToNotation'
import { configToDescription } from '~src/utils/configToDescription'

export function argumentToRollParameters(
argument: RollArgument
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'bun:test'
import { configToDescription } from '~src/core/utils/configToDescription'
import { configToDescription } from '~src/utils/configToDescription'

describe('configToDescription', () => {
test('returns an array strings matching the constraints', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'bun:test'
import { coreRandom } from '~src/core/utils/coreRandom'
import { coreRandom } from '~src/utils/coreRandom'

describe('coreRandom', () => {
test('it returns an object between 1 and the provided number', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'bun:test'
import { DicePoolLike } from '~src/core/types'
import { rollDicePools } from '~src/core/utils/rollDicePools'
import { rollDicePools } from '~src/utils/rollDicePools'
import { DicePoolLike } from '~types'

describe('rollDicePools', () => {
test('rolls the provided dice a number of times equal to the quantity', () => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DicePoolLike, DicePoolRollReturn } from '../types'
import { DicePoolLike, DicePoolRollReturn } from '~types'

export function rollDicePools<R>(
dicePools: DicePoolLike<R>
Expand Down

0 comments on commit a1d7ae1

Please sign in to comment.