Skip to content

Commit c7b3ce4

Browse files
authored
Merge pull request #78 from graphql-editor/stucco
adding stucco command for sending stucco file to the cloud
2 parents f667be0 + 13f8893 commit c7b3ce4

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { logger } from '@/common/log/index.js';
2+
import { Config } from '@/Configuration/index.js';
3+
import { Editor } from '@/Editor.js';
4+
import {
5+
CLOUD_FOLDERS,
6+
STUCCO_FILE,
7+
} from '@/gshared/constants/index.js';
8+
import path from 'path';
9+
import fs from 'fs';
10+
11+
export const pushStuccoJson = async ({ namespace, project }: { namespace?: string; project?: string }) => {
12+
const resolve = await Config.configure({ namespace, project }, ['namespace', 'project']);
13+
const p = await Editor.fetchProject({ accountName: resolve.namespace, projectName: resolve.project });
14+
if (!p.team?.id) {
15+
throw new Error('No team for this project. Invalid project');
16+
}
17+
logger('Pushing the stucco file to cloud', 'info');
18+
await Editor.saveFilesToCloud(
19+
p.id,
20+
[{
21+
name: path.join(CLOUD_FOLDERS.microserviceJs, STUCCO_FILE),
22+
content: fs.readFileSync(STUCCO_FILE),
23+
type: 'text/plain',
24+
}]
25+
);
26+
logger('Successfully uploaded stucco file to GraphQL Editor Cloud', 'success');
27+
return;
28+
};

packages/cli/src/index.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import ExternalCI from '@/commands/externalCi/CLI.js';
2020
import { confOptions, projectOptions } from '@/common/promptOptions.js';
2121
import { CommandPrune } from '@/commands/common/prune.js';
2222
import { CommandInspect } from '@/commands/common/inspect.js';
23+
import { pushStuccoJson } from '@/commands/cloud/pushStuccoJson.js';
2324

2425
welcome().then(() => {
2526
new Configuration();
@@ -51,15 +52,15 @@ welcome().then(() => {
5152
.command(
5253
'login',
5354
'Login to GraphQL Editor',
54-
async (yargs) => {},
55+
async (yargs) => { },
5556
async (argv) => {
5657
await Auth.login().then(Config.setTokenOptions);
5758
},
5859
)
5960
.command(
6061
'logout',
6162
'Logout from GraphQL Editor',
62-
async (yargs) => {},
63+
async (yargs) => { },
6364
(argv) => {
6465
Auth.logout();
6566
},
@@ -92,15 +93,15 @@ welcome().then(() => {
9293
.command(
9394
'prune',
9495
'Get information about redundant resolvers that do not exist in schema now.',
95-
async (yargs) => {},
96+
async (yargs) => { },
9697
async (argv) => {
9798
await CommandPrune();
9899
},
99100
)
100101
.command(
101102
'inspect',
102103
'Get information about non-scalar resolvers that are not implemented in stucco.json',
103-
async (yargs) => {},
104+
async (yargs) => { },
104105
async (argv) => {
105106
await CommandInspect();
106107
},
@@ -113,14 +114,24 @@ welcome().then(() => {
113114
.command(
114115
'dev',
115116
'Start Typescript server and stucco server with hot reload.',
116-
async (yargs) => {},
117+
async (yargs) => { },
117118
async (argv) => {
118119
CommandDev();
119120
},
120121
)
121122
.command('token', 'Get CI token', async (argv) => {
122123
await CommandGetCIToken();
123124
})
125+
.command(
126+
'stucco',
127+
'Update your stucco file to cloud for synchronizing resolvers',
128+
async (yargs) => { },
129+
async (argv) => {
130+
await pushStuccoJson(
131+
argv as Pick<ConfigurationOptions, 'project' | 'namespace'>,
132+
);
133+
},
134+
)
124135
.showHelpOnFail(true)
125136
.demandCommand()
126137
.version()

0 commit comments

Comments
 (0)