@nitrostack/cli 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.
Files changed (100) hide show
  1. package/README.md +131 -0
  2. package/dist/commands/build.d.ts +6 -0
  3. package/dist/commands/build.d.ts.map +1 -0
  4. package/dist/commands/build.js +185 -0
  5. package/dist/commands/dev.d.ts +7 -0
  6. package/dist/commands/dev.d.ts.map +1 -0
  7. package/dist/commands/dev.js +365 -0
  8. package/dist/commands/generate-types.d.ts +8 -0
  9. package/dist/commands/generate-types.d.ts.map +1 -0
  10. package/dist/commands/generate-types.js +219 -0
  11. package/dist/commands/generate.d.ts +12 -0
  12. package/dist/commands/generate.d.ts.map +1 -0
  13. package/dist/commands/generate.js +375 -0
  14. package/dist/commands/init.d.ts +7 -0
  15. package/dist/commands/init.d.ts.map +1 -0
  16. package/dist/commands/init.js +324 -0
  17. package/dist/commands/install.d.ts +10 -0
  18. package/dist/commands/install.d.ts.map +1 -0
  19. package/dist/commands/install.js +80 -0
  20. package/dist/commands/start.d.ts +6 -0
  21. package/dist/commands/start.d.ts.map +1 -0
  22. package/dist/commands/start.js +70 -0
  23. package/dist/commands/upgrade.d.ts +10 -0
  24. package/dist/commands/upgrade.d.ts.map +1 -0
  25. package/dist/commands/upgrade.js +214 -0
  26. package/dist/index.d.ts +11 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +94 -0
  29. package/dist/mcp-dev-wrapper.d.ts +15 -0
  30. package/dist/mcp-dev-wrapper.d.ts.map +1 -0
  31. package/dist/mcp-dev-wrapper.js +187 -0
  32. package/dist/ui/branding.d.ts +31 -0
  33. package/dist/ui/branding.d.ts.map +1 -0
  34. package/dist/ui/branding.js +136 -0
  35. package/package.json +69 -0
  36. package/templates/typescript-oauth/.env.example +27 -0
  37. package/templates/typescript-oauth/OAUTH_SETUP.md +592 -0
  38. package/templates/typescript-oauth/README.md +263 -0
  39. package/templates/typescript-oauth/package.json +29 -0
  40. package/templates/typescript-oauth/src/app.module.ts +92 -0
  41. package/templates/typescript-oauth/src/guards/oauth.guard.ts +126 -0
  42. package/templates/typescript-oauth/src/health/system.health.ts +55 -0
  43. package/templates/typescript-oauth/src/index.ts +63 -0
  44. package/templates/typescript-oauth/src/modules/flights/booking.tools.ts +323 -0
  45. package/templates/typescript-oauth/src/modules/flights/flights.module.ts +14 -0
  46. package/templates/typescript-oauth/src/modules/flights/flights.prompts.ts +228 -0
  47. package/templates/typescript-oauth/src/modules/flights/flights.resources.ts +215 -0
  48. package/templates/typescript-oauth/src/modules/flights/flights.tools.ts +457 -0
  49. package/templates/typescript-oauth/src/services/duffel.service.ts +285 -0
  50. package/templates/typescript-oauth/src/widgets/app/airport-search/page.tsx +270 -0
  51. package/templates/typescript-oauth/src/widgets/app/flight-details/page.tsx +261 -0
  52. package/templates/typescript-oauth/src/widgets/app/flight-search-results/page.tsx +378 -0
  53. package/templates/typescript-oauth/src/widgets/app/globals.css +167 -0
  54. package/templates/typescript-oauth/src/widgets/app/layout.tsx +18 -0
  55. package/templates/typescript-oauth/src/widgets/app/order-cancellation/page.tsx +207 -0
  56. package/templates/typescript-oauth/src/widgets/app/order-summary/page.tsx +245 -0
  57. package/templates/typescript-oauth/src/widgets/app/payment-confirmation/page.tsx +152 -0
  58. package/templates/typescript-oauth/src/widgets/app/seat-selection/page.tsx +486 -0
  59. package/templates/typescript-oauth/src/widgets/next-env.d.ts +5 -0
  60. package/templates/typescript-oauth/src/widgets/next.config.js +45 -0
  61. package/templates/typescript-oauth/src/widgets/package-lock.json +4493 -0
  62. package/templates/typescript-oauth/src/widgets/package.json +24 -0
  63. package/templates/typescript-oauth/src/widgets/tsconfig.json +28 -0
  64. package/templates/typescript-oauth/src/widgets/widget-manifest.json +395 -0
  65. package/templates/typescript-oauth/tsconfig.json +23 -0
  66. package/templates/typescript-pizzaz/README.md +252 -0
  67. package/templates/typescript-pizzaz/package.json +34 -0
  68. package/templates/typescript-pizzaz/src/app.module.ts +28 -0
  69. package/templates/typescript-pizzaz/src/index.ts +30 -0
  70. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.data.ts +106 -0
  71. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.module.ts +11 -0
  72. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.service.ts +60 -0
  73. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.tools.ts +197 -0
  74. package/templates/typescript-pizzaz/src/widgets/app/layout.tsx +18 -0
  75. package/templates/typescript-pizzaz/src/widgets/app/pizza-list/page.tsx +272 -0
  76. package/templates/typescript-pizzaz/src/widgets/app/pizza-map/page.tsx +216 -0
  77. package/templates/typescript-pizzaz/src/widgets/app/pizza-shop/page.tsx +374 -0
  78. package/templates/typescript-pizzaz/src/widgets/components/CompactShopCard.tsx +144 -0
  79. package/templates/typescript-pizzaz/src/widgets/components/PizzaCard.tsx +191 -0
  80. package/templates/typescript-pizzaz/src/widgets/next.config.js +45 -0
  81. package/templates/typescript-pizzaz/src/widgets/package.json +30 -0
  82. package/templates/typescript-pizzaz/src/widgets/tsconfig.json +28 -0
  83. package/templates/typescript-pizzaz/src/widgets/widget-manifest.json +253 -0
  84. package/templates/typescript-pizzaz/tsconfig.json +30 -0
  85. package/templates/typescript-starter/README.md +320 -0
  86. package/templates/typescript-starter/package.json +25 -0
  87. package/templates/typescript-starter/src/app.module.ts +34 -0
  88. package/templates/typescript-starter/src/health/system.health.ts +55 -0
  89. package/templates/typescript-starter/src/index.ts +29 -0
  90. package/templates/typescript-starter/src/modules/calculator/calculator.module.ts +12 -0
  91. package/templates/typescript-starter/src/modules/calculator/calculator.prompts.ts +73 -0
  92. package/templates/typescript-starter/src/modules/calculator/calculator.resources.ts +59 -0
  93. package/templates/typescript-starter/src/modules/calculator/calculator.tools.ts +166 -0
  94. package/templates/typescript-starter/src/widgets/app/calculator-result/page.tsx +180 -0
  95. package/templates/typescript-starter/src/widgets/app/layout.tsx +18 -0
  96. package/templates/typescript-starter/src/widgets/next.config.js +45 -0
  97. package/templates/typescript-starter/src/widgets/package.json +24 -0
  98. package/templates/typescript-starter/src/widgets/tsconfig.json +28 -0
  99. package/templates/typescript-starter/src/widgets/widget-manifest.json +48 -0
  100. package/templates/typescript-starter/tsconfig.json +23 -0
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @nitrostack/cli
2
+
3
+ Command-line interface for creating NitroStack MCP server projects.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Use npm create (recommended)
9
+ npm create nitrostack my-project
10
+
11
+ # Or use npx
12
+ npx create-nitrostack my-project
13
+
14
+ # Or install globally
15
+ npm install -g @nitrostack/cli
16
+ create-nitrostack my-project
17
+ ```
18
+
19
+ > **Note:** Once a project is created, use the `nitrostack` command from the main `nitrostack` package for development commands (`dev`, `build`, `start`, etc.).
20
+
21
+ ## Commands
22
+
23
+ ### `nitrostack init [project-name]`
24
+
25
+ Create a new NitroStack project from a template.
26
+
27
+ ```bash
28
+ nitrostack init my-mcp-server
29
+ ```
30
+
31
+ **Options:**
32
+ - `--template <template>` - Template to use (typescript-starter, typescript-pizzaz, typescript-oauth)
33
+ - `--skip-install` - Skip installing dependencies
34
+
35
+ ### `nitrostack dev`
36
+
37
+ Start development server with hot reload and NitroStack Studio.
38
+
39
+ ```bash
40
+ nitrostack dev
41
+ ```
42
+
43
+ **Options:**
44
+ - `--port <port>` - Port for Studio (default: 3000)
45
+ - `--no-open` - Don't open browser automatically
46
+
47
+ ### `nitrostack build`
48
+
49
+ Build the project for production.
50
+
51
+ ```bash
52
+ nitrostack build
53
+ ```
54
+
55
+ **Options:**
56
+ - `--output <path>` - Output directory (default: dist)
57
+
58
+ ### `nitrostack start`
59
+
60
+ Start the production server.
61
+
62
+ ```bash
63
+ nitrostack start
64
+ ```
65
+
66
+ **Options:**
67
+ - `--port <port>` - Port for server (default: 3000)
68
+
69
+ ### `nitrostack generate <type> [name]`
70
+
71
+ Generate boilerplate code.
72
+
73
+ ```bash
74
+ nitrostack generate module users
75
+ nitrostack g tools payment
76
+ ```
77
+
78
+ **Types:**
79
+ - `module` - Create a new module with tools, resources, prompts
80
+ - `tools` - Generate tool definitions
81
+ - `resources` - Generate resource definitions
82
+ - `prompts` - Generate prompt definitions
83
+ - `service` - Generate a service class
84
+ - `guard` - Generate an auth guard
85
+ - `middleware` - Generate middleware
86
+ - `health` - Generate health check
87
+
88
+ **Options:**
89
+ - `--module <name>` - Module name for module-specific generation
90
+ - `--force` - Overwrite existing files
91
+ - `--skip-related` - Skip generating related files
92
+
93
+ ### `nitrostack upgrade`
94
+
95
+ Upgrade nitrostack to the latest version.
96
+
97
+ ```bash
98
+ nitrostack upgrade
99
+ ```
100
+
101
+ **Options:**
102
+ - `--dry-run` - Show what would be upgraded without making changes
103
+ - `--latest` - Force upgrade even if already up to date
104
+
105
+ ### `nitrostack install`
106
+
107
+ Install dependencies in both root and widget directories.
108
+
109
+ ```bash
110
+ nitrostack install
111
+ ```
112
+
113
+ **Options:**
114
+ - `--skip-widgets` - Skip installing widget dependencies
115
+ - `--production` - Install production dependencies only
116
+
117
+ ## Templates
118
+
119
+ ### typescript-starter
120
+ Simple calculator example for learning NitroStack basics.
121
+
122
+ ### typescript-pizzaz
123
+ Pizza shop finder with maps, widgets, and advanced features.
124
+
125
+ ### typescript-oauth
126
+ Flight booking system with OAuth 2.1 authentication.
127
+
128
+ ## License
129
+
130
+ Apache-2.0
131
+
@@ -0,0 +1,6 @@
1
+ interface BuildOptions {
2
+ output: string;
3
+ }
4
+ export declare function buildCommand(options: BuildOptions): Promise<void>;
5
+ export {};
6
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAeA,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,iBA0MvD"}
@@ -0,0 +1,185 @@
1
+ import { execSync } from 'child_process';
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+ import * as esbuild from 'esbuild';
5
+ import { createHeader, createSuccessBox, createErrorBox, NitroSpinner, spacer, nextSteps } from '../ui/branding.js';
6
+ export async function buildCommand(options) {
7
+ console.log(createHeader('Build', 'Production bundle'));
8
+ const startTime = Date.now();
9
+ // Validate project
10
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
11
+ if (!fs.existsSync(packageJsonPath)) {
12
+ console.log(createErrorBox('Not a NitroStack Project', 'package.json not found'));
13
+ process.exit(1);
14
+ }
15
+ const tsconfigPath = path.join(process.cwd(), 'tsconfig.json');
16
+ if (!fs.existsSync(tsconfigPath)) {
17
+ console.log(createErrorBox('Missing Configuration', 'tsconfig.json not found'));
18
+ process.exit(1);
19
+ }
20
+ // Detect widgets
21
+ const widgetsPath = path.resolve(process.cwd(), 'src/widgets');
22
+ const widgetsPackageJsonPath = path.join(widgetsPath, 'package.json');
23
+ const hasWidgets = fs.existsSync(widgetsPackageJsonPath);
24
+ const buildArtifacts = [];
25
+ try {
26
+ // Build widgets first if they exist
27
+ if (hasWidgets) {
28
+ // Install dependencies if needed
29
+ const widgetsNodeModulesPath = path.join(widgetsPath, 'node_modules');
30
+ if (!fs.existsSync(widgetsNodeModulesPath)) {
31
+ const depsSpinner = new NitroSpinner('Installing widget dependencies...').start();
32
+ try {
33
+ execSync('npm install', { cwd: widgetsPath, stdio: 'pipe' });
34
+ depsSpinner.succeed('Widget dependencies installed');
35
+ }
36
+ catch {
37
+ depsSpinner.fail('Failed to install widget dependencies');
38
+ throw new Error('Widget dependency installation failed');
39
+ }
40
+ }
41
+ const widgetSpinner = new NitroSpinner('Bundling widgets...').start();
42
+ try {
43
+ const APP_DIR = path.join(widgetsPath, 'app');
44
+ const OUT_DIR = path.join(widgetsPath, 'out');
45
+ // Clean output directory
46
+ if (fs.existsSync(OUT_DIR)) {
47
+ fs.rmSync(OUT_DIR, { recursive: true });
48
+ }
49
+ fs.mkdirSync(OUT_DIR, { recursive: true });
50
+ // Find all widget pages
51
+ const widgetPages = [];
52
+ function findWidgetPages(dir, basePath = '') {
53
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
54
+ for (const entry of entries) {
55
+ const fullPath = path.join(dir, entry.name);
56
+ const relativePath = path.join(basePath, entry.name);
57
+ if (entry.isDirectory()) {
58
+ findWidgetPages(fullPath, relativePath);
59
+ }
60
+ else if (entry.name === 'page.tsx' || entry.name === 'page.jsx') {
61
+ const widgetName = basePath || 'index';
62
+ widgetPages.push({
63
+ name: widgetName,
64
+ entryPoint: fullPath,
65
+ outputName: widgetName.replace(/\//g, '-')
66
+ });
67
+ }
68
+ }
69
+ }
70
+ if (fs.existsSync(APP_DIR)) {
71
+ findWidgetPages(APP_DIR);
72
+ }
73
+ // Bundle each widget
74
+ for (const widget of widgetPages) {
75
+ const tempEntry = path.join(OUT_DIR, `_temp_${widget.outputName}.jsx`);
76
+ const jsOutput = path.join(OUT_DIR, `${widget.outputName}.js`);
77
+ const htmlOutput = path.join(OUT_DIR, `${widget.outputName}.html`);
78
+ const entryCode = `
79
+ import React from 'react';
80
+ import { createRoot } from 'react-dom/client';
81
+ import WidgetPage from '${widget.entryPoint.replace(/\\/g, '/')}';
82
+
83
+ if (document.readyState === 'loading') {
84
+ document.addEventListener('DOMContentLoaded', init);
85
+ } else {
86
+ init();
87
+ }
88
+
89
+ function init() {
90
+ const data = window.openai?.toolOutput || {};
91
+
92
+ let root = document.getElementById('widget-root');
93
+ if (!root) {
94
+ root = document.createElement('div');
95
+ root.id = 'widget-root';
96
+ document.body.appendChild(root);
97
+ }
98
+
99
+ const reactRoot = createRoot(root);
100
+ reactRoot.render(React.createElement(WidgetPage, { data }));
101
+ }
102
+ `;
103
+ fs.writeFileSync(tempEntry, entryCode);
104
+ await esbuild.build({
105
+ entryPoints: [tempEntry],
106
+ bundle: true,
107
+ format: 'iife',
108
+ outfile: jsOutput,
109
+ platform: 'browser',
110
+ target: ['es2020'],
111
+ minify: true,
112
+ jsx: 'automatic',
113
+ jsxImportSource: 'react',
114
+ external: [],
115
+ nodePaths: [path.join(widgetsPath, 'node_modules')],
116
+ define: {
117
+ 'process.env.NODE_ENV': '"production"'
118
+ },
119
+ logLevel: 'warning'
120
+ });
121
+ const bundledJs = fs.readFileSync(jsOutput, 'utf-8');
122
+ const html = `<!DOCTYPE html>
123
+ <html lang="en">
124
+ <head>
125
+ <meta charset="utf-8">
126
+ <meta name="viewport" content="width=device-width, initial-scale=1">
127
+ <style>
128
+ * { box-sizing: border-box; }
129
+ body {
130
+ margin: 0;
131
+ padding: 0;
132
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
133
+ }
134
+ #widget-root {
135
+ width: 100%;
136
+ min-height: 100vh;
137
+ }
138
+ </style>
139
+ </head>
140
+ <body>
141
+ <div id="widget-root"></div>
142
+ <script>${bundledJs}</script>
143
+ </body>
144
+ </html>`;
145
+ fs.writeFileSync(htmlOutput, html);
146
+ fs.unlinkSync(tempEntry);
147
+ fs.unlinkSync(jsOutput);
148
+ }
149
+ widgetSpinner.succeed(`Widgets bundled (${widgetPages.length} widgets)`);
150
+ buildArtifacts.push(`src/widgets/out/ (${widgetPages.length} widgets)`);
151
+ }
152
+ catch (error) {
153
+ widgetSpinner.fail('Widget bundling failed');
154
+ throw error;
155
+ }
156
+ }
157
+ // Build TypeScript
158
+ const tscSpinner = new NitroSpinner('Compiling TypeScript...').start();
159
+ try {
160
+ execSync('npx tsc', {
161
+ cwd: process.cwd(),
162
+ stdio: 'pipe',
163
+ });
164
+ tscSpinner.succeed('TypeScript compiled');
165
+ buildArtifacts.push(options.output);
166
+ }
167
+ catch (error) {
168
+ tscSpinner.fail('TypeScript compilation failed');
169
+ throw error;
170
+ }
171
+ // Summary
172
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
173
+ spacer();
174
+ console.log(createSuccessBox(`Build Complete (${elapsed}s)`, buildArtifacts));
175
+ nextSteps([
176
+ 'npm start - Start production server',
177
+ 'nitrostack start - Alternative start command',
178
+ ]);
179
+ }
180
+ catch (error) {
181
+ spacer();
182
+ console.log(createErrorBox('Build Failed', error instanceof Error ? error.message : String(error)));
183
+ process.exit(1);
184
+ }
185
+ }
@@ -0,0 +1,7 @@
1
+ interface DevOptions {
2
+ port: string;
3
+ noOpen?: boolean;
4
+ }
5
+ export declare function devCommand(options: DevOptions): Promise<void>;
6
+ export {};
7
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AA+LA,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,UAAU,iBAgPnD"}