Skip to content

Commit

Permalink
fix(nx-plugin): require importPath
Browse files Browse the repository at this point in the history
  • Loading branch information
juristr committed Jun 29, 2020
1 parent f137882 commit eaf2c59
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 17 deletions.
8 changes: 7 additions & 1 deletion docs/angular/api-nx-plugin/schematics/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nx g plugin ... --dry-run
Generate libs/plugins/my-plugin:

```bash
nx g plugin my-plugin --directory=plugins
nx g plugin my-plugin --directory=plugins --importPath=@myorg/my-plugin
```

## Options
Expand All @@ -40,6 +40,12 @@ Type: `string`

A directory where the plugin is placed

### importPath

Type: `string`

How the plugin will be published, like @myorg/my-awesome-plugin. Note this must be a valid npm name

### linter

Default: `tslint`
Expand Down
8 changes: 7 additions & 1 deletion docs/react/api-nx-plugin/schematics/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nx g plugin ... --dry-run
Generate libs/plugins/my-plugin:

```bash
nx g plugin my-plugin --directory=plugins
nx g plugin my-plugin --directory=plugins --importPath=@myorg/my-plugin
```

## Options
Expand All @@ -40,6 +40,12 @@ Type: `string`

A directory where the plugin is placed

### importPath

Type: `string`

How the plugin will be published, like @myorg/my-awesome-plugin. Note this must be a valid npm name

### linter

Default: `tslint`
Expand Down
6 changes: 4 additions & 2 deletions packages/create-nx-plugin/bin/create-nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ function createWorkspace(
}

