Skip to content

Commit

Permalink
fix(expo): use workspace layout apps dir for expo generate application (
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Nov 17, 2022
1 parent fb8631e commit fc2e6be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/expo/src/generators/application/application.ts
Expand Up @@ -22,7 +22,7 @@ export async function expoApplicationGenerator(
host: Tree,
schema: Schema
): Promise<GeneratorCallback> {
const options = normalizeOptions(schema);
const options = normalizeOptions(host, schema);

createApplicationFiles(host, options);
addProject(host, options);
Expand Down
@@ -1,8 +1,16 @@
import { Tree } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Linter } from '@nrwl/linter';
import { Schema } from '../schema';
import { normalizeOptions } from './normalize-options';

describe('Normalize Options', () => {
let appTree: Tree;

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace();
});

it('should normalize options with name in kebab case', () => {
const schema: Schema = {
name: 'my-app',
Expand All @@ -12,7 +20,7 @@ describe('Normalize Options', () => {
js: true,
unitTestRunner: 'jest',
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
appProjectRoot: 'apps/my-app',
className: 'MyApp',
Expand All @@ -38,7 +46,7 @@ describe('Normalize Options', () => {
js: true,
unitTestRunner: 'jest',
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
appProjectRoot: 'apps/my-app',
className: 'MyApp',
Expand All @@ -65,7 +73,7 @@ describe('Normalize Options', () => {
js: true,
unitTestRunner: 'jest',
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
appProjectRoot: 'apps/directory/my-app',
className: 'MyApp',
Expand All @@ -92,7 +100,7 @@ describe('Normalize Options', () => {
js: true,
unitTestRunner: 'jest',
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
appProjectRoot: 'apps/directory/my-app',
className: 'DirectoryMyApp',
Expand All @@ -119,7 +127,7 @@ describe('Normalize Options', () => {
js: true,
unitTestRunner: 'jest',
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
appProjectRoot: 'apps/my-app',
className: 'MyApp',
Expand Down
@@ -1,4 +1,5 @@
import { names } from '@nrwl/devkit';
import { getWorkspaceLayout, names, Tree } from '@nrwl/devkit';
import { join } from 'path';
import { Schema } from '../schema';

export interface NormalizedSchema extends Schema {
Expand All @@ -9,8 +10,12 @@ export interface NormalizedSchema extends Schema {
parsedTags: string[];
}

export function normalizeOptions(options: Schema): NormalizedSchema {
export function normalizeOptions(
host: Tree,
options: Schema
): NormalizedSchema {
const { fileName, className } = names(options.name);
const { appsDir } = getWorkspaceLayout(host);

const directoryName = options.directory
? names(options.directory).fileName
Expand All @@ -21,7 +26,7 @@ export function normalizeOptions(options: Schema): NormalizedSchema {

const appProjectName = projectDirectory.replace(new RegExp('/', 'g'), '-');

const appProjectRoot = `apps/${projectDirectory}`;
const appProjectRoot = join(appsDir, projectDirectory);

const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
Expand Down

0 comments on commit fc2e6be

Please sign in to comment.