Skip to content

Commit

Permalink
add rootFolderPath option to push() and watch() and pass them t…
Browse files Browse the repository at this point in the history
…hrough to `processScript()`
  • Loading branch information
samualtnorman committed Nov 25, 2024
1 parent c05cfc3 commit 6dd031a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type PushOptions = LaxPartial<{
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
*/
forceQuineCheats: boolean

rootFolderPath: string
}>

export class MissingSourceFolderError extends Error {}
Expand All @@ -53,7 +55,8 @@ Object.defineProperty(NoScriptsError.prototype, `name`, { value: `NoScriptsError
export async function push(
sourcePath: string,
hackmudPath: string,
{ scripts = [ `*.*` ], onPush = () => {}, minify = true, mangleNames = false, forceQuineCheats }: PushOptions = {}
{ scripts = [ `*.*` ], onPush = () => {}, minify = true, mangleNames = false, forceQuineCheats, rootFolderPath }:
PushOptions = {}
): Promise<MissingSourceFolderError | MissingHackmudFolderError | NoUsersError | NoScriptsError | Info[]> {
const [ sourceFolder, hackmudFolder ] = await Promise.all([
readDirectoryWithStats(sourcePath).catch(error => {
Expand Down Expand Up @@ -156,7 +159,6 @@ export async function push(
}

const allInfo: Info[] = []
const sourcePathResolved = resolvePath(sourcePath)

await Promise.all([ ...pathsToUsers ].map(async ([ path, [ ...users ] ]) => {
const scriptName = getBaseName(path.slice(0, -3))
Expand All @@ -171,7 +173,7 @@ export async function push(
filePath: path,
mangleNames,
forceQuineCheats,
rootFolderPath: sourcePathResolved
rootFolderPath
})

const info: Info = { path, users, characterCount: countHackmudCharacters(minifiedCode), error: undefined, warnings }
Expand Down
6 changes: 4 additions & 2 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type WatchOptions = PushOptions & LaxPartial<{
typeDeclarationPath: string

onReady: () => void
rootFolderPath: string
}>

/** Watches target file or folder for updates and builds and pushes updated file.
Expand All @@ -32,7 +33,8 @@ export async function watch(sourceDirectory: string, hackmudDirectory: string, {
mangleNames = false,
typeDeclarationPath: typeDeclarationPath_,
onReady,
forceQuineCheats
forceQuineCheats,
rootFolderPath
}: WatchOptions = {}): Promise<void> {
if (!scripts.length)
throw new Error(`scripts option was an empty array`)
Expand Down Expand Up @@ -190,7 +192,7 @@ export async function watch(sourceDirectory: string, hackmudDirectory: string, {
filePath,
mangleNames,
forceQuineCheats,
rootFolderPath: sourceDirectoryResolved
rootFolderPath
}))
} catch (error) {
assert(error instanceof Error, HERE)
Expand Down

0 comments on commit 6dd031a

Please sign in to comment.