Skip to content

Commit 6540a21

Browse files
committed
Merge branch 'refs/heads/feat-cli-g2' into feat-deploy-init-everything
# Conflicts: # templates/cli/lib/commands/push.js.twig # templates/cli/lib/questions.js.twig
2 parents 329acc3 + 9276294 commit 6540a21

File tree

9 files changed

+199
-134
lines changed

9 files changed

+199
-134
lines changed

src/SDK/Language/CLI.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ public function getFiles(): array
127127
'destination' => 'lib/questions.js',
128128
'template' => 'cli/lib/questions.js.twig',
129129
],
130+
[
131+
'scope' => 'default',
132+
'destination' => 'lib/validations.js',
133+
'template' => 'cli/lib/validations.js.twig',
134+
],
130135
[
131136
'scope' => 'default',
132137
'destination' => 'lib/parser.js',
@@ -152,20 +157,25 @@ public function getFiles(): array
152157
'destination' => 'lib/client.js',
153158
'template' => 'cli/lib/client.js.twig',
154159
],
160+
[
161+
'scope' => 'default',
162+
'destination' => 'lib/id.js',
163+
'template' => 'cli/lib/id.js.twig',
164+
],
155165
[
156166
'scope' => 'default',
157167
'destination' => 'lib/utils.js',
158168
'template' => 'cli/lib/utils.js.twig',
159169
],
160170
[
161171
'scope' => 'default',
162-
'destination' => 'lib/commands/init.js',
163-
'template' => 'cli/lib/commands/init.js.twig',
172+
'destination' => 'lib/commands/pull.js',
173+
'template' => 'cli/lib/commands/pull.js.twig',
164174
],
165175
[
166176
'scope' => 'default',
167-
'destination' => 'lib/commands/deploy.js',
168-
'template' => 'cli/lib/commands/deploy.js.twig',
177+
'destination' => 'lib/commands/push.js',
178+
'template' => 'cli/lib/commands/push.js.twig',
169179
],
170180
[
171181
'scope' => 'service',

templates/cli/index.js.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const { commandDescriptions, cliConfig } = require("./lib/parser");
1212
const { client } = require("./lib/commands/generic");
1313
{% if sdk.test != "true" %}
1414
const { login, logout } = require("./lib/commands/generic");
15-
const { init } = require("./lib/commands/init");
16-
const { deploy } = require("./lib/commands/deploy");
15+
const { pull } = require("./lib/commands/pull");
16+
const { push } = require("./lib/commands/push");
1717
{% endif %}
1818
{% for service in spec.services %}
1919
const { {{ service.name | caseLower }} } = require("./lib/commands/{{ service.name | caseLower }}");
@@ -37,14 +37,14 @@ program
3737
.showSuggestionAfterError()
3838
{% if sdk.test != "true" %}
3939
.addCommand(login)
40-
.addCommand(init)
41-
.addCommand(deploy)
40+
.addCommand(pull)
41+
.addCommand(push)
4242
.addCommand(logout)
4343
{% endif %}
4444
{% for service in spec.services %}
4545
.addCommand({{ service.name | caseLower }})
4646
{% endfor %}
4747
.addCommand(client)
4848
.parse(process.argv);
49-
50-
process.stdout.columns = oldWidth;
49+
50+
process.stdout.columns = oldWidth;

templates/cli/lib/commands/init.js.twig renamed to templates/cli/lib/commands/pull.js.twig

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat
1010
const { storageListBuckets } = require("./storage");
1111
const { sdkForConsole } = require("../sdks");
1212
const { localConfig } = require("../config");
13+
const ID = require("../id");
1314
const { paginate } = require("../paginate");
14-
const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
15+
const { questionsPullProject, questionsPullFunction, questionsPullCollection } = require("../questions");
1516
const { success, log, actionRunner, commandDescriptions } = require("../parser");
1617

17-
const init = new Command("init")
18-
.description(commandDescriptions['init'])
18+
const pull = new Command("pull")
19+
.description(commandDescriptions['pull'])
1920
.configureHelp({
2021
helpWidth: process.stdout.columns || 80
2122
})
2223
.action(actionRunner(async (_options, command) => {
2324
command.help();
2425
}));
2526

26-
const initProject = async () => {
27+
const pullProject = async () => {
2728
let response = {}
28-
const answers = await inquirer.prompt(questionsInitProject)
29+
const answers = await inquirer.prompt(questionsPullProject)
2930
if (!answers.project) process.exit(1)
3031

3132
let sdk = await sdkForConsole();
@@ -52,9 +53,9 @@ const initProject = async () => {
5253
success();
5354
}
5455

55-
const initFunction = async () => {
56+
const pullFunction = async () => {
5657
// TODO: Add CI/CD support (ID, name, runtime)
57-
const answers = await inquirer.prompt(questionsInitFunction)
58+
const answers = await inquirer.prompt(questionsPullFunction)
5859
const functionFolder = path.join(process.cwd(), 'functions');
5960

6061
if (!fs.existsSync(functionFolder)) {
@@ -63,22 +64,23 @@ const initFunction = async () => {
6364
});
6465
}
6566

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);
6769

6870
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.`);
7072
}
7173

7274
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.`);
7476
}
7577

7678
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.`);
7880
}
7981

8082
let response = await functionsCreate({
81-
functionId: answers.id,
83+
functionId,
8284
name: answers.name,
8385
runtime: answers.runtime.id,
8486
entrypoint: answers.runtime.entrypoint || '',
@@ -134,7 +136,7 @@ const initFunction = async () => {
134136

135137
fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
136138

137-
const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
139+
const readmePath = path.join(process.cwd(), 'functions', functionId, 'README.md');
138140
const readmeFile = fs.readFileSync(readmePath).toString();
139141
const newReadmeFile = readmeFile.split('\n');
140142
newReadmeFile[0] = `# ${answers.name}`;
@@ -154,14 +156,14 @@ const initFunction = async () => {
154156
entrypoint: response.entrypoint,
155157
commands: response.commands,
156158
ignore: answers.runtime.ignore || null,
157-
path: `functions/${answers.name}`,
159+
path: `functions/${functionId}`,
158160
};
159161

160162
localConfig.addFunction(data);
161163
success();
162164
}
163165

