Skip to content

Commit 0dea0cd

Browse files
committed
feat(nsconfig): read app folder path from nsconfig
1 parent bac6571 commit 0dea0cd

9 files changed

+39
-15
lines changed

lib/commands/test-init.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TestInitCommand implements ICommand {
6868

6969
await this.$pluginsService.add('nativescript-unit-test-runner', this.$projectData);
7070

71-
const testsDir = path.join(projectDir, 'app/tests');
71+
const testsDir = path.join(this.$projectData.appDirectoryPath, 'tests');
7272
let shouldCreateSampleTests = true;
7373
if (this.$fs.exists(testsDir)) {
7474
this.$logger.info('app/tests/ directory already exists, will not create an example test project.');

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const APK_DIR = "apk";
3030
export const RESOURCES_DIR = "res";
3131
export const CONFIG_NS_FILE_NAME = "nsconfig.json";
3232
export const CONFIG_NS_APP_RESOURCES_ENTRY = "app_resources";
33+
export const CONFIG_NS_APP_ENTRY = "app_folder";
3334

3435
export class PackageVersion {
3536
static NEXT = "next";

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ interface IProjectData extends IProjectDir {
6969
* @returns {void}
7070
*/
7171
initializeProjectData(projectDir?: string): void;
72+
getAppDirectoryPath(projectDir?: string): string;
7273
getAppResourcesDirectoryPath(projectDir?: string): string;
7374
}
7475

lib/project-data.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class ProjectData implements IProjectData {
3232
public projectFilePath: string;
3333
public projectId: string;
3434
public projectName: string;
35-
public appDirectoryPath: string;
35+
get appDirectoryPath(): string {
36+
return this.getAppDirectoryPath();
37+
}
3638
get appResourcesDirectoryPath(): string {
3739
return this.getAppResourcesDirectoryPath();
3840
}
@@ -70,7 +72,6 @@ export class ProjectData implements IProjectData {
7072
this.projectName = this.$projectHelper.sanitizeName(path.basename(projectDir));
7173
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME);
7274
this.projectFilePath = projectFilePath;
73-
this.appDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME);
7475
this.projectId = data.id;
7576
this.dependencies = fileContent.dependencies;
7677
this.devDependencies = fileContent.devDependencies;
@@ -106,7 +107,28 @@ export class ProjectData implements IProjectData {
106107
}
107108
}
108109

109-
return absoluteAppResourcesDirPath || path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
110+
return absoluteAppResourcesDirPath || path.join(this.getAppDirectoryPath(projectDir), constants.APP_RESOURCES_FOLDER_NAME);
111+
}
112+
113+
public getAppDirectoryPath(projectDir?: string): string {
114+
if (!projectDir) {
115+
projectDir = this.projectDir;
116+
}
117+
118+
const configNSFilePath = path.join(projectDir, constants.CONFIG_NS_FILE_NAME);
119+
let absoluteAppDirPath: string;
120+
121+
if (this.$fs.exists(configNSFilePath)) {
122+
const configNS = this.$fs.readJson(configNSFilePath);
123+
124+
if (configNS && configNS[constants.CONFIG_NS_APP_ENTRY]) {
125+
const appDirPath = configNS[constants.CONFIG_NS_APP_ENTRY];
126+
127+
absoluteAppDirPath = path.resolve(projectDir, appDirPath);
128+
}
129+
}
130+
131+
return absoluteAppDirPath || path.join(projectDir, constants.APP_FOLDER_NAME);
110132
}
111133

112134
private getProjectType(): string {

lib/providers/project-files-provider.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase {
1616
const platformData = this.$platformsData.getPlatformData(platform.toLowerCase(), projectData);
1717
const parsedFilePath = this.getPreparedFilePath(filePath, projectFilesConfig);
1818
let mappedFilePath = "";
19+
let relativePath;
1920
if (parsedFilePath.indexOf(constants.NODE_MODULES_FOLDER_NAME) > -1) {
20-
const relativePath = path.relative(path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME), parsedFilePath);
21+
relativePath = path.relative(path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME), parsedFilePath);
2122
mappedFilePath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, constants.TNS_MODULES_FOLDER_NAME, relativePath);
2223
} else {
23-
mappedFilePath = path.join(platformData.appDestinationDirectoryPath, path.relative(projectData.projectDir, parsedFilePath));
24+
relativePath = path.relative(projectData.appDirectoryPath, parsedFilePath);
25+
mappedFilePath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, relativePath);
2426
}
2527

2628
const appResourcesDirectoryPath = projectData.appResourcesDirectoryPath;

