@effect-gql/cli 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs ADDED
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ var effect = require('effect');
4
+ var core = require('@effect-gql/core');
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
27
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
28
+
29
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
30
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
31
+ }) : x)(function(x) {
32
+ if (typeof require !== "undefined") return require.apply(this, arguments);
33
+ throw Error('Dynamic require of "' + x + '" is not supported');
34
+ });
35
+ var loadSchema = (modulePath) => effect.Effect.gen(function* () {
36
+ const absolutePath = path__namespace.resolve(process.cwd(), modulePath);
37
+ if (!fs__namespace.existsSync(absolutePath)) {
38
+ return yield* effect.Effect.fail(new Error(`File not found: ${absolutePath}`));
39
+ }
40
+ const module = yield* effect.Effect.tryPromise({
41
+ try: async () => {
42
+ const resolved = __require.resolve(absolutePath);
43
+ delete __require.cache[resolved];
44
+ try {
45
+ return await import(absolutePath);
46
+ } catch {
47
+ return __require(absolutePath);
48
+ }
49
+ },
50
+ catch: (error) => new Error(`Failed to load module: ${error}`)
51
+ });
52
+ const exported = module.builder ?? module.schema ?? module.default;
53
+ if (!exported) {
54
+ return yield* effect.Effect.fail(
55
+ new Error(
56
+ `Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`
57
+ )
58
+ );
59
+ }
60
+ if (typeof exported.buildSchema === "function") {
61
+ return exported.buildSchema();
62
+ }
63
+ if (exported.getQueryType && exported.getTypeMap) {
64
+ return exported;
65
+ }
66
+ return yield* effect.Effect.fail(
67
+ new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)
68
+ );
69
+ });
70
+ var generateSDL = (schema, options = {}) => {
71
+ const finalSchema = options.sort !== false ? core.lexicographicSortSchema(schema) : schema;
72
+ return core.printSchema(finalSchema);
73
+ };
74
+ var generateSDLFromModule = (modulePath, options = {}) => loadSchema(modulePath).pipe(effect.Effect.map((schema) => generateSDL(schema, options)));
75
+
76
+ exports.generateSDL = generateSDL;
77
+ exports.generateSDLFromModule = generateSDLFromModule;
78
+ exports.loadSchema = loadSchema;
79
+ //# sourceMappingURL=index.cjs.map
80
+ //# sourceMappingURL=index.cjs.map
package/index.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/generate-schema.ts"],"names":["Effect","path","fs","lexicographicSortSchema","printSchema"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCO,IAAM,UAAA,GAAa,CAAC,UAAA,KACzBA,aAAA,CAAO,IAAI,aAAa;AACtB,EAAA,MAAM,YAAA,GAAoBC,eAAA,CAAA,OAAA,CAAQ,OAAA,CAAQ,GAAA,IAAO,UAAU,CAAA;AAG3D,EAAA,IAAI,CAAIC,aAAA,CAAA,UAAA,CAAW,YAAY,CAAA,EAAG;AAChC,IAAA,OAAO,OAAOF,cAAO,IAAA,CAAK,IAAI,MAAM,CAAA,gBAAA,EAAmB,YAAY,EAAE,CAAC,CAAA;AAAA,EACxE;AAGA,EAAA,MAAM,MAAA,GAAS,OAAOA,aAAA,CAAO,UAAA,CAAW;AAAA,I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AM,wBAAwB,CACnC,UAAA,EACA,UAA8B,EAAC,KAE/B,WAAW,UAAU,CAAA,CAAE,IAAA,CAAKJ,aAAA,CAAO,IAAI,CAAC,MAAA,KAAW,YAAY,MAAA,EAAQ,OAAO,CAAC,CAAC","file":"index.cjs","sourcesContent":["/**\n * Generate GraphQL SDL from an effect-gql schema builder.\n *\n * Usage:\n * effect-gql generate-schema <module-path> [options]\n *\n * The module should export one of:\n * - `builder` - A GraphQLSchemaBuilder instance\n * - `schema` - A GraphQLSchema instance\n * - `default` - Either of the above as default export\n */\n\nimport { Effect, Console } from \"effect\"\nimport { printSchema, lexicographicSortSchema } from \"@effect-gql/core\"\nimport type { GraphQLSchema } from \"graphql\"\nimport * as fs from \"fs\"\nimport * as path from \"path\"\n\ninterface GenerateOptions {\n /** Path to the schema module */\n modulePath: string\n /** Output file path (stdout if not specified) */\n output?: string\n /** Sort schema alphabetically */\n sort?: boolean\n /** Watch for changes */\n watch?: boolean\n}\n\n/**\n * Load a schema from a module path.\n * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.\n */\nexport const loadSchema = (modulePath: string): Effect.Effect<GraphQLSchema, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), modulePath)\n\n // Validate file exists\n if (!fs.existsSync(absolutePath)) {\n return yield* Effect.fail(new Error(`File not found: ${absolutePath}`))\n }\n\n // Dynamic import (works with both ESM and CJS via tsx/ts-node)\n const module = yield* Effect.tryPromise({\n try: async () => {\n // Clear require cache for watch mode\n const resolved = require.resolve(absolutePath)\n delete require.cache[resolved]\n\n // Try dynamic import first (ESM), fall back to require (CJS)\n try {\n return await import(absolutePath)\n } catch {\n return require(absolutePath)\n }\n },\n catch: (error) => new Error(`Failed to load module: ${error}`),\n })\n\n // Look for builder or schema export\n const exported = module.builder ?? module.schema ?? module.default\n\n if (!exported) {\n return yield* Effect.fail(\n new Error(\n `Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`\n )\n )\n }\n\n // If it's a builder, call buildSchema()\n if (typeof exported.buildSchema === \"function\") {\n return exported.buildSchema() as GraphQLSchema\n }\n\n // If it's already a GraphQLSchema\n if (exported.getQueryType && exported.getTypeMap) {\n return exported as GraphQLSchema\n }\n\n return yield* Effect.fail(\n new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)\n )\n })\n\n/**\n * Generate SDL from a schema\n */\nexport const generateSDL = (schema: GraphQLSchema, options: { sort?: boolean } = {}): string => {\n const finalSchema = options.sort !== false ? lexicographicSortSchema(schema) : schema\n return printSchema(finalSchema)\n}\n\n/**\n * Generate SDL from a module path\n */\nexport const generateSDLFromModule = (\n modulePath: string,\n options: { sort?: boolean } = {}\n): Effect.Effect<string, Error> =>\n loadSchema(modulePath).pipe(Effect.map((schema) => generateSDL(schema, options)))\n\n/**\n * Run the generate-schema command\n */\nconst run = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const schema = yield* loadSchema(options.modulePath)\n const sdl = generateSDL(schema, { sort: options.sort })\n\n if (options.output) {\n const outputPath = path.resolve(process.cwd(), options.output)\n fs.writeFileSync(outputPath, sdl)\n yield* Console.log(`Schema written to ${outputPath}`)\n } else {\n yield* Console.log(sdl)\n }\n })\n\n/**\n * Watch mode - regenerate on file changes\n */\nconst watch = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), options.modulePath)\n const dir = path.dirname(absolutePath)\n\n yield* Console.log(`Watching for changes in ${dir}...`)\n\n // Initial generation\n yield* run(options).pipe(Effect.catchAll((error) => Console.error(`Error: ${error.message}`)))\n\n // Watch for changes\n yield* Effect.async<void, Error>(() => {\n const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {\n if (filename?.endsWith(\".ts\") || filename?.endsWith(\".js\")) {\n Effect.runPromise(\n run(options).pipe(\n Effect.tap(() => Console.log(`\\nRegenerated at ${new Date().toLocaleTimeString()}`)),\n Effect.catchAll((error) => Console.error(`Error: ${error.message}`))\n )\n )\n }\n })\n\n return Effect.sync(() => watcher.close())\n })\n })\n\n/**\n * Parse CLI arguments for generate-schema command\n */\nconst parseArgs = (args: string[]): GenerateOptions | { help: true } | { error: string } => {\n const positional: string[] = []\n let output: string | undefined\n let sort = true\n let watchMode = false\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n\n if (arg === \"-h\" || arg === \"--help\") {\n return { help: true }\n } else if (arg === \"-o\" || arg === \"--output\") {\n output = args[++i]\n } else if (arg === \"--no-sort\") {\n sort = false\n } else if (arg === \"-w\" || arg === \"--watch\") {\n watchMode = true\n } else if (!arg.startsWith(\"-\")) {\n positional.push(arg)\n } else {\n return { error: `Unknown option: ${arg}` }\n }\n }\n\n if (positional.length === 0) {\n return { error: \"Missing module path\" }\n }\n\n return {\n modulePath: positional[0],\n output,\n sort,\n watch: watchMode,\n }\n}\n\nexport const printGenerateSchemaHelp = (): void => {\n console.log(`\nUsage: effect-gql generate-schema <module-path> [options]\n\nGenerate GraphQL SDL from an effect-gql schema builder.\n\nArguments:\n module-path Path to the schema module (.ts or .js)\n\nOptions:\n -o, --output Write SDL to file instead of stdout\n --no-sort Don't sort schema alphabetically\n -w, --watch Watch for changes and regenerate\n -h, --help Show this help message\n\nExamples:\n effect-gql generate-schema ./src/schema.ts\n effect-gql generate-schema ./src/schema.ts -o schema.graphql\n effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql\n\nThe module should export one of:\n - builder: A GraphQLSchemaBuilder instance\n - schema: A GraphQLSchema instance\n - default: Either of the above as default export\n`)\n}\n\n/**\n * Entry point for the generate-schema command\n */\nexport const runGenerateSchema = (args: string[]): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const parsed = parseArgs(args)\n\n if (\"help\" in parsed) {\n printGenerateSchemaHelp()\n return\n }\n\n if (\"error\" in parsed) {\n yield* Console.error(`Error: ${parsed.error}`)\n printGenerateSchemaHelp()\n process.exitCode = 1\n return\n }\n\n if (parsed.watch) {\n yield* watch(parsed)\n } else {\n yield* run(parsed)\n }\n })\n"]}
@@ -1,3 +1,6 @@
1
+ import { Effect } from 'effect';
2
+ import { GraphQLSchema } from 'graphql';
3
+
1
4
  /**
2
5
  * Generate GraphQL SDL from an effect-gql schema builder.
3
6
  *
@@ -9,28 +12,23 @@
9
12
  * - `schema` - A GraphQLSchema instance
10
13
  * - `default` - Either of the above as default export
11
14
  */
