Skip to content

Commit

Permalink
fix(react-native): use appsDir when generating app
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Jun 7, 2022
1 parent df61381 commit b923885
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (async () => {
assetExts: assetExts.filter((ext) => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
resolverMainFields: ['sbmodern', 'browser', 'main'],
blockList: exclusionList([/\.\/dist\/.*/]),
blockList: exclusionList([/\/dist\/.*/]),
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ module.exports = (async () => {
assetExts: assetExts.filter((ext) => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
resolverMainFields: ['sbmodern', 'browser', 'main'],
<<<<<<< HEAD
blockList: exclusionList([/\.\/dist\/.*/]),
=======
blockList: exclusionList([/\/dist\/.*/]),
>>>>>>> 9233fac92 (fix(react-native): rename blacklistRE to blockList in metro.config.js)
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export default async function update(tree: Tree) {
}
tree.write(
metroConfigPath,
metroConfigContent.replace('blacklistRE:', 'blockList:')
metroConfigContent.replace(
`blacklistRE: exclusionList([/\.\/dist\/.*/])`,
`blockList: exclusionList([/\/dist\/.*/])`
)
);
} catch {
logger.error(
Expand Down

0 comments on commit b923885

Please sign in to comment.