Skip to content
This repository has been archived by the owner on Apr 28, 2019. It is now read-only.

Commit

Permalink
Add regex check to ensure that --base is well-formatted.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonkearns committed Jan 6, 2018
1 parent 3d8b3a1 commit 2daa4ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,15 @@ if (args.version) {
console.log(version);
process.exit(0);
}
var baseArgRegex = /^[A-Z][a-z]*(\.[A-Z][a-z]*)*$/;
var baseModuleArg = args.base;
function isValidBaseArg(baseArg) {
return !!baseArg.match(baseArgRegex);
}
if (baseModuleArg && !isValidBaseArg(baseModuleArg)) {
console.log("--base was '" + baseModuleArg + "' but must be in format " + baseArgRegex);
process.exit(1);
}
var includeDeprecated = !!args.includeDeprecated;
var headerArg = args.header;
var addHeader = function (object, header) {
Expand Down Expand Up @@ -17238,7 +17246,7 @@ exports.introspectionQuery = "query IntrospectionQuery($includeDeprecated: Boole
/* 90 */
/***/ (function(module, exports) {

module.exports = {"name":"graphqelm","version":"0.0.11","scripts":{"build":"webpack","elm-nuke":"rm -rf elm-stuff && elm package install -y && cd tests && rm -rf elm-stuff && elm package install -y && cd ..","test":"elm-test","gen:starwars":"npm run build && cd examples && ../bin/graphqelm https://graphqelm.herokuapp.com --base Swapi && cd -","gen:normalize_test":"npm run build && cd ete_tests && ../bin/graphqelm http://localhost:4000 --base Normalize && cd -","gen:github":"npm run build && cd examples && ../bin/graphqelm https://api.github.com/graphql --header 'authorization: Bearer dbd4c239b0bbaa40ab0ea291fa811775da8f5b59' --base Github && cd -","approve":"npm run build && npm link && cd examples && graphqelm https://api.github.com/graphql --header 'authorization: Bearer dbd4c239b0bbaa40ab0ea291fa811775da8f5b59' --base Github && graphqelm https://graphqelm.herokuapp.com/api --base Swapi && cd - && echo 'Ensuring documentation is valid...' && elm-make --docs=documentation.json && echo 'Confirming that examples folder is clean...' && (git diff --exit-code -- examples || (echo 'FAILURE' && echo 'examples code has changed. Commit changes to approve.' && exit 1)) && echo 'SUCCESS'","elm-analyse":"elm-analyse --serve"},"keywords":["elm","graphql"],"repository":"https://github.com/dillonkearns/graphqelm","author":"Dillon Kearns","license":"BSD-3-Clause","devDependencies":{"@types/fs-extra":"^5.0.0","@types/minimist":"^1.2.0","@types/node":"^8.5.2","@types/request":"^2.0.9","@types/webpack":"^3.8.1","elm":"^0.18.0","elm-analyse":"^0.13.3","elm-hot-loader":"0.5.4","elm-test":"^0.18.12","elm-webpack-loader":"^4.3.1","fs-extra":"^5.0.0","ts-loader":"^3.2.0","typescript":"^2.6.2","webpack":"^3.10.0"},"dependencies":{"graphql-request":"^1.4.0","minimist":"^1.2.0","request":"^2.83.0","elm-format":"^0.7.0-exp"},"bin":{"graphqelm":"bin/graphqelm"}}
module.exports = {"name":"graphqelm","version":"0.0.12","scripts":{"build":"webpack","elm-nuke":"rm -rf elm-stuff && elm package install -y && cd tests && rm -rf elm-stuff && elm package install -y && cd ..","test":"elm-test","gen:starwars":"npm run build && cd examples && ../bin/graphqelm https://graphqelm.herokuapp.com --base Swapi && cd -","gen:normalize_test":"npm run build && cd ete_tests && ../bin/graphqelm http://localhost:4000 --base Normalize && cd -","gen:github":"npm run build && cd examples && ../bin/graphqelm https://api.github.com/graphql --header 'authorization: Bearer dbd4c239b0bbaa40ab0ea291fa811775da8f5b59' --base Github && cd -","approve":"npm run build && npm link && cd examples && graphqelm https://api.github.com/graphql --header 'authorization: Bearer dbd4c239b0bbaa40ab0ea291fa811775da8f5b59' --base Github && graphqelm https://graphqelm.herokuapp.com/api --base Swapi && cd - && echo 'Ensuring documentation is valid...' && elm-make --docs=documentation.json && echo 'Confirming that examples folder is clean...' && (git diff --exit-code -- examples || (echo 'FAILURE' && echo 'examples code has changed. Commit changes to approve.' && exit 1)) && echo 'SUCCESS'","elm-analyse":"elm-analyse --serve"},"keywords":["elm","graphql"],"repository":"https://github.com/dillonkearns/graphqelm","author":"Dillon Kearns","license":"BSD-3-Clause","devDependencies":{"@types/fs-extra":"^5.0.0","@types/minimist":"^1.2.0","@types/node":"^8.5.2","@types/request":"^2.0.9","@types/webpack":"^3.8.1","elm":"^0.18.0","elm-analyse":"^0.13.3","elm-hot-loader":"0.5.4","elm-test":"^0.18.12","elm-webpack-loader":"^4.3.1","fs-extra":"^5.0.0","ts-loader":"^3.2.0","typescript":"^2.6.2","webpack":"^3.10.0"},"dependencies":{"graphql-request":"^1.4.0","minimist":"^1.2.0","request":"^2.83.0","elm-format":"^0.7.0-exp"},"bin":{"graphqelm":"bin/graphqelm"}}

/***/ })
/******/ ]);
10 changes: 10 additions & 0 deletions src/graphqelm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ if (args.version) {
console.log(version)
process.exit(0)
}
const baseArgRegex = /^[A-Z][A-Za-z_]*(\.[A-Z][A-Za-z_]*)*$/
const baseModuleArg: undefined | string = args.base
function isValidBaseArg(baseArg: string): boolean {
return !!baseArg.match(baseArgRegex)
}
if (baseModuleArg && !isValidBaseArg(baseModuleArg)) {
console.log(
`--base was '${baseModuleArg}' but must be in format ${baseArgRegex}`
)
process.exit(1)
}
const includeDeprecated: boolean = !!args.includeDeprecated
const headerArg: undefined | string | [string] = args.header
const addHeader = (object: any, header: string) => {
Expand Down

0 comments on commit 2daa4ce

Please sign in to comment.