-
Notifications
You must be signed in to change notification settings - Fork 5
chore: simplify postinstall to advise running aidevops update #82
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,51 @@ | ||
| /** | ||
| * npm postinstall script for aidevops | ||
| * Runs setup.sh to deploy agents after npm install -g | ||
| * | ||
| * The npm package contains only the CLI wrapper. The full agent files | ||
| * are deployed from ~/Git/aidevops via `aidevops update`. | ||
| */ | ||
|
|
||
| const { execSync } = require('child_process'); | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
|
|
||
| const packageDir = path.resolve(__dirname, '..'); | ||
| const setupScript = path.join(packageDir, 'setup.sh'); | ||
| const agentsDir = path.join(os.homedir(), '.aidevops', 'agents'); | ||
| const versionFile = path.join(agentsDir, 'VERSION'); | ||
|
|
||
| // Check if this is a global install | ||
| const isGlobalInstall = process.env.npm_config_global === 'true'; | ||
|
|
||
| // Skip if not global install (local dev doesn't need postinstall) | ||
| if (!isGlobalInstall && fs.existsSync(agentsDir)) { | ||
| console.log('aidevops: Local install detected, skipping setup (agents already deployed)'); | ||
| process.exit(0); | ||
| // Check current installed version | ||
| let installedVersion = 'not installed'; | ||
| if (fs.existsSync(versionFile)) { | ||
| installedVersion = fs.readFileSync(versionFile, 'utf8').trim(); | ||
| } | ||
|
Comment on lines
+17
to
19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script could be more robust by handling potential errors when reading the version file. While |
||
|
|
||
| // Check if setup.sh exists | ||
| if (!fs.existsSync(setupScript)) { | ||
| console.log('aidevops: setup.sh not found, skipping postinstall'); | ||
| process.exit(0); | ||
| } | ||
| // Get package version | ||
| const packageJson = require('../package.json'); | ||
| const packageVersion = packageJson.version; | ||
|
|
||
| console.log('aidevops: Running setup to deploy agents...'); | ||
| console.log(''); | ||
| console.log('aidevops CLI installed successfully!'); | ||
| console.log(''); | ||
| console.log(` CLI version: ${packageVersion}`); | ||
| console.log(` Agents version: ${installedVersion}`); | ||
| console.log(''); | ||
|
|
||
| try { | ||
| // Run setup.sh non-interactively | ||
| execSync(`bash "${setupScript}"`, { | ||
| stdio: 'inherit', | ||
| cwd: packageDir, | ||
| env: { | ||
| ...process.env, | ||
| // Skip interactive prompts | ||
| AIDEVOPS_NONINTERACTIVE: '1' | ||
| } | ||
| }); | ||
|
|
||
| if (installedVersion === 'not installed') { | ||
| console.log('To complete installation, run:'); | ||
| console.log(''); | ||
| console.log('aidevops installed successfully!'); | ||
| console.log(' aidevops update'); | ||
| console.log(''); | ||
| console.log('This will clone the repository and deploy agents to ~/.aidevops/agents/'); | ||
| } else if (installedVersion !== packageVersion) { | ||
| console.log('To update agents to match CLI version, run:'); | ||
| console.log(''); | ||
| console.log(' aidevops update'); | ||
| console.log(''); | ||
| } else { | ||
| console.log('CLI and agents are in sync. Ready to use!'); | ||
| console.log(''); | ||
| console.log('Quick start:'); | ||
| console.log(' aidevops status # Check installation'); | ||
| console.log(' aidevops init # Initialize in a project'); | ||
| console.log(' aidevops help # Show all commands'); | ||
| console.log(''); | ||
| } catch (error) { | ||
| console.error('aidevops: Setup encountered issues (non-critical)'); | ||
| console.error(`Run manually: bash "${setupScript}"`); | ||
| console.error('Or reinstall with: bash <(curl -fsSL https://aidevops.sh)'); | ||
| // Don't fail the install | ||
| process.exit(0); | ||
| } | ||
| console.log(''); | ||
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.
fs.readFileSync(versionFile, ...)can still throw even ifexistsSyncreturned true (e.g., permission issues/broken symlink), which would fail the entire npm install because this postinstall script isn’t guarded. Consider wrapping version detection in a try/catch and falling back tonot installedto keep installs resilient.🤖 Was this useful? React with 👍 or 👎