@@ -10,22 +10,23 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat
10
10
const { storageListBuckets } = require("./storage");
11
11
const { sdkForConsole } = require("../sdks");
12
12
const { localConfig } = require("../config");
13
+ const ID = require("../id");
13
14
const { paginate } = require("../paginate");
14
- const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
15
+ const { questionsPullProject, questionsPullFunction, questionsPullCollection } = require("../questions");
15
16
const { success, log, actionRunner, commandDescriptions } = require("../parser");
16
17
17
- const init = new Command("init ")
18
- .description(commandDescriptions['init '])
18
+ const pull = new Command("pull ")
19
+ .description(commandDescriptions['pull '])
19
20
.configureHelp({
20
21
helpWidth: process.stdout.columns || 80
21
22
})
22
23
.action(actionRunner(async (_options, command) => {
23
24
command.help();
24
25
}));
25
26
26
- const initProject = async () => {
27
+ const pullProject = async () => {
27
28
let response = {}
28
- const answers = await inquirer.prompt(questionsInitProject )
29
+ const answers = await inquirer.prompt(questionsPullProject )
29
30
if (!answers.project) process.exit(1)
30
31
31
32
let sdk = await sdkForConsole();
@@ -52,9 +53,9 @@ const initProject = async () => {
52
53
success();
53
54
}
54
55
55
- const initFunction = async () => {
56
+ const pullFunction = async () => {
56
57
// TODO: Add CI/CD support (ID, name, runtime)
57
- const answers = await inquirer.prompt(questionsInitFunction )
58
+ const answers = await inquirer.prompt(questionsPullFunction )
58
59
const functionFolder = path.join(process.cwd(), 'functions');
59
60
60
61
if (!fs.existsSync(functionFolder)) {
@@ -63,22 +64,23 @@ const initFunction = async () => {
63
64
});
64
65
}
65
66
66
- const functionDir = path.join(functionFolder, answers.name);
67
+ const functionId = answers.id === 'unique()' ? ID.unique() : answers.id;
68
+ const functionDir = path.join(functionFolder, functionId);
67
69
68
70
if (fs.existsSync(functionDir)) {
69
- throw new Error(`( ${answers.name } ) already exists in the current directory. Please choose another name.`);
71
+ throw new Error(`( ${functionId } ) already exists in the current directory. Please choose another name.`);
70
72
}
71
73
72
74
if (!answers.runtime.entrypoint) {
73
- log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first deploy the function.`);
75
+ log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first push the function.`);
74
76
}
75
77
76
78
if (!answers.runtime.commands) {
77
- log(`Installation command for this runtime not found. You will be asked to configure the install command when you first deploy the function.`);
79
+ log(`Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.`);
78
80
}
79
81
80
82
let response = await functionsCreate({
81
- functionId: answers.id ,
83
+ functionId,
82
84
name: answers.name,
83
85
runtime: answers.runtime.id,
84
86
entrypoint: answers.runtime.entrypoint || '',
@@ -134,7 +136,7 @@ const initFunction = async () => {
134
136
135
137
fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
136
138
137
- const readmePath = path.join(process.cwd(), 'functions', answers.name , 'README.md');
139
+ const readmePath = path.join(process.cwd(), 'functions', functionId , 'README.md');
138
140
const readmeFile = fs.readFileSync(readmePath).toString();
139
141
const newReadmeFile = readmeFile.split('\n');
140
142
newReadmeFile[0] = `# ${answers.name}`;
@@ -154,14 +156,14 @@ const initFunction = async () => {
154
156
entrypoint: response.entrypoint,
155
157
commands: response.commands,
156
158
ignore: answers.runtime.ignore || null,
157
- path: `functions/${answers.name }`,
159
+ path: `functions/${functionId }`,
158
160
};
159
161
160
162
localConfig.addFunction(data);
161
163
success();
162
164
}
163
165
164
- const initCollection = async ({ all, databaseId } = {}) => {
166
+ const pullCollection = async ({ all, databaseId } = {}) => {
165
167
const databaseIds = [];
166
168
167
169
if (databaseId) {
@@ -175,7 +177,7 @@ const initCollection = async ({ all, databaseId } = {}) => {
175
177
}
176
178
177
179
if (databaseIds.length < = 0) {
178
- let answers = await inquirer.prompt(questionsInitCollection )
180
+ let answers = await inquirer.prompt(questionsPullCollection )
179
181
if (!answers.databases) process.exit(1)
180
182
databaseIds.push(...answers.databases);
181
183
}
@@ -208,7 +210,7 @@ const initCollection = async ({ all, databaseId } = {}) => {
208
210
success();
209
211
}
210
212
211
- const initBucket = async () => {
213
+ const pullBucket = async () => {
212
214
const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
213
215
214
216
log(`Found ${buckets.length} buckets`);
@@ -221,7 +223,7 @@ const initBucket = async () => {
221
223
success();
222
224
}
223
225
224
- const initTeam = async () => {
226
+ const pullTeam = async () => {
225
227
const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');
226
228
227
229
log(`Found ${teams.length} teams`);
@@ -235,33 +237,33 @@ const initTeam = async () => {
235
237
success();
236
238
}
237
239
238
- init
240
+ pull
239
241
.command("project")
240
- .description("Initialise your {{ spec .title | caseUcfirst }} project")
241
- .action(actionRunner(initProject ));
242
+ .description("Pulling your {{ spec .title | caseUcfirst }} project")
243
+ .action(actionRunner(pullProject ));
242
244
243
- init
245
+ pull
244
246
.command("function")
245
- .description("Initialise your {{ spec .title | caseUcfirst }} cloud function")
246
- .action(actionRunner(initFunction ))
247
+ .description("Pulling your {{ spec .title | caseUcfirst }} cloud function")
248
+ .action(actionRunner(pullFunction ))
247
249
248
- init
250
+ pull
249
251
.command("collection")
250
- .description("Initialise your {{ spec .title | caseUcfirst }} collections")
252
+ .description("Pulling your {{ spec .title | caseUcfirst }} collections")
251
253
.option(`--databaseId <databaseId >`, `Database ID`)
252
- .option(`--all`, `Flag to initialize all databases`)
253
- .action(actionRunner(initCollection ))
254
+ .option(`--all`, `Flag to pullialize all databases`)
255
+ .action(actionRunner(pullCollection ))
254
256
255
- init
257
+ pull
256
258
.command("bucket")
257
- .description("Initialise your Appwrite buckets")
258
- .action(actionRunner(initBucket ))
259
+ .description("Pulling your Appwrite buckets")
260
+ .action(actionRunner(pullBucket ))
259
261
260
- init
262
+ pull
261
263
.command("team")
262
- .description("Initialise your Appwrite teams")
263
- .action(actionRunner(initTeam ))
264
+ .description("Pulling your Appwrite teams")
265
+ .action(actionRunner(pullTeam ))
264
266
265
267
module.exports = {
266
- init ,
268
+ pull ,
267
269
};
0 commit comments