test-bdk-cli 0.1.16 → 0.1.18

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.
@@ -67,7 +67,8 @@ function registerPack(program) {
67
67
  const version = manifest.version || '0.0.0';
68
68
  const fmt = (opts.format || 'zip').toLowerCase();
69
69
  const outTarget = opts.output || './dist';
70
- let outputPath = path_1.default.resolve(process.cwd(), outTarget);
70
+ // Resolve output path relative to source directory, not current working directory
71
+ let outputPath = path_1.default.resolve(sourceDir, outTarget);
71
72
  try {
72
73
  const stat = fs_1.default.existsSync(outputPath) && fs_1.default.statSync(outputPath);
73
74
  if (!stat || stat.isDirectory()) {
@@ -26,7 +26,9 @@ function registerPublish(program) {
26
26
  console.log('No package file given — running `bdk pack` to create archive...');
27
27
  try {
28
28
  const cliEntry = path_1.default.resolve(__dirname, '../index.js');
29
- (0, child_process_1.execSync)(`node "${cliEntry}" pack --source . --output ./dist --format zip`, { cwd: sourceDir, stdio: 'inherit' });
29
+ // Pass sourceArg or sourceDir to pack command
30
+ const sourceArg_str = sourceArg ? `"${sourceArg}"` : '.';
31
+ (0, child_process_1.execSync)(`node "${cliEntry}" pack ${sourceArg_str} --output ./dist --format zip`, { cwd: process.cwd(), stdio: 'inherit' });
30
32
  }
31
33
  catch (e) {
32
34
  console.error('Automatic pack failed; please run `bdk pack` manually or provide --file');
@@ -1,16 +1,155 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.registerRun = registerRun;
37
+ const http = __importStar(require("http"));
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const child_process_1 = require("child_process");
4
41
  function registerRun(program) {
5
42
  program
6
- .command('run')
43
+ .command('run [source]')
7
44
  .alias('apps:run')
8
45
  .description('Run the app locally with live reload')
9
46
  .option('--port <number>', 'port to run', '3000')
10
47
  .option('--env <env>', 'environment', 'dev')
11
48
  .option('--open', 'open browser after start', false)
12
- .action((opts) => {
13
- console.log(`Starting dev server on port ${opts.port} (env=${opts.env})`);
14
- console.log('Dev server is a thin wrapper; run template-specific dev script for now.');
49
+ .action((sourceArg, opts) => {
50
+ const sourceDir = path.resolve(process.cwd(), sourceArg || '.');
51
+ const port = parseInt(opts.port || '3000', 10);
52
+ const env = opts.env || 'dev';
53
+ // Check if manifest.json exists
54
+ const manifestPath = path.join(sourceDir, 'manifest.json');
55
+ if (!fs.existsSync(manifestPath)) {
56
+ console.error(`manifest.json not found in ${sourceDir}`);
57
+ process.exit(1);
58
+ }
59
+ // Create a simple HTTP server
60
+ const server = http.createServer((req, res) => {
61
+ let filePath = req.url || '/';
62
+ if (filePath === '/') {
63
+ filePath = '/assets/iframe.html';
64
+ }
65
+ // Resolve the file path
66
+ const fullPath = path.join(sourceDir, filePath);
67
+ // Security: prevent directory traversal attacks
68
+ const resolvedPath = path.resolve(fullPath);
69
+ const basePath = path.resolve(sourceDir);
70
+ if (!resolvedPath.startsWith(basePath)) {
71
+ res.writeHead(403, { 'Content-Type': 'text/plain' });
72
+ res.end('Forbidden');
73
+ return;
74
+ }
75
+ // Try to serve the file
76
+ fs.readFile(resolvedPath, (err, data) => {
77
+ if (err) {
78
+ // If file not found, try to serve index.html or 404
79
+ if (err.code === 'ENOENT') {
80
+ res.writeHead(404, { 'Content-Type': 'text/html' });
81
+ res.end(`
82
+ <!DOCTYPE html>
83
+ <html>
84
+ <head><title>404 Not Found</title></head>
85
+ <body>
86
+ <h1>404 - File Not Found</h1>
87
+ <p>Could not find: ${filePath}</p>
88
+ <p><a href="/">Go back</a></p>
89
+ </body>
90
+ </html>
91
+ `);
92
+ }
93
+ else {
94
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
95
+ res.end('Internal Server Error');
96
+ }
97
+ return;
98
+ }
99
+ // Determine content type
100
+ const ext = path.extname(resolvedPath);
101
+ let contentType = 'application/octet-stream';
102
+ if (ext === '.html')
103
+ contentType = 'text/html; charset=utf-8';
104
+ else if (ext === '.js')
105
+ contentType = 'application/javascript; charset=utf-8';
106
+ else if (ext === '.json')
107
+ contentType = 'application/json; charset=utf-8';
108
+ else if (ext === '.css')
109
+ contentType = 'text/css; charset=utf-8';
110
+ else if (ext === '.svg')
111
+ contentType = 'image/svg+xml';
112
+ else if (ext === '.png')
113
+ contentType = 'image/png';
114
+ else if (ext === '.jpg' || ext === '.jpeg')
115
+ contentType = 'image/jpeg';
116
+ else if (ext === '.gif')
117
+ contentType = 'image/gif';
118
+ res.writeHead(200, { 'Content-Type': contentType });
119
+ res.end(data);
120
+ });
121
+ });
122
+ server.listen(port, () => {
123
+ console.log(`✅ Dev server started on http://localhost:${port} (env=${env})`);
124
+ console.log(`📁 Serving from: ${sourceDir}`);
125
+ console.log(`📄 Iframe: http://localhost:${port}/assets/iframe.html`);
126
+ console.log(`\nPress Ctrl+C to stop the server\n`);
127
+ // Open browser if --open flag is set
128
+ if (opts.open) {
129
+ const url = `http://localhost:${port}`;
130
+ try {
131
+ const isWindows = process.platform === 'win32';
132
+ const command = isWindows
133
+ ? `start ${url}`
134
+ : process.platform === 'darwin'
135
+ ? `open ${url}`
136
+ : `xdg-open ${url}`;
137
+ (0, child_process_1.execSync)(command, { stdio: 'ignore' });
138
+ }
139
+ catch (e) {
140
+ // Silently ignore if browser open fails
141
+ }
142
+ }
143
+ });
144
+ server.on('error', (err) => {
145
+ if (err.code === 'EADDRINUSE') {
146
+ console.error(`❌ Port ${port} is already in use. Try a different port:`);
147
+ console.error(` npx test-bdk-cli apps:run [source] --port 3001`);
148
+ }
149
+ else {
150
+ console.error(`❌ Server error: ${err.message}`);
151
+ }
152
+ process.exit(1);
153
+ });
15
154
  });
16
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-bdk-cli",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "test CLI",
5
5
  "author": "@raisulaslam",
6
6
  "bin": {
@@ -3,9 +3,9 @@
3
3
  "version": "0.1.0",
4
4
  "description": "Sample app scaffolded by bdk",
5
5
  "scripts": {
6
- "start": "echo \"No start script defined\" && exit 0",
7
- "build": "echo \"No build script defined\" && exit 0",
8
- "test": "echo \"No tests defined\" && exit 0"
6
+ "start": "echo Starting app...",
7
+ "build": "echo Building app...",
8
+ "test": "echo Running tests..."
9
9
  },
10
10
  "author": "",
11
11
  "license": "MIT"