appwrite-cli 0.18.3 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Appwrite Command Line SDK
2
2
 
3
3
  ![License](https://img.shields.io/github/license/appwrite/sdk-for-cli.svg?style=flat-square)
4
- ![Version](https://img.shields.io/badge/api%20version-0.15.1-blue.svg?style=flat-square)
4
+ ![Version](https://img.shields.io/badge/api%20version-0.15.2-blue.svg?style=flat-square)
5
5
  [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
6
6
  [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
7
7
  [![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
29
29
 
30
30
  ```sh
31
31
  $ appwrite -v
32
- 0.18.3
32
+ 0.18.4
33
33
  ```
34
34
 
35
35
  ### Install using prebuilt binaries
@@ -58,7 +58,7 @@ $ iwr -useb https://appwrite.io/cli/install.ps1 | iex
58
58
  Once the installation completes, you can verify your install using
59
59
  ```
60
60
  $ appwrite -v
61
- 0.18.3
61
+ 0.18.4
62
62
  ```
63
63
 
64
64
  ## Getting Started
package/install.ps1 CHANGED
@@ -13,8 +13,8 @@
13
13
  # You can use "View source" of this page to see the full script.
14
14
 
15
15
  # REPO
16
- $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.3/appwrite-cli-win-x64.exe"
17
- $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.3/appwrite-cli-win-arm64.exe"
16
+ $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.4/appwrite-cli-win-x64.exe"
17
+ $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.18.4/appwrite-cli-win-arm64.exe"
18
18
 
19
19
  $APPWRITE_BINARY_NAME = "appwrite.exe"
20
20
 
package/install.sh CHANGED
@@ -97,7 +97,7 @@ printSuccess() {
97
97
  downloadBinary() {
98
98
  echo "[2/4] Downloading executable for $OS ($ARCH) ..."
99
99
 
100
- GITHUB_LATEST_VERSION="0.18.3"
100
+ GITHUB_LATEST_VERSION="0.18.4"
101
101
  GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
102
102
  GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
103
103
 
package/lib/client.js CHANGED
@@ -12,8 +12,8 @@ class Client {
12
12
  this.endpoint = 'https://HOSTNAME/v1';
13
13
  this.headers = {
14
14
  'content-type': '',
15
- 'x-sdk-version': 'appwrite:cli:0.18.3',
16
- 'User-Agent' : `AppwriteCLI/0.18.3 (${os.type()} ${os.version()}; ${os.arch()})`,
15
+ 'x-sdk-version': 'appwrite:cli:0.18.4',
16
+ 'User-Agent' : `AppwriteCLI/0.18.4 (${os.type()} ${os.version()}; ${os.arch()})`,
17
17
  'X-Appwrite-Response-Format' : '0.15.0',
18
18
  };
19
19
  }
@@ -864,7 +864,7 @@ account
864
864
 
865
865
  account
866
866
  .command(`createPhoneSession`)
867
- .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.`)
867
+ .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.`)
868
868
  .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.`)
869
869
  .requiredOption(`--number <number>`, `Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.`)
870
870
  .action(actionRunner(accountCreatePhoneSession))
@@ -50,8 +50,17 @@ const initProject = async () => {
50
50
  const initFunction = async () => {
51
51
  // TODO: Add CI/CD support (ID, name, runtime)
52
52
  let answers = await inquirer.prompt(questionsInitFunction)
53
+ let functionFolder = path.join(process.cwd(), 'functions');
53
54
 
54
- if (fs.existsSync(path.join(process.cwd(), 'functions', answers.name))) {
55
+ if (!fs.existsSync(functionFolder)) {
56
+ fs.mkdirSync(functionFolder, {
57
+ recursive: true
58
+ });
59
+ }
60
+
61
+ const functionDir = path.join(functionFolder, answers.name);
62
+
63
+ if (fs.existsSync(functionDir)) {
55
64
  throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
56
65
  }
57
66
 
@@ -66,20 +75,53 @@ const initFunction = async () => {
66
75
  parseOutput: false
67
76
  })
68
77
 
69
- let command = `
70
- mkdir -m 777 -p 'functions/${answers.name}' && \
71
- cd 'functions/${answers.name}' && \
72
- git init && \
73
- git remote add -f origin https://github.com/appwrite/functions-starter && \
74
- git config core.sparseCheckout true && \
75
- echo '${answers.runtime.id}' >> .git/info/sparse-checkout && \
76
- git pull origin main && \
77
- rm -rf .git && \
78
- mv ${answers.runtime.id}/* . && \
79
- rm -rf ${answers.runtime.id}`;
80
-
81
- // Execute the child process but do not print any std output
82
- childProcess.execSync(command, { stdio: 'pipe' });
78
+ fs.mkdirSync(functionDir, "777");
79
+
80
+ let gitInitCommands = "git clone --depth 1 --sparse https://github.com/appwrite/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched
81
+
82
+ let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
83
+
84
+ /* Force use CMD as powershell does not support && */
85
+ if (process.platform == 'win32') {
86
+ gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
87
+ gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
88
+ }
89
+
90
+ /* Execute the child process but do not print any std output */
91
+ try {
92
+ childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
93
+ childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
94
+ } catch (error) {
95
+ /* Specialised errors with recommended actions to take */
96
+ if (error.message.includes('error: unknown option')) {
97
+ throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
98
+ } else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
99
+ throw new Error(`${error.message} \n\nSuggestion: It appears that git is not installed, try installing git then trying to run this command again.`)
100
+ } else {
101
+ throw error;
102
+ }
103
+ }
104
+
105
+ fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
106
+ const copyRecursiveSync = (src, dest) => {
107
+ let exists = fs.existsSync(src);
108
+ let stats = exists && fs.statSync(src);
109
+ let isDirectory = exists && stats.isDirectory();
110
+ if (isDirectory) {
111
+ if (!fs.existsSync(dest)) {
112
+ fs.mkdirSync(dest);
113
+ }
114
+
115
+ fs.readdirSync(src).forEach(function(childItemName) {
116
+ copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
117
+ });
118
+ } else {
119
+ fs.copyFileSync(src, dest);
120
+ }
121
+ };
122
+ copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir);
123
+
124
+ fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
83
125
 
84
126
  const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
85
127
  const readmeFile = fs.readFileSync(readmePath).toString();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "appwrite-cli",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "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",
5
- "version": "0.18.3",
5
+ "version": "0.18.4",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "index.js",
8
8
  "bin": {