Skip to content

Commit d4ee4ca

Browse files
Merge pull request #127 from Acurast/feat/auto-update-app-versions
Feat/auto update app versions
2 parents 1cd2dd7 + dc8816e commit d4ee4ca

2 files changed

Lines changed: 49 additions & 26 deletions

File tree

src/commands/new.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,38 +74,52 @@ export const addCommandNew = (program: Command) => {
7474
`\nProject "${projectName}" created successfully using the "${selectedTemplate}" template.`
7575
)
7676

77-
spinner.start('Updating package.json...')
78-
try {
79-
const packageJsonPath = path.join(projectPath, 'package.json')
80-
const packageJson = JSON.parse(
81-
fs.readFileSync(packageJsonPath, 'utf8')
82-
)
83-
packageJson.name = projectName
84-
fs.writeFileSync(
85-
packageJsonPath,
86-
JSON.stringify(packageJson, null, 2)
87-
)
88-
spinner.succeed('package.json updated successfully')
89-
} catch (error) {
90-
spinner.fail('Failed to update package.json')
91-
console.error(`Error updating package.json:`, error)
77+
const packageJsonPath = path.join(projectPath, 'package.json')
78+
const cargoTomlPath = path.join(projectPath, 'Cargo.toml')
79+
const hasPackageJson = fs.existsSync(packageJsonPath)
80+
const hasCargoToml = fs.existsSync(cargoTomlPath)
81+
82+
if (hasPackageJson) {
83+
spinner.start('Updating package.json...')
84+
try {
85+
const packageJson = JSON.parse(
86+
fs.readFileSync(packageJsonPath, 'utf8')
87+
)
88+
packageJson.name = projectName
89+
fs.writeFileSync(
90+
packageJsonPath,
91+
JSON.stringify(packageJson, null, 2)
92+
)
93+
spinner.succeed('package.json updated successfully')
94+
} catch (error) {
95+
spinner.fail('Failed to update package.json')
96+
console.error(`Error updating package.json:`, error)
97+
}
9298
}
9399

94100
spinner.start('Initializing git repository...')
95-
96101
try {
97102
process.chdir(projectPath)
98103
execSync('git init', { stdio: 'ignore' })
99104
spinner.succeed('Git repository initialized')
105+
} catch (error) {
106+
spinner.fail('Failed to initialize git repository')
107+
console.error(`Error:`, error)
108+
}
100109

110+
if (hasPackageJson) {
101111
spinner.start('Installing dependencies...')
102-
execSync('npm install', { stdio: 'ignore' })
103-
spinner.succeed('Dependencies installed')
104-
} catch (error) {
105-
spinner.fail(
106-
'Failed to initialize git repository or install dependencies'
112+
try {
113+
execSync('npm install', { stdio: 'ignore' })
114+
spinner.succeed('Dependencies installed')
115+
} catch (error) {
116+
spinner.fail('Failed to install dependencies')
117+
console.error(`Error:`, error)
118+
}
119+
} else if (hasCargoToml) {
120+
console.log(
121+
`\nCargo project detected. Run \`cargo build\` to compile.`
107122
)
108-
console.error(`Error:`, error)
109123
}
110124

111125
console.log(`\nNext steps:`)

src/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { addCommandEstimateFee } from './commands/estimate-fee.js'
2424
import { addCommandDevtools } from './commands/devtools.js'
2525
import { ACURAST_CLI_VERSION_CHECK_URL } from './constants.js'
2626
import { filelogger } from './util/fileLogger.js'
27+
import { fetchDeviceVersions } from '@acurast/sdk/chain'
2728

2829
const __filename = fileURLToPath(import.meta.url)
2930
const __dirname = dirname(__filename)
@@ -74,7 +75,7 @@ if (!process.argv.slice(2).length) {
7475
}
7576

7677
// Check if there's a newer version available
77-
fetch(ACURAST_CLI_VERSION_CHECK_URL)
78+
const cliVersionCheck = fetch(ACURAST_CLI_VERSION_CHECK_URL)
7879
.then((response) => response.json())
7980
.then((remotePackage) => {
8081
const localVersion = packageJson.version
@@ -95,6 +96,14 @@ fetch(ACURAST_CLI_VERSION_CHECK_URL)
9596
.catch(() => {
9697
// Silently fail if unable to check version
9798
})
98-
.finally(() => {
99-
program.parse(process.argv)
100-
})
99+
100+
// Refresh processor build-number → human-version map so `minProcessorVersions`
101+
// in acurast.json can be resolved against the latest releases (SDK ships a
102+
// stale bundled list).
103+
const deviceVersionsRefresh = fetchDeviceVersions().catch((err) => {
104+
filelogger.debug(`Failed to refresh device versions: ${err}`)
105+
})
106+
107+
Promise.allSettled([cliVersionCheck, deviceVersionsRefresh]).finally(() => {
108+
program.parse(process.argv)
109+
})

0 commit comments

Comments
 (0)