Skip to content

Commit

Permalink
fix(react-native): use appsDir when generating app (#10606)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Jun 7, 2022
1 parent b9012fa commit e493611
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
4 changes: 1 addition & 3 deletions lerna.json
@@ -1,7 +1,5 @@
{
"packages": [
"build/packages/*"
],
"packages": ["build/packages/*"],
"version": "14.2.1",
"granularPathspec": false,
"command": {
Expand Down
Expand Up @@ -23,7 +23,7 @@ export async function reactNativeApplicationGenerator(
host: Tree,
schema: Schema
): Promise<GeneratorCallback> {
const options = normalizeOptions(schema);
const options = normalizeOptions(host, schema);

createApplicationFiles(host, options);
addProject(host, options);
Expand Down
@@ -1,16 +1,24 @@
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',
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/my-app/android',
appProjectRoot: 'apps/my-app',
Expand All @@ -35,7 +43,7 @@ describe('Normalize Options', () => {
e2eTestRunner: 'none',
install: false,
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/my-app/android',
appProjectRoot: 'apps/my-app',
Expand All @@ -60,7 +68,7 @@ describe('Normalize Options', () => {
e2eTestRunner: 'none',
install: false,
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/directory/my-app/android',
appProjectRoot: 'apps/directory/my-app',
Expand All @@ -85,7 +93,7 @@ describe('Normalize Options', () => {
e2eTestRunner: 'none',
install: false,
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/directory/my-app/android',
appProjectRoot: 'apps/directory/my-app',
Expand All @@ -110,7 +118,7 @@ describe('Normalize Options', () => {
e2eTestRunner: 'none',
install: false,
};
const options = normalizeOptions(schema);
const options = normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/my-app/android',
appProjectRoot: 'apps/my-app',
Expand Down
@@ -1,4 +1,9 @@
import { names } from '@nrwl/devkit';
import {
getWorkspaceLayout,
joinPathFragments,
names,
Tree,
} from '@nrwl/devkit';
import { join } from 'path';
import { Schema } from '../schema';

Expand All @@ -13,8 +18,12 @@ export interface NormalizedSchema extends Schema {
entryFile: 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 @@ -25,7 +34,7 @@ export function normalizeOptions(options: Schema): NormalizedSchema {

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

const appProjectRoot = `apps/${projectDirectory}`;
const appProjectRoot = joinPathFragments(appsDir, projectDirectory);
const iosProjectRoot = join(appProjectRoot, 'ios');
const androidProjectRoot = join(appProjectRoot, 'android');

Expand Down

0 comments on commit e493611

Please sign in to comment.