Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kddimitrov/nsconfig app folder #3356

Merged
merged 9 commits into from
Feb 28, 2018
Merged

Conversation

KristianDD
Copy link
Contributor

Part of implementation for #3257

@KristianDD
Copy link
Contributor Author

run ci

return absoluteAppResourcesDirPath || path.join(this.getAppDirectoryPath(projectDir), constants.APP_RESOURCES_FOLDER_NAME);
}

public getAppDirectoryPath(projectDir?: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems to be very similar to the one above (getAppResourcesDirectoryPath). Do you think it would be a good idea to make a common method that accepts the property name as an argument? Or maybe have a method that parses the config file and validates it?

@dtopuzov
Copy link
Contributor

run ci

@KristianDD KristianDD force-pushed the kddimitrov/nsconfig-app-folder branch from 8901a1b to ef0f8c2 Compare February 20, 2018 18:58
this.errorInvalidProject(projectDir);
}

private errorInvalidProject(projectDir: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method needs return type

return this.nsConfig[constants.CONFIG_NS_APP_RESOURCES_ENTRY];
}

return path.join(this.getAppDirectoryRelativePath(), constants.APP_RESOURCES_FOLDER_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can shorten this:

return this.nsConfig && this.nsConfig[constants.CONFIG_NS_APP_RESOURCES_ENTRY]
           || path.join(this.getAppDirectoryRelativePath(), constants.APP_RESOURCES_FOLDER_NAME);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider mine more readable and structured. Will change it if you insist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, not a problem ;)

return this.nsConfig[constants.CONFIG_NS_APP_ENTRY];
}

return constants.APP_FOLDER_NAME;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above - you can shorten the code:

return this.nsConfig && this.nsConfig[constants.CONFIG_NS_APP_ENTRY] || constants.APP_FOLDER_NAME;


public getAppDirectoryRelativePath(): string {
if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_APP_ENTRY]) {
return this.nsConfig[constants.CONFIG_NS_APP_ENTRY];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen in case the path in the nsconfig.json is not relative?

Copy link
Contributor Author

@KristianDD KristianDD Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add validation for this as supporting paths not relative to the project will be very hard in cloud builds. Maybe we should also change the key inside nsconfig.json to appRelativePath or something in this lines.

this.errorInvalidProject(projectDir);
}

public initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sis0k0 is it ok to pass the content as string or you'll need a method that accepts the parsed json object (i.e. the parsed nsconfig.json) itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to pass the content as string and let the project data service do the parsing/validation.

@KristianDD KristianDD force-pushed the kddimitrov/nsconfig-app-folder branch 2 times, most recently from aff7576 to 09973b6 Compare February 22, 2018 12:43
lib/constants.ts Outdated
@@ -28,6 +28,9 @@ export const BUILD_DIR = "build";
export const OUTPUTS_DIR = "outputs";
export const APK_DIR = "apk";
export const RESOURCES_DIR = "res";
export const CONFIG_NS_FILE_NAME = "nsconfig.json";
export const CONFIG_NS_APP_RESOURCES_ENTRY = "app_resources";
export const CONFIG_NS_APP_ENTRY = "app_folder";
Copy link
Contributor Author

@KristianDD KristianDD Feb 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to camelCase and add Path suffix at the end

return;
}
let packageJsonContent: any = null;
packageJsonContent = this.$fs.readText(projectFilePath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with invalid location (no package.json file)

@@ -527,6 +527,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
}
}

