Skip to content

Commit 0c1bc45

Browse files
committed
chore(cli): Adapting pull request
1 parent b7f6f56 commit 0c1bc45

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

templates/cli/lib/commands/push.js.twig

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ const { Command } = require("commander");
55
const { localConfig, globalConfig } = require("../config");
66
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
77
const { paginate } = require('../paginate');
8-
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics } = require("../questions");
9-
const { actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser");
10-
const { cliConfig, actionRunner, success, log, error, commandDescriptions } = require("../parser");
8+
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
9+
const { cliConfig, actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser");
1110
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
1211
const {
1312
databasesGet,
@@ -29,7 +28,6 @@ const {
2928
databasesDeleteAttribute,
3029
databasesListAttributes,
3130
databasesListIndexes,
32-
databasesDeleteIndex,
3331
databasesUpdateCollection
3432
} = require("./databases");
3533
const {
@@ -376,7 +374,7 @@ const pushFunction = async ({ functionId, async } = {}) => {
376374
if (functions.length === 0) {
377375
throw new Error("No functions found in the current directory.");
378376
}
379-
functionIds.push(...functions.map((func, idx) => {
377+
functionIds.push(...functions.map((func) => {
380378
return func.$id;
381379
}));
382380
}
@@ -480,7 +478,7 @@ const pushFunction = async ({ functionId, async } = {}) => {
480478
});
481479
} catch (e) {
482480

483-
if (e.code == 404) {
481+
if (Number(e.code) === 404) {
484482
functionExists = false;
485483
} else {
486484
updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' });
@@ -835,15 +833,19 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection)
835833
if (changing.length === 0) {
836834
return changedAttributes;
837835
}
838-
log('There are pending changes in your collection deployment');
836+
837+
log(!cliConfig.force ? 'There are pending changes in your collection deployment' : 'List of applied changes');
838+
839839
drawTable(changing.map((change) => {
840840
return { Key: change.key, Action: change.action, Reason: change.reason, };
841841
}));
842842

843-
const answers = await inquirer.prompt(questionsPushCollections[1]);
843+
if (!cliConfig.force) {
844+
const answers = await inquirer.prompt(questionsPushCollections[1]);
844845

845-
if (answers.changes.toLowerCase() !== 'yes') {
846-
return changedAttributes;
846+
if (answers.changes.toLowerCase() !== 'yes') {
847+
return changedAttributes;
848+
}
847849
}
848850

849851
if (conflicts.length > 0) {
@@ -888,6 +890,7 @@ const pushCollection = async () => {
888890
})
889891
}
890892
const databases = Array.from(new Set(collections.map(collection => collection['databaseId'])));
893+
log('Checking for databases and collection changes');
891894

892895
// Parallel db actions
893896
await Promise.all(databases.map(async (databaseId) => {
@@ -926,15 +929,13 @@ const pushCollection = async () => {
926929
databaseId: collection['databaseId'],
927930
collectionId: collection['$id'],
928931
parseOutput: false,
929-
});
930932
});
931933

932934
if (remoteCollection.name !== collection.name) {
933935
await databasesUpdateCollection({
934936
databaseId: collection['databaseId'],
935937
collectionId: collection['$id'],
936938
name: collection.name,
937-
name: collection.name,
938939
parseOutput: false
939940
})
940941

@@ -944,7 +945,7 @@ const pushCollection = async () => {
944945

945946
collection.isExisted = true;
946947
} catch (e) {
947-
if (e.code == 404) {
948+
if (Number(e.code) === 404) {
948949
log(`Collection ${collection.name} does not exist in the project. Creating ... `);
949950
await databasesCreateCollection({
950951
databaseId: collection['databaseId'],
@@ -1092,7 +1093,6 @@ const pushBucket = async () => {
10921093
enabled: bucket.enabled,
10931094
maximumFileSize: bucket.maximumFileSize,
10941095
allowedFileExtensions: bucket.allowedFileExtensions,
1095-
compression: bucket.compression,
10961096
encryption: bucket.encryption,
10971097
antivirus: bucket.antivirus,
10981098
compression: bucket.compression,
@@ -1101,7 +1101,7 @@ const pushBucket = async () => {
11011101

11021102
success(`Pushed ${bucket.name} ( ${bucket['$id']} )`);
11031103
} catch (e) {
1104-
if (e.code == 404) {
1104+
if (Number(e.code) === 404) {
11051105
log(`Bucket ${bucket.name} does not exist in the project. Creating ... `);
11061106

11071107
response = await storageCreateBucket({
@@ -1172,15 +1172,15 @@ const pushTeam = async () => {
11721172

11731173
log(`Updating team ...`)
11741174

1175-
await teamsUpdate({
1175+
await teamsUpdateName({
11761176
teamId: team['$id'],
11771177
name: team.name,
11781178
parseOutput: false
11791179
});
11801180

11811181
success(`Pushed ${team.name} ( ${team['$id']} )`);
11821182
} catch (e) {
1183-
if (e.code == 404) {
1183+
if (Number(e.code) === 404) {
11841184
log(`Team ${team.name} does not exist in the project. Creating ... `);
11851185

11861186
response = await teamsCreate({
@@ -1257,7 +1257,7 @@ const pushMessagingTopic = async () => {
12571257

12581258
success(`Pushed ${topic.name} ( ${topic['$id']} )`);
12591259
} catch (e) {
1260-
if (e.code == 404) {
1260+
if (Number(e.code) === 404) {
12611261
log(`Topic ${topic.name} does not exist in the project. Creating ... `);
12621262

12631263
response = await messagingCreateTopic({

templates/cli/lib/questions.js.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const { accountListMfaFactors } = require("./commands/account");
77
const { sdkForConsole } = require("./sdks");
88
const { validateRequired } = require("./validations");
99
const { paginate } = require('./paginate');
10-
const chalk = require('chalk');
1110
const { databasesList } = require('./commands/databases');
1211
const { checkDeployConditions } = require('./utils');
1312
const JSONbig = require("json-bigint")({ storeAsString: false });

0 commit comments

Comments
 (0)