Skip to content

Commit 7a10919

Browse files
Merge pull request #720 from adarshjhaa100/feat-87-hint-where-to-run-init-and-deploy-command
feat: give a hint to run init and deploy command
2 parents af7e4b5 + e95ffaa commit 7a10919

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const {
3737
teamsUpdate,
3838
teamsCreate
3939
} = require("./teams");
40+
const { checkDeployConditions } = require('../utils');
4041

4142
const STEP_SIZE = 100; // Resources
4243
const POOL_DEBOUNCE = 2000; // Milliseconds
@@ -245,6 +246,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
245246
functionIds.push(functionId);
246247
} else if (all) {
247248
const functions = localConfig.getFunctions();
249+
checkDeployConditions(localConfig);
248250
if (functions.length === 0) {
249251
throw new Error("No functions found in the current directory.");
250252
}
@@ -535,6 +537,7 @@ const deployCollection = async ({ all, yes } = {}) => {
535537
const collections = [];
536538

537539
if (all) {
540+
checkDeployConditions(localConfig);
538541
if (localConfig.getCollections().length === 0) {
539542
throw new Error("No collections found in the current directory. Run `{{ language.params.executableName }} init collection` to fetch all your collections.");
540543
}
@@ -757,9 +760,7 @@ const deployBucket = async ({ all, yes } = {}) => {
757760
const configBuckets = localConfig.getBuckets();
758761

759762
if (all) {
760-
if (configBuckets.length === 0) {
761-
throw new Error("No buckets found in the current directory. Run `appwrite init bucket` to fetch all your buckets.");
762-
}
763+
checkDeployConditions(localConfig);
763764
bucketIds.push(...configBuckets.map((b) => b.$id));
764765
}
765766

@@ -844,9 +845,7 @@ const deployTeam = async ({ all, yes } = {}) => {
844845
const configTeams = localConfig.getTeams();
845846

846847
if (all) {
847-
if (configTeams.length === 0) {
848-
throw new Error("No teams found in the current directory. Run `appwrite init team` to fetch all your teams.");
849-
}
848+
checkDeployConditions(localConfig);
850849
teamIds.push(...configTeams.map((t) => t.$id));
851850
}
852851

templates/cli/lib/questions.js.twig

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { accountListMfaFactors } = require("./commands/account");
55
const { sdkForConsole } = require("./sdks");
66

77
const { databasesList } = require('./commands/databases');
8+
const { checkDeployConditions } = require('./utils');
89
const JSONbig = require("json-bigint")({ storeAsString: false });
910

1011
const getIgnores = (runtime) => {
@@ -209,12 +210,12 @@ const questionsInitFunction = [
209210
parseOutput: false
210211
})
211212
let runtimes = response["runtimes"]
212-
let choices = runtimes.map((runtime, idx) => {
213+
let choices = runtimes.map((runtime, idx) => {
213214
return {
214215
name: `${runtime.name} (${runtime['$id']})`,
215-
value: {
216-
id: runtime['$id'],
217-
entrypoint: getEntrypoint(runtime['$id']),
216+
value: {
217+
id: runtime['$id'],
218+
entrypoint: getEntrypoint(runtime['$id']),
218219
ignore: getIgnores(runtime['$id']),
219220
commands : getInstallCommand(runtime['$id'])
220221
},
@@ -283,6 +284,7 @@ const questionsDeployFunctions = [
283284
message: "Which functions would you like to deploy?",
284285
choices: () => {
285286
let functions = localConfig.getFunctions();
287+
checkDeployConditions(localConfig)
286288
if (functions.length === 0) {
287289
throw new Error("No functions found in the current directory.");
288290
}
@@ -309,6 +311,8 @@ const questionsDeployCollections = [
309311
message: "Which collections would you like to deploy?",
310312
choices: () => {
311313
let collections = localConfig.getCollections();
314+
checkDeployConditions(localConfig)
315+
312316
if (collections.length === 0) {
313317
throw new Error("No collections found in the current directory. Run `{{ language.params.executableName }} init collection` to fetch all your collections.");
314318
}
@@ -334,6 +338,7 @@ const questionsDeployBuckets = [
334338
message: "Which buckets would you like to deploy?",
335339
choices: () => {
336340
let buckets = localConfig.getBuckets();
341+
checkDeployConditions(localConfig)
337342
if (buckets.length === 0) {
338343
throw new Error("No buckets found in the current directory. Run `appwrite init bucket` to fetch all your buckets.");
339344
}
@@ -374,6 +379,7 @@ const questionsDeployTeams = [
374379
message: "Which teams would you like to deploy?",
375380
choices: () => {
376381
let teams = localConfig.getTeams();
382+
checkDeployConditions(localConfig);
377383
if (teams.length === 0) {
378384
throw new Error("No teams found in the current directory. Run `appwrite init team` to fetch all your teams.");
379385
}

templates/cli/lib/utils.js.twig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ function getAllFiles(folder) {
1414
return files;
1515
}
1616

17+
const checkDeployConditions = (localConfig) => {
18+
if (Object.keys(localConfig.data).length === 0) {
19+
throw new Error("No appwrite.json file found in the current directory. This command must be run in the folder holding your appwrite.json file. Please run this command again in the folder containing your appwrite.json file, or run appwrite init project.");
20+
}
21+
}
22+
1723
module.exports = {
18-
getAllFiles
24+
getAllFiles,
25+
checkDeployConditions
1926
};

0 commit comments

Comments
 (0)