feat(webpack): allow custom 'projectName' on Xcode project name from config (#10550)

This commit is contained in:
apburgess
2024-06-28 22:43:16 +01:00
committed by GitHub
parent c2f5e614da
commit b8fff3833e
3 changed files with 46 additions and 2 deletions

View File

@@ -196,6 +196,12 @@ export interface NativeScriptConfig {
shared?: boolean; shared?: boolean;
previewAppSchema?: string; previewAppSchema?: string;
overridePods?: 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 * Custom webpack config path
* The default is `webpack.config.js` in the root however you can use a custom name and place elsewhere. * The default is `webpack.config.js` in the root however you can use a custom name and place elsewhere.

View File

@@ -1,5 +1,9 @@
import { env } from '../../src/'; 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'; import { getValue } from '../../src/helpers/config';
@@ -47,3 +51,34 @@ describe('getEntryPath', () => {
expect(res).toEqual('__jest__/src/app.js'); 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);
});
});

View File

@@ -3,6 +3,7 @@ import { basename } from "path";
import { INativeScriptPlatform } from "../helpers/platform"; import { INativeScriptPlatform } from "../helpers/platform";
import { getProjectRootPath } from "../helpers/project"; import { getProjectRootPath } from "../helpers/project";
import { env } from '../'; import { env } from '../';
import { getValue } from '../helpers/config';
function sanitizeName(appName: string): string { function sanitizeName(appName: string): string {
return appName.split("").filter((c) => return appName.split("").filter((c) =>
@@ -10,7 +11,9 @@ function sanitizeName(appName: string): string {
).join(""); ).join("");
} }
function getDistPath() { 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`; return `${env.buildPath ?? "platforms"}/ios/${appName}/app`;
} }