@@ -44,7 +44,7 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
44
44
45
45
if (organizationId && projectId && projectName) {
46
46
answers = {
47
- project: { id: projectId, name: projectName},
47
+ project: { id: projectId, name: projectName },
48
48
organization: { id: organizationId },
49
49
start: 'existing'
50
50
}
@@ -86,62 +86,59 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
86
86
}
87
87
88
88
const initBucket = async () => {
89
- let response = {}
90
89
const answers = await inquirer.prompt(questionsCreateBucket)
91
90
92
- try {
93
- response = await storageCreateBucket({
94
- bucketId: answers.id,
95
- name: answers.bucket,
96
- fileSecurity: answers.fileSecurity.toLowerCase() === 'yes',
97
- enabled: true,
98
- parseOutput: false
99
- })
100
-
101
- localConfig.addBucket(response);
102
- success();
103
- } catch (e) {
104
- error(e.getMessage ?? 'Unknown error occurred. Please try again');
105
- }
91
+ localConfig.addBucket({
92
+ $id: answers.id === 'unique()' ? ID.unique() : answers.id,
93
+ name: answers.bucket,
94
+ fileSecurity: answers.fileSecurity.toLowerCase() === 'yes',
95
+ enabled: true,
96
+ });
97
+ success();
106
98
};
107
99
108
100
const initCollection = async () => {
109
- let response = {}
110
101
const answers = await inquirer.prompt(questionsCreateCollection)
102
+ const newDatabase = (answers.method ?? '').toLowerCase() !== 'existing';
111
103
112
- try {
113
- response = await databasesCreateCollection({
114
- databaseId: answers.database,
115
- collectionId: answers.id,
116
- name: answers.collection,
117
- documentSecurity: answers.documentSecurity.toLowerCase() === 'yes',
118
- enabled: true,
119
- parseOutput: false
120
- })
104
+ if (!newDatabase) {
105
+ answers.database_id = answers.database.$id;
106
+ answers.database_name = answers.database.name;
107
+ }
121
108
122
- localConfig.addCollection(response);
123
- success();
124
- } catch (e) {
125
- error(e.getMessage ?? 'Unknown error occurred. Please try again');
109
+ const databaseId = answers.database_id === 'unique()' ? ID.unique() : answers.database_id;
110
+
111
+ if (newDatabase || !localConfig.getDatabase(answers.database_id).$id) {
112
+ localConfig.addDatabase({
113
+ $id: databaseId,
114
+ name: answers.database_name,
115
+ enabled: true
116
+ });
126
117
}
118
+
119
+ localConfig.addCollection({
120
+ $id: answers.id === 'unique()' ? ID.unique() : answers.id,
121
+ databaseId: databaseId,
122
+ name: answers.collection,
123
+ documentSecurity: answers.documentSecurity.toLowerCase() === 'yes',
124
+ attributes: [],
125
+ indexes: [],
126
+ enabled: true,
127
+ });
128
+
129
+ success();
127
130
};
128
131
129
132
const initTopic = async () => {
130
- let response = {}
131
133
const answers = await inquirer.prompt(questionsCreateMessagingTopic)
132
134
133
- try {
134
- response = await messagingCreateTopic({
135
- topicId: answers.id,
136
- name: answers.topic,
137
- parseOutput: false
138
- })
135
+ localConfig.addMessagingTopic({
136
+ $id: answers.id === 'unique()' ? ID.unique() : answers.id,
137
+ name: answers.topic,
139
138
140
- localConfig.addMessagingTopic(response);
141
- success();
142
- } catch (e) {
143
- error(e.message ?? 'Unknown error occurred. Please try again');
144
- }
139
+ });
140
+
141
+ success();
145
142
};
146
143
147
144
const initFunction = async () => {
@@ -172,14 +169,7 @@ const initFunction = async () => {
172
169
log(`Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.`);
173
170
}
174
171
175
- let response = await functionsCreate({
176
- functionId,
177
- name: answers.name,
178
- runtime: answers.runtime.id,
179
- entrypoint: answers.runtime.entrypoint || '',
180
- commands: answers.runtime.commands || '',
181
- parseOutput: false
182
- })
172
+
183
173
184
174
fs.mkdirSync(functionDir, "777");
185
175
fs.mkdirSync(templatesDir, "777");
@@ -252,17 +242,17 @@ const initFunction = async () => {
252
242
fs.writeFileSync(readmePath, newReadmeFile.join('\n'));
253
243
254
244
let data = {
255
- $id: response['$id'] ,
256
- name: response .name,
257
- runtime: response .runtime,
258
- execute: response.execute ,
259
- events: response.events ,
260
- schedule: response.schedule ,
261
- timeout: response.timeout ,
262
- enabled: response.enabled ,
263
- logging: response.logging ,
264
- entrypoint: response. entrypoint,
265
- commands: response. commands,
245
+ $id: functionId ,
246
+ name: answers .name,
247
+ runtime: answers .runtime.id ,
248
+ execute: [] ,
249
+ events: [] ,
250
+ schedule: "" ,
251
+ timeout: 15 ,
252
+ enabled: true ,
253
+ logging: true ,
254
+ entrypoint: answers.runtime. entrypoint || '' ,
255
+ commands: answers.runtime. commands || '' ,
266
256
ignore: answers.runtime.ignore || null,
267
257
path: `functions/${functionId}`,
268
258
};
0 commit comments