Skip to content

Commit

Permalink
Merge pull request #639 from SUI-Components/feat/sui-app-icons
Browse files Browse the repository at this point in the history
feat(components/tool/app): Start to work on addBiometricConfig command
  • Loading branch information
oegea authored Nov 17, 2023
2 parents 068b4e4 + b85dabc commit 14b5f12
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 42 deletions.
26 changes: 26 additions & 0 deletions components/tool/app/bin/commands/addBiometricConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable no-console */

const {reportError} = require('../infrastructure/utils.js')

const {hasPackageJson, hasCapacitorConfig} = require('../domain/utils.js')

// 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 perform a sync operation\n\n`)
}

// If biometric has not been added yet

// Sync project
console.log('\nThis command is still not implemented.\n')
}
9 changes: 3 additions & 6 deletions components/tool/app/bin/commands/icons.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
// Infra
const {reportError, runCommand} = require('../infrastructure/utils.js')

Expand All @@ -11,9 +12,7 @@ const generateIcons = () => {
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`
)
reportError(`\n\n🚨 Something went wrong while installing dependencies 🚨\n\n`)
else console.log(`\n\n✅ Icons successfully generated\n\n`)
}

Expand All @@ -29,9 +28,7 @@ module.exports = () => {

// If app has already been initialized
if (!hasCapacitorConfig()) {
reportError(
`\n\nThis project has not been initialized. sui-app cannot be removed\n\n`
)
reportError(`\n\nThis project has not been initialized. sui-app cannot be removed\n\n`)
}

generateIcons()
Expand Down
27 changes: 25 additions & 2 deletions components/tool/app/bin/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const {
saveJSONFile
} = require('../infrastructure/utils.js')

const {confirmQuestion} = require('../infrastructure/input.js')

const initProject = () => {
return runCommand(`npx cap init`)
}
Expand Down Expand Up @@ -44,6 +46,10 @@ const optimizeConfigurations = () => {
saveJSONFile(config, './capacitor.config.json')
}

const addBiometricConfig = () => {
return runCommand(`npx sui-app add-biometric-config`)
}

// Business logic
const {hasPackageJson, hasCapacitorConfig} = require('../domain/utils.js')

Expand Down Expand Up @@ -77,7 +83,7 @@ const addAndroidProject = () => {
}

const addIOSProject = () => {
console.log('\n🍏 Adding iOS projectt\n')
console.log('\n🍏 Adding iOS project\n')
const result = initIOS()

if (result === false) reportError(`\n🚨 Something went wrong while configuring iOS 🚨\n`)
Expand All @@ -92,8 +98,22 @@ const applyConfigurationOptimizations = () => {
else console.log('\n✅ Configuration optimizations have been successfully applied\n')
}

const biometricAPIsPermissions = async () => {
const usesBiometric = await confirmQuestion('Do you plan to use biometric authentication in this app?')
if (usesBiometric === false) {
console.log('\n ⚠️ Run npx sui-app add-biometric-config if you need to use biometric APIs on the future \n')
return
}

console.log('\n🪪 Configuring biometric permissions\n')
const result = addBiometricConfig()

if (result === false) reportError(`\n🚨 Something went wrong while configuring biometric permissions 🚨\n`)
else console.log('\n✅ Biometric permissions has been successfully configured\n')
}

// Command
module.exports = () => {
module.exports = async () => {
// If we are not placed on a webapp, we cannot continue
if (!hasPackageJson()) {
reportError(
Expand Down Expand Up @@ -126,4 +146,7 @@ module.exports = () => {

// Apply optimizations to capacitor config file
applyConfigurationOptimizations()

// Add permissions for biometric APIs
await biometricAPIsPermissions()
}
5 changes: 2 additions & 3 deletions components/tool/app/bin/commands/sync.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
// Infra
// -> files
const {reportError, runCommand} = require('../infrastructure/utils.js')
Expand Down Expand Up @@ -30,9 +31,7 @@ module.exports = () => {

// If app has already been initialized
if (!hasCapacitorConfig()) {
reportError(
`\n\nThis project has not been initialized. sui-app cannot perform a sync operation\n\n`
)
reportError(`\n\nThis project has not been initialized. sui-app cannot perform a sync operation\n\n`)
}

// Sync project
Expand Down
5 changes: 1 addition & 4 deletions components/tool/app/bin/domain/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Constants
const {
PACKAGE_JSON_FILE,
PROJECT_CONFIG_FILE
} = require('../infrastructure/config.js')
const {PACKAGE_JSON_FILE, PROJECT_CONFIG_FILE} = require('../infrastructure/config.js')

const {getCurrentDirectory, fileExists} = require('../infrastructure/utils.js')

Expand Down
33 changes: 6 additions & 27 deletions components/tool/app/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,19 @@ const COMMAND_NAME = 'sui-app'
yargs
.scriptName(COMMAND_NAME)
.usage('$0 <cmd> [args]')
.command(
'init',
'inits an already-existing web app to start using sui-app',
require('./commands/init.js')
)
.command(
'remove',
'removes sui-app from an already-initialized project',
require('./commands/remove.js')
)
.command('init', 'inits an already-existing web app to start using sui-app', require('./commands/init.js'))
.command('remove', 'removes sui-app from an already-initialized project', require('./commands/remove.js'))
.command(
'sync',
'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(
'icons',
'generates and transforms icons both for ios an android',
require('./commands/icons.js')
'add-biometric-config',
'Configures both iOS and Android to use biometric authentication',
require('./commands/addBiometricConfig.js')
)
/* .command(
'asd [name]',
'welcome ter yargs!',
yargs => {
yargs.positional('name', {
type: 'string',
default: 'Cambi',
describe: 'the name to say hello to'
})
},
function (argv) {
console.log('hello', argv.name, 'welcome to yargs!')
}
) */
.help()
.command({
command: '*',
Expand Down
23 changes: 23 additions & 0 deletions components/tool/app/bin/infrastructure/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const confirmQuestion = async message => {
return new Promise((resolve, reject) => {
const readline = require('readline')

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

rl.question(`❓ ${message} (Y/n)`, answer => {
if (answer.toLowerCase() === 'n') {
resolve(false)
} else {
resolve(true)
}
rl.close()
})
})
}

module.exports = {
confirmQuestion
}
1 change: 1 addition & 0 deletions components/tool/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@capacitor/core": "^5.5.1",
"@capacitor/ios": "^5.5.1",
"@capgo/capacitor-native-biometric": "^5.1.0",
"readline": "^1.3.0",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down

0 comments on commit 14b5f12

Please sign in to comment.