appwrite-cli 6.0.0-rc.4 → 6.0.0-rc.5

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.
@@ -1,10 +1,14 @@
1
+ const tar = require("tar");
2
+ const ignore = require("ignore");
3
+ const net = require('net');
1
4
  const chalk = require('chalk');
2
5
  const childProcess = require('child_process');
3
6
  const { localConfig } = require("../config");
4
7
  const path = require('path');
5
8
  const fs = require('fs');
6
- const { log, success, hint } = require("../parser");
9
+ const { log, error, success, hint } = require("../parser");
7
10
  const { openRuntimesVersion, systemTools, Queue } = require("./utils");
11
+ const { getAllFiles } = require("../utils");
8
12
 
9
13
  async function dockerStop(id) {
10
14
  const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], {
@@ -49,7 +53,7 @@ async function dockerBuild(func, variables) {
49
53
 
50
54
  const params = [ 'run' ];
51
55
  params.push('--name', id);
52
- params.push('-v', `${functionDir}/:/mnt/code:rw`);
56
+ params.push('-v', `${tmpBuildPath}/:/mnt/code:rw`);
53
57
  params.push('-e', 'APPWRITE_ENV=development');
54
58
  params.push('-e', 'OPEN_RUNTIMES_ENV=development');
55
59
  params.push('-e', 'OPEN_RUNTIMES_SECRET=');
@@ -91,12 +95,11 @@ async function dockerBuild(func, variables) {
91
95
 
92
96
  await new Promise((res) => { buildProcess.on('close', res) });
93
97
 
94
- clearInterval(interval);
95
-
98
+ clearInterval(killInterval);
96
99
  if(!Queue.isEmpty()) {
97
100
  return;
98
101
  }
99
-
102
+
100
103
  const copyPath = path.join(process.cwd(), func.path, '.appwrite', 'build.tar.gz');
101
104
  const copyDir = path.dirname(copyPath);
102
105
  if (!fs.existsSync(copyDir)) {
@@ -120,9 +123,39 @@ async function dockerBuild(func, variables) {
120
123
  if (fs.existsSync(tempPath)) {
121
124
  fs.rmSync(tempPath, { force: true });
122
125
  }
126
+
127
+ fs.rmSync(tmpBuildPath, { recursive: true, force: true });
123
128
  }
124
129
 
125
130
  async function dockerStart(func, variables, port) {
131
+ // Pack function files
132
+ const functionDir = path.join(process.cwd(), func.path);
133
+
134
+ const ignorer = ignore();
135
+ ignorer.add('.appwrite');
136
+ if (func.ignore) {
137
+ ignorer.add(func.ignore);
138
+ } else if (fs.existsSync(path.join(functionDir, '.gitignore'))) {
139
+ ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString());
140
+ }
141
+
142
+ const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file));
143
+ const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build');
144
+ if (!fs.existsSync(tmpBuildPath)) {
145
+ fs.mkdirSync(tmpBuildPath, { recursive: true });
146
+ }
147
+
148
+ for(const f of files) {
149
+ const filePath = path.join(tmpBuildPath, f);
150
+ const fileDir = path.dirname(filePath);
151
+ if (!fs.existsSync(fileDir)) {
152
+ fs.mkdirSync(fileDir, { recursive: true });
153
+ }
154
+
155
+ const sourcePath = path.join(functionDir, f);
156
+ fs.copyFileSync(sourcePath, filePath);
157
+ }
158
+
126
159
  const runtimeChunks = func.runtime.split("-");
127
160
  const runtimeVersion = runtimeChunks.pop();
128
161
  const runtimeName = runtimeChunks.join("-");
@@ -168,6 +201,13 @@ async function dockerStart(func, variables, port) {
168
201
  process.stdout.write(chalk.blackBright(data));
169
202
  });
170
203
 
204
+ try {
205
+ await waitUntilPortOpen(port);
206
+ } catch(err) {
207
+ error("Failed to start function with error: " + err.message ? err.message : err.toString());
208
+ return;
209
+ }
210
+
171
211
  success(`Visit http://localhost:${port}/ to execute your function.`);
172
212
  }
