Skip to content

Commit

Permalink
Merge pull request #651 from SUI-Components/feat/app-live-updates
Browse files Browse the repository at this point in the history
feat(components/tool/app): Add live updates support to sui-app
  • Loading branch information
oegea committed Apr 15, 2024
2 parents 4d64791 + 2069ec7 commit 706e377
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 25 deletions.
24 changes: 24 additions & 0 deletions components/tool/app/bin/commands/addLiveUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable no-console */

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

const {hasDependency, installDependency, 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 configure live updates\n\n`)
}

if (!hasDependency('@capgo/capacitor-updater')) installDependency('@capgo/capacitor-updater')
else reportError(`\n\nLive updates were already installed\n\n`)
}
28 changes: 5 additions & 23 deletions components/tool/app/bin/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/* eslint-disable no-console */
// Constants
const {PACKAGE_JSON_FILE, PACKAGE_NAME} = require('../infrastructure/config.js')
const {PACKAGE_NAME} = require('../infrastructure/config.js')

// Infra

const {
getCurrentDirectory,
readJSONFile,
reportError,
runCommand,
installPackage,
saveJSONFile
} = require('../infrastructure/utils.js')
const {readJSONFile, reportError, runCommand, saveJSONFile} = require('../infrastructure/utils.js')

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

Expand Down Expand Up @@ -51,20 +44,7 @@ const addBiometricConfig = () => {
}

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

const hasDependency = dependency => {
const packageData = readJSONFile(`${getCurrentDirectory()}/${PACKAGE_JSON_FILE}`)
return packageData.dependencies.hasOwnProperty(dependency)
}

const installDependency = dependency => {
console.log(`\n🚚 Installing required dependency 👉 ${dependency}\n`)
const result = installPackage(dependency)

if (result === false) reportError(`\n🚨 Something went wrong while installing dependencies 🚨\n`)
else console.log(`\n✅ Dependency has been successfully installed\n`)
}
const {hasPackageJson, hasCapacitorConfig, installDependency, hasDependency} = require('../domain/utils.js')

const initAppProject = () => {
console.log('\n🚚 Initializing the project.\n')
Expand Down Expand Up @@ -130,6 +110,8 @@ module.exports = async () => {

if (!hasDependency('@capacitor/local-notifications')) installDependency('@capacitor/local-notifications')

if (!hasDependency('@capgo/capacitor-updater')) installDependency('@capgo/capacitor-updater')

// If app has already been initialized
if (hasCapacitorConfig()) {
reportError(`\nThis project has already-been initialized. Please run sui-app remove before initializing again.\n`)
Expand Down
1 change: 1 addition & 0 deletions components/tool/app/bin/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const uninstallSuiApp = () => {
const uninstallPlugins = () => {
uninstallPackage('@capgo/capacitor-native-biometric')
uninstallPackage('@capacitor/local-notifications')
uninstallPackage('@capgo/capacitor-updater')
}

// Business logic
Expand Down
26 changes: 24 additions & 2 deletions components/tool/app/bin/domain/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Constants
const {PACKAGE_JSON_FILE, PROJECT_CONFIG_FILE} = require('../infrastructure/config.js')

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

const hasPackageJson = () => {
return fileExists(`${getCurrentDirectory()}/${PACKAGE_JSON_FILE}`)
Expand All @@ -24,9 +31,24 @@ const hasAndroidUrlScheme = scheme => {
return fileContains(schemePattern, androidManifestPath)
}

const installDependency = dependency => {
console.log(`\n🚚 Installing required dependency 👉 ${dependency}\n`)
const result = installPackage(dependency)

if (result === false) reportError(`\n🚨 Something went wrong while installing dependencies 🚨\n`)
else console.log(`\n✅ Dependency has been successfully installed\n`)
}

const hasDependency = dependency => {
const packageData = readJSONFile(`${getCurrentDirectory()}/${PACKAGE_JSON_FILE}`)
return packageData.dependencies.hasOwnProperty(dependency)
}

module.exports = {
hasDependency,
hasPackageJson,
hasCapacitorConfig,
hasIosUrlScheme,
hasAndroidUrlScheme
hasAndroidUrlScheme,
installDependency
}
1 change: 1 addition & 0 deletions components/tool/app/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ yargs
'Adds a custom URL scheme to both iOS and Android projects',
require('./commands/addUrlScheme.js')
)
.command('add-live-update', 'Adds live update capabilities to the project', require('./commands/addLiveUpdate.js'))
.help()
.command({
command: '*',
Expand Down

0 comments on commit 706e377

Please sign in to comment.