lib/services/livesync/livesync-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as choki from "chokidar";
33
import { EOL } from "os";
44
import { EventEmitter } from "events";
55
import { hook } from "../../common/helpers";
6-
import { APP_FOLDER_NAME, PACKAGE_JSON_FILE_NAME, LiveSyncTrackActionNames, USER_INTERACTION_NEEDED_EVENT_NAME, DEBUGGER_ATTACHED_EVENT_NAME, DEBUGGER_DETACHED_EVENT_NAME, TrackActionNames } from "../../constants";
6+
import { PACKAGE_JSON_FILE_NAME, LiveSyncTrackActionNames, USER_INTERACTION_NEEDED_EVENT_NAME, DEBUGGER_ATTACHED_EVENT_NAME, DEBUGGER_DETACHED_EVENT_NAME, TrackActionNames } from "../../constants";
77
import { FileExtensions, DeviceTypes, DeviceDiscoveryEventNames } from "../../common/constants";
88
import { cache } from "../../common/decorators";
99

@@ -513,7 +513,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
513513
}
514514

515515
private async startWatcher(projectData: IProjectData, liveSyncData: ILiveSyncInfo): Promise<void> {
516-
const pattern = [APP_FOLDER_NAME];
516+
const pattern = [path.relative(projectData.projectDir, projectData.appDirectoryPath)];
517517

518518
if (liveSyncData.watchAllFiles) {
519519
const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);

lib/services/platform-service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,9 @@ export class PlatformService extends EventEmitter implements IPlatformService {
563563
public async cleanDestinationApp(platformInfo: IPreparePlatformInfo): Promise<void> {
564564
await this.ensurePlatformInstalled(platformInfo.platform, platformInfo.platformTemplate, platformInfo.projectData, platformInfo.config);
565565

566-
const appSourceDirectoryPath = path.join(platformInfo.projectData.projectDir, constants.APP_FOLDER_NAME);
567566
const platformData = this.$platformsData.getPlatformData(platformInfo.platform, platformInfo.projectData);
568567
const appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
569-
const appUpdater = new AppFilesUpdater(appSourceDirectoryPath, appDestinationDirectoryPath, platformInfo.appFilesUpdaterOptions, this.$fs);
568+
const appUpdater = new AppFilesUpdater(platformInfo.projectData.appDirectoryPath, appDestinationDirectoryPath, platformInfo.appFilesUpdaterOptions, this.$fs);
570569
appUpdater.cleanDestinationApp();
571570
}
572571

lib/services/prepare-platform-service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ export class PreparePlatformService {
2020

2121
// Copy app folder to native project
2222
this.$fs.ensureDirectoryExists(appDestinationDirectoryPath);
23-
const appSourceDirectoryPath = path.join(copyAppFilesData.projectData.projectDir, constants.APP_FOLDER_NAME);
2423

25-
const appUpdater = new AppFilesUpdater(appSourceDirectoryPath, appDestinationDirectoryPath, copyAppFilesData.appFilesUpdaterOptions, this.$fs);
24+
const appUpdater = new AppFilesUpdater(copyAppFilesData.projectData.appDirectoryPath, appDestinationDirectoryPath, copyAppFilesData.appFilesUpdaterOptions, this.$fs);
2625
appUpdater.updateApp(sourceFiles => {
2726
this.$xmlValidator.validateXmlFiles(sourceFiles);
2827
});

lib/services/project-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class ProjectService implements IProjectService {
101101
private async extractTemplate(projectDir: string, realTemplatePath: string): Promise<void> {
102102
this.$fs.ensureDirectoryExists(projectDir);
103103

104-
const appDestinationPath = path.join(projectDir, constants.APP_FOLDER_NAME);
104+
const appDestinationPath = this.$projectData.getAppDirectoryPath(projectDir);
105105
this.$fs.createDirectory(appDestinationPath);
106106

107107
this.$logger.trace(`Copying application from '${realTemplatePath}' into '${appDestinationPath}'.`);
@@ -111,7 +111,7 @@ export class ProjectService implements IProjectService {
111111
}
112112

113113
private async ensureAppResourcesExist(projectDir: string): Promise<void> {
114-
const appPath = path.join(projectDir, constants.APP_FOLDER_NAME),
114+
const appPath = this.$projectData.getAppDirectoryPath(projectDir),
115115
appResourcesDestinationPath = this.$projectData.getAppResourcesDirectoryPath(projectDir);
116116

117117
if (!this.$fs.exists(appResourcesDestinationPath)) {
@@ -138,7 +138,7 @@ export class ProjectService implements IProjectService {
138138
}
139139

140140
private removeMergedDependencies(projectDir: string, templatePackageJsonData: any): void {
141-
const extractedTemplatePackageJsonPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.PACKAGE_JSON_FILE_NAME);
141+
const extractedTemplatePackageJsonPath = path.join(this.$projectData.getAppDirectoryPath(projectDir), constants.PACKAGE_JSON_FILE_NAME);
142142
for (const key in templatePackageJsonData) {
143143
if (constants.PackageJsonKeysToKeep.indexOf(key) === -1) {
144144
delete templatePackageJsonData[key];

0 commit comments

Comments
 (0)