Skip to content

Commit

Permalink
Merge pull request #33 from mondaycom/feature/romka/setup-installer-d…
Browse files Browse the repository at this point in the history
…etection

yarn/npm detection in setup-api
  • Loading branch information
RomKadria authored Jul 9, 2024
2 parents 2354d5b + d3b78a8 commit 603c12f
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This monorepo contains all the packages for the monday.com GraphQL SDKs. Currently, it holds the following packages:

- [@mondaydotcomorg/api](./packages/api)
- [@mondaydotcomorg/api-types](./packages/api-types)
- [@mondaydotcomorg/setup-api](./packages/setup-api)
- [@mondaydotcomorg/api](./packages/api) - Our official sdk, used to make api calls
- [@mondaydotcomorg/api-types](./packages/api-types) - Types
- [@mondaydotcomorg/setup-api](./packages/setup-api) - After installing the api, use this to setup typed api environment

## Usage of generated code

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@ export const getBoards = gql`

const data = await SeamlessApiClient.query<GetBoardsQuery>(getBoards, variables);
```

### Type support

note that after usage, you'l get all the available fields, with no regard to the fields you asked for

![alt text](./public/image.png)

**But there's a solution, look [here!](https://www.npmjs.com/package/@mondaydotcomorg/setup-api)**
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mondaydotcomorg/api",
"version": "4.0.0",
"version": "4.0.2",
"description": "monday.com API client",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -37,7 +37,6 @@
"graphql-tag": "^2.12.6"
},
"devDependencies": {
"moment": "^2.30.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand All @@ -46,6 +45,7 @@
"@types/jest": "^29.5.12",
"@types/node": "^20.11.18",
"jest": "^29.7.0",
"moment": "^2.30.1",
"rollup": "^2.79.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^4.2.3",
Expand Down
Binary file added packages/api/public/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/setup-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

This library automates the setup of a development environment for working with the Monday API using GraphQL. It's designed to help developers quickly start projects with pre-configured tools and settings.

## Whats the end result?

You can start writing qeuries with auto complete on the types of your queries

![alt text](./public/image-1.png)

After usage, you can get only what you asked for

![alt text](./public/image-2.png)

## What does the script do?

The script gets the environment ready for graphql api development
Expand Down
19 changes: 13 additions & 6 deletions packages/setup-api/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import * as shell from 'shelljs';
import * as fs from 'fs';

export const installPackages = () => {
const commands = [
'npm install graphql-request',
'npm install --save-dev @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations',
];
const isYarn = fs.existsSync('yarn.lock');

const installCommands = isYarn
? [
'yarn add graphql-request',
'yarn add -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations',
]
: [
'npm install graphql-request',
'npm install --save-dev @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations',
];

commands.forEach((command) => {
export const installPackages = () => {
installCommands.forEach((command) => {
if (shell.exec(command).code !== 0) {
console.error(`Error executing command: ${command}`);
shell.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/setup-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mondaydotcomorg/setup-api",
"version": "1.0.2",
"version": "1.1.1",
"description": "monday.com setup api cli",
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
Expand Down
Binary file added packages/setup-api/public/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/setup-api/public/image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions packages/setup-api/tests/setup-graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { createFiles, installPackages, updatePackageJsonScripts } from '../lib/i
import * as shell from 'shelljs';
import * as fs from 'fs';

const useYarn = shell.which('yarn');
const packageManager = useYarn ? 'yarn' : 'npm';
const installCommand = useYarn ? 'add' : 'install';
const devFlag = useYarn ? '-D' : '--save-dev';

jest.mock('shelljs', () => ({
exec: jest.fn().mockReturnValue({ code: 0 }),
exit: jest.fn(),
mkdir: jest.fn(),
which: jest.fn().mockReturnValue(true),
}));

jest.mock('fs', () => ({
Expand All @@ -20,16 +26,18 @@ describe('setupGraphQL', () => {
jest.clearAllMocks();
});

it('should execute npm install commands', () => {
it('should install the necessary packages with appropriate package manager', () => {
installPackages();
expect(shell.exec).toHaveBeenCalledWith(expect.stringContaining('npm install graphql-request'));

expect(shell.exec).toHaveBeenCalledWith(
expect.stringContaining(`${packageManager} ${installCommand} graphql-request`),
);
expect(shell.exec).toHaveBeenCalledWith(
expect.stringContaining(
'npm install --save-dev @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations',
`${packageManager} ${installCommand} ${devFlag} @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations`,
),
);
});

it('should create necessary files', () => {
createFiles();
expect(fs.writeFileSync).toHaveBeenCalledWith('codegen.yml', expect.any(String));
Expand Down

0 comments on commit 603c12f

Please sign in to comment.