-
-
Notifications
You must be signed in to change notification settings - Fork 197
feat: introduce resources update command #3347
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
Conversation
e7a77fd
to
057ce07
Compare
d0b0311
to
510d564
Compare
990ec08
to
b9890bf
Compare
057ce07
to
2eae80d
Compare
9dd55f8
to
b1aa8dd
Compare
@@ -0,0 +1,27 @@ | |||
resources-update |
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 you have to add some jekyll specific logic, ping @etabakov for further info
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.
That's right. You need to put this header, in order the article to be part of docs.nativescript.org (otherwise, it will be just skipped):
<% if (isJekyll) { %>---
title: <some title>
position: <order number>
---<% } %>
You can take a look at any of the other articles for an example.
As a side note, put a # sign before the title to make it look ok in html.
lib/commands/resources-update.ts
Outdated
|
||
for (const platform of args) { | ||
if (!this.$androidResourcesV4MigrationService.canMigrate(platform)) { | ||
this.$errors.failWithoutHelp("The iOS platform does not need to have its resources updated."); |
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 cannot be sure that user had stated "iOS" as a platform. I would use
`The ${platform} does not need...
lib/declarations.d.ts
Outdated
@@ -497,6 +497,12 @@ interface IInfoService { | |||
printComponentsInfo(): Promise<void>; | |||
} | |||
|
|||
interface IAndroidResourcesV4MigrationService { |
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 name is somehow misleading. In case we need additional resources update in the future we will have to create new service. Can we use IAndroidResourcesMigrationService
, so all future migrations will be included in this service?
} | ||
} | ||
|
||
private getAppResourcesDestinationDirectoryPathOldAppResourcesDirStructure(projectData: IProjectData): 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.
private methods should be last - after all public and protected. Also this name is a little bit confusing. I think you should remove the Structure
from its name - it returns path, not a structure.
Maybe getOldAppResourcesDestinationDirPath
And the next method can be called getNewAppResourcesDestinationDirPath
However, old
and new
will not mean a lot after six months, maybe we can name the methods:
getLegacyAppResourcesDestinationDirPath
getUpdatedAppResourcesDestinationDirPath
|
||
let stringsFilePath: string; | ||
|
||
if (!this.$androidResourcesV4MigrationService.hasMigrated(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.
can we switch the if
- it is easier for reading in case there's not !
in the if:
if (this.$androidResourcesV4MigrationService.hasMigrated(appResourcesDirectoryPath)) {
stringsFilePath = path.join(this.getAppResourcesDestinationDirectoryPath(projectData), "main", "res", 'values', 'strings.xml');
} else {
stringsFilePath = path.join(this.getAppResourcesDestinationDirectoryPath(projectData), 'values', 'strings.xml');
}
async migrate(appResourcesDir: string): Promise<void> { | ||
const originalAppResources = path.join(appResourcesDir, AndroidResourcesV4MigrationService.ANDROID_DIR); | ||
const appResourcesDestination = path.join(appResourcesDir, AndroidResourcesV4MigrationService.ANDROID_DIR_TEMP); | ||
const appMainSourceSet = path.join(appResourcesDestination, "src", "main"); |
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.
src and main from constants maybe
const originalAppResources = path.join(appResourcesDir, AndroidResourcesV4MigrationService.ANDROID_DIR); | ||
const appResourcesDestination = path.join(appResourcesDir, AndroidResourcesV4MigrationService.ANDROID_DIR_TEMP); | ||
const appMainSourceSet = path.join(appResourcesDestination, "src", "main"); | ||
const appResourcesMainSourceSetResourcesDestination = path.join(appMainSourceSet, "res"); |
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.
res -> RESOURCES_DIR from constants
this.$fs.readDirectory(source).map(name => path.join(source, name)).filter(isDirectory); | ||
|
||
shell.cp(path.join(originalAppResources, "app.gradle"), path.join(appResourcesDestination, "app.gradle")); | ||
shell.cp(path.join(originalAppResources, "AndroidManifest.xml"), path.join(appMainSourceSet, "AndroidManifest.xml")); |
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.
AndroidManifest.xml -> MANIFEST_FILE_NAME from constants
const resourceDirectories = getDirectories(originalAppResources); | ||
|
||
resourceDirectories.forEach(dir => { | ||
shell.cp("-Rf", dir, appResourcesMainSourceSetResourcesDestination); |
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.
fs.copyFile
// move the new, updated app_resources to App_Resources/Android, as the de facto resources | ||
shell.mv(appResourcesDestination, originalAppResources); | ||
|
||
this.$logger.out(`Successfully updated your project's App_Resources/Android directory structure.\nThe previous version of App_Resources/Android has been renamed to App_Resources/${AndroidResourcesV4MigrationService.ANDROID_DIR_OLD}`); |
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.
Is it possible for the App_Resources dir to be called something else? For example in case I name it "my_resources" and use nsconfig.json, this message may be misleading.
@rosen-vladimirov thanks for the review. I'll address your comments and come back to you when it's ready. |
6b6c5fa
to
6cee992
Compare
6cee992
to
5e6b255
Compare
5e6b255
to
7fe0380
Compare
let stringsFilePath: string; | ||
|
||
if (this.$androidResourcesMigrationService.hasMigrated(appResourcesDirectoryPath)) { | ||
stringsFilePath = path.join(this.getAppResourcesDestinationDirectoryPath(projectData), constants.MAIN_DIR, constants.RESOURCES_DIR, 'values', 'strings.xml'); |
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 extract this.getAppResourcesDestinationDirectoryPath(projectData)
to a variable outside the if statements.
4228eeb
to
88d3f24
Compare
if (this.$fs.exists(resourcesDirPath)) { | ||
const resourcesDirs = this.$fs.readDirectory(resourcesDirPath).filter(resDir => !resDir.match(valuesDirRegExp)); | ||
_.each(resourcesDirs, resourceDir => { | ||
this.$fs.deleteDirectory(path.join(this.getAppResourcesDestinationDirectoryPath(projectData), resourceDir)); |
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 extract getAppResourcesDestinationDirectoryPath outside of the each
statement.
88d3f24
to
216a83d
Compare
const getDirectories = (source: string) => | ||
this.$fs.readDirectory(source).map(name => path.join(source, name)).filter(isDirectory); | ||
|
||
this.$fs.copyFile(path.join(originalAppResources, "app.gradle"), path.join(appResourcesDestination, "app.gradle")); |
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.
Please take in consideration other files that might be inside the root of the App_Resources directory like "settings.gradle" and "settings.josn".
if (appResourcesDirStructureHasMigrated) { | ||
this.$fs.copyFile(path.join(appResourcesAndroid, "src", "*"), appResourcesDestination); | ||
|
||
this.$fs.deleteDirectory(path.join(appResourcesDestination, "libs")); |
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 seems unnecessary for migrated projects.
const resourceDirectories = getDirectories(originalAppResources); | ||
|
||
resourceDirectories.forEach(dir => { | ||
this.$fs.copyFile(dir, appResourcesMainSourceSetResourcesDestination); |
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.
Skip "libs" folder when coping resources.
216a83d
to
829b97a
Compare
@KristianDD I addressed those comments. |
829b97a
to
9a7cc04
Compare
run ci |
lib/commands/resources-update.ts
Outdated
} | ||
} | ||
|
||
$injector.registerCommand("resources-update", ResourcesUpdateCommand); |
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 rename the command to resources|migrate
. This will allow us to have a command hierarchical structure with this PR, where we can name the commands resources|generate
.
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.
Sure!
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.
docs/man_pages/index.md
Outdated
@@ -32,6 +32,7 @@ Command | Description | |||
[platform list](project/configuration/platform.html) | Lists all platforms that the project currently targets. | |||
[platform remove `<Platform>`](project/configuration/platform-remove.html) | Removes the selected platform from the platforms that the project currently targets. This operation deletes all platform-specific files and subdirectories from your project. | |||
[platform update `<Platform>`](project/configuration/platform-update.html) | Updates the NativeScript runtime for the specified platform. | |||
[resources-update](project/configuration/resources-update.html) | Updates the App_Resources/<platform>'s internal folder structure to conform to that of an Android project. |
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 an idea - " conform to that of an Android project." might sound more concrete if we change "Android project" to "Android Native project" or "Android Studio project".
`$ tns resources-update` | Defaults to executing `$ tns resources-update android`. Updates the App_Resources/Android's folder structure. | ||
`$ tns resources-update android` | Updates the App_Resources/Android's folder structure. | ||
|
||
Updates the App_Resources/<platform>'s internal folder structure to conform to that of an Android project. Android resource files and directories will be located at the following paths: |
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. If we change it, update here too.
9a7cc04
to
a5d89f4
Compare
Introduce the 'tns resources-update android' command. By design, upon execution it should migrate the directory structure of App_Resources/Android to the new v4 structure - the one that supports inclusion of java source files, arbitrary assets, and any resource files in the App_Resources/Android/src/main directory structure. Additional, user-defined flavors can also be created taking advantage of the new dir structure. docs(resources-update-command): add documentation for the new resources-update command fix(resources-update-command): make prepare and run backward-compatible fix(resource-update-command-tests): inject the new service in tests chore: address PR comments chore: fix git rebase error
a5d89f4
to
2031a8c
Compare
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.
Great Work @Pip3r4o !
Introduce the 'tns resources update android' command. By design, upon execution it should migrate the directory structure of App_Resources/Android to the new v4 structure - the one that supports the inclusion of java source files, arbitrary assets, and any resource files in the App_Resources/Android/src/main directory structure. Additional, user-defined flavors can also be created taking advantage of the new dir structure.