Skip to content

Commit 06dfc73

Browse files
committed
feat(android): custom buildPath from nativescript.config
It requires a PR on @nativescript/webpack too
1 parent 7c010fe commit 06dfc73

30 files changed

+1382
-1034
lines changed

lib/commands/clean.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
IProjectCleanupResult,
77
IProjectCleanupService,
88
IProjectConfigService,
9+
IProjectData,
910
IProjectService,
1011
} from "../definitions/project";
1112

@@ -85,6 +86,7 @@ export class CleanCommand implements ICommand {
8586
constructor(
8687
private $projectCleanupService: IProjectCleanupService,
8788
private $projectConfigService: IProjectConfigService,
89+
private $projectData: IProjectData,
8890
private $terminalSpinnerService: ITerminalSpinnerService,
8991
private $projectService: IProjectService,
9092
private $prompter: IPrompter,
@@ -109,7 +111,7 @@ export class CleanCommand implements ICommand {
109111

110112
let pathsToClean = [
111113
constants.HOOKS_DIR_NAME,
112-
constants.PLATFORMS_DIR_NAME,
114+
this.$projectData.getBuildRelativeDirectoryPath(),
113115
constants.NODE_MODULES_FOLDER_NAME,
114116
constants.PACKAGE_LOCK_JSON_FILE_NAME,
115117
];

lib/commands/typings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class TypingsCommand implements ICommand {
6666

6767
const dtsGeneratorPath = path.resolve(
6868
this.$projectData.projectDir,
69-
"platforms",
69+
this.$projectData.getBuildRelativeDirectoryPath(),
7070
"android",
7171
"build-tools",
7272
"dts-generator.jar"

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const BUNDLE_DIR = "bundle";
5858
export const RESOURCES_DIR = "res";
5959
export const CONFIG_NS_FILE_NAME = "nsconfig.json";
6060
export const CONFIG_NS_APP_RESOURCES_ENTRY = "appResourcesPath";
61+
export const CONFIG_NS_BUILD_ENTRY = "buildPath";
6162
export const CONFIG_NS_APP_ENTRY = "appPath";
6263
export const CONFIG_FILE_NAME_DISPLAY = "nativescript.config.(js|ts)";
6364
export const CONFIG_FILE_NAME_JS = "nativescript.config.js";

lib/controllers/migrate-controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class MigrateController
6666
private $pluginsService: IPluginsService,
6767
private $projectDataService: IProjectDataService,
6868
private $projectConfigService: IProjectConfigService,
69+
private $projectData: IProjectData,
6970
private $options: IOptions,
7071
private $resources: IResourceLoader,
7172
private $injector: IInjector,
@@ -719,7 +720,7 @@ export class MigrateController
719720
private async cleanUpProject(projectData: IProjectData): Promise<void> {
720721
await this.$projectCleanupService.clean([
721722
constants.HOOKS_DIR_NAME,
722-
constants.PLATFORMS_DIR_NAME,
723+
this.$projectData.getBuildRelativeDirectoryPath(),
723724
constants.NODE_MODULES_FOLDER_NAME,
724725
constants.PACKAGE_LOCK_JSON_FILE_NAME,
725726
]);

lib/controllers/platform-controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export class PlatformController implements IPlatformController {
6868
packageToInstall,
6969
addPlatformData
7070
);
71-
71+
const buildPath = projectData.platformsDir;
72+
console.log('buildPath', buildPath, projectData.getBuildRelativeDirectoryPath())
7273
this.$fs.ensureDirectoryExists(
7374
path.join(projectData.platformsDir, platform)
7475
);
@@ -96,6 +97,7 @@ export class PlatformController implements IPlatformController {
9697
commentHeader,
9798
`appPath = ${appPath}`,
9899
`appResourcesPath = ${appResourcesPath}`,
100+
`buildPath = ${buildPath}`,
99101
"",
100102
].join("\n");
101103

lib/controllers/prepare-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export class PrepareController extends EventEmitter {
357357
this.$logger.info(`Chokidar raised event ${event} for ${filePath}.`);
358358
await this.writeRuntimePackageJson(projectData, platformData);
359359
this.emitPrepareEvent({
360-
files: [],
360+
files: [filePath],
361361
staleFiles: [],
362362
hasOnlyHotUpdateFiles: false,
363363
hmrData: null,

lib/controllers/update-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export class UpdateController
296296
private async cleanUpProject(): Promise<void> {
297297
await this.$projectCleanupService.clean([
298298
constants.HOOKS_DIR_NAME,
299-
constants.PLATFORMS_DIR_NAME,
299+
this.$projectDataService.getProjectData().getBuildRelativeDirectoryPath(),
300300
constants.NODE_MODULES_FOLDER_NAME,
301301
constants.PACKAGE_LOCK_JSON_FILE_NAME,
302302
]);

lib/definitions/project.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ interface INsConfig {
153153
main?: string;
154154
appPath?: string;
155155
appResourcesPath?: string;
156+
buildPath?: string;
156157
shared?: boolean;
157158
overridePods?: string;
158159
webpackConfigPath?: string;
@@ -209,6 +210,7 @@ interface IProjectData extends ICreateProjectData {
209210
getAppDirectoryRelativePath(): string;
210211
getAppResourcesDirectoryPath(projectDir?: string): string;
211212
getAppResourcesRelativeDirectoryPath(): string;
213+
getBuildRelativeDirectoryPath(): string;
212214
}
213215

214216
interface IProjectDataService {

lib/project-data.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ export class ProjectData implements IProjectData {
164164
this.projectName = this.$projectHelper.sanitizeName(
165165
path.basename(projectDir)
166166
);
167-
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME);
167+
this.nsConfig = nsConfig;
168+
this.platformsDir = path.join(projectDir, this.getBuildRelativeDirectoryPath());
168169
this.projectFilePath = projectFilePath;
169170
this.projectIdentifiers = this.initializeProjectIdentifiers(nsConfig);
170171
this.packageJsonData = packageJsonData;
171172
this.dependencies = packageJsonData.dependencies;
172173
this.devDependencies = packageJsonData.devDependencies;
173174
this.projectType = this.getProjectType();
174-
this.nsConfig = nsConfig;
175175
this.ignoredDependencies = nsConfig?.ignoredNativeDependencies;
176176
this.appDirectoryPath = this.getAppDirectoryPath();
177177
this.appResourcesDirectoryPath = this.getAppResourcesDirectoryPath();
@@ -270,6 +270,17 @@ export class ProjectData implements IProjectData {
270270
return this.resolveToProjectDir(appRelativePath, projectDir);
271271
}
272272

273+
public getBuildRelativeDirectoryPath(): string {
274+
if (
275+
this.nsConfig &&
276+
this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY]
277+
) {
278+
return this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY];
279+
}
280+
281+
return constants.PLATFORMS_DIR_NAME;
282+
}
283+
273284
public getAppDirectoryRelativePath(): string {
274285
if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_APP_ENTRY]) {
275286
return this.nsConfig[constants.CONFIG_NS_APP_ENTRY];

lib/services/android-plugin-build-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,11 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
775775
`-PtempBuild=true`,
776776
`-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`,
777777
`-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`,
778+
`-PprojectRoot=${this.$projectData.projectDir}`,
779+
`-DprojectRoot=${this.$projectData.projectDir}`, // we need it as a -D to be able to read it from settings.gradle
778780
`-PappPath=${this.$projectData.getAppDirectoryPath()}`,
781+
`-PappBuildPath=${this.$projectData.getBuildRelativeDirectoryPath()}`,
782+
`-DappBuildPath=${this.$projectData.getBuildRelativeDirectoryPath()}`, // we need it as a -D to be able to read it from settings.gradle
779783
`-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`,
780784
];
781785
if (pluginBuildSettings.gradleArgs) {

0 commit comments

Comments
 (0)