@@ -9,6 +9,7 @@ const { storageCreateBucket } = require("./storage");
9
9
const { messagingCreateTopic } = require("./messaging");
10
10
const { functionsCreate } = require("./functions");
11
11
const { databasesCreateCollection } = require("./databases");
12
+ const { pullResources } = require("./pull");
12
13
const ID = require("../id");
13
14
const { localConfig, globalConfig } = require("../config");
14
15
const {
@@ -18,10 +19,11 @@ const {
18
19
questionsCreateMessagingTopic,
19
20
questionsCreateCollection,
20
21
questionsInitProject,
22
+ questionsInitProjectAutopull,
21
23
questionsInitResources,
22
24
questionsCreateTeam
23
25
} = require("../questions");
24
- const { success, log, error, actionRunner, commandDescriptions } = require("../parser");
26
+ const { cliConfig, success, log, hint , error, actionRunner, commandDescriptions } = require("../parser");
25
27
const { accountGet } = require("./account");
26
28
const { sdkForConsole } = require("../sdks");
27
29
@@ -56,7 +58,7 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
56
58
sdk: client
57
59
});
58
60
} catch (e) {
59
- error(' Error Session not found. Please run ` appwrite login` to create a session' );
61
+ error(" Error Session not found. Please run ' appwrite login' to create a session" );
60
62
process.exit(1);
61
63
}
62
64
@@ -104,11 +106,17 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
104
106
105
107
success(`Project successfully ${answers.start === 'existing' ? 'linked' : 'created'}. Details are now stored in appwrite.json file.`);
106
108
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
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.");
110
+ answers = await inquirer.prompt(questionsInitProjectAutopull);
111
+ if(answers.autopull) {
112
+ cliConfig.all = true;
113
+ await pullResources();
114
+ } else {
115
+ log("You can run 'appwrite pull all' to synchronize all of your existing resources.");
116
+ }
111
117
}
118
+
119
+ hint("Next you can use 'appwrite init' to create resources in your project, or use 'appwrite pull' and 'appwrite push' to synchronize your project.")
112
120
}
113
121
114
122
const initBucket = async () => {
@@ -210,22 +218,24 @@ const initFunction = async () => {
210
218
log(`Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.`);
211
219
}
212
220
213
-
214
221
fs.mkdirSync(functionDir, "777");
215
222
fs.mkdirSync(templatesDir, "777");
216
223
const repo = "https://github.com/{{ sdk .gitUserName }}/templates";
217
224
const api = `https://api.github.com/repos/{{ sdk .gitUserName }}/templates/contents/${answers.runtime.name}`
218
- const templates = ['starter'];
219
225
let selected = undefined;
220
226
221
- try {
222
- const res = await fetch(api);
223
- templates.push(...(await res.json()).map((template) => template.name));
224
-
225
- selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates))
226
- } catch {
227
- // Not a problem will go with directory pulling
228
- log('Loading templates...');
227
+ if(answers.template === 'starter') {
228
+ selected = { template: 'starter' };
229
+ } else {
230
+ try {
231
+ const res = await fetch(api);
232
+ const templates = [];
233
+ templates.push(...(await res.json()).map((template) => template.name));
234
+ selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates));
235
+ } catch {
236
+ // Not a problem will go with directory pulling
237
+ log('Loading templates...');
238
+ }
229
239
}
230
240
231
241
const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase();
@@ -257,6 +267,7 @@ const initFunction = async () => {
257
267
258
268
fs.rmSync(path.join(templatesDir, ".git"), { recursive: true });
259
269
if (!selected) {
270
+ const templates = [];
260
271
templates.push(...fs.readdirSync(runtimeDir, { withFileTypes: true })
261
272
.filter(item => item.isDirectory() && item.name !== 'starter')
262
273
.map(dirent => dirent.name));
0 commit comments