Skip to content

Commit 32f8fc5

Browse files
authored
feat: add support for custom platform 'projectName' from nativescript.config (#2107) (#5801)
1 parent 67e68c6 commit 32f8fc5

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

lib/definitions/project.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ interface INsConfig {
161161
visionos?: INSConfigVisionOS;
162162
ignoredNativeDependencies?: string[];
163163
hooks?: INsConfigHooks[];
164+
projectName?: string;
164165
}
165166

166167
interface IProjectData extends ICreateProjectData {
@@ -195,6 +196,7 @@ interface IProjectData extends ICreateProjectData {
195196
* The value can be changed by setting `webpackConfigPath` in nativescript.config.
196197
*/
197198
webpackConfigPath: string;
199+
projectName: string;
198200

199201
/**
200202
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.

lib/project-data.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ export class ProjectData implements IProjectData {
162162
}
163163

164164
if (packageJsonData) {
165-
this.projectName = this.$projectHelper.sanitizeName(
166-
path.basename(projectDir)
167-
);
165+
this.projectName =
166+
nsConfig && nsConfig.projectName
167+
? nsConfig.projectName
168+
: this.$projectHelper.sanitizeName(path.basename(projectDir));
168169
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME);
169170
this.projectFilePath = projectFilePath;
170171
this.projectIdentifiers = this.initializeProjectIdentifiers(nsConfig);

test/project-data.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ describe("projectData", () => {
5353
dependencies?: IStringDictionary;
5454
devDependencies: IStringDictionary;
5555
};
56-
configData?: { shared?: boolean; webpackConfigPath?: string };
56+
configData?: {
57+
shared?: boolean;
58+
webpackConfigPath?: string;
59+
projectName?: string;
60+
};
5761
}): IProjectData => {
5862
const testInjector = createTestInjector();
5963
const fs = testInjector.resolve("fs");
@@ -172,6 +176,20 @@ describe("projectData", () => {
172176
});
173177
});
174178

179+
describe("projectName", () => {
180+
it("has correct name when no value is set in nativescript.conf", () => {
181+
const projectData = prepareTest();
182+
assert.isString("projectDir", projectData.projectName);
183+
});
184+
185+
it("has correct name when a project name is set in nativescript.conf", () => {
186+
const projectData = prepareTest({
187+
configData: { projectName: "specifiedProjectName" },
188+
});
189+
assert.isString("specifiedProjectName", projectData.projectName);
190+
});
191+
});
192+
175193
describe("webpackConfigPath", () => {
176194
it("default path to webpack.config.js is set when nsconfig.json does not set value", () => {
177195
const projectData = prepareTest();

0 commit comments

Comments
 (0)