-
Notifications
You must be signed in to change notification settings - Fork 25
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
Chore: Migrating from using the cordova-res package to using the capacitor-assets package for asset generation #2364
base: master
Are you sure you want to change the base?
Conversation
…ing the ➤ YN0000: ┌ Resolution step ➤ YN0000: └ Completed in 0s 259ms ➤ YN0000: ┌ Fetch step ➤ YN0000: └ Completed in 0s 607ms ➤ YN0000: ┌ Link step ➤ YN0000: └ Completed in 0s 769ms ➤ YN0000: Done in 1s 717ms command. Solved by chnaging the to that of the default that the terminal runs from (which is the directory).
Updated to allow for new to be created. Changed commands in to allow for iOS app launcher icons and splash screens to be generated. Changed commands in to allow for Android app launcher icons and splash screens to be generated with updated and legacy methods.
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.
Good job figuring this out. I've added quite a few comments (mostly minor) inline.
Also, you should remove the now unused cordova-res
package via yarn remove
, and delete any imports that may still exist.
const relativeAssetPath = path.relative(process.cwd(), assetPath).replace(/^(\.\.\/|\.\/)+/, ""); | ||
|
||
const cmd = `npx @capacitor/assets generate --assetPath ${relativeAssetPath} --ios`; | ||
const cwd = process.cwd().replace("/packages/scripts", ""); // output will be: "/../../idems/open-app-builder/packages/scripts" |
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.
nit: Rather than doing a string replace, it would probably be better to use the path
npm library to get the correct path – path.relative(from, to) might be what you need
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 have found out that only relative paths work for the npx
command, so I am attempting to find methods of converting the path to a relative one (without the /../..
)
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.
With research ( and help with ChatGPT ), this may be the best way to get rid of leading dots in a directory.
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.
OK. Line 68 is effectively just getting the relative path to the root directory, right? I think you can delete this line and instead import ROOT_DIR
from packages/scripts/src/paths.ts
(look at the file changes for this PR, you'll see that packages/scripts/src/tasks/providers/android.ts
used to import ROOT_DIR
). Then you should be able to just pass this value to the execSync()
function below, like:
execSync(cmd, { stdio: "inherit", cwd: ROOT_DIR });
See also comment on line 65
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 have made these changes, and they function the same.
}); | ||
} | ||
|
||
const relativeAssetPath = path.relative(process.cwd(), assetPath).replace(/^(\.\.\/|\.\/)+/, ""); |
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 there a nicer way to do this, without the .replace()
and regex? Potentially an existing method of path
? It could be worth thinking if this whole logic of manipulating the path and then then executing the command relative to the cwd
could be simplified (I'm not saying that it definitely can, but it's quite hard to follow currently)
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.
See comment on line 68 below. I think this line could also use the ROOT_DIR
value instead of process.cwd()
, and avoid doing the regex replacement. Try logging out ROOT_DIR
and assetPath
at this point, and see if there's a method(s) of path
that could be used to combine them and give the output you want
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.
Made the change here too.
}, | ||
], | ||
}, | ||
// Generate iOS assets from source images (splash.png, icon.png and, optionally, icon-foreground.png and icon-background.png) |
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 icon.png
should be icon-only.png
instead
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 am not too sure what this comment is specifically referencing. When I checked my assets, the image was called icon.png
. However, I think any name changes can be solved by accessing the Google Drive.
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 was going off the docs, which suggest that the source asset should be called "icon-only.png". So I think that's what this comment should specify as the name for the source file too.
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.
Okay will do
}, | ||
}; | ||
// Generate android assets | ||
const assetDirPath = assetPath.includes(".png") ? path.dirname(assetPath) : assetPath; |
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.
Do we know whether the file has to be a .png
? Either way, I think it would be better to check whether the path is to a file in a more general way. Have a look at these docs (we're already importing fs
so can use its methods)
@@ -19,6 +19,20 @@ const childWorkflows: IDeploymentWorkflows = { | |||
}, | |||
], | |||
}, | |||
set_icons_and_splash_images: { | |||
label: | |||
"Generate app launcher icon and splash screen image from icon.png and splash.png asset respectively. Then if provided, it will generate adaptive icon from icon-foreground.png and icon-background.png. Copy generated files to relevant folders.", |
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 again that this should be "icon-only.png" instead of "icon.png". And no harm in linking to the docs again... Also copy over this comment to corresponding Android equivalent
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 this one may have to be changed within the gdrive. The comment I have changed but the actual name itself might have to be changed.
PR Checklist
Description
package.json
usingyarn
.android.ts
andandroid.workflow.ts
for Android.ios.ts
andios.workflow.ts
for iOScapacitor-assets
package, splash image and icon generation can co-occur using new commands.config.ts
anddeployment.model.ts
files to incorporate an asset path for bothandroid
andios
.ios.ts
andandroid.ts
has been enabled to support legacy.yarn workplace android configure
must be used before running the new commands.Git Issues
Closes #2072
Screenshots/Videos
It is recommended that you watch these videos in full-screen
Android:
android.yarn.commands.mov
iOS:
ios.yarn.commands.mov