Skip to content

Commit

Permalink
feat: small tweaks (#729)
Browse files Browse the repository at this point in the history
* feat: small tweaks

filter out Upload from the generated scalars as that's apollo built-in one
do not use the 'latest' version of chimp when initializing or creating a chimp tooling

* test: e2e script updated
  • Loading branch information
lgandecki authored Jan 31, 2021
1 parent a710ccc commit 01566c6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 6 deletions.
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/tmp
node_modules
.idea
.eslintcache
3 changes: 3 additions & 0 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
// @ts-ignore
import shelljs from 'shelljs';
import { Command, flags } from '@oclif/command';
import { getChimpVersion } from '../helpers/get-chimp-version';

function updatePrefixes(appDirectory: string, appPrefix: string, generatedPrefix: string) {
if (appPrefix || generatedPrefix) {
Expand All @@ -29,6 +30,8 @@ function updatePrefixes(appDirectory: string, appPrefix: string, generatedPrefix
`chimp generate${gqlGenerateCustomPrefixString}`,
`${appDirectory}/package.json`,
);
const currentChimpVersion = getChimpVersion();
shelljs.sed('-i', '"chimp": "latest"', `"chimp": "${currentChimpVersion}"`, `${appDirectory}/package.json`);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { findProjectMainPath } from '../generate/helpers/findProjectMainPath';
import { ListrRenderer, newTask } from '../generate/helpers/ListrHelper';
import { assertModulePathInTopLevelSrc } from '../init/assert-module-path-in-top-level-src';
import { assertGitCleanState } from '../init/assert-git-clean-state';
import { getChimpVersion } from '../helpers/get-chimp-version';
const DEFAULT_MODULES_PATH = './src/modules';

const debug = configDebug('commands:init');
Expand All @@ -26,7 +27,7 @@ const addProjectDependencies = async (projectMainPath: string, modulesPath: stri
chimpCommand = `${chimpCommand} -p ${modulesPath}`;
// }
packageJsonFile.scripts.chimp = chimpCommand;
packageJsonFile.devDependencies.chimp = 'latest';
packageJsonFile.devDependencies.chimp = getChimpVersion();
}

function addDevDependenciesWithMatchingVersions(packages: string[]) {
Expand Down
27 changes: 27 additions & 0 deletions src/generate/parse-graphql/getScalars.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@ test('get the non extended types with apollo key annotation', () => {

expect(res).toEqual(['MyOwn']);
});

test('ignore built-in Upload scalar', () => {
const schemaString = gql`
type TodoItem @key(fields: "id") {
id: ID!
list: List
}
extend type List {
id: ID!
todos: [TodoItem!]!
incompleteCount: Int!
}
type InMemory {
id: ID!
}
scalar First
scalar Upload
scalar ThirdOne
`;

const res = getScalars(schemaString);

expect(res).toEqual(['First', 'ThirdOne']);
});
11 changes: 8 additions & 3 deletions src/generate/parse-graphql/getScalars.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import gql from 'graphql-tag';

export default (graphqlString: string) => {
export default (graphqlString: string): string[] => {
const graphqlAST = gql`
${graphqlString}
`;

// @ts-ignore
return graphqlAST.definitions.filter((d) => d.kind === 'ScalarTypeDefinition').map((f) => f.name.value);
return (
graphqlAST.definitions
.filter((d) => d.kind === 'ScalarTypeDefinition')
// @ts-ignore
.map((f) => f.name.value)
.filter((s) => s !== 'Upload')
);
};
9 changes: 9 additions & 0 deletions src/helpers/get-chimp-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-ignore
import finder from 'find-package-json';

export const getChimpVersion = () => {
const f = finder(__dirname);
const packageJson = f.next();

return packageJson.value.version;
};
2 changes: 1 addition & 1 deletion src/scripts/end-to-end-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ quietExec('./chimp/bin/run create chimp-test-repo', { cwd: pathToRunFrom });
shelljs.cp('-R', './test-module', '../chimp-test-repo/src/modules/');
const pathToRunFromChimp = path.join(process.cwd(), '../chimp-test-repo');
console.log('GOZDECKI pathToRunFromChimp', pathToRunFromChimp);
shelljs.sed('-i', /"chimp": "latest"/, '"chimp": "../chimp"', path.join(pathToRunFromChimp, 'package.json'));
shelljs.sed('-i', /"chimp": "0.0.0-development"/, '"chimp": "../chimp"', path.join(pathToRunFromChimp, 'package.json'));

quietExec('npm install', { cwd: pathToRunFromChimp });
quietExec('npm run type-check', { cwd: pathToRunFromChimp });
Expand Down

0 comments on commit 01566c6

Please sign in to comment.