Skip to content

Commit

Permalink
feat: feature bundle
Browse files Browse the repository at this point in the history
- jest: coverage
- typescript: jest, mergify and eslint added by default
- node: nodeVersion in "engines"
- typescript: typescript, @types/node
  • Loading branch information
Elad Ben-Israel committed Jun 15, 2020
1 parent 50077ec commit 6a23f20
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
48 changes: 47 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Name|Description
Name|Description
----|-----------
[CommonOptions](#projen-commonoptions)|*No description*
[CoverageThreshold](#projen-coveragethreshold)|*No description*
[FileBaseOptions](#projen-filebaseoptions)|*No description*
[JestOptions](#projen-jestoptions)|*No description*
[JsiiDotNetTarget](#projen-jsiidotnettarget)|*No description*
[JsiiJavaTarget](#projen-jsiijavatarget)|*No description*
[JsiiProjectOptions](#projen-jsiiprojectoptions)|*No description*
Expand Down Expand Up @@ -297,11 +299,13 @@ include(...patterns: string[]): void
<span style="text-decoration: underline">Usage:</span>

```ts
new Jest(project: NodeProject)
new Jest(project: NodeProject, options?: JestOptions)
```

<span style="text-decoration: underline">Parameters:</span>
* **project** (<code>[NodeProject](#projen-nodeproject)</code>) *No description*
* **options** (<code>[JestOptions](#projen-jestoptions)</code>) *No description*
* **globalCoverageThreshold** (<code>[CoverageThreshold](#projen-coveragethreshold)</code>) *No description* <span style="text-decoration: underline">*Optional*</span>



Expand Down Expand Up @@ -537,6 +541,7 @@ new NodeProject(options: NodeProjectOptions)
* **gitignore** (<code>Array<string></code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **homepage** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **license** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **nodeVersion** (<code>[Semver](#projen-semver)</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **npmignore** (<code>Array<string></code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **repository** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **repositoryDirectory** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
Expand All @@ -549,6 +554,7 @@ new NodeProject(options: NodeProjectOptions)

Name | Type | Description
-----|------|-------------
**nodeVersion**🔹 | <code>[Semver](#projen-semver)</code> | <span></span>
**npmignore**🔹 | <code>[IgnoreFile](#projen-ignorefile)</code> | <span></span>
**version**🔹 | <code>any</code> | Returns the current version of the project.
**buildWorkflow**?🔹 | <code>[NodeBuildWorkflow](#projen-nodebuildworkflow)</code> | The PR build GitHub workflow.<br/><span style="text-decoration: underline">*Optional*</span>
Expand Down Expand Up @@ -861,10 +867,15 @@ new TypeScriptLibraryProject(options: TypeScriptLibraryProjectOptions)
* **gitignore** (<code>Array<string></code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **homepage** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **license** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **nodeVersion** (<code>[Semver](#projen-semver)</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **npmignore** (<code>Array<string></code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **repository** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **repositoryDirectory** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **stability** (<code>string</code>) *No description* <span style="text-decoration: underline">*Optional*</span>
* **eslint** (<code>boolean</code>) Setup eslint. <span style="text-decoration: underline">*Default*</span>: true
* **jest** (<code>boolean</code>) Setup jest unit tests. <span style="text-decoration: underline">*Default*</span>: true
* **jestOptions** (<code>[JestOptions](#projen-jestoptions)</code>) Jest options. <span style="text-decoration: underline">*Default*</span>: default options
* **typescriptVersion** (<code>[Semver](#projen-semver)</code>) TypeScript version to use. <span style="text-decoration: underline">*Default*</span>: ^3.9.5



Expand Down Expand Up @@ -929,6 +940,22 @@ Name | Type | Description



## struct CoverageThreshold 🔹 <a id="projen-coveragethreshold"></a>






Name | Type | Description
-----|------|-------------
**branches**?🔹 | <code>number</code> | <span style="text-decoration: underline">*Optional*</span>
**functions**?🔹 | <code>number</code> | <span style="text-decoration: underline">*Optional*</span>
**lines**?🔹 | <code>number</code> | <span style="text-decoration: underline">*Optional*</span>
**statements**?🔹 | <code>number</code> | <span style="text-decoration: underline">*Optional*</span>



## struct FileBaseOptions 🔹 <a id="projen-filebaseoptions"></a>


Expand All @@ -943,6 +970,19 @@ Name | Type | Description



## struct JestOptions 🔹 <a id="projen-jestoptions"></a>






Name | Type | Description
-----|------|-------------
**globalCoverageThreshold**?🔹 | <code>[CoverageThreshold](#projen-coveragethreshold)</code> | <span style="text-decoration: underline">*Optional*</span>



## struct JsiiDotNetTarget 🔹 <a id="projen-jsiidotnettarget"></a>


Expand Down Expand Up @@ -1088,6 +1128,7 @@ Name | Type | Description
**homepage**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**keywords**?🔹 | <code>Array<string></code> | <span style="text-decoration: underline">*Optional*</span>
**license**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**nodeVersion**?🔹 | <code>[Semver](#projen-semver)</code> | <span style="text-decoration: underline">*Optional*</span>
**npmignore**?🔹 | <code>Array<string></code> | <span style="text-decoration: underline">*Optional*</span>
**outdir**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Default*</span>: . current directory
**peerDependencies**?🔹 | <code>Map<string, [Semver](#projen-semver)></code> | <span style="text-decoration: underline">*Optional*</span>
Expand Down Expand Up @@ -1151,10 +1192,14 @@ Name | Type | Description
**dependencies**?🔹 | <code>Map<string, [Semver](#projen-semver)></code> | <span style="text-decoration: underline">*Optional*</span>
**description**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**devDependencies**?🔹 | <code>Map<string, [Semver](#projen-semver)></code> | <span style="text-decoration: underline">*Optional*</span>
**eslint**?🔹 | <code>boolean</code> | Setup eslint.<br/><span style="text-decoration: underline">*Default*</span>: true
**gitignore**?🔹 | <code>Array<string></code> | <span style="text-decoration: underline">*Optional*</span>
**homepage**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**jest**?🔹 | <code>boolean</code> | Setup jest unit tests.<br/><span style="text-decoration: underline">*Default*</span>: true
**jestOptions**?🔹 | <code>[JestOptions](#projen-jestoptions)</code> | Jest options.<br/><span style="text-decoration: underline">*Default*</span>: default options
**keywords**?🔹 | <code>Array<string></code> | <span style="text-decoration: underline">*Optional*</span>
**license**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**nodeVersion**?🔹 | <code>[Semver](#projen-semver)</code> | <span style="text-decoration: underline">*Optional*</span>
**npmignore**?🔹 | <code>Array<string></code> | <span style="text-decoration: underline">*Optional*</span>
**outdir**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Default*</span>: . current directory
**peerDependencies**?🔹 | <code>Map<string, [Semver](#projen-semver)></code> | <span style="text-decoration: underline">*Optional*</span>
Expand All @@ -1166,6 +1211,7 @@ Name | Type | Description
**repository**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**repositoryDirectory**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**stability**?🔹 | <code>string</code> | <span style="text-decoration: underline">*Optional*</span>
**typescriptVersion**?🔹 | <code>[Semver](#projen-semver)</code> | TypeScript version to use.<br/><span style="text-decoration: underline">*Default*</span>: ^3.9.5
**workflowBootstrapSteps**?🔹 | <code>Array<any></code> | Workflow steps to use in order to bootstrap this repo.<br/><span style="text-decoration: underline">*Default*</span>: [ { run: `npx projen${PROJEN_VERSION}` }, { run: 'yarn install --frozen-lockfile' } ]
**workflowContainerImage**?🔹 | <code>string</code> | Container image to use for GitHub workflows.<br/><span style="text-decoration: underline">*Default*</span>: default image

Expand Down
17 changes: 16 additions & 1 deletion lib/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ import { Construct } from 'constructs';
import { NodeProject } from './node-project';
import { Semver } from './semver';

export interface JestOptions {
readonly globalCoverageThreshold?: CoverageThreshold;
}

export interface CoverageThreshold {
readonly branches?: number;
readonly functions?: number;
readonly lines?: number;
readonly statements?: number;
}

export class Jest extends Construct {
constructor(project: NodeProject) {
constructor(project: NodeProject, options: JestOptions = { }) {
super(project, 'jest');

project.addDevDependencies({
Expand All @@ -15,6 +26,10 @@ export class Jest extends Construct {
project.addFields({
jest: {
clearMocks: true,
collectCoverage: true,
coverageThreshold: options.globalCoverageThreshold ? {
global: options.globalCoverageThreshold,
} : undefined,
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [ '/node_modules/' ],
moduleFileExtensions: [ 'js' ],
Expand Down
6 changes: 6 additions & 0 deletions lib/node-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface NodeProjectOptions extends ProjectOptions, CommonOptions {
readonly stability?: string;
readonly gitignore?: string[];
readonly npmignore?: string[];
readonly nodeVersion?: Semver;
}

export class NodeProject extends Project {
Expand All @@ -125,9 +126,13 @@ export class NodeProject extends Project {
*/
protected readonly releaseWorkflow?: NodeBuildWorkflow;

public readonly nodeVersion: Semver;

constructor(options: NodeProjectOptions) {
super(options);

this.nodeVersion = options.nodeVersion ?? Semver.caret('14.0.2');

this.manifest = {
'//': GENERATION_DISCLAIMER,
name: options.name,
Expand All @@ -151,6 +156,7 @@ export class NodeProject extends Project {
dependencies: this.dependencies,
bundledDependencies: this.bundledDependencies,
keywords: options.keywords,
engines: { node: this.nodeVersion.spec },
};

const commitPackageJson = options.commitPackageJson ?? false;
Expand Down
49 changes: 49 additions & 0 deletions lib/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import { NodeProject, NodeProjectOptions } from './node-project';
import { JsonFile } from './json';
import { JestOptions, Jest } from './jest';
import { Eslint } from './eslint';
import { Semver } from './semver';
import { Mergify } from './mergify';

export interface TypeScriptLibraryProjectOptions extends NodeProjectOptions {
/**
* Setup jest unit tests
* @default true
*/
readonly jest?: boolean;

/**
* Jest options
* @default - default options
*/
readonly jestOptions?: JestOptions;

/**
* Setup eslint.
* @default true
*/
readonly eslint?: boolean;

/**
* TypeScript version to use.
* @default ^3.9.5
*/
readonly typescriptVersion?: Semver;

/**
* Adds mergify configuration.
* @default true
*/
readonly mergify?: boolean;
}

export class TypeScriptLibraryProject extends NodeProject {
Expand Down Expand Up @@ -56,5 +88,22 @@ export class TypeScriptLibraryProject extends NodeProject {
this.npmignore.comment('include javascript files and typescript declarations');
this.npmignore.include('*.js');
this.npmignore.include('*.d.ts');

if (options.jest ?? true) {
new Jest(this, options.jestOptions);
}

if (options.eslint ?? true) {
new Eslint(this);
}

this.addDevDependencies({
'typescript': options.typescriptVersion ?? Semver.caret('3.9.5'),
'@types/node': this.nodeVersion,
});

if (options.mergify ?? true) {
new Mergify(this);
}
}
}

0 comments on commit 6a23f20

Please sign in to comment.