Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Command Line SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-cli.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-0.15.1-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-0.15.2-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
Expand Down Expand Up @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using

```sh
$ appwrite -v
0.18.3
0.18.4
```

### Install using prebuilt binaries
Expand Down Expand Up @@ -58,7 +58,7 @@ $ iwr -useb https://appwrite.io/cli/install.ps1 | iex
Once the installation completes, you can verify your install using
```
$ appwrite -v
0.18.3
0.18.4
```

## Getting Started
Expand Down
4 changes: 2 additions & 2 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# You can use "View source" of this page to see the full script.

# REPO
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.3/appwrite-cli-win-x64.exe"
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.3/appwrite-cli-win-arm64.exe"
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.4/appwrite-cli-win-x64.exe"
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.4/appwrite-cli-win-arm64.exe"

$APPWRITE_BINARY_NAME = "appwrite.exe"

Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ printSuccess() {
downloadBinary() {
echo "[2/4] Downloading executable for $OS ($ARCH) ..."

GITHUB_LATEST_VERSION="0.18.3"
GITHUB_LATEST_VERSION="0.18.4"
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"

Expand Down
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Client {
this.endpoint = 'https://HOSTNAME/v1';
this.headers = {
'content-type': '',
'x-sdk-version': 'appwrite:cli:0.18.3',
'User-Agent' : `AppwriteCLI/0.18.3 (${os.type()} ${os.version()}; ${os.arch()})`,
'x-sdk-version': 'appwrite:cli:0.18.4',
'User-Agent' : `AppwriteCLI/0.18.4 (${os.type()} ${os.version()}; ${os.arch()})`,
'X-Appwrite-Response-Format' : '0.15.0',
};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ account

account
.command(`createPhoneSession`)
.description(`Sends the user an SMS with a secret key for creating a session. Use the returned user ID and secret and submit a request to the [PUT /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.`)
.description(`Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [PUT /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.`)
.requiredOption(`--userId <userId>`, `Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`)
.requiredOption(`--number <number>`, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`)
.action(actionRunner(accountCreatePhoneSession))
Expand Down
72 changes: 57 additions & 15 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@ const initProject = async () => {
const initFunction = async () => {
// TODO: Add CI/CD support (ID, name, runtime)
let answers = await inquirer.prompt(questionsInitFunction)
let functionFolder = path.join(process.cwd(), 'functions');

if (fs.existsSync(path.join(process.cwd(), 'functions', answers.name))) {
if (!fs.existsSync(functionFolder)) {
fs.mkdirSync(functionFolder, {
recursive: true
});
}

const functionDir = path.join(functionFolder, answers.name);

if (fs.existsSync(functionDir)) {
throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
}

Expand All @@ -66,20 +75,53 @@ const initFunction = async () => {
parseOutput: false
})

let command = `
mkdir -m 777 -p 'functions/${answers.name}' && \
cd 'functions/${answers.name}' && \
git init && \
git remote add -f origin https://github.com/appwrite/functions-starter && \
git config core.sparseCheckout true && \
echo '${answers.runtime.id}' >> .git/info/sparse-checkout && \
git pull origin main && \
rm -rf .git && \
mv ${answers.runtime.id}/* . && \
rm -rf ${answers.runtime.id}`;

// Execute the child process but do not print any std output
childProcess.execSync(command, { stdio: 'pipe' });
fs.mkdirSync(functionDir, "777");

let gitInitCommands = "git clone --depth 1 --sparse https://github.com/appwrite/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched

let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;

/* Force use CMD as powershell does not support && */
if (process.platform == 'win32') {
gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
}

/* Execute the child process but do not print any std output */
try {
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
} catch (error) {
/* Specialised errors with recommended actions to take */
if (error.message.includes('error: unknown option')) {
throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
} else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
throw new Error(`${error.message} \n\nSuggestion: It appears that git is not installed, try installing git then trying to run this command again.`)
} else {
throw error;
}
}

fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
const copyRecursiveSync = (src, dest) => {
let exists = fs.existsSync(src);
let stats = exists && fs.statSync(src);
let isDirectory = exists && stats.isDirectory();
if (isDirectory) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}

fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir);

fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });

const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
const readmeFile = fs.readFileSync(readmePath).toString();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "appwrite-cli",
"homepage": "https://appwrite.io/support",
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
"version": "0.18.3",
"version": "0.18.4",
"license": "BSD-3-Clause",
"main": "index.js",
"bin": {
Expand Down