-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Conversation
0dea0cd
to
461f597
Compare
run ci |
lib/project-data.ts
Outdated
return absoluteAppResourcesDirPath || path.join(this.getAppDirectoryPath(projectDir), constants.APP_RESOURCES_FOLDER_NAME); | ||
} | ||
|
||
public getAppDirectoryPath(projectDir?: string): string { |
There was a problem hiding this comment.
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?
run ci |
8901a1b
to
ef0f8c2
Compare
lib/project-data.ts
Outdated
this.errorInvalidProject(projectDir); | ||
} | ||
|
||
private errorInvalidProject(projectDir: string) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
aff7576
to
09973b6
Compare
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"; |
There was a problem hiding this comment.
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
lib/project-data.ts
Outdated
return; | ||
} | ||
let packageJsonContent: any = null; | ||
packageJsonContent = this.$fs.readText(projectFilePath); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/project-data.ts
Outdated
} | ||
|
||
public getAppDirectoryPath(projectDir?: string): string { | ||
if (!projectDir) { |
There was a problem hiding this comment.
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
a3a2814
to
8c302a3
Compare
lib/definitions/project.d.ts
Outdated
@@ -63,12 +63,18 @@ interface IProjectData extends IProjectDir { | |||
appDirectoryPath: string; | |||
appResourcesDirectoryPath: string; | |||
projectType: string; | |||
nsConfig: any; |
There was a problem hiding this comment.
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
lib/project-data.ts
Outdated
return; | ||
} | ||
let packageJsonContent: any = null; | ||
packageJsonContent = this.$fs.readText(projectFilePath); |
There was a problem hiding this comment.
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.
lib/project-data.ts
Outdated
} | ||
let packageJsonContent: any = null; | ||
packageJsonContent = this.$fs.readText(projectFilePath); | ||
const nsConfigContent: any = this.getNsConfigContent(projectDir); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return type
lib/project-data.ts
Outdated
const projectFilePath = this.getProjectFilePath(projectDir); | ||
// If no project found, projectDir should be null | ||
let nsData: any = null; | ||
let nsConfig: any = null; |
There was a problem hiding this comment.
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
.
lib/services/app-files-updater.ts
Outdated
// 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))); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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:
- Update the documentation: https://github.com/NativeScript/nativescript-cli/blob/master/PublicAPI.md
- Add the service and the exposed methods in the nativescript-cli-lib tests
NOTE: More information is available here
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
cd5267e
to
79d744b
Compare
run ci |
ae4f213
to
b96a8cc
Compare
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
b96a8cc
to
2b5ef94
Compare
this.errorInvalidProject(projectDir); | ||
} | ||
|
||
public initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't nsconfigContent
optional?
There was a problem hiding this comment.
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.
run ci |
Part of implementation for #3257