12
- import { Effect } from "effect";
13
- import type { GraphQLSchema } from "graphql";
15
+
14
16
  /**
15
17
  * Load a schema from a module path.
16
18
  * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.
17
19
  */
18
- export declare const loadSchema: (modulePath: string) => Effect.Effect<GraphQLSchema, Error>;
20
+ declare const loadSchema: (modulePath: string) => Effect.Effect<GraphQLSchema, Error>;
19
21
  /**
20
22
  * Generate SDL from a schema
21
23
  */
22
- export declare const generateSDL: (schema: GraphQLSchema, options?: {
24
+ declare const generateSDL: (schema: GraphQLSchema, options?: {
23
25
  sort?: boolean;
24
26
  }) => string;
25
27
  /**
26
28
  * Generate SDL from a module path
27
29
  */
28
- export declare const generateSDLFromModule: (modulePath: string, options?: {
30
+ declare const generateSDLFromModule: (modulePath: string, options?: {
29
31
  sort?: boolean;
30
32
  }) => Effect.Effect<string, Error>;
31
- export declare const printGenerateSchemaHelp: () => void;
32
- /**
33
- * Entry point for the generate-schema command
34
- */
35
- export declare const runGenerateSchema: (args: string[]) => Effect.Effect<void, Error>;
36
- //# sourceMappingURL=generate-schema.d.ts.map
33
+
34
+ export { generateSDL, generateSDLFromModule, loadSchema };
package/index.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { Effect } from 'effect';
2
+ import { GraphQLSchema } from 'graphql';
3
+
4
+ /**
5
+ * Generate GraphQL SDL from an effect-gql schema builder.
6
+ *
7
+ * Usage:
8
+ * effect-gql generate-schema <module-path> [options]
9
+ *
10
+ * The module should export one of:
11
+ * - `builder` - A GraphQLSchemaBuilder instance
12
+ * - `schema` - A GraphQLSchema instance
13
+ * - `default` - Either of the above as default export
14
+ */
15
+
16
+ /**
17
+ * Load a schema from a module path.
18
+ * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.
19
+ */
20
+ declare const loadSchema: (modulePath: string) => Effect.Effect<GraphQLSchema, Error>;
21
+ /**
22
+ * Generate SDL from a schema
23
+ */
24
+ declare const generateSDL: (schema: GraphQLSchema, options?: {
25
+ sort?: boolean;
26
+ }) => string;
27
+ /**
28
+ * Generate SDL from a module path
29
+ */
30
+ declare const generateSDLFromModule: (modulePath: string, options?: {
31
+ sort?: boolean;
32
+ }) => Effect.Effect<string, Error>;
33
+
34
+ export { generateSDL, generateSDLFromModule, loadSchema };
package/index.js ADDED
@@ -0,0 +1,55 @@
1
+ import { Effect } from 'effect';
2
+ import { lexicographicSortSchema, printSchema } from '@effect-gql/core';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+
6
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
7
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
8
+ }) : x)(function(x) {
9
+ if (typeof require !== "undefined") return require.apply(this, arguments);
10
+ throw Error('Dynamic require of "' + x + '" is not supported');
11
+ });
12
+ var loadSchema = (modulePath) => Effect.gen(function* () {
13
+ const absolutePath = path.resolve(process.cwd(), modulePath);
14
+ if (!fs.existsSync(absolutePath)) {
15
+ return yield* Effect.fail(new Error(`File not found: ${absolutePath}`));
16
+ }
17
+ const module = yield* Effect.tryPromise({
18
+ try: async () => {
19
+ const resolved = __require.resolve(absolutePath);
20
+ delete __require.cache[resolved];
21
+ try {
22
+ return await import(absolutePath);
23
+ } catch {
24
+ return __require(absolutePath);
25
+ }
26
+ },
27
+ catch: (error) => new Error(`Failed to load module: ${error}`)
28
+ });
29
+ const exported = module.builder ?? module.schema ?? module.default;
30
+ if (!exported) {
31
+ return yield* Effect.fail(
32
+ new Error(
33
+ `Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`
34
+ )
35
+ );
36
+ }
37
+ if (typeof exported.buildSchema === "function") {
38
+ return exported.buildSchema();
39
+ }
40
+ if (exported.getQueryType && exported.getTypeMap) {
41
+ return exported;
42
+ }
43
+ return yield* Effect.fail(
44
+ new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)
45
+ );
46
+ });
47
+ var generateSDL = (schema, options = {}) => {
48
+ const finalSchema = options.sort !== false ? lexicographicSortSchema(schema) : schema;
49
+ return printSchema(finalSchema);
50
+ };
51
+ var generateSDLFromModule = (modulePath, options = {}) => loadSchema(modulePath).pipe(Effect.map((schema) => generateSDL(schema, options)));
52
+
53
+ export { generateSDL, generateSDLFromModule, loadSchema };
54
+ //# sourceMappingURL=index.js.map
55
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/generate-schema.ts"],"names":[],"mappings":";;;;;;;;;;;AAiCO,IAAM,UAAA,GAAa,CAAC,UAAA,KACzB,MAAA,CAAO,IAAI,aAAa;AACtB,EAAA,MAAM,YAAA,GAAoB,IAAA,CAAA,OAAA,CAAQ,OAAA,CAAQ,GAAA,IAAO,UAAU,CAAA;AAG3D,EAAA,IAAI,CAAI,EAAA,CAAA,UAAA,CAAW,YAAY,CAAA,EAAG;AAChC,IAAA,OAAO,OAAO,OAAO,IAAA,CAAK,IAAI,MAAM,CAAA,gBAAA,EAAmB,YAAY,EAAE,CAAC,CAAA;AAAA,EACxE;AAGA,EAAA,MAAM,MAAA,GAAS,OAAO,MAAA,CAAO,UAAA,CAAW;AAAA,IACtC,KAAK,YAAY;AAEf,MAAA,MAAM,QAAA,GAAW,SAAA,CAAQ,OAAA,CAAQ,YAAY,CAAA;AAC7C,MAAA,OAAO,SAAA,CAAQ,MAAM,QAAQ,CAAA;AAG7B,MAAA,IAAI;AACF,QAAA,OAAO,MAAM,OAAO,YAAA,CAAA;AAAA,MACt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n *\n * Usage:\n * effect-gql generate-schema <module-path> [options]\n *\n * The module should export one of:\n * - `builder` - A GraphQLSchemaBuilder instance\n * - `schema` - A GraphQLSchema instance\n * - `default` - Either of the above as default export\n */\n\nimport { Effect, Console } from \"effect\"\nimport { printSchema, lexicographicSortSchema } from \"@effect-gql/core\"\nimport type { GraphQLSchema } from \"graphql\"\nimport * as fs from \"fs\"\nimport * as path from \"path\"\n\ninterface GenerateOptions {\n /** Path to the schema module */\n modulePath: string\n /** Output file path (stdout if not specified) */\n output?: string\n /** Sort schema alphabetically */\n sort?: boolean\n /** Watch for changes */\n watch?: boolean\n}\n\n/**\n * Load a schema from a module path.\n * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.\n */\nexport const loadSchema = (modulePath: string): Effect.Effect<GraphQLSchema, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), modulePath)\n\n // Validate file exists\n if (!fs.existsSync(absolutePath)) {\n return yield* Effect.fail(new Error(`File not found: ${absolutePath}`))\n }\n\n // Dynamic import (works with both ESM and CJS via tsx/ts-node)\n const module = yield* Effect.tryPromise({\n try: async () => {\n // Clear require cache for watch mode\n const resolved = require.resolve(absolutePath)\n delete require.cache[resolved]\n\n // Try dynamic import first (ESM), fall back to require (CJS)\n try {\n return await import(absolutePath)\n } catch {\n return require(absolutePath)\n }\n },\n catch: (error) => new Error(`Failed to load module: ${error}`),\n })\n\n // Look for builder or schema export\n const exported = module.builder ?? module.schema ?? module.default\n\n if (!exported) {\n return yield* Effect.fail(\n new Error(\n `Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`\n )\n )\n }\n\n // If it's a builder, call buildSchema()\n if (typeof exported.buildSchema === \"function\") {\n return exported.buildSchema() as GraphQLSchema\n }\n\n // If it's already a GraphQLSchema\n if (exported.getQueryType && exported.getTypeMap) {\n return exported as GraphQLSchema\n }\n\n return yield* Effect.fail(\n new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`)\n )\n })\n\n/**\n * Generate SDL from a schema\n */\nexport const generateSDL = (schema: GraphQLSchema, options: { sort?: boolean } = {}): string => {\n const finalSchema = options.sort !== false ? lexicographicSortSchema(schema) : schema\n return printSchema(finalSchema)\n}\n\n/**\n * Generate SDL from a module path\n */\nexport const generateSDLFromModule = (\n modulePath: string,\n options: { sort?: boolean } = {}\n): Effect.Effect<string, Error> =>\n loadSchema(modulePath).pipe(Effect.map((schema) => generateSDL(schema, options)))\n\n/**\n * Run the generate-schema command\n */\nconst run = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const schema = yield* loadSchema(options.modulePath)\n const sdl = generateSDL(schema, { sort: options.sort })\n\n if (options.output) {\n const outputPath = path.resolve(process.cwd(), options.output)\n fs.writeFileSync(outputPath, sdl)\n yield* Console.log(`Schema written to ${outputPath}`)\n } else {\n yield* Console.log(sdl)\n }\n })\n\n/**\n * Watch mode - regenerate on file changes\n */\nconst watch = (options: GenerateOptions): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const absolutePath = path.resolve(process.cwd(), options.modulePath)\n const dir = path.dirname(absolutePath)\n\n yield* Console.log(`Watching for changes in ${dir}...`)\n\n // Initial generation\n yield* run(options).pipe(Effect.catchAll((error) => Console.error(`Error: ${error.message}`)))\n\n // Watch for changes\n yield* Effect.async<void, Error>(() => {\n const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {\n if (filename?.endsWith(\".ts\") || filename?.endsWith(\".js\")) {\n Effect.runPromise(\n run(options).pipe(\n Effect.tap(() => Console.log(`\\nRegenerated at ${new Date().toLocaleTimeString()}`)),\n Effect.catchAll((error) => Console.error(`Error: ${error.message}`))\n )\n )\n }\n })\n\n return Effect.sync(() => watcher.close())\n })\n })\n\n/**\n * Parse CLI arguments for generate-schema command\n */\nconst parseArgs = (args: string[]): GenerateOptions | { help: true } | { error: string } => {\n const positional: string[] = []\n let output: string | undefined\n let sort = true\n let watchMode = false\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n\n if (arg === \"-h\" || arg === \"--help\") {\n return { help: true }\n } else if (arg === \"-o\" || arg === \"--output\") {\n output = args[++i]\n } else if (arg === \"--no-sort\") {\n sort = false\n } else if (arg === \"-w\" || arg === \"--watch\") {\n watchMode = true\n } else if (!arg.startsWith(\"-\")) {\n positional.push(arg)\n } else {\n return { error: `Unknown option: ${arg}` }\n }\n }\n\n if (positional.length === 0) {\n return { error: \"Missing module path\" }\n }\n\n return {\n modulePath: positional[0],\n output,\n sort,\n watch: watchMode,\n }\n}\n\nexport const printGenerateSchemaHelp = (): void => {\n console.log(`\nUsage: effect-gql generate-schema <module-path> [options]\n\nGenerate GraphQL SDL from an effect-gql schema builder.\n\nArguments:\n module-path Path to the schema module (.ts or .js)\n\nOptions:\n -o, --output Write SDL to file instead of stdout\n --no-sort Don't sort schema alphabetically\n -w, --watch Watch for changes and regenerate\n -h, --help Show this help message\n\nExamples:\n effect-gql generate-schema ./src/schema.ts\n effect-gql generate-schema ./src/schema.ts -o schema.graphql\n effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql\n\nThe module should export one of:\n - builder: A GraphQLSchemaBuilder instance\n - schema: A GraphQLSchema instance\n - default: Either of the above as default export\n`)\n}\n\n/**\n * Entry point for the generate-schema command\n */\nexport const runGenerateSchema = (args: string[]): Effect.Effect<void, Error> =>\n Effect.gen(function* () {\n const parsed = parseArgs(args)\n\n if (\"help\" in parsed) {\n printGenerateSchemaHelp()\n return\n }\n\n if (\"error\" in parsed) {\n yield* Console.error(`Error: ${parsed.error}`)\n printGenerateSchemaHelp()\n process.exitCode = 1\n return\n }\n\n if (parsed.watch) {\n yield* watch(parsed)\n } else {\n yield* run(parsed)\n }\n })\n"]}
package/package.json CHANGED
@@ -1,32 +1,29 @@
1
1
  {
2
2
  "name": "@effect-gql/cli",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "CLI tools for Effect GraphQL development",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "repository": {
6
+ "url": "https://github.com/nrf110/effect-gql"
7
+ },
8
+ "type": "module",
9
+ "main": "./index.cjs",
10
+ "module": "dist/index.js",
11
+ "types": "./index.d.ts",
7
12
  "bin": {
8
- "effect-gql": "./dist/bin.js"
13
+ "effect-gql": "./bin.js"
9
14
  },
10
15
  "exports": {
11
16
  ".": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/index.js"
17
+ "types": "./index.d.ts",
18
+ "import": "./index.js",
19
+ "require": "./index.cjs"
14
20
  }
15
21
  },
