Skip to content

Commit

Permalink
refactor: optimzie getting tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Apr 23, 2024
1 parent 3f68c7b commit 00b6fc1
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/tscx/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,22 @@ export class Compiler {
});
}

private getTasks(): Array<() => childProcess.ChildProcess> {
const { project, remove: rm, copyfiles: cp, exec: ex } = this.options;
return [
...(rm ? [() => remove(this.outDir)] : []),
() => tsc({ project }),
...(cp ? [() => copyfiles(this.rootDir, this.outDir)] : []),
...(ex ? [() => exec(ex)] : []),
];
}

private execTasks(id: string) {
if (this.id !== id) {
return;
}

const removeTask = () => remove(this.outDir);
const tscTask = () => tsc({ project: this.options.project });
const copyfilesTask = () => copyfiles(this.rootDir, this.outDir);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const execTask = () => exec(this.options.exec!);

const tasks = [
...(this.options.remove ? [removeTask] : []),
tscTask,
...(this.options.copyfiles ? [copyfilesTask] : []),
...(this.options.exec ? [execTask] : []),
];

const tasks = this.getTasks();
const execNextTask = (index = 0) => {
const currentTask = tasks[index];
if (!currentTask || this.id !== id) {
Expand Down

0 comments on commit 00b6fc1

Please sign in to comment.