Skip to content

Create Organisation using CLI #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { storageListBuckets } = require("./storage");
const { sdkForConsole } = require("../sdks");
const { localConfig } = require("../config");
const { paginate } = require("../paginate");
const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
const { questionsInitProject, questionsInitTeams, questionsInitFunction, questionsInitCollection } = require("../questions");
const { success, log, actionRunner, commandDescriptions } = require("../parser");

const init = new Command("init")
Expand Down Expand Up @@ -222,16 +222,32 @@ const initBucket = async () => {
}

const initTeam = async () => {
const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');
let response = {}
const answers = await inquirer.prompt(questionsInitTeams)
if (!answers.team) process.exit(1)

log(`Found ${teams.length} teams`);
let sdk = await sdkForConsole();

teams.forEach(async team => {
log(`Fetching ${team.name} ...`);
const { total, $updatedAt, $createdAt, prefs, ...rest } = team;
localConfig.addTeam(rest);
});
if (answers.start === "new"){
response = await teamsCreate({
teamId: 'unique()',
name: answers.team,
sdk,
parseOutput: false
})

localConfig.addTeam(response['$id'], response.name);
}else{
const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');

log(`Found ${teams.length} teams`);

teams.forEach(async team => {
log(`Fetching ${team.name} ...`);
const { total, $updatedAt, $createdAt, prefs, ...rest } = team;
localConfig.addTeam(rest);
});
}
success();
}

Expand Down
67 changes: 67 additions & 0 deletions lib/questions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { localConfig } = require('./config');
const { teamsList } = require('./commands/teams');
const { projectsList } = require('./commands/projects');
const { functionsListRuntimes } = require('./commands/functions');
const { accountListMfaFactors } = require("./commands/account");
Expand Down Expand Up @@ -372,6 +373,71 @@ const questionsGetEntrypoint = [
},
]

const questionsInitTeams = [
{
type: "list",
name: "start",
message: "Would you like to create a new organization?",
choices: [
{
name: "Create a new Appwrite organization",
value: "new",
},
{
name: "Link this directory to an existing Appwrite organization",
value: "existing"
}
],
},
{
type: "input",
name: "name",
message: "What would you like to name your organization?",
default: "My Awesome Organization",
when(answers) {
return answers.start == "new";
},
},
{
type: "input",
name: "id",
message: "What ID would like to have for your organization?",
default: "unique()",
when(answers) {
return answers.start == "new";
}
},
{
type: "list",
name: "organization",
message: "Choose your Appwrite organization.",
when(answers) {
return answers.start == "existing";
},
choices: async () => {
let response = await teamsList({
parseOutput: false
})
let teams = response["teams"]
let choices = teams.map((team, idx) => {
return {
name: `${team.name} (${team['$id']})`,
value: {
name: team.name,
id: team['$id']
}
}
})

if (choices.length == 0){
throw new Error("No organization found. Please create a new organization")
}

return choices;
}
},
]

const questionsDeployTeams = [
{
type: "checkbox",
Expand Down Expand Up @@ -453,6 +519,7 @@ module.exports = {
questionsLogin,
questionsInitFunction,
questionsInitCollection,
questionsInitTeams,
questionsDeployFunctions,
questionsDeployCollections,
questionsDeployBuckets,
Expand Down