Skip to content

Commit

Permalink
update arc pass transform mode to definition transform
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstyles committed May 17, 2024
1 parent 0ca2966 commit 351df88
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions scripts/arc/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const buildCommand: CommandModule = {
})
const dtsStats = await generateDefinitions(opts.include, {
outDir: opts.outDir,
mode: 'build',
})

/**
Expand Down
1 change: 1 addition & 0 deletions scripts/arc/src/commands/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const watchCommand: CommandModule = {
})
const dtsStats = await generateDefinitions([file.name], {
outDir: opts.outDir,
mode: 'watch',
})

// Disregard pipeline stats for now
Expand Down
12 changes: 9 additions & 3 deletions scripts/arc/src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import ts from 'typescript'
import { createLogger } from '@urban-ui/arc-log'
import { readFile, writeFile } from './file.ts'
import { log } from './log'
import { type TransformMode, TransformModes } from './transform/modes.ts'
import { Pipeline } from './transform/pipeline.ts'
import { createTask } from './transform/task.ts'

const { debug } = createLogger('rk::definition', chalk.green)

type FilesDts = Record<string, string>
type DefinitionTransformContext = {
mode: TransformModes
}

/**
* Grabs the tsconfig file and writes ts definition files to disk
Expand All @@ -25,14 +29,16 @@ export async function generateDefinitions(
files: Array<string>,
options: {
outDir: string
mode: TransformMode
},
) {
const pipeline = new Pipeline<
// biome-ignore lint/suspicious/noExplicitAny: type gets mapped anyways by the pipeline
any,
DefinitionTransformContext,
TaskInputParameters<typeof readConfig>,
TaskReturnType<typeof write>
>('dts')
>('dts', {
mode: TransformModes[options.mode],
})
pipeline.addStep(readConfig)
pipeline.addStep(
compile(files, {
Expand Down
15 changes: 6 additions & 9 deletions scripts/arc/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ import { readFile, writeFile } from './file.ts'
import { log } from './log'
import { traceFn } from './trace.ts'
import { fileEvents, measure } from './transform/analytics.ts'
import { type TransformMode, TransformModes } from './transform/modes.ts'
import { Pipeline } from './transform/pipeline.ts'
import { createTask } from './transform/task.ts'

const gzip = promisify(zlib.gzip)
const { debug } = createLogger('rk::transform', chalk.blue)

enum TransformModes {
watch = 'watch',
build = 'build',
}
type TransformContext = {
type TranspileTransformContext = {
outDir: string
rootDir: string
mode: TransformModes
Expand All @@ -40,12 +37,12 @@ type TransformContext = {
*/
export async function transformFiles(
files: Array<string>,
options: Omit<TransformContext, 'mode'> & {
mode: `${TransformModes}`
options: Omit<TranspileTransformContext, 'mode'> & {
mode: TransformMode
},
) {
const pipeline = new Pipeline<
TransformContext,
TranspileTransformContext,
TaskInputParameters<typeof parse>,
TaskReturnType<typeof write>
>('transform', {
Expand Down Expand Up @@ -157,7 +154,7 @@ const compile = createTask(
const write = createTask(
'write',
async (
ctx: PipelineContext<TransformContext>,
ctx: PipelineContext<TranspileTransformContext>,
files: Awaited<TaskReturnType<typeof compile>>,
) => {
if (!(await fs.exists(ctx.outDir))) {
Expand Down
6 changes: 6 additions & 0 deletions scripts/arc/src/transform/modes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum TransformModes {
watch = 'watch',
build = 'build',
}

export type TransformMode = `${TransformModes}`

0 comments on commit 351df88

Please sign in to comment.