@@ -2,7 +2,7 @@ const inquirer = require("inquirer");
22const JSONbig = require("json-bigint")({ storeAsString: false });
33const { Command } = require("commander");
44const { localConfig } = require("../config");
5- const { questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
5+ const { questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
66const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
77const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
88const {
@@ -25,6 +25,11 @@ const {
2525 databasesListIndexes,
2626 databasesDeleteIndex
2727} = require("./databases");
28+ const {
29+ teamsGet,
30+ teamsUpdate,
31+ teamsCreate
32+ } = require("./teams");
2833
2934const POOL_DEBOUNCE = 2000; // in milliseconds
3035const POOL_MAX_DEBOUNCES = 30;
@@ -593,6 +598,76 @@ const deployCollection = async ({ all, yes } = {}) => {
593598 }
594599}
595600
601+ const deployTeam = async ({ all, yes } = {}) => {
602+ let response = {};
603+
604+ let teamIds = [];
605+ const configTeams = localConfig.getTeams();
606+
607+ if(all) {
608+ if (configTeams.length === 0) {
609+ throw new Error("No teams found in the current directory. Run `appwrite init team` to fetch all your teams.");
610+ }
611+ teamIds.push(...configTeams.map((t) => t.$id));
612+ }
613+
614+ if(teamIds.length === 0) {
615+ let answers = await inquirer.prompt(questionsDeployTeams[0])
616+ teamIds.push(...answers.teams);
617+ }
618+
619+ let teams = [];
620+
621+ for(const teamId of teamIds) {
622+ const idTeams = configTeams.filter((t) => t.$id === teamId);
623+ teams.push(...idTeams);
624+ }
625+
626+ for (let team of teams) {
627+ log(`Deploying team ${team.name} ( ${team['$id']} )`)
628+
629+ try {
630+ response = await teamsGet({
631+ teamId: team['$id'],
632+ parseOutput: false,
633+ })
634+ log(`Team ${team.name} ( ${team['$id']} ) already exists.`);
635+
636+ if(!yes) {
637+ answers = await inquirer.prompt(questionsDeployTeams[1])
638+ if (answers.override !== "YES") {
639+ log(`Received "${answers.override}". Skipping ${team.name} ( ${team['$id']} )`);
640+ continue;
641+ }
642+ }
643+
644+ log(`Updating team ...`)
645+
646+ await teamsUpdate({
647+ teamId: team['$id'],
648+ name: team.name,
649+ parseOutput: false
650+ });
651+
652+ success(`Deployed ${team.name} ( ${team['$id']} )`);
653+ } catch (e) {
654+ if (e.code == 404) {
655+ log(`Team ${team.name} does not exist in the project. Creating ... `);
656+
657+ response = await teamsCreate({
658+ teamId: team['$id'],
659+ name: team.name,
660+ parseOutput: false
661+ })
662+
663+ success(`Deployed ${team.name} ( ${team['$id']} )`);
664+ } else {
665+ throw e;
666+ }
667+ }
668+ }
669+ }
670+
596671deploy
597672 .command("function")
598673 .description("Deploy functions in the current directory.")
@@ -608,6 +683,13 @@ deploy
608683 .option(`--yes`, `Flag to confirm all warnings`)
609684 .action(actionRunner(deployCollection));
610685
686+ deploy
687+ .command("team")
688+ .description("Deploy teams in the current project.")
689+ .option(`--all`, `Flag to deploy all teams`)
690+ .option(`--yes`, `Flag to confirm all warnings`)
691+ .action(actionRunner(deployTeam));
692+
611693module.exports = {
612694 deploy
613695}
0 commit comments