diff --git a/README.md b/README.md index 9b00b66..ea3cf96 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 diff --git a/install.ps1 b/install.ps1 index ad45e2c..85f1254 100644 --- a/install.ps1 +++ b/install.ps1 @@ -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" diff --git a/install.sh b/install.sh index c013735..44951bf 100644 --- a/install.sh +++ b/install.sh @@ -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" diff --git a/lib/client.js b/lib/client.js index 6ee8fb9..6f33259 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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', }; } diff --git a/lib/commands/account.js b/lib/commands/account.js index c117d5a..3f45bd5 100644 --- a/lib/commands/account.js +++ b/lib/commands/account.js @@ -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 `, `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 `, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`) .action(actionRunner(accountCreatePhoneSession)) diff --git a/lib/commands/init.js b/lib/commands/init.js index fd75c80..b21527f 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -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.`); } @@ -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(); diff --git a/package.json b/package.json index 70a6c3f..2ce3bfe 100644 --- a/package.json +++ b/package.json @@ -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": {