164-
const initCollection = async ({ all, databaseId } = {}) => {
166+
const pullCollection = async ({ all, databaseId } = {}) => {
165167
const databaseIds = [];
166168

167169
if (databaseId) {
@@ -175,7 +177,7 @@ const initCollection = async ({ all, databaseId } = {}) => {
175177
}
176178

177179
if (databaseIds.length <= 0) {
178-
let answers = await inquirer.prompt(questionsInitCollection)
180+
let answers = await inquirer.prompt(questionsPullCollection)
179181
if (!answers.databases) process.exit(1)
180182
databaseIds.push(...answers.databases);
181183
}
@@ -208,7 +210,7 @@ const initCollection = async ({ all, databaseId } = {}) => {
208210
success();
209211
}
210212

211-
const initBucket = async () => {
213+
const pullBucket = async () => {
212214
const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
213215

214216
log(`Found ${buckets.length} buckets`);
@@ -221,7 +223,7 @@ const initBucket = async () => {
221223
success();
222224
}
223225

224-
const initTeam = async () => {
226+
const pullTeam = async () => {
225227
const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');
226228

227229
log(`Found ${teams.length} teams`);
@@ -235,33 +237,33 @@ const initTeam = async () => {
235237
success();
236238
}
237239

238-
init
240+
pull
239241
.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));
242244

243-
init
245+
pull
244246
.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))
247249

248-
init
250+
pull
249251
.command("collection")
250-
.description("Initialise your {{ spec.title|caseUcfirst }} collections")
252+
.description("Pulling your {{ spec.title|caseUcfirst }} collections")
251253
.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))
254256

255-
init
257+
pull
256258
.command("bucket")
257-
.description("Initialise your Appwrite buckets")
258-
.action(actionRunner(initBucket))
259+
.description("Pulling your Appwrite buckets")
260+
.action(actionRunner(pullBucket))
259261

260-
init
262+
pull
261263
.command("team")
262-
.description("Initialise your Appwrite teams")
263-
.action(actionRunner(initTeam))
264+
.description("Pulling your Appwrite teams")
265+
.action(actionRunner(pullTeam))
264266

265267
module.exports = {
266-
init,
268+
pull,
267269
};

0 commit comments

Comments
 (0)