Skip to content

Commit 930685c

Browse files
committed
feat(cli): headless project setup
1 parent 7efedaf commit 930685c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require("path");
33
const childProcess = require('child_process');
44
const { Command } = require("commander");
55
const inquirer = require("inquirer");
6-
const { projectsCreate } = require("./projects");
6+
const { projectsCreate, projectsGet } = require("./projects");
77
const { storageCreateBucket } = require("./storage");
88
const { messagingCreateTopic } = require("./messaging");
99
const { functionsCreate } = require("./functions");
@@ -23,7 +23,7 @@ const { accountGet } = require("./account");
2323
const { loginCommand } = require("./generic");
2424
const { sdkForConsole } = require("../sdks");
2525

26-
const initProject = async () => {
26+
const initProject = async ({ organizationId, projectId, projectName } = {}) => {
2727
let response = {};
2828

2929
try {
@@ -40,12 +40,22 @@ const initProject = async () => {
4040
log('You must login first')
4141
await loginCommand();
4242
}
43+
let answers = {};
4344

44-
const answers = await inquirer.prompt(questionsInitProject)
45-
if (answers.override === false) {
46-
process.exit(1)
45+
if (organizationId && projectId) {
46+
answers = {
47+
project: { id: projectId, name: projectName },
48+
organization: { id: organizationId },
49+
start: 'existing'
50+
}
51+
} else {
52+
answers = await inquirer.prompt(questionsInitProject)
53+
if (answers.override === false) {
54+
process.exit(1)
55+
}
4756
}
4857

58+
4959
if (answers.start === 'new') {
5060
response = await projectsCreate({
5161
projectId: answers.id,
@@ -201,7 +211,6 @@ const initFunction = async () => {
201211
}
202212

203213

204-
205214
const copyRecursiveSync = (src, dest) => {
206215
let exists = fs.existsSync(src);
207216
let stats = exists && fs.statSync(src);
@@ -254,6 +263,9 @@ const init = new Command("init")
254263
.configureHelp({
255264
helpWidth: process.stdout.columns || 80
256265
})
266+
.option("--organizationId <organizationId>", "{{ spec.title|caseUcfirst }} organization ID")
267+
.option("--projectId <projectId>", "{{ spec.title|caseUcfirst }} project ID")
268+
.option("--projectName <projectnName>", "{{ spec.title|caseUcfirst }} project name")
257269
.action(actionRunner(initProject));
258270

259271
init

0 commit comments

Comments
 (0)