Skip to content

Commit

Permalink
chore(stencil): align package to nx 20
Browse files Browse the repository at this point in the history
BREAKING CHANGE: generator option 'name' is optional in favor of 'directory' one
  • Loading branch information
pawel-twardziak committed Oct 13, 2024
1 parent 1f0afa5 commit 1823cfe
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 211 deletions.
40 changes: 24 additions & 16 deletions docs/docs/stencil/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ nx g application ... --dry-run

### Options

#### name (_**required**_)

Type: `string`

#### directory
#### directory (_**required**_)

Alias(es): d

Type: `string`

A directory where the project is placed
A directory where the project is placed.

#### e2eTestRunner

Expand All @@ -60,6 +56,14 @@ Possible values: `eslint`, `none`

The tool to use for running lint checks.

#### name

Alias(es): n

Type: `string`

A name of the project.

#### skipFormat

Default: `false`
Expand Down Expand Up @@ -126,10 +130,14 @@ nx g library ... --dry-run

### Options

#### name (_**required**_)
#### directory (_**required**_)

Alias(es): d

Type: `string`

A directory where the project is placed.

#### buildable

Default: `false`
Expand All @@ -144,14 +152,6 @@ Type: `boolean`

Generate a default component.

#### directory

Alias(es): d

Type: `string`

A directory where the project is placed

#### e2eTestRunner

Default: `puppeteer`
Expand All @@ -178,6 +178,14 @@ Possible values: `eslint`, `none`

The tool to use for running lint checks.

#### name

Alias(es): n

Type: `string`

A name of the project.

#### publishable

Type: `boolean`
Expand Down Expand Up @@ -268,7 +276,7 @@ Alias(es): d

Type: `string`

A directory where the project is placed
A directory where the project is placed.

#### skipFormat

