Skip to content

Commit

Permalink
feat(node): add library schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored and vsavkin committed Dec 20, 2019
1 parent cee6888 commit 6328b8f
Show file tree
Hide file tree
Showing 13 changed files with 747 additions and 1 deletion.
95 changes: 95 additions & 0 deletions docs/angular/api-node/schematics/library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# library

Create a library

## Usage

```bash
ng generate library ...
```

```bash
ng g lib ... # same
```

By default, Nx will search for `library` in the default collection provisioned in `angular.json`.

You can specify the collection explicitly as follows:

```bash
ng g @nrwl/node:library ...
```

Show what will be generated without writing to disk:

```bash
ng g library ... --dry-run
```

### Examples

Generate libs/myapp/mylib:

```bash
ng g lib mylib --directory=myapp
```

## Options

### directory

Alias(es): d

Type: `string`

A directory where the app is placed

### linter

Default: `tslint`

Type: `string`

Possible values: `eslint`, `tslint`

The tool to use for running lint checks.

### name

Type: `string`

Library name

### skipFormat

Default: `false`

Type: `boolean`

Skip formatting files

### skipTsConfig

Default: `false`

Type: `boolean`

Do not update tsconfig.json for development experience.

### tags

Alias(es): t

Type: `string`

Add tags to the library (used for linting)

### unitTestRunner

Default: `jest`

Type: `string`

Possible values: `jest`, `none`

Test runner to use for unit tests
95 changes: 95 additions & 0 deletions docs/react/api-node/schematics/library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# library

Create a library

## Usage

```bash
nx generate library ...
```

```bash
nx g lib ... # same
```

By default, Nx will search for `library` in the default collection provisioned in `workspace.json`.

You can specify the collection explicitly as follows:

```bash
nx g @nrwl/node:library ...
```

Show what will be generated without writing to disk:

```bash
nx g library ... --dry-run
```

### Examples

Generate libs/myapp/mylib:

```bash
nx g lib mylib --directory=myapp
```

## Options

### directory

Alias(es): d

Type: `string`

A directory where the app is placed

### linter

Default: `tslint`

Type: `string`

Possible values: `eslint`, `tslint`

The tool to use for running lint checks.

### name

Type: `string`

Library name

### skipFormat

Default: `false`

Type: `boolean`

Skip formatting files

### skipTsConfig

Default: `false`

Type: `boolean`

Do not update tsconfig.json for development experience.

### tags

Alias(es): t

Type: `string`

Add tags to the library (used for linting)

### unitTestRunner

Default: `jest`

Type: `string`

Possible values: `jest`, `none`

Test runner to use for unit tests
95 changes: 95 additions & 0 deletions docs/web/api-node/schematics/library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# library

Create a library

## Usage

```bash
nx generate library ...
```

```bash
nx g lib ... # same
```

By default, Nx will search for `library` in the default collection provisioned in `workspace.json`.

You can specify the collection explicitly as follows:

```bash
nx g @nrwl/node:library ...
```

Show what will be generated without writing to disk:

```bash
nx g library ... --dry-run
```

### Examples

Generate libs/myapp/mylib:

```bash
nx g lib mylib --directory=myapp
```

## Options

### directory

Alias(es): d

Type: `string`

A directory where the app is placed

### linter

Default: `tslint`

Type: `string`

Possible values: `eslint`, `tslint`

The tool to use for running lint checks.

### name

Type: `string`

Library name

### skipFormat

Default: `false`

Type: `boolean`

Skip formatting files

### skipTsConfig

Default: `false`

Type: `boolean`

Do not update tsconfig.json for development experience.

### tags

Alias(es): t

Type: `string`

Add tags to the library (used for linting)

### unitTestRunner

Default: `jest`

Type: `string`

Possible values: `jest`, `none`

Test runner to use for unit tests
13 changes: 13 additions & 0 deletions e2e/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,18 @@ forEachCli(currentCLIName => {
}).toString();
expect(result).toContain('Hello World!');
}, 60000);

it('should be able to generate a node library', async () => {
ensureProject();
const nodelib = uniq('nodelib');

runCLI(`generate @nrwl/node:lib ${nodelib}`);

const lintResults = runCLI(`lint ${nodelib}`);
expect(lintResults).toContain('All files pass linting.');

const jestResult = await runCLIAsync(`test ${nodelib}`);
expect(jestResult.stderr).toContain('Test Suites: 1 passed, 1 total');
}, 60000);
});
});
7 changes: 6 additions & 1 deletion packages/node/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
"aliases": ["ng-add"],
"hidden": true
},

"application": {
"factory": "./src/schematics/application/application",
"schema": "./src/schematics/application/schema.json",
"aliases": ["app"],
"description": "Create a node application"
},
"library": {
"factory": "./src/schematics/library/library",
"schema": "./src/schematics/library/schema.json",
"aliases": ["lib"],
"description": "Create a library"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { <%= propertyName %> } from './<%= fileName %>';

describe('<%= propertyName %>', () => {
it('should work', () => {
expect(<%= propertyName %>()).toEqual('<%= name %>');
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function <%= propertyName %>(): string {
return '<%= name %>';
}
9 changes: 9 additions & 0 deletions packages/node/src/schematics/library/files/lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "<%= offsetFromRoot %>tsconfig.json",
"compilerOptions": {
"types": [
"node"
]
},
"include": ["**/*.ts"]
}
11 changes: 11 additions & 0 deletions packages/node/src/schematics/library/files/lib/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": [
"node"
]
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"]
}

0 comments on commit 6328b8f

Please sign in to comment.