patterns.push(projectData.appResourcesDirectoryPath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check what happens if app resources are still inside app folder.

@@ -101,7 +101,7 @@ export class ProjectService implements IProjectService {
private async extractTemplate(projectDir: string, realTemplatePath: string): Promise<void> {
this.$fs.ensureDirectoryExists(projectDir);

const appDestinationPath = path.join(projectDir, constants.APP_FOLDER_NAME);
const appDestinationPath = this.$projectData.getAppDirectoryPath(projectDir);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check usages here. What happens if template has existing nsconfig.json inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Templates currently contain only the contents of the app folder. No option to add nsconfig in template for the moment.

}

public getAppDirectoryPath(projectDir?: string): string {
if (!projectDir) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return null if missing projectDir

@KristianDD KristianDD self-assigned this Feb 22, 2018
@KristianDD KristianDD force-pushed the kddimitrov/nsconfig-app-folder branch 2 times, most recently from a3a2814 to 8c302a3 Compare February 23, 2018 13:34
@@ -63,12 +63,18 @@ interface IProjectData extends IProjectDir {
appDirectoryPath: string;
appResourcesDirectoryPath: string;
projectType: string;
nsConfig: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use some interface here? - for example INsConfig

return;
}
let packageJsonContent: any = null;
packageJsonContent = this.$fs.readText(projectFilePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just let packageJsonContent = this.$fs.readText(projectFilePath). There is no need to declare the variable on a saparate line.

}
let packageJsonContent: any = null;
packageJsonContent = this.$fs.readText(projectFilePath);
const nsConfigContent: any = this.getNsConfigContent(projectDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to specify the type. It will be automatically inferred by typescript compiler.

return path.join(this.getAppDirectoryRelativePath(), constants.APP_RESOURCES_FOLDER_NAME);
}

public getAppDirectoryPath(projectDir?: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in this method is very similiar to getAppResourcesDirectoryPath(). Can we try to extract the common part?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -101,6 +102,13 @@ export class PreparePlatformJSService extends PreparePlatformService implements
this.$errors.failWithoutHelp(`Processing node_modules failed. ${error}`);
}
}

private copyAppResourcesFiles(config: IPreparePlatformJSInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type

const projectFilePath = this.getProjectFilePath(projectDir);
// If no project found, projectDir should be null
let nsData: any = null;
let nsConfig: any = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we definitely need an interface for nsConfig and the data that can be included in it. Can you please add a new one and use it as a type here instead of any.

// exclude the app_resources directory from being enumerated
// for copying if it is present in the application sources dir
const appResourcesPath = projectData.appResourcesDirectoryPath;
sourceFiles = sourceFiles.filter(dirName => !path.normalize(dirName).startsWith(path.normalize(appResourcesPath)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can extract the path.normalize(appResourcesPath) in a separate variable before applying the filtering. This way you'll not calculate it on each iteration.

@@ -6,7 +6,7 @@ $injector.require("options", "./options");
$injector.require("nativescript-cli", "./nativescript-cli");

$injector.require("projectData", "./project-data");
$injector.require("projectDataService", "./services/project-data-service");
$injector.requirePublic("projectDataService", "./services/project-data-service");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you add a new method to PublicApi, you have to:

  1. Update the documentation: https://github.com/NativeScript/nativescript-cli/blob/master/PublicAPI.md
  2. Add the service and the exposed methods in the nativescript-cli-lib tests

NOTE: More information is available here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -41,6 +42,13 @@ export class ProjectDataService implements IProjectDataService {
return projectDataInstance;
}

@exported("projectDataService")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you export getProjectData as well - it will be used from Sidekick to get paths to app and App_Resources directories

const appDestinationDirectoryPath = path.join(config.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
const appResourcesSourcePath = config.projectData.appResourcesDirectoryPath;

shell.cp("-Rf", appResourcesSourcePath, appDestinationDirectoryPath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use fileSystem module?

@petekanev petekanev force-pushed the kddimitrov/nsconfig-app-folder branch from cd5267e to 79d744b Compare February 26, 2018 15:43
@KristianDD
Copy link
Contributor Author

run ci

petekanev and others added 9 commits February 28, 2018 13:44
Refactor the project-data service to read a config.json for the
'app_resources' property entry, which points relatively to the
App_Resources directory.

All references to app/App_Resources now retrieve the path from
said service.

To keep the service backwards compatible, if no config.json is
present, or the app_resources entry isn't available, location
defaults to projectDir/app/App_Resources.
the name of the app_resources directory basename is
@KristianDD KristianDD force-pushed the kddimitrov/nsconfig-app-folder branch from b96a8cc to 2b5ef94 Compare February 28, 2018 12:01
this.errorInvalidProject(projectDir);
}

public initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't nsconfigContent optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I have missed to make it optional as we don't use it in the codebase.

@KristianDD
Copy link
Contributor Author

run ci

@KristianDD KristianDD merged commit 00e7a30 into master Feb 28, 2018
@KristianDD KristianDD deleted the kddimitrov/nsconfig-app-folder branch June 18, 2018 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants