CDK for software projects - synthesizes configuration files from well-typed JavaScript/TypeScript definitions.
npx @tessl/cli install tessl/npm-projen@0.95.0Projen is a comprehensive software project configuration management system that provides a Cloud Development Kit (CDK) approach to defining and maintaining complex project configurations through code. It synthesizes project configuration files such as package.json, tsconfig.json, .gitignore, GitHub Workflows, eslint, jest, and other essential project files from well-typed JavaScript/TypeScript definitions. Unlike traditional templating or scaffolding tools, projen is not a one-off generator but maintains ongoing project configuration management through code, enforcing that synthesized files should never be manually edited.
npm install projenconstructs ^10.0.0import { Project, Component, Task, Dependencies } from "projen";
import { TypeScriptProject, NodeProject, PythonProject, JavaProject } from "projen";For CommonJS:
const { Project, Component, Task, Dependencies } = require("projen");
const { TypeScriptProject, NodeProject, PythonProject, JavaProject } = require("projen");For submodules:
import { typescript, javascript, python, java, github, awscdk } from "projen";
import { TypeScriptProject } from "projen/lib/typescript";import { TypeScriptProject } from "projen";
// Create a new TypeScript project
const project = new TypeScriptProject({
name: "my-awesome-project",
defaultReleaseBranch: "main",
author: "Jane Developer",
authorEmail: "jane@example.com",
repository: "https://github.com/user/my-awesome-project.git",
// TypeScript configuration
srcdir: "src",
testdir: "test",
libdir: "lib",
// Dependencies
deps: ["axios", "lodash"],
devDeps: ["@types/node", "@types/jest"],
// Testing
jest: true,
eslint: true,
prettier: true,
});
// Add custom tasks
project.addTask("custom-build", {
description: "Custom build process",
exec: "echo 'Running custom build'",
});
// Synthesize all project files
project.synth();Projen is built around several key architectural concepts:
Project class extended by language-specific projects like TypeScriptProject, PythonProject, etc.Component that can be added to projects - from file management to CI/CD workflowsFoundation classes and utilities for creating and managing software projects of any type.
class Project extends Construct {
constructor(options: ProjectOptions);
readonly name: string;
readonly outdir: string;
readonly tasks: Tasks;
readonly deps: Dependencies;
addTask(name: string, props?: TaskOptions): Task;
synth(): void;
static of(construct: IConstruct): Project;
}
interface ProjectOptions {
name: string;
parent?: Project;
outdir?: string;
logging?: LoggerOptions;
projenrcJson?: boolean;
renovatebot?: boolean;
commitGenerated?: boolean;
}Complete TypeScript project setup with compilation, testing, linting, and documentation generation.
class TypeScriptProject extends NodeProject {
constructor(options: TypeScriptProjectOptions);
readonly srcdir: string;
readonly libdir: string;
readonly testdir: string;
readonly tsconfig?: TypescriptConfig;
readonly tsconfigDev: TypescriptConfig;
readonly watchTask: Task;
}Node.js projects with package management, testing frameworks, and JavaScript tooling.
class NodeProject extends GitHubProject {
constructor(options: NodeProjectOptions);
readonly package: NodePackage;
readonly jest?: Jest;
readonly eslint?: Eslint;
readonly prettier?: Prettier;
readonly bundler?: Bundler;
}Python projects with packaging, virtual environments, and testing frameworks.
class PythonProject extends GitHubProject {
constructor(options: PythonProjectOptions);
readonly moduleName: string;
readonly pip?: Pip;
readonly poetry?: Poetry;
readonly venv?: Venv;
readonly pytest?: Pytest;
}Java projects with Maven build system and dependency management.
class JavaProject extends GitHubProject {
constructor(options: JavaProjectOptions);
readonly pom: Pom;
readonly junit?: Junit;
readonly packaging: MavenPackaging;
readonly compile: MavenCompile;
}React and Next.js projects with modern web development tooling.
class ReactProject extends NodeProject {
constructor(options: ReactProjectOptions);
}
class NextJsProject extends NodeProject {
constructor(options: NextJsProjectOptions);
}AWS CDK applications and construct libraries for cloud infrastructure.
class AwsCdkTypeScriptApp extends TypeScriptProject {
constructor(options: AwsCdkTypeScriptAppOptions);
}
class AwsCdkConstructLibrary extends ConstructLibrary {
constructor(options: AwsCdkConstructLibraryOptions);
}Unified task system for build processes, testing, and custom workflows.
class Task {
constructor(name: string, props?: TaskOptions);
readonly name: string;
exec(command: string, options?: TaskStepOptions): void;
spawn(subtask: string, options?: TaskStepOptions): void;
lock(): void;
}
interface TaskOptions {
description?: string;
exec?: string;
steps?: TaskStep[];
env?: Record<string, string>;
cwd?: string;
condition?: string;
}Cross-platform dependency management for different package managers.
class Dependencies extends Component {
constructor(project: Project);
addDependency(spec: string, type: DependencyType, metadata?: object): Dependency;
removeDependency(name: string, type?: DependencyType): void;
getDependency(name: string, type?: DependencyType): Dependency;
}
enum DependencyType {
RUNTIME = "runtime",
PEER = "peer",
BUNDLED = "bundled",
BUILD = "build",
TEST = "test",
DEVENV = "devenv",
OVERRIDE = "override",
OPTIONAL = "optional"
}Abstract file system for managing configuration files, source code, and generated content.
abstract class FileBase extends Component {
constructor(scope: IConstruct, filePath: string, options?: FileBaseOptions);
readonly path: string;
readonly absolutePath: string;
readonly readonly: boolean;
readonly executable: boolean;
}
class JsonFile extends ObjectFile {
constructor(scope: IConstruct, filePath: string, options?: JsonFileOptions);
}
class YamlFile extends ObjectFile {
constructor(scope: IConstruct, filePath: string, options?: YamlFileOptions);
}GitHub Actions workflows, issue templates, and repository management.
class GitHub extends Component {
constructor(project: GitHubProject, options?: GitHubOptions);
}
class GitHubProject extends Project {
constructor(options: GitHubProjectOptions);
readonly github?: GitHub;
}interface Component {
readonly node: Node;
readonly project: Project;
toString(): string;
}
interface Dependency {
name: string;
version?: string;
type: DependencyType;
metadata?: object;
}
interface TaskStep {
exec?: string;
spawn?: string;
builtin?: string;
env?: Record<string, string>;
cwd?: string;
condition?: string;
}
interface LoggerOptions {
level?: LogLevel;
usePrefix?: boolean;
}
enum LogLevel {
OFF = 0,
ERROR = 1,
WARN = 2,
INFO = 3,
DEBUG = 4,
VERBOSE = 5
}