16
- "files": [
17
- "dist",
18
- "src"
19
- ],
20
22
  "peerDependencies": {
21
- "@effect-gql/core": "^0.1.0",
23
+ "@effect-gql/core": "^1.0.0",
22
24
  "effect": "^3.19.0",
23
25
  "graphql": "^16.0.0"
24
26
  },
25
- "devDependencies": {
26
- "@effect-gql/core": "*",
27
- "effect": "^3.19.13",
28
- "graphql": "^16.0.0"
29
- },
30
27
  "keywords": [
31
28
  "effect",
32
29
  "graphql",
@@ -34,12 +31,5 @@
34
31
  "schema",
35
32
  "codegen"
36
33
  ],
37
- "license": "MIT",
38
- "scripts": {
39
- "build": "tsc",
40
- "dev": "tsc --watch",
41
- "clean": "rm -rf dist",
42
- "test": "vitest run",
43
- "test:watch": "vitest"
44
- }
45
- }
34
+ "license": "MIT"
35
+ }
package/dist/bin.d.ts DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Effect GraphQL CLI
4
- *
5
- * Usage:
6
- * effect-gql <command> [options]
7
- *
8
- * Commands:
9
- * generate-schema Generate GraphQL SDL from a schema module
10
- * create Create a new Effect GraphQL project (coming soon)
11
- */
12
- export {};
13
- //# sourceMappingURL=bin.d.ts.map
package/dist/bin.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG"}
package/dist/bin.js DELETED
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- /**
4
- * Effect GraphQL CLI
5
- *
6
- * Usage:
7
- * effect-gql <command> [options]
8
- *
9
- * Commands:
10
- * generate-schema Generate GraphQL SDL from a schema module
11
- * create Create a new Effect GraphQL project (coming soon)
12
- */
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const effect_1 = require("effect");
15
- const generate_schema_1 = require("./commands/generate-schema");
16
- const VERSION = "0.1.0";
17
- const printHelp = () => {
18
- console.log(`
19
- Effect GraphQL CLI v${VERSION}
20
-
21
- Usage: effect-gql <command> [options]
22
-
23
- Commands:
24
- generate-schema Generate GraphQL SDL from a schema module
25
- create Create a new Effect GraphQL project (coming soon)
26
-
27
- Options:
28
- -h, --help Show this help message
29
- -v, --version Show version number
30
-
31
- Examples:
32
- effect-gql generate-schema ./src/schema.ts
33
- effect-gql generate-schema ./src/schema.ts -o schema.graphql
34
- effect-gql create my-app
35
-
36
- Run 'effect-gql <command> --help' for command-specific help.
37
- `);
38
- };
39
- const printVersion = () => {
40
- console.log(`effect-gql v${VERSION}`);
41
- };
42
- const main = effect_1.Effect.gen(function* () {
43
- const args = process.argv.slice(2);
44
- if (args.length === 0 || args[0] === "-h" || args[0] === "--help") {
45
- printHelp();
46
- return;
47
- }
48
- if (args[0] === "-v" || args[0] === "--version") {
49
- printVersion();
50
- return;
51
- }
52
- const command = args[0];
53
- const commandArgs = args.slice(1);
54
- switch (command) {
55
- case "generate-schema":
56
- yield* (0, generate_schema_1.runGenerateSchema)(commandArgs);
57
- break;
58
- case "create":
59
- yield* effect_1.Console.log("The 'create' command is coming soon!");
60
- yield* effect_1.Console.log("It will help you scaffold new Effect GraphQL projects.");
61
- break;
62
- default:
63
- yield* effect_1.Console.error(`Unknown command: ${command}`);
64
- printHelp();
65
- process.exitCode = 1;
66
- }
67
- });
68
- effect_1.Effect.runPromise(main.pipe(effect_1.Effect.catchAll((error) => effect_1.Console.error(`Error: ${error.message}`).pipe(effect_1.Effect.andThen(effect_1.Effect.sync(() => { process.exitCode = 1; }))))));
69
- //# sourceMappingURL=bin.js.map
package/dist/bin.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";;AACA;;;;;;;;;GASG;;AAEH,mCAAwC;AACxC,gEAA8D;AAE9D,MAAM,OAAO,GAAG,OAAO,CAAA;AAEvB,MAAM,SAAS,GAAG,GAAS,EAAE;IAC3B,OAAO,CAAC,GAAG,CAAC;sBACQ,OAAO;;;;;;;;;;;;;;;;;;CAkB5B,CAAC,CAAA;AACF,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,GAAS,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,EAAE,CAAC,CAAA;AACvC,CAAC,CAAA;AAED,MAAM,IAAI,GAAG,eAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAElC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QAClE,SAAS,EAAE,CAAA;QACX,OAAM;IACR,CAAC;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC;QAChD,YAAY,EAAE,CAAA;QACd,OAAM;IACR,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACvB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAEjC,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,iBAAiB;YACpB,KAAK,CAAC,CAAC,IAAA,mCAAiB,EAAC,WAAW,CAAC,CAAA;YACrC,MAAK;QAEP,KAAK,QAAQ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AAI,CAAC,EAAE,OAAO,CAAA;CAAO,KAC/B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CACqD,CAAA;AA0FnF,eAAO,MAAM,uBAAuB,QAAO,IAyB1C,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAqBxE,CAAA"}
@@ -1,230 +0,0 @@
1
- "use strict";
2
- /**
3
- * Generate GraphQL SDL from an effect-gql schema builder.
4
- *
5
- * Usage:
6
- * effect-gql generate-schema <module-path> [options]
7
- *
8
- * The module should export one of:
9
- * - `builder` - A GraphQLSchemaBuilder instance
10
- * - `schema` - A GraphQLSchema instance
11
- * - `default` - Either of the above as default export
12
- */
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || (function () {
30
- var ownKeys = function(o) {
31
- ownKeys = Object.getOwnPropertyNames || function (o) {
32
- var ar = [];
33
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
- return ar;
35
- };
36
- return ownKeys(o);
37
- };
38
- return function (mod) {
39
- if (mod && mod.__esModule) return mod;
40
- var result = {};
41
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
- __setModuleDefault(result, mod);
43
- return result;
44
- };
45
- })();
46
- Object.defineProperty(exports, "__esModule", { value: true });
47
- exports.runGenerateSchema = exports.printGenerateSchemaHelp = exports.generateSDLFromModule = exports.generateSDL = exports.loadSchema = void 0;
48
- const effect_1 = require("effect");
49
- const core_1 = require("@effect-gql/core");
50
- const fs = __importStar(require("fs"));
51
- const path = __importStar(require("path"));
52
- /**
53
- * Load a schema from a module path.
54
- * Supports both GraphQLSchemaBuilder and GraphQLSchema exports.
55
- */
56
- const loadSchema = (modulePath) => effect_1.Effect.gen(function* () {
57
- const absolutePath = path.resolve(process.cwd(), modulePath);
58
- // Validate file exists
59
- if (!fs.existsSync(absolutePath)) {
60
- return yield* effect_1.Effect.fail(new Error(`File not found: ${absolutePath}`));
61
- }
62
- // Dynamic import (works with both ESM and CJS via tsx/ts-node)
63
- const module = yield* effect_1.Effect.tryPromise({
64
- try: async () => {
65
- // Clear require cache for watch mode
66
- const resolved = require.resolve(absolutePath);
67
- delete require.cache[resolved];
68
- // Try dynamic import first (ESM), fall back to require (CJS)
69
- try {
70
- return await Promise.resolve(`${absolutePath}`).then(s => __importStar(require(s)));
71
- }
72
- catch {
73
- return require(absolutePath);
74
- }
75
- },
76
- catch: (error) => new Error(`Failed to load module: ${error}`),
77
- });
78
- // Look for builder or schema export
79
- const exported = module.builder ?? module.schema ?? module.default;
80
- if (!exported) {
81
- return yield* effect_1.Effect.fail(new Error(`Module must export 'builder' (GraphQLSchemaBuilder), 'schema' (GraphQLSchema), or a default export`));
82
- }
83
- // If it's a builder, call buildSchema()
84
- if (typeof exported.buildSchema === "function") {
85
- return exported.buildSchema();
86
- }
87
- // If it's already a GraphQLSchema
88
- if (exported.getQueryType && exported.getTypeMap) {
89
- return exported;
90
- }
91
- return yield* effect_1.Effect.fail(new Error(`Export is not a GraphQLSchemaBuilder or GraphQLSchema. Got: ${typeof exported}`));
92
- });
93
- exports.loadSchema = loadSchema;
94
- /**
95
- * Generate SDL from a schema
96
- */
97
- const generateSDL = (schema, options = {}) => {
98
- const finalSchema = options.sort !== false ? (0, core_1.lexicographicSortSchema)(schema) : schema;
99
- return (0, core_1.printSchema)(finalSchema);
100
- };
101
- exports.generateSDL = generateSDL;
102
- /**
103
- * Generate SDL from a module path
104
- */
105
- const generateSDLFromModule = (modulePath, options = {}) => (0, exports.loadSchema)(modulePath).pipe(effect_1.Effect.map((schema) => (0, exports.generateSDL)(schema, options)));
106
- exports.generateSDLFromModule = generateSDLFromModule;
107
- /**
108
- * Run the generate-schema command
109
- */
110
- const run = (options) => effect_1.Effect.gen(function* () {
111
- const schema = yield* (0, exports.loadSchema)(options.modulePath);
112
- const sdl = (0, exports.generateSDL)(schema, { sort: options.sort });
113
- if (options.output) {
114
- const outputPath = path.resolve(process.cwd(), options.output);
115
- fs.writeFileSync(outputPath, sdl);
116
- yield* effect_1.Console.log(`Schema written to ${outputPath}`);
117
- }
118
- else {
119
- yield* effect_1.Console.log(sdl);
120
- }
121
- });
122
- /**
123
- * Watch mode - regenerate on file changes
124
- */
125
- const watch = (options) => effect_1.Effect.gen(function* () {
126
- const absolutePath = path.resolve(process.cwd(), options.modulePath);
127
- const dir = path.dirname(absolutePath);
128
- yield* effect_1.Console.log(`Watching for changes in ${dir}...`);
129
- // Initial generation
130
- yield* run(options).pipe(effect_1.Effect.catchAll((error) => effect_1.Console.error(`Error: ${error.message}`)));
131
- // Watch for changes
132
- yield* effect_1.Effect.async(() => {
133
- const watcher = fs.watch(dir, { recursive: true }, (_, filename) => {
134
- if (filename?.endsWith(".ts") || filename?.endsWith(".js")) {
135
- effect_1.Effect.runPromise(run(options).pipe(effect_1.Effect.tap(() => effect_1.Console.log(`\nRegenerated at ${new Date().toLocaleTimeString()}`)), effect_1.Effect.catchAll((error) => effect_1.Console.error(`Error: ${error.message}`))));
136
- }
137
- });
138
- return effect_1.Effect.sync(() => watcher.close());
139
- });
140
- });
141
- /**
142
- * Parse CLI arguments for generate-schema command
143
- */
144
- const parseArgs = (args) => {
145
- const positional = [];
146
- let output;
147
- let sort = true;
148
- let watchMode = false;
149
- for (let i = 0; i < args.length; i++) {
150
- const arg = args[i];
151
- if (arg === "-h" || arg === "--help") {
152
- return { help: true };
153
- }
154
- else if (arg === "-o" || arg === "--output") {
155
- output = args[++i];
156
- }
157
- else if (arg === "--no-sort") {
158
- sort = false;
159
- }
160
- else if (arg === "-w" || arg === "--watch") {
161
- watchMode = true;
162
- }
163
- else if (!arg.startsWith("-")) {
164
- positional.push(arg);
165
- }
166
- else {
167
- return { error: `Unknown option: ${arg}` };
168
- }
169
- }
170
- if (positional.length === 0) {
171
- return { error: "Missing module path" };
172
- }
173
- return {
174
- modulePath: positional[0],
175
- output,
176
- sort,
177
- watch: watchMode,
178
- };
179
- };
180
- const printGenerateSchemaHelp = () => {
181
- console.log(`
182
- Usage: effect-gql generate-schema <module-path> [options]
183
-
184
- Generate GraphQL SDL from an effect-gql schema builder.
185
-
186
- Arguments:
187
- module-path Path to the schema module (.ts or .js)
188
-
189
- Options:
190
- -o, --output Write SDL to file instead of stdout
191
- --no-sort Don't sort schema alphabetically
192
- -w, --watch Watch for changes and regenerate
193
- -h, --help Show this help message
194
-
195
- Examples:
196
- effect-gql generate-schema ./src/schema.ts
197
- effect-gql generate-schema ./src/schema.ts -o schema.graphql
198
- effect-gql generate-schema ./src/schema.ts --watch -o schema.graphql
199
-
200
- The module should export one of:
201
- - builder: A GraphQLSchemaBuilder instance
202
- - schema: A GraphQLSchema instance
203
- - default: Either of the above as default export
204
- `);
205
- };
206
- exports.printGenerateSchemaHelp = printGenerateSchemaHelp;
207
- /**
208
- * Entry point for the generate-schema command
209
- */
210
- const runGenerateSchema = (args) => effect_1.Effect.gen(function* () {
211
- const parsed = parseArgs(args);
212
- if ("help" in parsed) {
213
- (0, exports.printGenerateSchemaHelp)();
214
- return;
215
- }
216
- if ("error" in parsed) {
217
- yield* effect_1.Console.error(`Error: ${parsed.error}`);
218
- (0, exports.printGenerateSchemaHelp)();
219
- process.exitCode = 1;
220
- return;
221
- }
222
- if (parsed.watch) {
223
- yield* watch(parsed);
224
- }
225
- else {
226
- yield* run(parsed);
227
- }
228
- });
229
- exports.runGenerateSchema = runGenerateSchema;
230
- //# sourceMappingURL=generate-schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-schema.js","sourceRoot":"","sources":["../../src/commands/generate-schema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mCAAwC;AACxC,2CAAuE;AAEvE,uCAAwB;AACxB,2CAA4B;AAa5B;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAuC,EAAE,CACpF,eAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAA;IAE5D,uBAAuB;IACvB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC,CAAC,eAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,mBAAmB,YAAY,EAAE,CAAC,CAAC,CAAA;IACzE,CAAC;IAED,+DAA+D;IAC/D,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,eAAM,CAAC,UAAU,CAAC;QACtC,GAAG,EAAE,KAAK,IAAI,EAAE;YACd,qCAAqC;YACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;YAC9C,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;YAE9B,6DAA6D;YAC7D,IAAI,CAAC;gBACH,OAAO,yBAAa,YAAY,uCAAC,CAAA;YACnC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,OAAO,CAAC,YAAY,CAAC,CAAA;YAC9B,CAAC;QACH,CAAC;QACD,KAAK,EAAE,CAAC,KAAK,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