@@ -230,6 +230,59 @@ export function generateRootBarrel(options: RootBarrelOptions = {}): string {
230230 return generateCode ( statements ) ;
231231}
232232
233+ // ============================================================================
234+ // Multi-target root barrel (re-exports each target as a namespace)
235+ // ============================================================================
236+
237+ /** JS reserved words that need an alias when used as export names */
238+ const JS_RESERVED = new Set ( [
239+ 'abstract' , 'arguments' , 'await' , 'boolean' , 'break' , 'byte' , 'case' , 'catch' ,
240+ 'char' , 'class' , 'const' , 'continue' , 'debugger' , 'default' , 'delete' , 'do' ,
241+ 'double' , 'else' , 'enum' , 'eval' , 'export' , 'extends' , 'false' , 'final' ,
242+ 'finally' , 'float' , 'for' , 'function' , 'goto' , 'if' , 'implements' , 'import' ,
243+ 'in' , 'instanceof' , 'int' , 'interface' , 'let' , 'long' , 'native' , 'new' ,
244+ 'null' , 'package' , 'private' , 'protected' , 'public' , 'return' , 'short' ,
245+ 'static' , 'super' , 'switch' , 'synchronized' , 'this' , 'throw' , 'throws' ,
246+ 'transient' , 'true' , 'try' , 'typeof' , 'var' , 'void' , 'volatile' , 'while' ,
247+ 'with' , 'yield' ,
248+ ] ) ;
249+
250+ /**
251+ * Generate a root index.ts for multi-target output that re-exports each
252+ * target as a namespace.
253+ *
254+ * Example output:
255+ * export * as admin from './admin';
256+ * export * as auth from './auth';
257+ * export * as public_ from './public';
258+ */
259+ export function generateMultiTargetBarrel ( targetNames : string [ ] ) : string {
260+ const statements : t . Statement [ ] = [ ] ;
261+
262+ for ( const name of targetNames ) {
263+ const alias = JS_RESERVED . has ( name ) ? `${ name } _` : name ;
264+ const exportDecl = t . exportNamedDeclaration (
265+ null ,
266+ [ t . exportNamespaceSpecifier ( t . identifier ( alias ) ) ] ,
267+ t . stringLiteral ( `./${ name } ` ) ,
268+ ) ;
269+ statements . push ( exportDecl ) ;
270+ }
271+
272+ if ( statements . length > 0 ) {
273+ addJSDocComment ( statements [ 0 ] , [
274+ '@constructive-io/sdk' ,
275+ '' ,
276+ 'Auto-generated GraphQL types and ORM client.' ,
277+ 'Run `pnpm run generate` to populate this package from the schema files.' ,
278+ '' ,
279+ '@generated by @constructive-io/graphql-codegen' ,
280+ ] ) ;
281+ }
282+
283+ return generateCode ( statements ) ;
284+ }
285+
233286// ============================================================================
234287// Custom operation barrels (includes both table and custom hooks)
235288// ============================================================================
0 commit comments