Skip to content

Commit

Permalink
Merge pull request #5 from form8ion/alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
travi authored Feb 10, 2024
2 parents 053fd93 + 7fdd15c commit ae853b9
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 19 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@




/node_modules/
/lib/
/coverage/

.eslintcache
.eslintcache
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,26 @@ Java language plugin for the @form8ion toolset

## Table of Contents

Run `npm run generate:md` to generate a table of contents
* [Features](#features)
* [`scaffold`](#scaffold)
* [Usage](#usage)
* [Installation](#installation)
* [Example](#example)
* [Import](#import)
* [Execute](#execute)
* [API](#api)
* [`scaffold`](#scaffold-1)
* [`projectRoot` __string__ (_required_)](#projectroot-string-required)
* [`projectName` __string__ (_required_)](#projectname-string-required)
* [Contributing](#contributing)
* [Dependencies](#dependencies)
* [Verification](#verification)

## Features

### `scaffold`

* creates a [minimal POM](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Minimal_POM)

## Usage

Expand All @@ -32,7 +51,34 @@ $ npm install @form8ion/java --save

### Example

run `npm run generate:md` to inject the usage example
#### Import

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

#### Execute

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

### API

#### `scaffold`

##### `projectRoot` __string__ (_required_)

path to the root of the project

##### `projectName` __string__ (_required_)

name of the project

## Contributing

Expand Down
5 changes: 4 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ stubbedFs();
// #### Execute

(async () => {
await scaffold({projectRoot: process.cwd()});
await scaffold({
projectRoot: process.cwd(),
projectName: 'project-name'
});
})();
75 changes: 74 additions & 1 deletion package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"devDependencies": {
"@cucumber/cucumber": "10.3.1",
"@form8ion/commitlint-config": "1.0.68",
"@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 @@ -73,5 +74,8 @@
"rollup": "4.9.6",
"rollup-plugin-auto-external": "2.0.0",
"vitest": "1.2.2"
},
"dependencies": {
"fast-xml-parser": "^4.3.4"
}
}
7 changes: 0 additions & 7 deletions src/canary.test.js

This file was deleted.

1 change: 1 addition & 0 deletions src/pom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default as scaffold} from './scaffolder.js';
11 changes: 11 additions & 0 deletions src/pom/scaffolder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {promises as fs} from 'node:fs';
import {XMLBuilder} from 'fast-xml-parser';

export default async function ({projectRoot, projectName}) {
const builder = new XMLBuilder({format: true});

await fs.writeFile(
`${projectRoot}/pom.xml`,
builder.build({project: {modelVersion: '4.0.0', artifactId: projectName}})
);
}
31 changes: 31 additions & 0 deletions src/pom/scaffolder.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {promises as fs} from 'node:fs';

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

import scaffold from './scaffolder.js';

vi.mock('node:fs');

describe('pom scaffolder', () => {
afterEach(() => {
vi.clearAllMocks();
});

it('should create the pom file', async () => {
const projectRoot = any.string();
const projectName = any.word();

await scaffold({projectRoot, projectName});

expect(fs.writeFile)
.toHaveBeenCalledWith(
`${projectRoot}/pom.xml`,
`<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>${projectName}</artifactId>
</project>
`
);
});
});
8 changes: 6 additions & 2 deletions src/scaffolder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export default function () {
return undefined;
import {scaffold as scaffoldPom} from './pom/index.js';

export default async function ({projectRoot, projectName}) {
await scaffoldPom({projectRoot, projectName});

return {};
}
21 changes: 21 additions & 0 deletions src/scaffolder.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {describe, it, expect, afterEach, vi} from 'vitest';
import any from '@travi/any';

import {scaffold as scaffoldPom} from './pom/index.js';
import scaffold from './scaffolder.js';

vi.mock('./pom/index.js');

describe('scaffolder', () => {
afterEach(() => {
vi.clearAllMocks();
});

it('should configure java', async () => {
const projectRoot = any.string();
const projectName = any.word();

expect(await scaffold({projectRoot, projectName})).toEqual({});
expect(scaffoldPom).toHaveBeenCalledWith({projectRoot, projectName});
});
});
2 changes: 2 additions & 0 deletions test/integration/features/scaffolder.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Feature: Scaffolder

Scenario: Scaffold
Given the project should be named "project-name"
When the project is scaffolded
Then the pom file is created
4 changes: 3 additions & 1 deletion test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ Before(async function () {
stubbedFs({
node_modules: stubbedNodeModules
});

this.projectRoot = process.cwd();
});

After(function () {
stubbedFs.restore();
});

When('the project is scaffolded', async function () {
await scaffold({projectRoot: process.cwd()});
await scaffold({projectRoot: this.projectRoot, projectName: this.projectName});
});
12 changes: 12 additions & 0 deletions test/integration/features/step_definitions/pom-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {promises as fs} from 'node:fs';
import {XMLParser} from 'fast-xml-parser';

import {Then} from '@cucumber/cucumber';
import {assert} from 'chai';

Then('the pom file is created', async function () {
const parser = new XMLParser();
const parsedContent = parser.parse(await fs.readFile(`${this.projectRoot}/pom.xml`, 'utf-8'));

assert.deepEqual(parsedContent, {project: {modelVersion: '4.0.0', artifactId: this.projectName}});
});
5 changes: 5 additions & 0 deletions test/integration/features/step_definitions/project-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Given} from '@cucumber/cucumber';

Given('the project should be named {string}', async function (projectName) {
this.projectName = projectName;
});

0 comments on commit ae853b9

Please sign in to comment.