spaps 0.5.0 → 0.5.1

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.
@@ -0,0 +1,155 @@
1
+ const chalk = require('chalk');
2
+ const fs = require('fs');
3
+ const { DEFAULT_PORT } = require('./config');
4
+ const { handleError } = require('./error-handler');
5
+ const { showInteractiveHelp, showQuickHelp } = require('./help-system');
6
+ const { showInteractiveDocs, showQuickReference, searchDocs } = require('./docs-system');
7
+ const { getQuickStartInstructions, getServerStatus, runQuickTest } = require('./ai-helper');
8
+
9
+ function createHandlers(version, logo) {
10
+ return {
11
+ local: async ({ options }) => {
12
+ const isJson = options.json;
13
+ if (!isJson) console.log(logo);
14
+ try {
15
+ const LocalServer = require('./local-server.js');
16
+ const server = new LocalServer({ port: options.port, json: isJson });
17
+ if (isJson) {
18
+ await server.start();
19
+ console.log(JSON.stringify({
20
+ success: true,
21
+ command: 'local',
22
+ server: {
23
+ url: `http://localhost:${options.port}`,
24
+ docs: `http://localhost:${options.port}/docs`,
25
+ mode: 'local-development',
26
+ port: Number(options.port),
27
+ features: { autoAuth: true, corsEnabled: true, testUsers: ['user', 'admin', 'premium'], apiKeyRequired: false }
28
+ }
29
+ }));
30
+ } else {
31
+ await server.start();
32
+ if (options.open) {
33
+ const { exec } = require('child_process');
34
+ const url = `http://localhost:${options.port}/docs`;
35
+ const start = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
36
+ exec(`${start} ${url}`);
37
+ }
38
+ }
39
+ process.on('SIGINT', () => {
40
+ if (!isJson) console.log(chalk.yellow('\nšŸ‘‹ Shutting down SPAPS local server...'));
41
+ process.exit(0);
42
+ });
43
+ } catch (error) {
44
+ handleError(error, { port: options.port, command: 'local' }, { json: isJson });
45
+ }
46
+ },
47
+ quickstart: async ({ options }) => {
48
+ const instructions = getQuickStartInstructions(options.port);
49
+ if (options.json) {
50
+ console.log(JSON.stringify(instructions, null, 2));
51
+ } else {
52
+ console.log(chalk.yellow('\nšŸ  SPAPS Quick Start Instructions\n'));
53
+ console.log('1. Install SDK: npm install spaps-sdk');
54
+ console.log('2. Create test file with the code above');
55
+ console.log('3. Run: node test-spaps.js');
56
+ console.log('\nFor JSON output: npx spaps quickstart --json');
57
+ }
58
+ },
59
+ status: async ({ options }) => {
60
+ const status = await getServerStatus(options.port);
61
+ if (options.json) {
62
+ console.log(JSON.stringify(status));
63
+ } else {
64
+ if (!status.running) {
65
+ console.log(chalk.red('\nāŒ SPAPS server is not running'));
66
+ console.log('Start it with:');
67
+ console.log(chalk.cyan(` npx spaps local --port ${options.port}`));
68
+ console.log();
69
+ } else {
70
+ console.log(chalk.green('\nāœ… SPAPS server is running!\n'));
71
+ console.log(' URL:', chalk.cyan(status.url));
72
+ console.log(' Docs:', chalk.cyan(status.docs));
73
+ console.log();
74
+ }
75
+ }
76
+ },
77
+ test: async ({ options }) => {
78
+ const result = await runQuickTest(options.port);
79
+ console.log(JSON.stringify(result, null, 2));
80
+ },
81
+ init: async ({ options }) => {
82
+ const isJson = options.json;
83
+ const envContent = `# SPAPS Local Development\nSPAPS_API_URL=http://localhost:${DEFAULT_PORT}\n# SPAPS_API_KEY=your-api-key-here\n`;
84
+ const result = { success: true, command: 'init', files_created: [], files_skipped: [], next_steps: ['npx spaps local', 'npm install @spaps/sdk', 'Start coding!'] };
85
+ if (!fs.existsSync('.env.local')) {
86
+ fs.writeFileSync('.env.local', envContent);
87
+ result.files_created.push('.env.local');
88
+ if (!isJson) console.log(chalk.green('āœ… Created .env.local'));
89
+ } else {
90
+ result.files_skipped.push('.env.local');
91
+ result.message = '.env.local already exists';
92
+ if (!isJson) console.log(chalk.yellow('āš ļø .env.local already exists'));
93
+ }
94
+ if (isJson) {
95
+ console.log(JSON.stringify(result));
96
+ } else {
97
+ console.log();
98
+ console.log(chalk.green('✨ SPAPS initialized!'));
99
+ console.log();
100
+ console.log('Next steps:');
101
+ console.log(chalk.cyan(' 1. Run: npx spaps local'));
102
+ console.log(chalk.cyan(' 2. Install SDK: npm install @spaps/sdk'));
103
+ console.log(chalk.cyan(' 3. Start coding!'));
104
+ }
105
+ },
106
+ create: () => {
107
+ console.log(chalk.yellow('šŸ  SPAPS'));
108
+ console.log(chalk.yellow(`🚧 'spaps create' coming in v0.3.0!`));
109
+ console.log();
110
+ console.log('For now, check out our examples:');
111
+ console.log(chalk.cyan(' https://github.com/yourusername/sweet-potato/tree/main/examples'));
112
+ },
113
+ types: () => {
114
+ console.log(chalk.yellow('šŸ  SPAPS'));
115
+ console.log(chalk.yellow(`🚧 'spaps types' coming in v0.4.0!`));
116
+ },
117
+ help: async ({ options }) => {
118
+ if (options.interactive) {
119
+ await showInteractiveHelp();
120
+ } else if (options.quick) {
121
+ showQuickHelp();
122
+ } else {
123
+ showQuickHelp();
124
+ }
125
+ },
126
+ docs: async ({ options }) => {
127
+ if (options.search) {
128
+ const results = searchDocs(options.search);
129
+ if (options.json) {
130
+ console.log(JSON.stringify({ results }, null, 2));
131
+ } else {
132
+ console.log(chalk.yellow(`\nšŸ” Search results for "${options.search}":\n`));
133
+ if (results.length === 0) {
134
+ console.log(chalk.gray(' No results found'));
135
+ } else {
136
+ results.forEach((result, i) => {
137
+ console.log(chalk.green(` ${i + 1}. ${result.title}`));
138
+ console.log(chalk.gray(` ${result.preview}`));
139
+ console.log();
140
+ });
141
+ }
142
+ console.log(chalk.blue(' Run: npx spaps docs --interactive'));
143
+ console.log(chalk.blue(' to browse full documentation\n'));
144
+ }
145
+ } else if (options.interactive) {
146
+ await showInteractiveDocs();
147
+ } else {
148
+ showQuickReference();
149
+ }
150
+ }
151
+ };
152
+ }
153
+
154
+ module.exports = { createHandlers };
155
+
@@ -6,6 +6,8 @@
6
6
  const chalk = require('chalk');
7
7
  const prompts = require('prompts');
8
8
 
9
+ const { DEFAULT_PORT } = require('./config');
10
+
9
11
  const HELP_TREE = {
10
12
  root: {
11
13
  question: 'What would you like to do?',
@@ -45,12 +47,12 @@ const HELP_TREE = {
45
47
  title: 'Quick start (default settings)',
46
48
  value: 'quick-start',
47
49
  command: 'npx spaps local',
48
- description: 'Start on port 3300'
50
+ description: `Start on port ${DEFAULT_PORT}`
49
51
  },
50
52
  {
51
53
  title: 'Custom port',
52
54
  value: 'custom-port',
53
- command: 'npx spaps local --port 3001',
55
+ command: `npx spaps local --port ${DEFAULT_PORT + 1}`,
54
56
  description: 'Choose your own port'
55
57
  },
56
58
  {
@@ -484,4 +486,4 @@ module.exports = {
484
486
  showInteractiveHelp,
485
487
  showQuickHelp,
486
488
  HELP_TREE
487
- };
489
+ };