Skip to content
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
2 changes: 2 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ interface INsConfig {
visionos?: INSConfigVisionOS;
ignoredNativeDependencies?: string[];
hooks?: INsConfigHooks[];
projectName?: string;
}

interface IProjectData extends ICreateProjectData {
Expand Down Expand Up @@ -195,6 +196,7 @@ interface IProjectData extends ICreateProjectData {
* The value can be changed by setting `webpackConfigPath` in nativescript.config.
*/
webpackConfigPath: string;
projectName: string;

/**
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.
Expand Down
7 changes: 4 additions & 3 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ export class ProjectData implements IProjectData {
}

if (packageJsonData) {
this.projectName = this.$projectHelper.sanitizeName(
path.basename(projectDir)
);
this.projectName =
nsConfig && nsConfig.projectName
? nsConfig.projectName
: this.$projectHelper.sanitizeName(path.basename(projectDir));
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME);
this.projectFilePath = projectFilePath;
this.projectIdentifiers = this.initializeProjectIdentifiers(nsConfig);
Expand Down
20 changes: 19 additions & 1 deletion test/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ describe("projectData", () => {
dependencies?: IStringDictionary;
devDependencies: IStringDictionary;
};
configData?: { shared?: boolean; webpackConfigPath?: string };
configData?: {
shared?: boolean;
webpackConfigPath?: string;
projectName?: string;
};
}): IProjectData => {
const testInjector = createTestInjector();
const fs = testInjector.resolve("fs");
Expand Down Expand Up @@ -172,6 +176,20 @@ describe("projectData", () => {
});
});

describe("projectName", () => {
it("has correct name when no value is set in nativescript.conf", () => {
const projectData = prepareTest();
assert.isString("projectDir", projectData.projectName);
});

it("has correct name when a project name is set in nativescript.conf", () => {
const projectData = prepareTest({
configData: { projectName: "specifiedProjectName" },
});
assert.isString("specifiedProjectName", projectData.projectName);
});
});

describe("webpackConfigPath", () => {
it("default path to webpack.config.js is set when nsconfig.json does not set value", () => {
const projectData = prepareTest();
Expand Down