Skip to content
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

Ailly install script. #23

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions content/31_ailly_version/.aillyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
combined: true
---
47 changes: 47 additions & 0 deletions content/31_ailly_version/01_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
combined: true
skip: true
debug:
engine: bedrock
finish: end_turn
id: null
model: anthropic.claude-3-sonnet-20240229-v1:0
usage: null
isolated: false
prompt: >
```
#!/bin/bash

package_name="@ailly/cli" package_version=latest
```
Finish this script. It should check to see if the package_version of package_name
is installed globally with npm. package_version should be used to augment the package_name.

If the package is not installed, it should install it.
---
Here's the completed script that checks if the specified package is installed globally with npm, and installs it if it's not:

```bash
#!/bin/bash

package_name="@ailly/cli"
package_version="latest"

# Check if the package is installed globally
if ! npm list -g "$package_name" | grep -q "$package_version"; then
echo "Installing $package_name@$package_version globally..."
npm install -g "$package_name@$package_version"
else
echo "$package_name@$package_version is already installed globally."
fi
```

Here's how the script works:

The package_name and package_version variables are defined at the beginning of the script.
The npm list -g "$package_name" command lists all globally installed packages, and the output is piped to grep -q "$package_version" which searches for the specified $package_version.
If the grep command doesn't find the specified version, the negated condition ! causes the if block to execute.
Inside the if block, the script prints a message indicating that it's installing the package globally, and then runs npm install -g "$package_name@$package_version" to install the specified package and version globally.
If the grep command finds the specified version, the else block executes, printing a message indicating that the package is already installed globally.

Note that this script assumes that npm is installed and available in the system's PATH. If you're using a different package manager (e.g., yarn), you'll need to modify the commands accordingly.
46 changes: 46 additions & 0 deletions content/31_ailly_version/02_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
combined: true
debug:
engine: bedrock
finish: end_turn
id: null
model: anthropic.claude-3-sonnet-20240229-v1:0
usage: null
isolated: false
prompt: >
The next step is to handle the case where package version is "latest", this is
a special keyword that gets the most recent package version. If package
version is set to latest, we need to find out what the latest version is
before we grep
---
Sure, here's the updated script that handles the case where `package_version` is set to `"latest"`:

```bash
#!/bin/bash

package_name="@ailly/cli"
package_version="latest"

# If package_version is "latest", get the latest version number
if [ "$package_version" = "latest" ]; then
package_version=$(npm view "$package_name" version)
fi

# Check if the package is installed globally
if ! npm list -g "$package_name" | grep -q "$package_version"; then
echo "Installing $package_name@$package_version globally..."
npm install -g "$package_name@$package_version"
else
echo "$package_name@$package_version is already installed globally."
fi
```

Here's what's different in this script:

1. We first check if `package_version` is set to `"latest"`. If it is, we use the `npm view` command to get the actual latest version of the package. The `npm view` command displays the latest version of the specified package without installing it.

2. If `package_version` is not `"latest"`, we simply reassign its value to `package_version`.

This way, if `package_version` is set to `"latest"`, the script will determine the actual latest version of the package and use that for installation or checking if it's already installed.

Note that this script assumes that the `npm view` command is available and working correctly. If you encounter any issues with `npm view`, you may need to explore alternative ways to retrieve the latest package version, such as using a package registry API or parsing the output of `npm show` command.