Skip to content

Commit c772d4f

Browse files
committed
Changes after manual QA
1 parent d907ef8 commit c772d4f

File tree

10 files changed

+334
-213
lines changed

10 files changed

+334
-213
lines changed

composer.lock

Lines changed: 181 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/cli/install.ps1.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ function CleanUp {
7979
function InstallCompleted {
8080
Write-Host "[4/4] Finishing Installation ... "
8181
cleanup
82-
Write-Host "🤘 May the force be with you."
8382
Write-Host "To get started with {{ spec.title | caseUcfirst }} CLI, please visit {{ sdk.url }}/docs/command-line"
83+
Write-Host "As first step, you can login to your {{ spec.title | caseUcfirst }} account using 'appwrite login'"
8484
}
8585

8686

templates/cli/install.sh.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ cleanup() {
139139
installCompleted() {
140140
echo "[4/4] Wrapping up installation ... "
141141
cleanup
142-
printf "🤘 May the force be with you. \n"
143142
echo "🚀 To get started with {{ spec.title | caseUcfirst }} CLI, please visit {{ sdk.url }}/docs/command-line"
143+
echo "As first step, you can login to your {{ spec.title | caseUcfirst }} account using 'appwrite login'"
144144
}
145145

146146
# Installation Starts here

templates/cli/lib/commands/generic.js.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
8989
}
9090

9191
success("Signed in as user with ID: " + account.$id);
92+
info("Next you can create or link to your project using 'appwrite init project'");
9293
};
9394

9495
const whoami = new Command("whoami")

templates/cli/lib/commands/init.js.twig

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,31 @@ const {
1717
questionsCreateBucket,
1818
questionsCreateMessagingTopic,
1919
questionsCreateCollection,
20-
questionsInitProject
20+
questionsInitProject,
21+
questionsInitResources,
22+
questionsCreateTeam
2123
} = require("../questions");
22-
const { success, log, error, actionRunner } = require("../parser");
24+
const { success, log, error, actionRunner, commandDescriptions } = require("../parser");
2325
const { accountGet } = require("./account");
2426
const { sdkForConsole } = require("../sdks");
2527

28+
const initResources = async () => {
29+
const actions = {
30+
function: initFunction,
31+
collection: initCollection,
32+
bucket: initBucket,
33+
team: initTeam,
34+
message: initTopic
35+
}
36+
37+
const answers = await inquirer.prompt(questionsInitResources[0]);
38+
39+
const action = actions[answers.resource];
40+
if (action !== undefined) {
41+
await action({ returnOnZero: true });
42+
}
43+
};
44+
2645
const initProject = async ({ organizationId, projectId, projectName } = {}) => {
2746
let response = {};
2847

@@ -83,7 +102,13 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
83102
localConfig.setProject(answers.project);
84103
}
85104

86-
success();
105+
success(`Project successfully ${answers.start === 'existing' ? 'linked' : 'created'}. Details are now stored in appwrite.json file.`);
106+
107+
log("Next you can use 'appwrite init' to create resources in your project, or use 'appwrite pull' and 'appwite push' to synchronize your project.")
108+
109+
if(answers.start === 'existing') {
110+
log("Since you connected to an existing project, we highly recommend to run 'appwrite pull all' to synchronize all of your existing resources.");
111+
}
87112
}
88113

89114
const initBucket = async () => {
@@ -96,23 +121,36 @@ const initBucket = async () => {
96121
enabled: true,
97122
});
98123
success();
124+
log("Next you can use 'appwrite push bucket' to deploy the changes.");
125+
};
126+
127+
const initTeam = async () => {
128+
const answers = await inquirer.prompt(questionsCreateTeam)
129+
130+
localConfig.addTeam({
131+
$id: answers.id === 'unique()' ? ID.unique() : answers.id,
132+
name: answers.bucket,
133+
});
134+
135+
success();
136+
log("Next you can use 'appwrite push team' to deploy the changes.");
99137
};
100138

101139
const initCollection = async () => {
102140
const answers = await inquirer.prompt(questionsCreateCollection)
103141
const newDatabase = (answers.method ?? '').toLowerCase() !== 'existing';
104142

105143
if (!newDatabase) {
106-
answers.databaseId = answers.database.$id;
107-
answers.databaseName = answers.database.name;
144+
answers.databaseId = answers.database;
145+
answers.databaseName = localConfig.getDatabase(answers.database).name;
108146
}
109147

110-
const databaseId = answers.database_id === 'unique()' ? ID.unique() : answers.database_id;
148+
const databaseId = answers.databaseId === 'unique()' ? ID.unique() : answers.databaseId;
111149

112-
if (newDatabase || !localConfig.getDatabase(answers.database_id).$id) {
150+
if (newDatabase || !localConfig.getDatabase(answers.databaseId)) {
113151
localConfig.addDatabase({
114152
$id: databaseId,
115-
name: answers.database_name,
153+
name: answers.databaseName,
116154
enabled: true
117155
});
118156
}
@@ -128,6 +166,7 @@ const initCollection = async () => {
128166
});
129167

130168
success();
169+
log("Next you can use 'appwrite push collection' to deploy the changes.");
131170
};
132171

