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
4 changes: 3 additions & 1 deletion lib/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IProjectCleanupResult,
IProjectCleanupService,
IProjectConfigService,
IProjectData,
IProjectService,
} from "../definitions/project";

Expand Down Expand Up @@ -83,6 +84,7 @@ export class CleanCommand implements ICommand {
constructor(
private $projectCleanupService: IProjectCleanupService,
private $projectConfigService: IProjectConfigService,
private $projectData: IProjectData,
private $terminalSpinnerService: ITerminalSpinnerService,
private $projectService: IProjectService,
private $prompter: IPrompter,
Expand All @@ -108,7 +110,7 @@ export class CleanCommand implements ICommand {

let pathsToClean = [
constants.HOOKS_DIR_NAME,
constants.PLATFORMS_DIR_NAME,
this.$projectData.getBuildRelativeDirectoryPath(),
constants.NODE_MODULES_FOLDER_NAME,
];

Expand Down
3 changes: 1 addition & 2 deletions lib/commands/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ export class TypingsCommand implements ICommand {
);

const dtsGeneratorPath = path.resolve(
this.$projectData.projectDir,
"platforms",
this.$projectData.platformsDir,
"android",
"build-tools",
"dts-generator.jar",
Expand Down
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const BUNDLE_DIR = "bundle";
export const RESOURCES_DIR = "res";
export const CONFIG_NS_FILE_NAME = "nsconfig.json";
export const CONFIG_NS_APP_RESOURCES_ENTRY = "appResourcesPath";
export const CONFIG_NS_BUILD_ENTRY = "buildPath";
export const CONFIG_NS_APP_ENTRY = "appPath";
export const CONFIG_FILE_NAME_DISPLAY = "nativescript.config.(js|ts)";
export const CONFIG_FILE_NAME_JS = "nativescript.config.js";
Expand Down
2 changes: 2 additions & 0 deletions lib/contracts/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ export abstract class ProjectData {
abstract getAppResourcesDirectoryPath(projectDir?: string): string;

abstract getAppResourcesRelativeDirectoryPath(): string;

abstract getBuildRelativeDirectoryPath(): string;
}
2 changes: 1 addition & 1 deletion lib/controllers/migrate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ export class MigrateController
private async cleanUpProject(projectData: IProjectData): Promise<void> {
await this.$projectCleanupService.clean([
constants.HOOKS_DIR_NAME,
constants.PLATFORMS_DIR_NAME,
projectData.getBuildRelativeDirectoryPath(),
constants.NODE_MODULES_FOLDER_NAME,
constants.PACKAGE_LOCK_JSON_FILE_NAME,
]);
Expand Down
6 changes: 3 additions & 3 deletions lib/controllers/update-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class UpdateController
// clean up project files
this.spinner.info("Cleaning up project files before update");

await this.cleanUpProject();
await this.cleanUpProject(projectData);

this.spinner.succeed("Project files have been cleaned up");

Expand Down Expand Up @@ -293,10 +293,10 @@ export class UpdateController
}
}

private async cleanUpProject(): Promise<void> {
private async cleanUpProject(projectData: IProjectData): Promise<void> {
await this.$projectCleanupService.clean([
constants.HOOKS_DIR_NAME,
constants.PLATFORMS_DIR_NAME,
projectData.getBuildRelativeDirectoryPath(),
constants.NODE_MODULES_FOLDER_NAME,
constants.PACKAGE_LOCK_JSON_FILE_NAME,
]);
Expand Down
5 changes: 5 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ interface INsConfig {
main?: string;
appPath?: string;
appResourcesPath?: string;
/**
* Where the native projects are generated, relative to the project root.
* Defaults to `platforms`.
*/
buildPath?: string;
shared?: boolean;
overridePods?: string;
webpackConfigPath?: string;
Expand Down
20 changes: 18 additions & 2 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,18 @@ export class ProjectData implements IProjectData {
nsConfig && nsConfig.projectName
? nsConfig.projectName
: this.$projectHelper.sanitizeName(path.basename(projectDir));
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME);
// read before `platformsDir`, which is derived from it
this.nsConfig = nsConfig;
this.platformsDir = path.join(
projectDir,
this.getBuildRelativeDirectoryPath(),
);
this.projectFilePath = projectFilePath;
this.projectIdentifiers = this.initializeProjectIdentifiers(nsConfig);
this.packageJsonData = packageJsonData;
this.dependencies = packageJsonData.dependencies;
this.devDependencies = packageJsonData.devDependencies;
this.projectType = this.getProjectType();
this.nsConfig = nsConfig;
this.ignoredDependencies = nsConfig?.ignoredNativeDependencies;
this.appDirectoryPath = this.getAppDirectoryPath();
this.appResourcesDirectoryPath = this.getAppResourcesDirectoryPath();
Expand Down Expand Up @@ -276,6 +280,18 @@ export class ProjectData implements IProjectData {
// );
}

/**
* Where the native projects are generated, relative to the project root.
* `buildPath` in the project config overrides the default `platforms`.
*/
public getBuildRelativeDirectoryPath(): string {
if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY]) {
return this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY];
}

return constants.PLATFORMS_DIR_NAME;
}

public getAppDirectoryPath(projectDir?: string): string {
const appRelativePath = this.getAppDirectoryRelativePath();

Expand Down
1 change: 1 addition & 0 deletions test/controllers/update-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function createTestInjector(projectDir: string = projectFolder): IInjector {
initializeProjectData: () => {
/* empty */
},
getBuildRelativeDirectoryPath: () => "platforms",
dependencies: {
"@nativescript/core": "next",
},
Expand Down
31 changes: 31 additions & 0 deletions test/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe("projectData", () => {
bundlerConfigPath?: string;
projectName?: string;
bundler?: string;
buildPath?: string;
};
}): IProjectData => {
const testInjector = createTestInjector();
Expand Down Expand Up @@ -96,6 +97,36 @@ describe("projectData", () => {
return projectData;
};

describe("buildPath", () => {
it("defaults to the platforms directory", () => {
const projectData = prepareTest();

assert.deepStrictEqual(
projectData.getBuildRelativeDirectoryPath(),
"platforms",
);
assert.deepStrictEqual(
projectData.platformsDir,
path.join(projectDir, "platforms"),
);
});

it("is read from the project config", () => {
const projectData = prepareTest({
configData: { buildPath: "build/native" },
});

assert.deepStrictEqual(
projectData.getBuildRelativeDirectoryPath(),
"build/native",
);
assert.deepStrictEqual(
projectData.platformsDir,
path.join(projectDir, "build/native"),
);
});
});

describe("projectType", () => {
const assertProjectType = (
dependencies: any,
Expand Down
4 changes: 4 additions & 0 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ export class ProjectDataStub implements IProjectData {
public getAppDirectoryRelativePath(): string {
return "app";
}

public getBuildRelativeDirectoryPath(): string {
return constants.PLATFORMS_DIR_NAME;
}
}

export class AndroidPluginBuildServiceStub implements IAndroidPluginBuildService {
Expand Down