Skip to content

Commit

Permalink
feat(predicate): added the function to determine if the lifter should…
Browse files Browse the repository at this point in the history
… be applied
  • Loading branch information
travi committed Feb 13, 2024
1 parent 496c705 commit 6dd29a1
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 34 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,20 @@ $ npm install @form8ion/java --save
#### Import

```javascript
import {scaffold} from '@form8ion/java';
import {scaffold, lift, test} from '@form8ion/java';
```

#### Execute

```javascript
(async () => {
await scaffold({
projectRoot: process.cwd(),
projectName: 'project-name'
});
const projectRoot = process.cwd();

await scaffold({projectRoot, projectName: 'project-name'});

if (await test({projectRoot})) {
await lift({projectRoot, vcs: {}});
}
})();
```

Expand Down
13 changes: 8 additions & 5 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// #### Import
// remark-usage-ignore-next
import stubbedFs from 'mock-fs';
import {scaffold} from './lib/index.js';
import {scaffold, lift, test} from './lib/index.js';

// remark-usage-ignore-next
stubbedFs();

// #### Execute

(async () => {
await scaffold({
projectRoot: process.cwd(),
projectName: 'project-name'
});
const projectRoot = process.cwd();

await scaffold({projectRoot, projectName: 'project-name'});

if (await test({projectRoot})) {
await lift({projectRoot, vcs: {}});
}
})();
23 changes: 4 additions & 19 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"devDependencies": {
"@cucumber/cucumber": "10.3.1",
"@form8ion/commitlint-config": "1.0.69",
"@form8ion/core": "4.2.0",
"@form8ion/eslint-config": "7.0.8",
"@form8ion/eslint-config-cucumber": "1.4.1",
"@form8ion/remark-lint-preset": "6.0.2",
Expand All @@ -76,6 +75,7 @@
"vitest": "1.2.2"
},
"dependencies": {
"@form8ion/core": "^4.2.0",
"fast-xml-parser": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {default as scaffold} from './scaffolder.js';
export {lift} from './pom/index.js';
export {lift, test} from './pom/index.js';
1 change: 1 addition & 0 deletions src/pom/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export {default as scaffold} from './scaffolder.js';
export {default as lift} from './lifter.js';
export {default as test} from './predicate.js';
5 changes: 5 additions & 0 deletions src/pom/predicate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {fileExists} from '@form8ion/core';

export default function ({projectRoot}) {
return fileExists(`${projectRoot}/pom.xml`);
}
29 changes: 29 additions & 0 deletions src/pom/predicate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {fileExists} from '@form8ion/core';

import {afterEach, describe, it, vi, expect} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

import pomExists from './predicate.js';

vi.mock('@form8ion/core');

describe('maven predicate', () => {
const projectRoot = any.string();

afterEach(() => {
vi.clearAllMocks();
});

it('should return `true` when a root pom exists', async () => {
when(fileExists).calledWith(`${projectRoot}/pom.xml`).mockReturnValue(true);

expect(await pomExists({projectRoot})).toBe(true);
});

it('should return `false` when a root pom does not exist', async () => {
when(fileExists).calledWith(`${projectRoot}/pom.xml`).mockReturnValue(false);

expect(await pomExists({projectRoot})).toBe(false);
});
});
8 changes: 5 additions & 3 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import stubbedFs from 'mock-fs';
const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-line no-underscore-dangle
const stubbedNodeModules = stubbedFs.load(resolve(__dirname, '..', '..', '..', '..', 'node_modules'));

let scaffold, lift;
let scaffold, lift, test;

Before(async function () {
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
({scaffold, lift} = await import('@form8ion/java'));
({scaffold, lift, test} = await import('@form8ion/java'));

stubbedFs({
node_modules: stubbedNodeModules
Expand All @@ -29,5 +29,7 @@ When('the project is scaffolded', async function () {
});

When('the project is lifted', async function () {
await lift({projectRoot: this.projectRoot, vcs: this.vcsDetails});
if (await test({projectRoot: this.projectRoot})) {
await lift({projectRoot: this.projectRoot, vcs: this.vcsDetails});
}
});

0 comments on commit 6dd29a1

Please sign in to comment.