Expand Down
22 changes: 11 additions & 11 deletions packages/stencil/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
"executors": "./executors.json",
"dependencies": {
"@nxext/common": "^19.0.0",
"@nx/devkit": "19.8.3",
"@nx/devkit": "20.0.0",
"@stencil/core": "4.12.6",
"@nx/workspace": "19.8.3",
"@nx/js": "19.8.3",
"@nx/workspace": "20.0.0",
"@nx/js": "20.0.0",
"typescript": "5.5.4",
"@nx/eslint": "19.8.3",
"@nx/web": "19.8.3",
"@nx/cypress": "19.8.3",
"@nx/jest": "19.8.3",
"@nx/storybook": "19.8.3",
"@nx/eslint": "20.0.0",
"@nx/web": "20.0.0",
"@nx/cypress": "20.0.0",
"@nx/jest": "20.0.0",
"@nx/storybook": "20.0.0",
"@phenomnomnominal/tsquery": "~5.0.1",
"tslib": "^2.3.0",
"nx": "19.8.3",
"nx": "20.0.0",
"fs-extra": "^10.1.0",
"@nx/angular": "19.8.3",
"@nx/react": "19.8.3"
"@nx/angular": "20.0.0",
"@nx/react": "20.0.0"
},
"peerDependencies": {},
"peerDependenciesMeta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ async function prepareAngularLibrary(
options: AddOutputtargetSchematicSchema
) {
const angularProjectName = `${options.projectName}-angular`;
const { libsDir } = getWorkspaceLayout(host);
const angularProjectDir = `libs/${angularProjectName}`;

await ensurePackage('@nx/angular', NX_VERSION);
const generators = await import('@nx/angular/generators');
const libraryTarget = await generators.libraryGenerator(host, {
name: angularProjectName,
directory: angularProjectDir,
skipFormat: true,
publishable: options.publishable,
importPath: options.importPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { AddOutputtargetSchematicSchema } from './schema';

xdescribe('add-outputtarget angular', () => {
let tree: Tree;
const projectName = uniq('testproject');
const projectName = uniq('testprojekt');
const projectAppDirectory = `apps/${projectName}`;
const projectLibDirectory = `libs/${projectName}`;
const options = {
projectName: projectName,
publishable: false,
skipFormat: false,
};

beforeEach(async () => {
tree = await createTestUILib(projectName);
tree = await createTestUILib(projectLibDirectory);
});

describe('using angular', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { AddOutputtargetSchematicSchema } from './schema';

xdescribe('add-outputtarget react', () => {
let tree: Tree;
const projectName = uniq('testproject');
const projectName = uniq('testprojekt');
const projectAppDirectory = `apps/${projectName}`;
const projectLibDirectory = `libs/${projectName}`;
const options = {
projectName: projectName,
publishable: false,
skipFormat: false,
};

beforeEach(async () => {
tree = await createTestUILib(projectName);
tree = await createTestUILib(projectLibDirectory);
});

describe('using react', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async function prepareReactLibrary(
) {
const { libsDir } = getWorkspaceLayout(host);
const reactProjectName = `${options.projectName}-react`;
const reactProjectDir = `libs/${reactProjectName}`;

const jsInitTask = await jsInitGenerator(host, {
...options,
Expand All @@ -34,7 +35,7 @@ async function prepareReactLibrary(
ensurePackage('@nx/react', NX_VERSION);
const { libraryGenerator } = await import('@nx/react');
const libraryTarget = await libraryGenerator(host, {
name: reactProjectName,
directory: reactProjectDir,
style: 'css',
publishable: options.publishable,
bundler: options.publishable ? 'rollup' : 'none',
Expand Down
22 changes: 15 additions & 7 deletions packages/stencil/src/generators/application/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ describe('schematic:application', () => {
jest.spyOn(readNxVersionModule, 'readNxVersion').mockReturnValue('17.0.0');

let host: Tree;
const options: RawApplicationSchema = { name: 'test', linter: Linter.None };
const options: RawApplicationSchema = {
directory: 'apps/test',
linter: Linter.None,
};

beforeEach(() => {
host = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
Expand All @@ -39,7 +42,10 @@ describe('schematic:application', () => {
it('should add tags to nx.json', async () => {
await applicationGenerator(host, { ...options, tags: 'e2etag,e2ePackage' });

const projectConfig = readProjectConfiguration(host, options.name);
const projectConfig = readProjectConfiguration(
host,
options.directory.replace('apps/', '')
);
expect(projectConfig.tags).toEqual(['e2etag', 'e2ePackage']);
});

Expand All @@ -55,7 +61,7 @@ describe('schematic:application', () => {
await applicationGenerator(host, { ...options, linter: Linter.EsLint });

const fileList = fileListForAppType(
options.name,
options.directory,
SupportedStyles.css,
'application'
);
Expand All @@ -74,10 +80,9 @@ describe('schematic:application', () => {
await applicationGenerator(host, { ...options, directory: 'subdir' });

const fileList = fileListForAppType(
options.name,
options.directory,
SupportedStyles.css,
'application',
'subdir'
'application'
);
fileList.forEach((file) => expect(host.exists(file)));
});
Expand Down Expand Up @@ -106,7 +111,10 @@ describe('schematic:application', () => {
style: SupportedStyles[style],
});

const projectConfig = readProjectConfiguration(host, options.name);
const projectConfig = readProjectConfiguration(
host,
options.directory.replace('apps/', '')
);
expect(projectConfig.generators).toEqual({
'@nxext/stencil:component': {
style: style,
Expand Down
29 changes: 19 additions & 10 deletions packages/stencil/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ import { join } from 'path';
import { addProject } from './lib/add-project';
import { addLinting } from './lib/add-linting';
import { addCypress } from './lib/add-cypress';
import {
determineProjectNameAndRootOptions,
ensureProjectName,
} from '@nx/devkit/src/generators/project-name-and-root-utils';

function normalizeOptions(
async function normalizeOptions(
host: Tree,
options: RawApplicationSchema
): ApplicationSchema {
const { appsDir } = getWorkspaceLayout(host);
const projectName = names(options.name).fileName;
const projectDirectory = options.directory
? `${names(options.directory).fileName}/${projectName}`
: projectName;
const projectRoot = `${appsDir}/${projectDirectory}`;
): Promise<ApplicationSchema> {
await ensureProjectName(host, options, 'application');
const { projectName, projectRoot } = await determineProjectNameAndRootOptions(
host,
{
name: options.name,
projectType: 'application',
directory: options.directory,
}
);

const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
: [];
Expand All @@ -52,9 +60,10 @@ function normalizeOptions(

return {
...options,
name: projectName,
projectName,
projectRoot,
projectDirectory,
projectDirectory: projectRoot,
parsedTags,
e2eProjectName,
e2eProjectRoot,
Expand Down Expand Up @@ -89,7 +98,7 @@ export async function applicationGenerator(
host: Tree,
schema: RawApplicationSchema
) {
const options = normalizeOptions(host, schema);
const options = await normalizeOptions(host, schema);
const initTask = await initGenerator(host, {
...options,
skipFormat: true,
Expand Down
5 changes: 3 additions & 2 deletions packages/stencil/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SupportedStyles } from '../../stencil-core-utils';
import { Linter } from '@nx/eslint';

export interface RawApplicationSchema {
name: string;
directory: string;
name?: string;
tags?: string;
directory?: string;
style?: SupportedStyles;
skipFormat?: boolean;
appType?: AppType;
Expand All @@ -16,6 +16,7 @@ export interface RawApplicationSchema {
}

export interface ApplicationSchema extends RawApplicationSchema {
name: string;
projectName: string;
projectRoot: string;
projectDirectory: string;
Expand Down
29 changes: 15 additions & 14 deletions packages/stencil/src/generators/application/schema.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "Nxext-Application",
"$id": "Stencil-Application",
"title": "",
"type": "object",
"properties": {
"name": {
"directory": {
"type": "string",
"description": "",
"description": "A directory where the project is placed.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use?"
"x-prompt": "What directory would you like to use? (full path; e.g. apps/<my-app-name>)",
"alias": "d"
},
"name": {
"type": "string",
"description": "A name of the project.",
"alias": "n"
},
"tags": {
"type": "string",
"description": "Add tags to the project (used for linting)",
"alias": "t"
},
"directory": {
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"description": "A directory where the project is placed",
"alias": "d"
"enum": ["eslint", "none"],
"default": "eslint"
},
"e2eTestRunner": {
"type": "string",
Expand All @@ -39,12 +46,6 @@
"type": "boolean",
"default": false
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint", "none"],
"default": "eslint"
},
"style": {
"description": "The file extension to be used for style files.",
"type": "string",
Expand All @@ -66,5 +67,5 @@
}
}
},
"required": ["name"]
"required": ["directory"]
}
Loading

0 comments on commit 1823cfe

Please sign in to comment.