Skip to content

Commit

Permalink
feat: nodeProject.addTestCommands(...commands)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Ben-Israel committed May 11, 2020
1 parent dae0c83 commit 5a08eb0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/jsii-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class JsiiProject extends NodeProject {
this.addScripts({
compile: 'jsii',
watch: 'jsii -w',
test: 'echo ok',
compat: 'npx jsii-diff npm:$(node -p "require(\'./package.json\').name")',
package: 'jsii-pacmak',
build: 'yarn compile && yarn test && yarn run package',
Expand Down
17 changes: 16 additions & 1 deletion lib/node-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Semver } from './semver';
import { IgnoreFile } from './ignore-file';
import { License } from './license';
import { GENERATION_DISCLAIMER } from './common';
import { Lazy } from 'constructs';

// eslint-disable-next-line @typescript-eslint/no-require-imports
const PROJEN_VERSION = require('../package.json').version;
Expand Down Expand Up @@ -56,7 +57,7 @@ export class NodeProject extends Project {
private readonly bin: Record<string, string> = { };

private readonly manifest: any;

private readonly testCommands = new Array<string>();

constructor(options: NodeProjectOptions) {
super(options);
Expand Down Expand Up @@ -111,6 +112,8 @@ export class NodeProject extends Project {
const projenVersion = options.projenVersion ?? Semver.caret(PROJEN_VERSION);
this.addDevDependencies({ projen: projenVersion });
}

this.addScripts({ test: Lazy.stringValue({ produce: () => this.renderTestCommand() }) });
}

public addBins(bins: Record<string, string>) {
Expand Down Expand Up @@ -166,12 +169,24 @@ export class NodeProject extends Project {
}
}

public addTestCommands(...commands: string[]) {
this.testCommands.push(...commands);
}

public addFields(fields: { [name: string]: any }) {
for (const [ name, value ] of Object.entries(fields)) {
this.manifest[name] = value;
}
}

private renderTestCommand() {
if (this.testCommands.length === 0) {
return "echo 'no tests'";
} else {
return this.testCommands.join(' && ');
}
}

private resolveVersion() {
const versionFile = `${this.outdir}/version.json`;
if (!fs.existsSync(versionFile)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
},
"scripts": {
"projen": "node projen.js && yarn install",
"test": "echo 'no tests'",
"compile": "jsii",
"watch": "jsii -w",
"test": "echo ok",
"compat": "npx jsii-diff npm:$(node -p \"require('./package.json').name\")",
"package": "jsii-pacmak",
"build": "yarn compile && yarn test && yarn run package",
Expand Down

0 comments on commit 5a08eb0

Please sign in to comment.