From ae7f3ef63e480898a7db409198b450d3658cca5b Mon Sep 17 00:00:00 2001 From: Oriol Egea Date: Tue, 14 Nov 2023 18:13:43 +0100 Subject: [PATCH] feat(components/tool/app): Add icons command --- components/tool/app/bin/commands/icons.js | 38 +++++++++++++++++++++++ components/tool/app/bin/index.js | 5 +++ components/tool/app/package.json | 3 ++ 3 files changed, 46 insertions(+) create mode 100644 components/tool/app/bin/commands/icons.js diff --git a/components/tool/app/bin/commands/icons.js b/components/tool/app/bin/commands/icons.js new file mode 100644 index 000000000..ccb96755f --- /dev/null +++ b/components/tool/app/bin/commands/icons.js @@ -0,0 +1,38 @@ +// Infra +const {reportError, runCommand} = require('../infrastructure/utils.js') + +// Business logic +const {hasPackageJson, hasCapacitorConfig} = require('../domain/utils.js') + +const generateIcons = () => { + console.log(`\n\n🎨 Generating icons\n\n`) + + if ( + runCommand('npx @capacitor/assets generate ios') === false || + runCommand('npx @capacitor/assets generate android') === false + ) + reportError( + `\n\n🚨 Something went wrong while installing dependencies 🚨\n\n` + ) + else console.log(`\n\n✅ Icons successfully generated\n\n`) +} + +// Command +module.exports = () => { + // If we are not placed on a webapp, we cannot continue + if (!hasPackageJson()) { + reportError( + '\n\nsui-app should be executed from a web-app project.\nPlease be sure that there is a package.json file in your current directory.\n\n' + ) + return + } + + // If app has already been initialized + if (!hasCapacitorConfig()) { + reportError( + `\n\nThis project has not been initialized. sui-app cannot be removed\n\n` + ) + } + + generateIcons() +} diff --git a/components/tool/app/bin/index.js b/components/tool/app/bin/index.js index b0b705e08..44baebe4f 100755 --- a/components/tool/app/bin/index.js +++ b/components/tool/app/bin/index.js @@ -21,6 +21,11 @@ yargs 'syncs the compiled version of the web app with the ios and android projects', require('./commands/sync.js') ) + .command( + 'icons', + 'generates and transforms icons both for ios an android', + require('./commands/icons.js') + ) /* .command( 'asd [name]', 'welcome ter yargs!', diff --git a/components/tool/app/package.json b/components/tool/app/package.json index 1f478f92b..3fcd45f00 100644 --- a/components/tool/app/package.json +++ b/components/tool/app/package.json @@ -28,5 +28,8 @@ "@capacitor/ios": "^5.5.1", "@capgo/capacitor-native-biometric": "^5.1.0", "yargs": "^17.7.2" + }, + "devDependencies": { + "@capacitor/assets": "^3.0.1" } }