133172
const initTopic = async () => {
@@ -140,6 +179,7 @@ const initTopic = async () => {
140179
});
141180

142181
success();
182+
log("Next you can use 'appwrite push topic' to deploy the changes.");
143183
};
144184

145185
const initFunction = async () => {
@@ -175,7 +215,7 @@ const initFunction = async () => {
175215
fs.mkdirSync(templatesDir, "777");
176216
const repo = "https://github.com/{{ sdk.gitUserName }}/templates";
177217
const api = `https://api.github.com/repos/{{ sdk.gitUserName }}/templates/contents/${answers.runtime.name}`
178-
const templates = ['Starter'];
218+
const templates = ['starter'];
179219
let selected = undefined;
180220

181221
try {
@@ -188,13 +228,12 @@ const initFunction = async () => {
188228
log('Loading templates...');
189229
}
190230

191-
const sparse = selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name;
231+
const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase();
192232

193233
let gitInitCommands = `git clone --single-branch --depth 1 --sparse ${repo} .`; // depth prevents fetching older commits reducing the amount fetched
194234

195235
let gitPullCommands = `git sparse-checkout add ${sparse}`;
196236

197-
198237
/* Force use CMD as powershell does not support && */
199238
if (process.platform === 'win32') {
200239
gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
@@ -273,36 +312,48 @@ const initFunction = async () => {
273312

274313
localConfig.addFunction(data);
275314
success();
276-
log(`* Use 'appwrite dev function' for local development\n${' '.repeat(7)}* Use 'appwrite push functions' to push the function to your {{ spec.title|caseUcfirst }} instance`)
315+
log("Next you can use 'appwrite run function' to develop a function locally. To deploy the function, use 'appwrite push function'");
277316
}
278317

279318
const init = new Command("init")
280-
.description('Init an {{ spec.title|caseUcfirst }} project')
281-
.configureHelp({
282-
helpWidth: process.stdout.columns || 80
283-
})
319+
.description(commandDescriptions['init'])
320+
.action(actionRunner(initResources));
321+
322+
init
323+
.command("project")
324+
.description("Init a new {{ spec.title|caseUcfirst }} project")
284325
.option("--organizationId <organizationId>", "{{ spec.title|caseUcfirst }} organization ID")
285326
.option("--projectId <projectId>", "{{ spec.title|caseUcfirst }} project ID")
286327
.option("--projectName <projectName>", "{{ spec.title|caseUcfirst }} project ID")
287328
.action(actionRunner(initProject));
288329

289330
init
290331
.command("function")
332+
.alias("functions")
291333
.description("Init a new {{ spec.title|caseUcfirst }} function")
292334
.action(actionRunner(initFunction));
293335

294336
init
295337
.command("bucket")
338+
.alias("buckets")
296339
.description("Init a new {{ spec.title|caseUcfirst }} bucket")
297340
.action(actionRunner(initBucket));
298341

342+
init
343+
.command("team")
344+
.alias("teams")
345+
.description("Init a new {{ spec.title|caseUcfirst }} team")
346+
.action(actionRunner(initTeam));
347+
299348
init
300349
.command("collection")
350+
.alias("collections")
301351
.description("Init a new {{ spec.title|caseUcfirst }} collection")
302352
.action(actionRunner(initCollection));
303353

304354
init
305355
.command("topic")
356+
.alias("topics")
306357
.description("Init a new {{ spec.title|caseUcfirst }} topic")
307358
.action(actionRunner(initTopic));
308359

templates/cli/lib/commands/pull.js.twig

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ const pullResources = async () => {
3030
} else {
3131
const answers = await inquirer.prompt(questionsPullResources[0]);
3232

33-
for (let resource of answers.resources) {
34-
const action = actions[resource];
35-
if (action !== undefined) {
36-
await action();
37-
}
33+
const action = actions[answers.resource];
34+
if (action !== undefined) {
35+
await action({ returnOnZero: true });
3836
}
3937
}
4038
};
@@ -183,15 +181,15 @@ const pullMessagingTopic = async () => {
183181

184182
const pull = new Command("pull")
185183
.description(commandDescriptions['pull'])
186-
.configureHelp({
187-
helpWidth: process.stdout.columns || 80
188-
});
184+
.action(actionRunner(pullResources));
189185

190186
pull
191187
.command("all")
192188
.description("Pull all resource.")
193-
.action(actionRunner(pullResources));
194-
189+
.action(actionRunner(() => {
190+
cliConfig.all = true;
191+
return pullResources();
192+
}));
195193

196194
pull
197195
.command("project")

templates/cli/lib/commands/push.js.twig

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,9 @@ const pushResources = async () => {
580580
} else {
581581
const answers = await inquirer.prompt(questionsPushResources[0]);
582582

583-
for (let resource of answers.resources) {
584-
const action = actions[resource];
585-
if (action !== undefined) {
586-
await action({ returnOnZero: true });
587-
}
583+
const action = actions[answers.resource];
584+
if (action !== undefined) {
585+
await action({ returnOnZero: true });
588586
}
589587
}
590588
};
@@ -593,9 +591,9 @@ const pushProject = async () => {
593591
try {
594592
const projectId = localConfig.getProject().projectId;
595593
const projectName = localConfig.getProject().projectName;
596-
const settings = localConfig.getProject().projectSettings;
594+
const settings = localConfig.getProject().projectSettings ?? {};
597595

598-
log(`Updating project ${projectName} ( ${projectId} )`);
596+
log(`Updating project ${projectId}`);
599597

600598
if (projectName) {
601599
await projectsUpdate({
@@ -605,7 +603,6 @@ const pushProject = async () => {
605603
});
606604
}
607605

608-
609606
if (settings.services) {
610607
log('Updating service statuses');
611608
for (let [service, status] of Object.entries(settings.services)) {
@@ -643,7 +640,7 @@ const pushProject = async () => {
643640
}
644641
}
645642

646-
success();
643+
success("Project configuration updated.");
647644
} catch (e) {
648645
throw e;
649646
}
@@ -664,7 +661,7 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero
664661
log('No functions found, skipping');
665662
return;
666663
}
667-
throw new Error("No functions found in the current directory.");
664+
throw new Error("No functions found in the current directory. Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one.");
668665
}
669666
functionIds.push(...functions.map((func) => {
670667
return func.$id;
@@ -970,7 +967,7 @@ const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => {
970967
return;
971968
}
972969

973-
throw new Error("No collections found in the current directory. Run `{{ language.params.executableName }} pull collection` to fetch all your collections.");
970+
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.");
974971
}
975972
collections.push(...localConfig.getCollections());
976973
} else {
@@ -1102,7 +1099,7 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => {
11021099
log('No buckets found, skipping');
11031100
return;
11041101
}
1105-
throw new Error("No buckets found in the current directory. Run `appwrite pull bucket` to fetch all your buckets.");
1102+
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.");
11061103
}
11071104
bucketIds.push(...configBuckets.map((b) => b.$id));
11081105
}
@@ -1127,15 +1124,6 @@ const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => {
11271124
bucketId: bucket['$id'],
11281125
parseOutput: false,
11291126
})
1130-
log(`Bucket ${bucket.name} ( ${bucket['$id']} ) already exists.`);
1131-
1132-
if (!cliConfig.force) {
1133-
const answers = await inquirer.prompt(questionsPushBuckets[1])
1134-
if (answers.override.toLowerCase() !== "yes") {
1135-
log(`Received "${answers.override}". Skipping ${bucket.name} ( ${bucket['$id']} )`);
1136-
continue;
1137-
}
1138-
}
11391127

11401128
log(`Updating bucket ...`)
11411129

@@ -1193,7 +1181,7 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => {
11931181
log('No teams found, skipping');
11941182
return;
11951183
}
1196-
throw new Error("No teams found in the current directory. Run `appwrite pull team` to fetch all your teams.");
1184+
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.");
11971185
}
11981186
teamIds.push(...configTeams.map((t) => t.$id));
11991187
}
@@ -1218,15 +1206,6 @@ const pushTeam = async ({ returnOnZero } = { returnOnZero: false }) => {
12181206
teamId: team['$id'],
12191207
parseOutput: false,
12201208
})
1221-
log(`Team ${team.name} ( ${team['$id']} ) already exists.`);
1222-
1223-
if (!cliConfig.force) {
1224-
const answers = await inquirer.prompt(questionsPushTeams[1])
1225-
if (answers.override.toLowerCase() !== "yes") {
1226-
log(`Received "${answers.override}". Skipping ${team.name} ( ${team['$id']} )`);
1227-
continue;
1228-
}
1229-
}
12301209

12311210
log(`Updating team ...`)
12321211

@@ -1269,7 +1248,7 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
12691248
log('No topics found, skipping');
12701249
return;
12711250
}
1272-
throw new Error("No topics found in the current directory. Run `appwrite pull topics` to pull all your messaging topics.");
1251+
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.");
12731252
}
12741253
topicsIds.push(...configTopics.map((b) => b.$id));
12751254
}
@@ -1338,14 +1317,16 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
13381317
}
13391318

13401319
const push = new Command("push")
1341-
.alias('deploy')
13421320
.description(commandDescriptions['push'])
13431321
.action(actionRunner(pushResources));
13441322

13451323
push
13461324
.command("all")
13471325
.description("Push all resource.")
1348-
.action(actionRunner(pushResources));
1326+
.action(actionRunner(() => {
1327+
cliConfig.all = true;
1328+
return pushResources();
1329+
}));
13491330

13501331
push
13511332
.command("project")

0 commit comments

Comments
 (0)