8000 feat(webpack): allow custom 'projectName' on Xcode project name from … · CatchABus/NativeScript@b8fff38 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8fff38

Browse files
authored
feat(webpack): allow custom 'projectName' on Xcode project name from config (NativeScript#10550)
1 parent c2f5e61 commit b8fff38

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

packages/core/config/config.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ export interface NativeScriptConfig {
196196
shared?: boolean;
197197
previewAppSchema?: string;
198198
overridePods?: string;
199+
/**
200+
* Custom platform project name.
201+
* By default, the platforms/{platform}/{name} is based on the basename of the project directory.
202+
* You can override that to use a name of your choice by setting this.
203+
*/
204+
projectName?: string;
199205
/**
200206
* Custom webpack config path
201207
* The default is `webpack.config.js` in the root however you can use a custom name and place elsewhere.

packages/webpack5/__tests__/helpers/platform.spec.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { env } from '../../src/';
2-
import { addPlatform, getEntryPath } from '../../src/helpers/platform';
2+
import {
3+
addPlatform,
4+
getEntryPath,
5+
getDistPath,
6+
} from '../../src/helpers/platform';
37

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

@@ -47,3 +51,34 @@ describe('getEntryPath', () => {
4751
expect(res).toEqual('__jest__/src/app.js');
4852
});
4953
});
54+
55+
describe('getDistPath', () => {
56+
it('is generated from working directory when no projectName setting in nativescript.config.ts', () => {
57+
env.ios = true;
58+
59+
const distPath = getDistPath();
60+
61+
expect(distPath).toEqual('platforms/ios/jest/app');
62+
env.ios = false;
63+
});
64+
65+
it('is generated using projectName value from nativescript.config.ts when set', () => {
66+
env.ios = true;
67+
68+
// mock getValue
69+
const getValueMock = getValue as jest.Mock;
70+
const getValueMockImpl = getValueMock.getMockImplementation();
71+
72+
getValueMock.mockImplementation((key) => {
73+
if (key === 'projectName') {
74+
return 'projectNameSpecified';
75+
}
76+
});
77+
78+
const distPath = getDistPath();
79+
80+
expect(distPath).toEqual('platforms/ios/projectNameSpecified/app');
81+
82+
getValueMock.mockImplementation(getValueMockImpl);
83+
});
84+
});

packages/webpack5/src/platforms/ios.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { basename } from "path";
33
import { INativeScriptPlatform } from "../helpers/platform";
44
import { getProjectRootPath } from "../helpers/project";
55
import { env } from '../';
6+
import { getValue } from '../helpers/config';
67

78
function sanitizeName(appName: string): string {
89
return appName.split("").filter((c) =>
910
/[a-zA-Z0-9]/.test(c)
1011
).join("");
1112
}
1213
function getDistPath() {
13-
const appName = sanitizeName(basename(getProjectRootPath()));
14+
// try projectName from nativescript.config.ts, if not set, use original method
15+
const appName = getValue('projectName') ?? sanitizeName(basename(getProjectRootPath()));
16+
1417
return `${env.buildPath ?? "platforms"}/ios/${appName}/app`;
1518
}
1619

0 commit comments

Comments
 (0)
0