Skip to content

Commit

Permalink
chore(cli): Adapting pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
byawitz committed May 29, 2024
1 parent b7f6f56 commit 0c1bc45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
36 changes: 18 additions & 18 deletions templates/cli/lib/commands/push.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ const { Command } = require("commander");
const { localConfig, globalConfig } = require("../config");
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
const { paginate } = require('../paginate');
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics } = require("../questions");
const { actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser");
const { cliConfig, actionRunner, success, log, error, commandDescriptions } = require("../parser");
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
const { cliConfig, actionRunner, success, log, error, commandDescriptions, drawTable } = require("../parser");
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
const {
databasesGet,
Expand All @@ -29,7 +28,6 @@ const {
databasesDeleteAttribute,
databasesListAttributes,
databasesListIndexes,
databasesDeleteIndex,
databasesUpdateCollection
} = require("./databases");
const {
Expand Down Expand Up @@ -376,7 +374,7 @@ const pushFunction = async ({ functionId, async } = {}) => {
if (functions.length === 0) {
throw new Error("No functions found in the current directory.");
}
functionIds.push(...functions.map((func, idx) => {
functionIds.push(...functions.map((func) => {
return func.$id;
}));
}
Expand Down Expand Up @@ -480,7 +478,7 @@ const pushFunction = async ({ functionId, async } = {}) => {
});
} catch (e) {

if (e.code == 404) {
if (Number(e.code) === 404) {
functionExists = false;
} else {
updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' });
Expand Down Expand Up @@ -835,15 +833,19 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection)
if (changing.length === 0) {
return changedAttributes;
}
log('There are pending changes in your collection deployment');

log(!cliConfig.force ? 'There are pending changes in your collection deployment' : 'List of applied changes');

drawTable(changing.map((change) => {
return { Key: change.key, Action: change.action, Reason: change.reason, };
}));

const answers = await inquirer.prompt(questionsPushCollections[1]);
if (!cliConfig.force) {
const answers = await inquirer.prompt(questionsPushCollections[1]);

if (answers.changes.toLowerCase() !== 'yes') {
return changedAttributes;
if (answers.changes.toLowerCase() !== 'yes') {
return changedAttributes;
}
}

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

// Parallel db actions
await Promise.all(databases.map(async (databaseId) => {
Expand Down Expand Up @@ -926,15 +929,13 @@ const pushCollection = async () => {
databaseId: collection['databaseId'],
collectionId: collection['$id'],
parseOutput: false,
});
});

if (remoteCollection.name !== collection.name) {
await databasesUpdateCollection({
databaseId: collection['databaseId'],
collectionId: collection['$id'],
name: collection.name,
name: collection.name,
parseOutput: false
})

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

collection.isExisted = true;
} catch (e) {
if (e.code == 404) {
if (Number(e.code) === 404) {
log(`Collection ${collection.name} does not exist in the project. Creating ... `);
await databasesCreateCollection({
databaseId: collection['databaseId'],
Expand Down Expand Up @@ -1092,7 +1093,6 @@ const pushBucket = async () => {
enabled: bucket.enabled,
maximumFileSize: bucket.maximumFileSize,
allowedFileExtensions: bucket.allowedFileExtensions,
compression: bucket.compression,
encryption: bucket.encryption,
antivirus: bucket.antivirus,
compression: bucket.compression,
Expand All @@ -1101,7 +1101,7 @@ const pushBucket = async () => {

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

response = await storageCreateBucket({
Expand Down Expand Up @@ -1172,15 +1172,15 @@ const pushTeam = async () => {

log(`Updating team ...`)

await teamsUpdate({
await teamsUpdateName({
teamId: team['$id'],
name: team.name,
parseOutput: false
});

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

response = await teamsCreate({
Expand Down Expand Up @@ -1257,7 +1257,7 @@ const pushMessagingTopic = async () => {

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

response = await messagingCreateTopic({
Expand Down
1 change: 0 additions & 1 deletion templates/cli/lib/questions.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { accountListMfaFactors } = require("./commands/account");
const { sdkForConsole } = require("./sdks");
const { validateRequired } = require("./validations");
const { paginate } = require('./paginate');
const chalk = require('chalk');
const { databasesList } = require('./commands/databases');
const { checkDeployConditions } = require('./utils');
const JSONbig = require("json-bigint")({ storeAsString: false });
Expand Down

0 comments on commit 0c1bc45

Please sign in to comment.