173
213
 
@@ -186,6 +226,39 @@ async function dockerCleanup(functionId) {
186
226
  }
187
227
  }
188
228
 
229
+ function waitUntilPortOpen(port, iteration = 0) {
230
+ return new Promise((resolve, reject) => {
231
+ const client = new net.Socket();
232
+
233
+ client.once('connect', () => {
234
+ client.removeAllListeners('connect');
235
+ client.removeAllListeners('error');
236
+ client.end();
237
+ client.destroy();
238
+ client.unref();
239
+
240
+ resolve();
241
+ });
242
+
243
+ client.once('error', async (err) => {
244
+ client.removeAllListeners('connect');
245
+ client.removeAllListeners('error');
246
+ client.end();
247
+ client.destroy();
248
+ client.unref();
249
+
250
+ if(iteration > 100) {
251
+ reject(err);
252
+ } else {
253
+ await new Promise((res) => setTimeout(res, 100));
254
+ waitUntilPortOpen(port, iteration + 1).then(resolve).catch(reject);
255
+ }
256
+ });
257
+
258
+ client.connect({port, host: '127.0.0.1'}, function() {});
259
+ });
260
+ }
261
+
189
262
  module.exports = {
190
263
  dockerPull,
191
264
  dockerBuild,
package/lib/parser.js CHANGED
@@ -90,20 +90,9 @@ const drawTable = (data) => {
90
90
  if (row[key] === null) {
91
91
  rowValues.push("-");
92
92
  } else if (Array.isArray(row[key])) {
93
- switch (row[key].length) {
94
- case 1:
95
- if (typeof row[key][0] === 'object') {
96
- rowValues.push(`array(${row[key].length})`);
97
- } else {
98
- rowValues.push(row[key][0]);
99
- }
100
- break;
101
- default:
102
- rowValues.push(`array(${row[key].length})`);
103
- break;
104
- }
93
+ rowValues.push(JSON.stringify(row[key]));
105
94
  } else if (typeof row[key] === 'object') {
106
- rowValues.push("object");
95
+ rowValues.push(JSON.stringify(row[key]));
107
96
  } else {
108
97
  rowValues.push(row[key]);
109
98
  }
@@ -131,7 +120,7 @@ const parseError = (err) => {
131
120
  } catch {
132
121
  }
133
122
 
134
- const version = '6.0.0-rc.4';
123
+ const version = '6.0.0-rc.5';
135
124
  const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``;
136
125
  const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`;
137
126
 
package/lib/questions.js CHANGED
@@ -247,11 +247,10 @@ const questionsPullFunctions = [
247
247
  if (functions.length === 0) {
248
248
  throw "We couldn't find any functions in your Appwrite project";
249
249
  }
250
-
251
250
  return functions.map(func => {
252
251
  return {
253
252
  name: `${func.name} (${func.$id})`,
254
- value: func
253
+ value: { ...func }
255
254
  }
256
255
  });
257
256
  }
@@ -634,12 +633,10 @@ const questionsPushFunctions = [
634
633
  name: "functions",
635
634
  message: "Which functions would you like to push?",
636
635
  validate: (value) => validateRequired('function', value),
636
+ when: () => localConfig.getFunctions().length > 0,
637
637
  choices: () => {
638
638
  let functions = localConfig.getFunctions();
639
639
  checkDeployConditions(localConfig)
640
- if (functions.length === 0) {
641
- throw new Error("No functions found Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one.");
642
- }
643
640
  let choices = functions.map((func, idx) => {
644
641
  return {
645
642
  name: `${func.name} (${func.$id})`,
@@ -662,13 +659,11 @@ const questionsPushCollections = [
662
659
  name: "collections",
663
660
  message: "Which collections would you like to push?",
664
661
  validate: (value) => validateRequired('collection', value),
662
+ when: () => localConfig.getCollections().length > 0,
665
663
  choices: () => {
666
664
  let collections = localConfig.getCollections();
667
665
  checkDeployConditions(localConfig)
668
666
 
669
- if (collections.length === 0) {
670
- throw new Error("No collections found in the current directory. Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one.");
671
- }
672
667
  return collections.map(collection => {
673
668
  return {
674
669
  name: `${collection.name} (${collection['databaseId']} - ${collection['$id']})`,
@@ -676,13 +671,16 @@ const questionsPushCollections = [
676
671
  }
677
672
  });
678
673
  }
679
- },
674
+ }
675
+ ];
676
+
677
+ const questionPushChanges = [
680
678
  {
681
679
  type: "input",
682
680
  name: "changes",
683
681
  message: `Would you like to apply these changes? Type "YES" to confirm.`
684
682
  }
685
- ]
683
+ ];
686
684
 
687
685
  const questionsPushBuckets = [
688
686
  {
@@ -690,12 +688,11 @@ const questionsPushBuckets = [
690
688
  name: "buckets",
691
689
  message: "Which buckets would you like to push?",
692
690
  validate: (value) => validateRequired('bucket', value),
691
+ when: () => localConfig.getBuckets().length > 0,
693
692
  choices: () => {
694
693
  let buckets = localConfig.getBuckets();
695
694
  checkDeployConditions(localConfig)
696
- if (buckets.length === 0) {
697
- throw new Error("No buckets found in the current directory. Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one.");
698
- }
695
+
699
696
  return buckets.map(bucket => {
700
697
  return {
701
698
  name: `${bucket.name} (${bucket['$id']})`,
@@ -711,11 +708,10 @@ const questionsPushMessagingTopics = [
711
708
  type: "checkbox",
712
709
  name: "topics",
713
710
  message: "Which messaging topic would you like to push?",
711
+ when: () => localConfig.getMessagingTopics().length > 0,
714
712
  choices: () => {
715
713
  let topics = localConfig.getMessagingTopics();
716
- if (topics.length === 0) {
717
- throw new Error("No topics found in the current directory. Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one.");
718
- }
714
+
719
715
  return topics.map(topic => {
720
716
  return {
721
717
  name: `${topic.name} (${topic['$id']})`,
@@ -752,12 +748,11 @@ const questionsPushTeams = [
752
748
  name: "teams",
753
749
  message: "Which teams would you like to push?",
754
750
  validate: (value) => validateRequired('team', value),
751
+ when: () => localConfig.getTeams().length > 0,
755
752
  choices: () => {
756
753
  let teams = localConfig.getTeams();
757
754
  checkDeployConditions(localConfig);
758
- if (teams.length === 0) {
759
- throw new Error("No teams found in the current directory. Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one.");
760
- }
755
+
761
756
  return teams.map(team => {
762
757
  return {
763
758
  name: `${team.name} (${team['$id']})`,
@@ -866,5 +861,6 @@ module.exports = {
866
861
  questionsRunFunctions,
867
862
  questionGetEndpoint,
868
863
  questionsInitResources,
869
- questionsCreateTeam
864
+ questionsCreateTeam,
865
+ questionPushChanges
870
866
  };
package/lib/spinner.js CHANGED
@@ -22,6 +22,7 @@ class Spinner {
22
22
  hideCursor,
23
23
  clearOnComplete,
24
24
  stopOnComplete: true,
25
+ linewrap: true,
25
26
  noTTYOutput: true
26
27
  });
27
28
  }
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": "6.0.0-rc.4",
5
+ "version": "6.0.0-rc.5",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "index.js",
8
8
  "bin": {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
3
- "version": "6.0.0-rc.4",
3
+ "version": "6.0.0-rc.5",
4
4
  "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.",
5
5
  "homepage": "https://github.com/appwrite/sdk-for-cli",
6
6
  "license": "BSD-3-Clause",
7
7
  "architecture": {
8
8
  "64bit": {
9
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-x64.exe",
9
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-x64.exe",
10
10
  "bin": [
11
11
  [
12
12
  "appwrite-cli-win-x64.exe",
@@ -15,7 +15,7 @@
15
15
  ]
16
16
  },
17
17
  "arm64": {
18
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.4/appwrite-cli-win-arm64.exe",
18
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/6.0.0-rc.5/appwrite-cli-win-arm64.exe",
19
19
  "bin": [
20
20
  [
21
21
  "appwrite-cli-win-arm64.exe",