function createNxPlugin(workspaceName, pluginName) {
console.log(`nx generate @nrwl/nx-plugin:plugin ${pluginName}`);
console.log(
`nx generate @nrwl/nx-plugin:plugin ${pluginName} --importPath=${workspaceName}/${pluginName}`
);
execSync(
`node ./node_modules/@nrwl/cli/bin/nx.js generate @nrwl/nx-plugin:plugin ${pluginName}`,
`node ./node_modules/@nrwl/cli/bin/nx.js generate @nrwl/nx-plugin:plugin ${pluginName} --importPath=${workspaceName}/${pluginName}`,
{
cwd: workspaceName,
stdio: [0, 1, 2],
Expand Down
6 changes: 5 additions & 1 deletion packages/nx-plugin/src/schematics/builder/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ describe('NxPlugin builder', () => {
beforeEach(async () => {
projectName = 'my-plugin';
appTree = createEmptyWorkspace(ngSchematics.Tree.empty());
appTree = await runSchematic('plugin', { name: projectName }, appTree);
appTree = await runSchematic(
'plugin',
{ name: projectName, importPath: '@proj/my-plugin' },
appTree
);
});

it('should generate files', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ describe('NxPlugin migration', () => {
beforeEach(async () => {
projectName = 'my-plugin';
appTree = createEmptyWorkspace(ngSchematics.Tree.empty());
appTree = await runSchematic('plugin', { name: projectName }, appTree);
appTree = await runSchematic(
'plugin',
{ name: projectName, importPath: '@proj/my-plugin' },
appTree
);
});

it('should update the workspace.json file', async () => {
Expand Down
48 changes: 40 additions & 8 deletions packages/nx-plugin/src/schematics/plugin/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ describe('NxPlugin plugin', () => {
});

it('should update the workspace.json file', async () => {
const tree = await runSchematic('plugin', { name: 'myPlugin' }, appTree);
const tree = await runSchematic(
'plugin',
{ name: 'myPlugin', importPath: '@proj/my-plugin' },
appTree
);
const workspace = await readWorkspace(tree);
const project = workspace.projects['my-plugin'];
expect(project.root).toEqual('libs/my-plugin');
Expand Down Expand Up @@ -62,7 +66,11 @@ describe('NxPlugin plugin', () => {
});

it('should update the tsconfig.lib.json file', async () => {
const tree = await runSchematic('plugin', { name: 'myPlugin' }, appTree);
const tree = await runSchematic(
'plugin',
{ name: 'myPlugin', importPath: '@proj/my-plugin' },
appTree
);
const tsLibConfig = readJsonInTree(
tree,
'libs/my-plugin/tsconfig.lib.json'
Expand All @@ -71,7 +79,11 @@ describe('NxPlugin plugin', () => {
});

it('should create schematic and builder files', async () => {
const tree = await runSchematic('plugin', { name: 'myPlugin' }, appTree);
const tree = await runSchematic(
'plugin',
{ name: 'myPlugin', importPath: '@proj/my-plugin' },
appTree
);
expect(tree.exists('libs/my-plugin/collection.json')).toBeTruthy();
expect(tree.exists('libs/my-plugin/builders.json')).toBeTruthy();
expect(
Expand Down Expand Up @@ -115,7 +127,11 @@ describe('NxPlugin plugin', () => {

it('should call the @nrwl/node:lib schematic', async () => {
const externalSchematicSpy = jest.spyOn(ngSchematics, 'externalSchematic');
await runSchematic('plugin', { name: 'myPlugin' }, appTree);
await runSchematic(
'plugin',
{ name: 'myPlugin', importPath: '@proj/my-plugin' },
appTree
);
expect(externalSchematicSpy).toBeCalledWith(
'@nrwl/node',
'lib',
Expand All @@ -127,7 +143,11 @@ describe('NxPlugin plugin', () => {

it('should call the @nrwl/nx-plugin:e2e schematic', async () => {
const schematicSpy = jest.spyOn(ngSchematics, 'schematic');
const tree = await runSchematic('plugin', { name: 'myPlugin' }, appTree);
const tree = await runSchematic(
'plugin',
{ name: 'myPlugin', importPath: '@proj/my-plugin' },
appTree
);
expect(schematicSpy).toBeCalledWith(
'e2e-project',
expect.objectContaining({
Expand All @@ -140,7 +160,11 @@ describe('NxPlugin plugin', () => {

it('should call the @nrwl/nx-plugin:schematic schematic', async () => {
const schematicSpy = jest.spyOn(ngSchematics, 'schematic');
const tree = await runSchematic('plugin', { name: 'myPlugin' }, appTree);
const tree = await runSchematic(
'plugin',
{ name: 'myPlugin', importPath: '@proj/my-plugin' },
appTree
);
expect(schematicSpy).toBeCalledWith(
'schematic',
expect.objectContaining({
Expand All @@ -152,7 +176,11 @@ describe('NxPlugin plugin', () => {

it('should call the @nrwl/nx-plugin:builder schematic', async () => {
const schematicSpy = jest.spyOn(ngSchematics, 'schematic');
const tree = await runSchematic('plugin', { name: 'myPlugin' }, appTree);
const tree = await runSchematic(
'plugin',
{ name: 'myPlugin', importPath: '@proj/my-plugin' },
appTree
);
expect(schematicSpy).toBeCalledWith(
'builder',
expect.objectContaining({
Expand All @@ -171,7 +199,11 @@ describe('NxPlugin plugin', () => {
);
const tree = await runSchematic(
'plugin',
{ name: 'myPlugin', unitTestRunner: 'none' },
{
name: 'myPlugin',
importPath: '@proj/my-plugin',
unitTestRunner: 'none',
},
appTree
);

Expand Down
1 change: 1 addition & 0 deletions packages/nx-plugin/src/schematics/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function (schema: NormalizedSchema): Rule {
externalSchematic('@nrwl/node', 'lib', {
...schema,
publishable: true,
importPath: schema.importPath,
unitTestRunner: options.unitTestRunner,
}),
addFiles(options),
Expand Down
1 change: 1 addition & 0 deletions packages/nx-plugin/src/schematics/plugin/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Linter } from '@nrwl/workspace';
export interface Schema {
name: string;
directory?: string;
importPath: string;
skipTsConfig: boolean;
skipFormat: boolean;
tags?: string;
Expand Down
8 changes: 6 additions & 2 deletions packages/nx-plugin/src/schematics/plugin/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "object",
"examples": [
{
"command": "g plugin my-plugin --directory=plugins",
"command": "g plugin my-plugin --directory=plugins --importPath=@myorg/my-plugin",
"description": "Generate libs/plugins/my-plugin"
}
],
Expand All @@ -24,6 +24,10 @@
"description": "A directory where the plugin is placed",
"alias": "d"
},
"importPath": {
"type": "string",
"description": "How the plugin will be published, like @myorg/my-awesome-plugin. Note this must be a valid npm name"
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
Expand Down Expand Up @@ -52,5 +56,5 @@
"description": "Do not update tsconfig.json for development experience."
}
},
"required": ["name"]
"required": ["name", "importPath"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ describe('NxPlugin schematic', () => {
beforeEach(async () => {
projectName = 'my-plugin';
appTree = createEmptyWorkspace(ngSchematics.Tree.empty());
appTree = await runSchematic('plugin', { name: projectName }, appTree);
appTree = await runSchematic(
'plugin',
{ name: projectName, importPath: '@proj/my-plugin' },
appTree
);
});

it('should generate files', async () => {
Expand Down

0 comments on commit eaf2c59

Please sign in to comment.