2019-08-07 22:46:35 +03:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-29 18:47:54 +03:00
|
|
|
import {EntryPoint, EntryPointJsonProperty, JsonObject} from '../packages/entry_point';
|
2019-08-27 17:36:25 +03:00
|
|
|
import {PartiallyOrderedList} from '../utils';
|
2019-08-07 22:46:35 +03:00
|
|
|
|
2019-08-29 15:28:00 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The type of the function that analyzes entry-points and creates the list of tasks.
|
|
|
|
|
*
|
|
|
|
|
* @return A list of tasks that need to be executed in order to process the necessary format
|
|
|
|
|
* properties for all entry-points.
|
|
|
|
|
*/
|
2019-08-27 17:36:25 +03:00
|
|
|
export type AnalyzeEntryPointsFn = () => TaskQueue;
|
2019-08-07 22:46:35 +03:00
|
|
|
|
2019-08-09 15:01:57 +03:00
|
|
|
/** The type of the function that can process/compile a task. */
|
|
|
|
|
export type CompileFn = (task: Task) => void;
|
|
|
|
|
|
|
|
|
|
/** The type of the function that creates the `CompileFn` function used to process tasks. */
|
|
|
|
|
export type CreateCompileFn = (onTaskCompleted: TaskCompletedCallback) => CompileFn;
|
2019-08-07 22:46:35 +03:00
|
|
|
|
|
|
|
|
/**
|
2019-08-19 17:10:09 +03:00
|
|
|
* A class that orchestrates and executes the required work (i.e. analyzes the entry-points,
|
|
|
|
|
* processes the resulting tasks, does book-keeping and validates the final outcome).
|
2019-08-07 22:46:35 +03:00
|
|
|
*/
|
2019-08-19 17:10:09 +03:00
|
|
|
export interface Executor {
|
2019-08-29 01:33:15 +03:00
|
|
|
execute(analyzeEntryPoints: AnalyzeEntryPointsFn, createCompileFn: CreateCompileFn):
|
|
|
|
|
void|Promise<void>;
|
2019-08-19 17:10:09 +03:00
|
|
|
}
|
2019-08-07 22:46:35 +03:00
|
|
|
|
2019-08-27 17:36:25 +03:00
|
|
|
/**
|
|
|
|
|
* Represents a partially ordered list of tasks.
|
|
|
|
|
*
|
|
|
|
|
* The ordering/precedence of tasks is determined by the inter-dependencies between their associated
|
|
|
|
|
* entry-points. Specifically, the tasks' order/precedence is such that tasks associated to
|
|
|
|
|
* dependent entry-points always come after tasks associated with their dependencies.
|
|
|
|
|
*
|
|
|
|
|
* As result of this ordering, it is guaranteed that - by processing tasks in the order in which
|
|
|
|
|
* they appear in the list - a task's dependencies will always have been processed before processing
|
|
|
|
|
* the task itself.
|
|
|
|
|
*
|
|
|
|
|
* See `DependencyResolver#sortEntryPointsByDependency()`.
|
|
|
|
|
*/
|
|
|
|
|
export type PartiallyOrderedTasks = PartiallyOrderedList<Task>;
|
|
|
|
|
|
2019-08-07 22:46:35 +03:00
|
|
|
/** Represents a unit of work: processing a specific format property of an entry-point. */
|
2019-08-29 18:47:54 +03:00
|
|
|
export interface Task extends JsonObject {
|
2019-08-07 22:46:35 +03:00
|
|
|
/** The `EntryPoint` which needs to be processed as part of the task. */
|
|
|
|
|
entryPoint: EntryPoint;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The `package.json` format property to process (i.e. the property which points to the file that
|
|
|
|
|
* is the program entry-point).
|
|
|
|
|
*/
|
|
|
|
|
formatProperty: EntryPointJsonProperty;
|
|
|
|
|
|
2019-08-08 03:23:46 +03:00
|
|
|
/**
|
|
|
|
|
* The list of all format properties (including `task.formatProperty`) that should be marked as
|
|
|
|
|
* processed once the taksk has been completed, because they point to the format-path that will be
|
|
|
|
|
* processed as part of the task.
|
|
|
|
|
*/
|
|
|
|
|
formatPropertiesToMarkAsProcessed: EntryPointJsonProperty[];
|
|
|
|
|
|
2019-08-07 22:46:35 +03:00
|
|
|
/** Whether to also process typings for this entry-point as part of the task. */
|
|
|
|
|
processDts: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 15:01:57 +03:00
|
|
|
/** A function to be called once a task has been processed. */
|
|
|
|
|
export type TaskCompletedCallback = (task: Task, outcome: TaskProcessingOutcome) => void;
|
|
|
|
|
|
2019-08-07 22:46:35 +03:00
|
|
|
/** Represents the outcome of processing a `Task`. */
|
|
|
|
|
export const enum TaskProcessingOutcome {
|
|
|
|
|
/** The target format property was already processed - didn't have to do anything. */
|
|
|
|
|
AlreadyProcessed,
|
|
|
|
|
|
|
|
|
|
/** Successfully processed the target format property. */
|
|
|
|
|
Processed,
|
|
|
|
|
}
|
2019-08-27 17:36:25 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A wrapper around a list of tasks and providing utility methods for getting the next task of
|
|
|
|
|
* interest and determining when all tasks have been completed.
|
|
|
|
|
*
|
|
|
|
|
* (This allows different implementations to impose different constraints on when a task's
|
|
|
|
|
* processing can start.)
|
|
|
|
|
*/
|
|
|
|
|
export interface TaskQueue {
|
|
|
|
|
/** Whether all tasks have been completed. */
|
|
|
|
|
allTasksCompleted: boolean;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the next task whose processing can start (if any).
|
|
|
|
|
*
|
|
|
|
|
* This implicitly marks the task as in-progress.
|
|
|
|
|
* (This information is used to determine whether all tasks have been completed.)
|
|
|
|
|
*
|
|
|
|
|
* @return The next task available for processing or `null`, if no task can be processed at the
|
|
|
|
|
* moment (including if there are no more unprocessed tasks).
|
|
|
|
|
*/
|
|
|
|
|
getNextTask(): Task|null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mark a task as completed.
|
|
|
|
|
*
|
|
|
|
|
* This removes the task from the internal list of in-progress tasks.
|
|
|
|
|
* (This information is used to determine whether all tasks have been completed.)
|
|
|
|
|
*
|
|
|
|
|
* @param task The task to mark as completed.
|
|
|
|
|
*/
|
|
|
|
|
markTaskCompleted(task: Task): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a string representation of the task queue (for debugging purposes).
|
|
|
|
|
*
|
|
|
|
|
* @return A string representation of the task queue.
|
|
|
|
|
*/
|
|
|
|
|
toString(): string;
|
|
|
|
|
}
|