1 | #! /usr/bin/env node
|
2 | "use strict";
|
3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const spawn = require("cross-spawn");
|
13 | const fs = require("fs-extra");
|
14 | const glob = require("glob");
|
15 | const path = require("path");
|
16 | const util = require("util");
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function libDir(cwd) {
|
26 | const lib = path.resolve(cwd, "lib");
|
27 | const src = path.resolve(cwd, "src");
|
28 | if (fs.existsSync(lib)) {
|
29 | return lib;
|
30 | }
|
31 | else if (fs.existsSync(src)) {
|
32 | return src;
|
33 | }
|
34 | else {
|
35 | return lib;
|
36 | }
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | function main() {
|
42 | return __awaiter(this, void 0, void 0, function* () {
|
43 | try {
|
44 | const cwd = process.cwd();
|
45 | const lib = libDir(cwd);
|
46 |
|
47 | const customSchemaLocation = path.join(lib, "graphql", "schema.json");
|
48 | const defaultSchemaLocation = path.join(cwd, "node_modules", "@atomist", "automation-client", "lib", "graph", "schema.json");
|
49 | const schema = fs.existsSync(customSchemaLocation) ? customSchemaLocation : defaultSchemaLocation;
|
50 | const gqlGenCmd = path.join(cwd, "node_modules", ".bin", "gql-gen") +
|
51 | ((process.platform === "win32") ? ".cmd" : "");
|
52 | const gqlGenOutput = path.join(lib, "typings", "types.ts");
|
53 | const gqlGenArgs = [
|
54 | "--file", schema,
|
55 | "--template", "typescript",
|
56 | "--no-schema",
|
57 | "--out", gqlGenOutput,
|
58 | ];
|
59 | const opts = {
|
60 | cwd,
|
61 | env: process.env,
|
62 | stdio: "inherit",
|
63 | };
|
64 | const graphQlGlob = `${lib}/graphql/!(ingester)/*.graphql`;
|
65 | const graphqlFiles = yield util.promisify(glob)(graphQlGlob);
|
66 | if (graphqlFiles && graphqlFiles.length > 0) {
|
67 | gqlGenArgs.push(graphQlGlob);
|
68 | }
|
69 | else {
|
70 | console.info("No GraphQL files found in project, generating default types");
|
71 | }
|
72 | const cp = spawn(gqlGenCmd, gqlGenArgs, opts);
|
73 | cp.on("exit", (code, signal) => {
|
74 | if (code === 0) {
|
75 | process.exit(code);
|
76 | }
|
77 | else if (code) {
|
78 | console.error(`Generating GraphQL failed with non-zero status: ${code}`);
|
79 | process.exit(code);
|
80 | }
|
81 | else {
|
82 | console.error(`Generating GraphQL exited due to signal: ${signal}`);
|
83 | process.exit(128 + 2);
|
84 | }
|
85 | });
|
86 | cp.on("error", err => {
|
87 | console.error(`Generating GraphQL types errored: ${err.message}`);
|
88 | process.exit(2);
|
89 | });
|
90 | }
|
91 | catch (e) {
|
92 | console.error(`Generating GraphQL types failed: ${e.message}`);
|
93 | process.exit(1);
|
94 | }
|
95 | });
|
96 | }
|
97 | main()
|
98 | .catch((err) => {
|
99 | console.error(`Unhandled exception: ${err.message}`);
|
100 | process.exit(101);
|
101 | });
|
102 |
|
\ | No newline at end of file |