Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: custom task-runtimes #2468

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const { cdk, JsonFile, TextFile } = require("./lib");
const { cdk, JsonFile, TextFile, ReplicaTaskRuntime } = require("./lib");
const { PROJEN_MARKER } = require("./lib/common");

const project = new cdk.JsiiProject({
name: "projen",
description: "CDK for software projects",
repository: "https://github.com/projen/projen.git",

services: {
taskRuntime: {
produce: (p) => new ReplicaTaskRuntime(p),
},
},

authorName: "Amazon Web Services",
authorUrl: "https://aws.amazon.com",
authorOrganization: true,
Expand Down
219 changes: 219 additions & 0 deletions .replica.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { synth } from "./synth";
import { discoverTaskCommands } from "./tasks";
import { PROJEN_RC, PROJEN_VERSION } from "../common";
import * as logging from "../logging";
import { Project } from "../project";
import { TaskRuntime } from "../task-runtime";
import { getNodeMajorVersion } from "../util";

Expand All @@ -14,8 +15,10 @@ async function main() {
const ya = yargs;
ya.command(newCommand);

const runtime = new TaskRuntime(".");
discoverTaskCommands(runtime, ya);
const runtime = new Project({
name: "task-runner",
}).taskRuntime;
discoverTaskCommands(runtime as TaskRuntime, ya);

ya.recommendCommands();
ya.strictCommands();
Expand Down Expand Up @@ -69,7 +72,7 @@ async function main() {
console.log(PROJEN_VERSION);
process.exit(0);
}
await synth(runtime, {
await synth(runtime as TaskRuntime, {
post: args.post as boolean,
watch: args.watch as boolean,
rcfile: args.rc as string,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from "./readme";
export * from "./renovatebot";
export * from "./sample-file";
export * from "./semver";
export * from "./services";
export * from "./source-code";
export * from "./task";
export * from "./tasks";
Expand Down
15 changes: 13 additions & 2 deletions src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import { InitProjectOptionHints } from "./option-hints";
import { ProjectBuild as ProjectBuild } from "./project-build";
import { Projenrc, ProjenrcOptions } from "./projenrc-json";
import { Renovatebot, RenovatebotOptions } from "./renovatebot";
import { ServiceConfiguration, ServiceLocator } from "./services";
import { Task, TaskOptions } from "./task";
import { ITaskRuntime, TaskRuntime } from "./task-runtime";
import { Tasks } from "./tasks";
import { isTruthy } from "./util";

/**
* Options for `Project`.
*/
export interface ProjectOptions {
export interface ProjectOptions extends ServiceConfiguration {
/**
* This is the name of your project.
*
Expand Down Expand Up @@ -123,7 +125,7 @@ export interface GitOptions {
/**
* Base project
*/
export class Project {
export class Project extends ServiceLocator {
/**
* The name of the default task (the task executed when `projen` is run without arguments). Normally
* this task should synthesize the project files.
Expand Down Expand Up @@ -211,13 +213,19 @@ export class Project {
*/
public readonly commitGenerated: boolean;

/**
* The task runtime implementation used.
*/
public readonly taskRuntime: ITaskRuntime;

private readonly _components = new Array<Component>();
private readonly subprojects = new Array<Project>();
private readonly tips = new Array<string>();
private readonly excludeFromCleanup: string[];
private readonly _ejected: boolean;

constructor(options: ProjectOptions) {
super();
this.initProject = resolveInitProject(options);

this.name = options.name;
Expand All @@ -235,6 +243,9 @@ export class Project {
this.outdir = this.determineOutdir(options.outdir);
this.root = this.parent ? this.parent.root : this;

this.taskRuntime =
options.services?.taskRuntime?.produce?.(this) ?? new TaskRuntime(this);

// must happen after this.outdir, this.parent and this.root are initialized
this.parent?._addSubProject(this);

Expand Down
4 changes: 1 addition & 3 deletions src/python/pip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Component } from "../component";
import { Dependency, DependencyType } from "../dependencies";
import { Project } from "../project";
import { Task } from "../task";
import { TaskRuntime } from "../task-runtime";

/**
* Options for pip
Expand Down Expand Up @@ -59,8 +58,7 @@ export class Pip extends Component implements IPythonDeps {
public installDependencies() {
this.project.logger.info("Installing dependencies...");

const runtime = new TaskRuntime(this.project.outdir);
runtime.runTask(this.installTask.name);
this.project.taskRuntime.runTask(this.installTask.name);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/python/poetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Component } from "../component";
import { DependencyType } from "../dependencies";
import { Project } from "../project";
import { Task } from "../task";
import { TaskRuntime } from "../task-runtime";
import { TomlFile } from "../toml";
import { decamelizeKeysRecursively, exec, execOrUndefined } from "../util";

Expand Down Expand Up @@ -155,8 +154,7 @@ export class Poetry
*/
public installDependencies() {
this.project.logger.info("Installing dependencies...");
const runtime = new TaskRuntime(this.project.outdir);
runtime.runTask(this.installTask.name);
this.project.taskRuntime.runTask(this.installTask.name);
}
}

Expand Down
Loading