8000 feat(webpack): add support for 'projectName' config on Xcode build files by apburgess · Pull Request #10550 · NativeScript/NativeScript · GitHub
[go: up one dir, main page]

Skip to content

feat(webpack): add support for 'projectName' config on Xcode build files #10550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core/config/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ export interface NativeScriptConfig {
shared?: boolean;
previewAppSchema?: string;
overridePods?: string;
/**
* Custom platform project name.
* By default, the platforms/{platform}/{name} is based on the basename of the project directory.
* You can override that to use a name of your choice by setting this.
*/
projectName?: string;
/**
* Custom webpack config path
* The default is `webpack.config.js` in the root however you can use a custom name and place elsewhere.
Expand Down
37 changes: 36 additions & 1 deletion packages/webpack5/__tests__/helpers/platform.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { env } from '../../src/';
import { addPlatform, getEntryPath } from '../../src/helpers/platform';
import {
addPlatform,
getEntryPath,
getDistPath,
} from '../../src/helpers/platform';

import { getValue } from '../../src/helpers/config';

Expand Down Expand Up @@ -47,3 +51,34 @@ describe('getEntryPath', () => {
expect(res).toEqual('__jest__/src/app.js');
});
});

describe('getDistPath', () => {
it('is generated from working directory when no projectName setting in nativescript.config.ts', () => {
env.ios = true;

const distPath = getDistPath();

expect(distPath).toEqual('platforms/ios/jest/app');
env.ios = false;
});

it('is generated using projectName value from nativescript.config.ts when set', () => {
env.ios = true;

// mock getValue
const getValueMock = getValue as jest.Mock;
const getValueMockImpl = getValueMock.getMockImplementation();

getValueMock.mockImplementation((key) => {
if (key === 'projectName') {
return 'projectNameSpecified';
}
});

const distPath = getDistPath();

expect(distPath).toEqual('platforms/ios/projectNameSpecified/app');

getValueMock.mockImplementation(getValueMockImpl);
});
});
5 changes: 4 additions & 1 deletion packages/webpack5/src/platforms/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { basename } from "path";
import { INativeScriptPlatform } from "../helpers/platform";
import { getProjectRootPath } from "../helpers/project";
import { env } from '../';
import { getValue } from '../helpers/config';

function sanitizeName(appName: string): string {
return appName.split("").filter((c) =>
/[a-zA-Z0-9]/.test(c)
).join("");
}
function getDistPath() {
const appName = sanitizeName(basename(getProjectRootPath()));
// try projectName from nativescript.config.ts, if not set, use original method
const appName = getValue('projectName') ?? sanitizeName(basename(getProjectRootPath()));

return `${env.buildPath ?? "platforms"}/ios/${appName}/app`;
}

Expand Down
Loading
0