@@ -9,6 +9,7 @@ const { storageCreateBucket } = require("./storage");
99const { messagingCreateTopic } = require ( "./messaging" ) ;
1010const { functionsCreate } = require ( "./functions" ) ;
1111const { databasesCreateCollection } = require ( "./databases" ) ;
12+ const { pullResources } = require ( "./pull" ) ;
1213const ID = require ( "../id" ) ;
1314const { localConfig, globalConfig } = require ( "../config" ) ;
1415const {
@@ -18,10 +19,11 @@ const {
1819 questionsCreateMessagingTopic,
1920 questionsCreateCollection,
2021 questionsInitProject,
22+ questionsInitProjectAutopull,
2123 questionsInitResources,
2224 questionsCreateTeam
2325} = require ( "../questions" ) ;
24- const { success, log, error, actionRunner, commandDescriptions } = require ( "../parser" ) ;
26+ const { cliConfig , success, log, hint , error, actionRunner, commandDescriptions } = require ( "../parser" ) ;
2527const { accountGet } = require ( "./account" ) ;
2628const { sdkForConsole } = require ( "../sdks" ) ;
2729
@@ -56,7 +58,7 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
5658 sdk : client
5759 } ) ;
5860 } 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" ) ;
6062 process . exit ( 1 ) ;
6163 }
6264
@@ -104,11 +106,17 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
104106
105107 success ( `Project successfully ${ answers . start === 'existing' ? 'linked' : 'created' } . Details are now stored in appwrite.json file.` ) ;
106108
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-
109109 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+ }
111117 }
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." )
112120}
113121
114122const initBucket = async ( ) => {
@@ -210,22 +218,24 @@ const initFunction = async () => {
210218 log ( `Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.` ) ;
211219 }
212220
213-
214221 fs . mkdirSync ( functionDir , "777" ) ;
215222 fs . mkdirSync ( templatesDir , "777" ) ;
216223 const repo = "https://github.com/appwrite/templates" ;
217224 const api = `https://api.github.com/repos/appwrite/templates/contents/${ answers . runtime . name } `
218- const templates = [ 'starter' ] ;
219225 let selected = undefined ;
220226
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+ }
229239 }
230240
231241 const sparse = ( selected ? `${ answers . runtime . name } /${ selected . template } ` : answers . runtime . name ) . toLowerCase ( ) ;
@@ -257,6 +267,7 @@ const initFunction = async () => {
257267
258268 fs . rmSync ( path . join ( templatesDir , ".git" ) , { recursive : true } ) ;
259269 if ( ! selected ) {
270+ const templates = [ ] ;
260271 templates . push ( ...fs . readdirSync ( runtimeDir , { withFileTypes : true } )
261272 . filter ( item => item . isDirectory ( ) && item . name !== 'starter' )
262273 . map ( dirent => dirent . name ) ) ;
0 commit comments