@orion-js/core 4.0.0-next.4 → 4.0.0-next.5

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/dist/index.js CHANGED
@@ -7,142 +7,68 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
  });
8
8
 
9
9
  // src/index.ts
10
+ import chalk11 from "chalk";
10
11
  import { Command } from "commander";
11
12
 
12
- // src/start/index.ts
13
- import colors7 from "colors/safe";
14
-
15
- // src/start/runner/index.ts
16
- import colors from "colors/safe";
17
-
18
- // src/helpers/writeFile.ts
19
- import fs2 from "fs";
20
-
21
- // src/helpers/ensureDirectory.ts
22
- import fs from "fs";
23
- import path from "path";
24
- var ensureDirectory = function(filePath) {
25
- const dirname = path.dirname(filePath);
26
- if (fs.existsSync(dirname)) return true;
27
- ensureDirectory(dirname);
28
- fs.mkdirSync(dirname);
29
- };
30
- var ensureDirectory_default = ensureDirectory;
31
-
32
- // src/helpers/writeFile.ts
33
- async function writeFile_default(path9, content) {
34
- ensureDirectory_default(path9);
35
- fs2.writeFileSync(path9, content);
36
- }
37
-
38
- // src/start/runner/startProcess.ts
39
- import { spawn } from "child_process";
40
-
41
- // src/start/runner/getArgs.ts
42
- function getArgs(options) {
43
- let startCommand = process.env.START_COMMAND || "node";
44
- const args = [];
45
- if (process.env.START_COMMAND) {
46
- const [first, ...otherArgs] = process.env.START_COMMAND.split(" ");
47
- startCommand = first;
48
- args.push(...otherArgs);
49
- console.log("Using custom command: " + [startCommand, ...args].join(" "));
50
- } else if (options.shell) {
51
- args.push("--inspect");
52
- }
53
- args.push(".orion/build/index.js");
54
- return { startCommand, args };
55
- }
56
-
57
- // src/start/runner/startProcess.ts
58
- function startProcess(options) {
59
- const { startCommand, args } = getArgs(options);
60
- return spawn(startCommand, args, {
61
- env: {
62
- ORION_DEV: "local",
63
- ...process.env
64
- },
65
- cwd: process.cwd(),
66
- stdio: "inherit",
67
- detached: false
68
- });
69
- }
13
+ // src/build/index.ts
14
+ import chalk2 from "chalk";
70
15
 
71
- // src/start/runner/index.ts
72
- function getRunner(options) {
73
- let appProcess = null;
74
- if (options.clean) {
75
- console.log(colors.bold("=> Cleaning directory...\n"));
76
- }
77
- const start = () => {
78
- console.log(colors.bold("=> Starting app...\n"));
79
- appProcess = startProcess(options);
80
- appProcess.on("exit", function(code, signal) {
81
- if (!code || code === 143 || code === 0 || signal === "SIGTERM" || signal === "SIGINT") {
16
+ // src/helpers/execute.ts
17
+ import { exec } from "child_process";
18
+ async function execute_default(command) {
19
+ return new Promise((resolve, reject) => {
20
+ exec(command, (error, stdout, stderr) => {
21
+ if (error) {
22
+ reject(error);
82
23
  } else {
83
- console.log(colors.bold(`=> Error running app. Exit code: ${code}`));
24
+ resolve({ stdout, stderr });
84
25
  }
85
26
  });
86
- writeFile_default(".orion/process", `${appProcess.pid}`);
87
- };
88
- const stop = () => {
89
- if (appProcess) {
90
- appProcess.kill();
91
- }
92
- };
93
- const restart = () => {
94
- stop();
95
- start();
96
- };
97
- return {
98
- restart,
99
- stop,
100
- basePath: `${process.cwd()}/.orion/build`
101
- };
27
+ });
102
28
  }
103
29
 
104
- // src/start/watchAndCompile/index.ts
30
+ // src/build/compile.ts
31
+ import chalk from "chalk";
105
32
  import ts4 from "typescript";
106
33
 
107
- // src/start/watchAndCompile/cleanDirectory.ts
108
- import fs3 from "fs";
34
+ // src/build/getOptions.ts
109
35
  import path2 from "path";
110
- function rimraf(dir_path) {
111
- if (fs3.existsSync(dir_path)) {
112
- fs3.readdirSync(dir_path).forEach(function(entry) {
113
- var entry_path = path2.join(dir_path, entry);
114
- if (fs3.lstatSync(entry_path).isDirectory()) {
115
- rimraf(entry_path);
116
- } else {
117
- fs3.unlinkSync(entry_path);
118
- }
119
- });
120
- fs3.rmdirSync(dir_path);
121
- }
122
- }
123
- async function cleanDirectory() {
124
- try {
125
- const path9 = `${process.cwd()}/.orion/build`;
126
- rimraf(path9);
127
- } catch {
128
- }
129
- }
130
-
131
- // src/start/watchAndCompile/getHost.ts
132
36
  import ts3 from "typescript";
133
37
 
134
38
  // src/start/watchAndCompile/getConfigPath.ts
135
39
  import ts from "typescript";
136
40
 
41
+ // src/start/watchAndCompile/ensureConfigComplies.ts
42
+ import { parse, stringify } from "comment-json";
43
+
137
44
  // src/helpers/getFileContents.ts
138
- import fs4 from "fs";
45
+ import fs from "fs";
139
46
  function readFile(filePath) {
140
- if (!fs4.existsSync(filePath)) return null;
141
- return fs4.readFileSync(filePath).toString();
47
+ if (!fs.existsSync(filePath)) return null;
48
+ return fs.readFileSync(filePath).toString();
49
+ }
50
+
51
+ // src/helpers/writeFile.ts
52
+ import fs3 from "fs";
53
+
54
+ // src/helpers/ensureDirectory.ts
55
+ import fs2 from "fs";
56
+ import path from "path";
57
+ var ensureDirectory = (filePath) => {
58
+ const dirname = path.dirname(filePath);
59
+ if (fs2.existsSync(dirname)) return true;
60
+ ensureDirectory(dirname);
61
+ fs2.mkdirSync(dirname);
62
+ };
63
+ var ensureDirectory_default = ensureDirectory;
64
+
65
+ // src/helpers/writeFile.ts
66
+ async function writeFile_default(path8, content) {
67
+ ensureDirectory_default(path8);
68
+ fs3.writeFileSync(path8, content);
142
69
  }
143
70
 
144
71
  // src/start/watchAndCompile/ensureConfigComplies.ts
145
- import { parse, stringify } from "comment-json";
146
72
  function ensureConfigComplies(configPath) {
147
73
  var _a, _b;
148
74
  try {
@@ -152,16 +78,16 @@ function ensureConfigComplies(configPath) {
152
78
  ...config,
153
79
  compilerOptions: {
154
80
  ...config.compilerOptions,
155
- outDir: `./.orion/build/app`,
156
- baseUrl: `./`
81
+ outDir: "./.orion/build/app",
82
+ baseUrl: "./"
157
83
  }
158
84
  };
159
85
  if (!((_a = config.compilerOptions) == null ? void 0 : _a.rootDir) && !((_b = config.compilerOptions) == null ? void 0 : _b.rootDirs)) {
160
- newConfig.compilerOptions.rootDir = `./app`;
86
+ newConfig.compilerOptions.rootDir = "./app";
161
87
  }
162
88
  writeFile_default(configPath, stringify(newConfig, null, 2));
163
89
  } catch (error) {
164
- console.log(`Error reading tsconfig ${error.message}`);
90
+ console.log(`Error reading tsconfig: ${error.message}`);
165
91
  }
166
92
  }
167
93
 
@@ -176,7 +102,7 @@ function getConfigPath() {
176
102
  return configPath;
177
103
  }
178
104
 
179
- // src/start/watchAndCompile/reports.ts
105
+ // src/build/reports.ts
180
106
  import ts2 from "typescript";
181
107
  var format = {
182
108
  getCanonicalFileName: (fileName) => fileName,
@@ -187,123 +113,86 @@ function reportDiagnostic(diagnostic) {
187
113
  console.log(ts2.formatDiagnosticsWithColorAndContext([diagnostic], format));
188
114
  }
189
115
 
190
- // src/start/watchAndCompile/getHost.ts
191
- import colors2 from "colors/safe";
192
-
193
- // src/start/watchAndCompile/writeIndex/index.ts
194
- import fs5 from "fs";
195
- import path3 from "path";
196
- function writeIndex_default({ basePath }) {
197
- const libPath = `${basePath}/moduleAliasLib.js`;
198
- const libContentPath = path3.resolve(__dirname, "../../../../moduleAlias.js.txt");
199
- const libContent = fs5.readFileSync(libContentPath).toString();
200
- writeFile_default(libPath, libContent);
201
- const aliasPath = `${basePath}/moduleAlias.js`;
202
- writeFile_default(
203
- aliasPath,
204
- `"use strict";
205
- Object.defineProperty(exports, "__esModule", { value: true });
206
- const moduleAlias = require('./moduleAliasLib')
207
- const path = __dirname + '/app'
208
- moduleAlias.addAlias('app', path)
209
- `
210
- );
211
- const indexPath = `${basePath}/index.js`;
212
- writeFile_default(
213
- indexPath,
214
- `"use strict";
215
- Object.defineProperty(exports, "__esModule", { value: true });
216
- require("./moduleAlias");
217
- require("./app");
218
- `
219
- );
220
- }
221
-
222
- // src/start/watchAndCompile/getHost.ts
223
- function getHost(runner) {
224
- const reportWatchStatusChanged = (diagnostic) => {
225
- if (diagnostic.category !== 3) return;
226
- if (diagnostic.code === 6032 || diagnostic.code === 6031) {
227
- runner.stop();
228
- }
229
- console.log(colors2.bold(`=> ${diagnostic.messageText}`));
230
- if (diagnostic.code === 6194) {
231
- if (/^Found .+ errors?/.test(diagnostic.messageText.toString())) {
232
- if (!diagnostic.messageText.toString().includes("Found 0 errors.")) {
233
- return;
234
- }
235
- }
236
- writeIndex_default({ basePath: runner.basePath });
237
- runner.restart();
238
- }
116
+ // src/build/getOptions.ts
117
+ function getCompilerOptionsJSONFollowExtends(filename) {
118
+ let compopts = {};
119
+ const config = ts3.readConfigFile(filename, ts3.sys.readFile).config;
120
+ if (config.extends) {
121
+ const rqrpath = __require.resolve(config.extends);
122
+ compopts = getCompilerOptionsJSONFollowExtends(rqrpath);
123
+ }
124
+ return {
125
+ ...compopts,
126
+ ...config.compilerOptions
239
127
  };
128
+ }
129
+ function getOptions({ output }) {
240
130
  const configPath = getConfigPath();
241
- const createProgram = ts3.createEmitAndSemanticDiagnosticsBuilderProgram;
242
- const host = ts3.createWatchCompilerHost(
243
- configPath,
244
- {},
245
- ts3.sys,
246
- createProgram,
247
- reportDiagnostic,
248
- reportWatchStatusChanged
249
- );
250
- return host;
131
+ const config = getCompilerOptionsJSONFollowExtends(configPath);
132
+ config.outDir = `${output}/app`;
133
+ config.incremental = false;
134
+ const { options, errors } = ts3.convertCompilerOptionsFromJson(config, path2.dirname(configPath));
135
+ if (errors.length) {
136
+ errors.forEach(reportDiagnostic);
137
+ process.exit(1);
138
+ }
139
+ return options;
251
140
  }
252
141
 
253
- // src/start/watchAndCompile/watchDeletes.ts
254
- import chokidar from "chokidar";
255
- import path4 from "path";
256
- import fs6 from "fs";
257
- async function watchDeletes() {
258
- const projectPath = path4.resolve("./app");
259
- const watcher = chokidar.watch(projectPath, {
260
- ignoreInitial: true
261
- });
262
- watcher.on("unlink", async (filepath) => {
263
- if (!filepath.endsWith(".ts")) return;
264
- const relative = path4.relative(process.cwd(), filepath);
265
- const atBuildPath = path4.resolve(".orion/build", relative.replace(/.ts$/, ""));
266
- try {
267
- fs6.unlinkSync(`${atBuildPath}.js`);
268
- fs6.unlinkSync(`${atBuildPath}.d.ts`);
269
- } catch (error) {
270
- console.log(
271
- `Error cleaning ${atBuildPath}. Restar project is suggested. Error: ${error.message}`
272
- );
273
- }
274
- });
142
+ // src/build/compile.ts
143
+ function compile({ output }) {
144
+ const options = getOptions({ output });
145
+ const program2 = ts4.createProgram(["./app/index.ts"], options);
146
+ const preEmitDiagnostics = ts4.getPreEmitDiagnostics(program2);
147
+ if (preEmitDiagnostics.length > 0) {
148
+ console.log(chalk.red("\n==> Error builing Orion app\n"));
149
+ }
150
+ preEmitDiagnostics.forEach(reportDiagnostic);
151
+ if (preEmitDiagnostics.length > 0) {
152
+ process.exit(1);
153
+ }
154
+ const emitResult = program2.emit();
155
+ emitResult.diagnostics.forEach(reportDiagnostic);
156
+ if (emitResult.emitSkipped) {
157
+ process.exit(1);
158
+ }
275
159
  }
276
160
 
277
- // src/start/watchAndCompile/writeEnvFile.ts
278
- import chokidar2 from "chokidar";
279
- import colors3 from "colors/safe";
280
- import { writeDtsFileFromConfigFile } from "@orion-js/env";
281
- var envFilePath = process.env.ORION_ENV_FILE_PATH;
282
- var dtsFilePath = "./app/env.d.ts";
283
- var watchEnvFile = async (runner) => {
284
- if (!envFilePath) return;
285
- writeDtsFileFromConfigFile(envFilePath, dtsFilePath);
286
- chokidar2.watch(envFilePath, { ignoreInitial: true }).on("change", async () => {
287
- console.log(colors3.bold(`=> Environment file changed. Restarting...`));
288
- writeDtsFileFromConfigFile(envFilePath, dtsFilePath);
289
- runner.restart();
290
- });
291
- };
161
+ // src/build/index.ts
162
+ async function build_default({ output }) {
163
+ if (!output) {
164
+ output = "./build";
165
+ }
166
+ console.log(chalk2.bold(`Cleaning directory ${output}...`));
167
+ await execute_default(`rm -rf ${output}`);
168
+ console.log(chalk2.bold("Compiling your app..."));
169
+ compile({ output });
170
+ console.log(chalk2.bold("Build created"));
171
+ }
292
172
 
293
- // src/start/watchAndCompile/index.ts
294
- async function watchAndCompile(runner) {
295
- await cleanDirectory();
296
- const host = getHost(runner);
297
- ts4.createWatchProgram(host);
298
- watchDeletes();
299
- watchEnvFile(runner);
173
+ // src/create/index.ts
174
+ async function create_default({ name, kit }) {
175
+ if (!name) {
176
+ throw new Error("Please set the name of the app");
177
+ }
178
+ if (!kit) {
179
+ throw new Error("Please select which kit to use");
180
+ }
181
+ const repo = `https://github.com/siturra/boilerplate-orionjs-${kit}`;
182
+ console.log("Downloading starter kit...");
183
+ await execute_default(`git clone ${repo} ${name}`);
184
+ await execute_default(`cd ${name} && rm -rf .git`);
185
+ console.log("Your starter kit is ready");
300
186
  }
301
187
 
188
+ // src/start/index.ts
189
+ import chalk8 from "chalk";
190
+
302
191
  // src/start/copyCursorRule/index.ts
303
- import path5 from "path";
304
- import fs7 from "fs/promises";
192
+ import fs4 from "fs/promises";
305
193
  import https from "https";
306
- import colors4 from "colors/safe";
194
+ import path3 from "path";
195
+ import chalk3 from "chalk";
307
196
  var rules = [
308
197
  "orionjs.mdx",
309
198
  "orionjs-component.mdx",
@@ -333,73 +222,55 @@ var downloadFile = (url) => {
333
222
  });
334
223
  };
335
224
  async function copyCursorRule() {
336
- const baseUrl = `https://raw.githubusercontent.com/orionjs/orionjs/refs/heads/master/mdc`;
225
+ const baseUrl = "https://raw.githubusercontent.com/orionjs/orionjs/refs/heads/master/mdc";
337
226
  try {
338
- const targetDir = path5.join(process.cwd(), ".cursor", "rules");
339
- await fs7.mkdir(targetDir, { recursive: true });
227
+ const targetDir = path3.join(process.cwd(), ".cursor", "rules");
228
+ await fs4.mkdir(targetDir, { recursive: true });
340
229
  for (const rule of rules) {
341
230
  const targetFileName = rule.replace(".mdx", ".mdc");
342
- const targetFile = path5.join(targetDir, targetFileName);
231
+ const targetFile = path3.join(targetDir, targetFileName);
343
232
  const sourceUrl = `${baseUrl}/${rule}`;
344
233
  const content = await downloadFile(sourceUrl);
345
- await fs7.writeFile(targetFile, content, "utf8");
346
- console.log(colors4.bold(`=> \u2728 Successfully downloaded ${colors4.cyan(targetFileName)}`));
234
+ await fs4.writeFile(targetFile, content, "utf8");
235
+ console.log(chalk3.bold(`=> \u2728 Successfully downloaded ${chalk3.cyan(targetFileName)}`));
347
236
  }
348
- console.log(colors4.bold("=> \u2728 All rule files have been successfully copied"));
237
+ console.log(chalk3.bold("=> \u2728 All rule files have been successfully copied"));
349
238
  } catch (error) {
350
- console.error(colors4.red(`Error copying rule files: ${error.message}`));
239
+ console.error(chalk3.red(`Error copying rule files: ${error.message}`));
351
240
  }
352
241
  }
353
242
 
354
243
  // src/start/copyMCP/index.ts
355
- import path7 from "path";
356
- import fs9 from "fs/promises";
357
-
358
- // src/helpers/execute.ts
359
- import { exec } from "child_process";
360
- async function execute_default(command) {
361
- return new Promise(function(resolve, reject) {
362
- exec(command, (error, stdout, stderr) => {
363
- if (error) {
364
- reject(error);
365
- } else {
366
- resolve({ stdout, stderr });
367
- }
368
- });
369
- });
370
- }
371
-
372
- // src/start/copyMCP/index.ts
373
- import colors6 from "colors/safe";
374
-
375
- // src/start/copyMCP/isValidMCPRepo.ts
376
- import fs8 from "fs/promises";
377
- import path6 from "path";
378
- import colors5 from "colors/safe";
244
+ import fs6 from "fs/promises";
245
+ import path5 from "path";
246
+ import chalk5 from "chalk";
379
247
 
380
248
  // src/start/copyMCP/consts.ts
381
249
  var MCP_VERSION = "v1";
382
250
  var VERSION_FILE = "version.txt";
383
251
 
384
252
  // src/start/copyMCP/isValidMCPRepo.ts
253
+ import fs5 from "fs/promises";
254
+ import path4 from "path";
255
+ import chalk4 from "chalk";
385
256
  async function isValidMCPRepository(directoryPath) {
386
257
  try {
387
- const stats = await fs8.stat(directoryPath);
258
+ const stats = await fs5.stat(directoryPath);
388
259
  if (!stats.isDirectory()) return false;
389
260
  const expectedFiles = ["settings.js", "package.json"];
390
261
  for (const file of expectedFiles) {
391
262
  try {
392
- await fs8.access(path6.join(directoryPath, file));
263
+ await fs5.access(path4.join(directoryPath, file));
393
264
  } catch {
394
265
  return false;
395
266
  }
396
267
  }
397
268
  try {
398
- const versionPath = path6.join(directoryPath, VERSION_FILE);
399
- const versionContent = await fs8.readFile(versionPath, "utf-8");
269
+ const versionPath = path4.join(directoryPath, VERSION_FILE);
270
+ const versionContent = await fs5.readFile(versionPath, "utf-8");
400
271
  if (versionContent.trim() !== MCP_VERSION) {
401
272
  console.log(
402
- colors5.yellow(
273
+ chalk4.yellow(
403
274
  `=> \u2728 MCP version mismatch: installed=${versionContent.trim()}, required=${MCP_VERSION}`
404
275
  )
405
276
  );
@@ -417,204 +288,267 @@ async function isValidMCPRepository(directoryPath) {
417
288
  // src/start/copyMCP/index.ts
418
289
  async function copyMCP() {
419
290
  const repoUrl = "https://github.com/orionjs/mcp-docs";
420
- const targetDir = path7.join(process.cwd(), ".orion", "mcp");
291
+ const targetDir = path5.join(process.cwd(), ".orion", "mcp");
421
292
  try {
422
- await fs9.mkdir(path7.join(process.cwd(), ".orion"), { recursive: true });
293
+ await fs6.mkdir(path5.join(process.cwd(), ".orion"), { recursive: true });
423
294
  if (await isValidMCPRepository(targetDir)) {
424
- console.log(colors6.bold(`=> \u2728 MCP documentation already installed`));
295
+ console.log(chalk5.bold("=> \u2728 MCP documentation already installed"));
425
296
  return;
426
297
  }
427
298
  try {
428
- const stats = await fs9.stat(targetDir);
299
+ const stats = await fs6.stat(targetDir);
429
300
  if (stats.isDirectory()) {
430
- await fs9.rm(targetDir, { recursive: true, force: true });
301
+ await fs6.rm(targetDir, { recursive: true, force: true });
431
302
  console.log(
432
- colors6.bold(
433
- `=> \u2728 Removed existing .orion/mcp directory (invalid, incomplete, or outdated)`
303
+ chalk5.bold(
304
+ "=> \u2728 Removed existing .orion/mcp directory (invalid, incomplete, or outdated)"
434
305
  )
435
306
  );
436
307
  }
437
- } catch (error) {
308
+ } catch (_) {
438
309
  }
439
- console.log(colors6.bold(`=> \u2728 Downloading MCP documentation ${MCP_VERSION}...`));
310
+ console.log(chalk5.bold(`=> \u2728 Downloading MCP documentation ${MCP_VERSION}...`));
440
311
  await execute_default(`git clone ${repoUrl} ${targetDir}`);
441
- await execute_default(`rm -rf ${path7.join(targetDir, ".git")}`);
442
- await fs9.writeFile(path7.join(targetDir, VERSION_FILE), MCP_VERSION, "utf-8");
312
+ await execute_default(`rm -rf ${path5.join(targetDir, ".git")}`);
313
+ await fs6.writeFile(path5.join(targetDir, VERSION_FILE), MCP_VERSION, "utf-8");
443
314
  console.log(
444
- colors6.bold(`=> \u2728 Successfully downloaded MCP documentation v${MCP_VERSION} to .orion/mcp`)
315
+ chalk5.bold(`=> \u2728 Successfully downloaded MCP documentation v${MCP_VERSION} to .orion/mcp`)
445
316
  );
446
- console.log(colors6.bold(`=> \u2728 Installing MCP dependencies...`));
317
+ console.log(chalk5.bold("=> \u2728 Installing MCP dependencies..."));
447
318
  await execute_default(`cd ${targetDir} && npm install`);
448
- console.log(colors6.bold(`=> \u2728 Successfully installed MCP dependencies`));
319
+ console.log(chalk5.bold("=> \u2728 Successfully installed MCP dependencies"));
449
320
  const mcpServerConfig = {
450
321
  mcpServers: {
451
322
  "Orionjs documentation search": {
452
323
  command: "node",
453
- args: [path7.join(targetDir, "src", "index.js")]
324
+ args: [path5.join(targetDir, "src", "index.js")]
454
325
  }
455
326
  }
456
327
  };
457
- const configPath = path7.join(process.cwd(), ".cursor", "mcp.json");
328
+ const configPath = path5.join(process.cwd(), ".cursor", "mcp.json");
458
329
  try {
459
- const existingConfig = await fs9.readFile(configPath, "utf-8");
330
+ const existingConfig = await fs6.readFile(configPath, "utf-8");
460
331
  const parsedConfig = JSON.parse(existingConfig);
461
332
  parsedConfig.mcpServers = {
462
333
  ...parsedConfig.mcpServers,
463
334
  ...mcpServerConfig.mcpServers
464
335
  };
465
- await fs9.writeFile(configPath, JSON.stringify(parsedConfig, null, 2), "utf-8");
466
- console.log(colors6.bold(`=> \u2728 Updated MCP server configuration in .cursor/mcp.json`));
467
- } catch (error) {
468
- await fs9.mkdir(path7.dirname(configPath), { recursive: true });
469
- await fs9.writeFile(configPath, JSON.stringify(mcpServerConfig, null, 2), "utf-8");
470
- console.log(colors6.bold(`=> \u2728 Created new MCP server configuration in .cursor/mcp.json`));
336
+ await fs6.writeFile(configPath, JSON.stringify(parsedConfig, null, 2), "utf-8");
337
+ console.log(chalk5.bold("=> \u2728 Updated MCP server configuration in .cursor/mcp.json"));
338
+ } catch (_) {
339
+ await fs6.mkdir(path5.dirname(configPath), { recursive: true });
340
+ await fs6.writeFile(configPath, JSON.stringify(mcpServerConfig, null, 2), "utf-8");
341
+ console.log(chalk5.bold("=> \u2728 Created new MCP server configuration in .cursor/mcp.json"));
471
342
  }
472
343
  } catch (error) {
473
- console.error(colors6.red("=> \u2728 Error copying MCP documentation:"), error);
344
+ console.error(chalk5.red("=> \u2728 Error copying MCP documentation:"), error);
474
345
  throw error;
475
346
  }
476
347
  }
477
348
 
478
- // src/start/index.ts
479
- async function start_default(options) {
480
- console.log(colors7.bold("\nOrionjs App " + colors7.green(colors7.bold("V3\n"))));
481
- if (!options.omitCursorRule) {
482
- await copyCursorRule().catch(console.error);
483
- }
484
- if (!options.omitMcpServer) {
485
- await copyMCP().catch(console.error);
486
- }
487
- if (!options.omitMcpServer && !options.omitCursorRule) {
488
- console.log(colors7.bold(`=> \u2728 Orionjs AI is ready
489
- `));
349
+ // src/start/runner/index.ts
350
+ import chalk6 from "chalk";
351
+
352
+ // src/start/runner/startProcess.ts
353
+ import { spawn } from "child_process";
354
+
355
+ // src/start/runner/getArgs.ts
356
+ function getArgs(options) {
357
+ let startCommand = process.env.START_COMMAND || "node";
358
+ const args = [];
359
+ if (process.env.START_COMMAND) {
360
+ const [first, ...otherArgs] = process.env.START_COMMAND.split(" ");
361
+ startCommand = first;
362
+ args.push(...otherArgs);
363
+ console.log(`Using custom command: ${[startCommand, ...args].join(" ")}`);
364
+ } else if (options.shell) {
365
+ args.push("--inspect");
490
366
  }
491
- const runner = getRunner(options);
492
- watchAndCompile(runner);
367
+ args.push(".orion/build/index.js");
368
+ return { startCommand, args };
493
369
  }
494
370
 
495
- // src/build/index.ts
496
- import colors9 from "colors/safe";
497
-
498
- // src/build/compile.ts
499
- import ts6 from "typescript";
371
+ // src/start/runner/startProcess.ts
372
+ function startProcess(options) {
373
+ const { startCommand, args } = getArgs(options);
374
+ return spawn(startCommand, args, {
375
+ env: {
376
+ ORION_DEV: "local",
377
+ ...process.env
378
+ },
379
+ cwd: process.cwd(),
380
+ stdio: "inherit",
381
+ detached: false
382
+ });
383
+ }
500
384
 
501
- // src/build/getOptions.ts
502
- import ts5 from "typescript";
503
- import path8 from "path";
504
- function getCompilerOptionsJSONFollowExtends(filename) {
505
- let compopts = {};
506
- const config = ts5.readConfigFile(filename, ts5.sys.readFile).config;
507
- if (config.extends) {
508
- const rqrpath = __require.resolve(config.extends);
509
- compopts = getCompilerOptionsJSONFollowExtends(rqrpath);
385
+ // src/start/runner/index.ts
386
+ function getRunner(options) {
387
+ let appProcess = null;
388
+ if (options.clean) {
389
+ console.log(chalk6.bold("=> Cleaning directory...\n"));
510
390
  }
391
+ const start = () => {
392
+ console.log(chalk6.bold("=> Starting app...\n"));
393
+ appProcess = startProcess(options);
394
+ appProcess.on("exit", (code, signal) => {
395
+ if (!code || code === 143 || code === 0 || signal === "SIGTERM" || signal === "SIGINT") {
396
+ } else {
397
+ console.log(chalk6.bold(`=> Error running app. Exit code: ${code}`));
398
+ }
399
+ });
400
+ writeFile_default(".orion/process", `${appProcess.pid}`);
401
+ };
402
+ const stop = () => {
403
+ if (appProcess) {
404
+ appProcess.kill();
405
+ }
406
+ };
407
+ const restart = () => {
408
+ stop();
409
+ start();
410
+ };
511
411
  return {
512
- ...compopts,
513
- ...config.compilerOptions
412
+ restart,
413
+ stop,
414
+ basePath: `${process.cwd()}/.orion/build`
514
415
  };
515
416
  }
516
- function getOptions({ output }) {
517
- const configPath = getConfigPath();
518
- const config = getCompilerOptionsJSONFollowExtends(configPath);
519
- config.outDir = `${output}/app`;
520
- config.incremental = false;
521
- const { options, errors } = ts5.convertCompilerOptionsFromJson(config, path8.dirname(configPath));
522
- if (errors.length) {
523
- errors.forEach(reportDiagnostic);
524
- process.exit(1);
525
- }
526
- return options;
527
- }
528
417
 
529
- // src/build/compile.ts
530
- import colors8 from "colors/safe";
531
- function compile({ output }) {
532
- const options = getOptions({ output });
533
- const program2 = ts6.createProgram(["./app/index.ts"], options);
534
- const preEmitDiagnostics = ts6.getPreEmitDiagnostics(program2);
535
- if (preEmitDiagnostics.length > 0) {
536
- console.log(colors8.red(`
537
- ==> Error builing Orion app
538
- `));
539
- }
540
- preEmitDiagnostics.forEach(reportDiagnostic);
541
- if (preEmitDiagnostics.length > 0) {
542
- process.exit(1);
418
+ // src/start/watchAndCompile/index.ts
419
+ import { spawn as spawn2 } from "child_process";
420
+
421
+ // src/start/watchAndCompile/cleanDirectory.ts
422
+ import fs7 from "fs";
423
+ import path6 from "path";
424
+ function rimraf(dir_path) {
425
+ if (fs7.existsSync(dir_path)) {
426
+ fs7.readdirSync(dir_path).forEach((entry) => {
427
+ const entry_path = path6.join(dir_path, entry);
428
+ if (fs7.lstatSync(entry_path).isDirectory()) {
429
+ rimraf(entry_path);
430
+ } else {
431
+ fs7.unlinkSync(entry_path);
432
+ }
433
+ });
434
+ fs7.rmdirSync(dir_path);
543
435
  }
544
- const emitResult = program2.emit();
545
- emitResult.diagnostics.forEach(reportDiagnostic);
546
- if (emitResult.emitSkipped) {
547
- process.exit(1);
436
+ }
437
+ async function cleanDirectory() {
438
+ try {
439
+ const dirPath = path6.join(process.cwd(), ".orion", "build");
440
+ rimraf(dirPath);
441
+ } catch (_) {
548
442
  }
549
443
  }
550
444
 
551
- // src/build/index.ts
552
- async function build_default({ output }) {
553
- if (!output) {
554
- output = "./build";
555
- }
556
- console.log(colors9.bold(`Cleaning directory ${output}...`));
557
- await execute_default(`rm -rf ${output}`);
558
- console.log(colors9.bold("Compiling your app..."));
559
- compile({ output });
560
- writeIndex_default({ basePath: output });
561
- console.log(colors9.bold("Build created"));
445
+ // src/start/watchAndCompile/watchDeletes.ts
446
+ import fs8 from "fs";
447
+ import path7 from "path";
448
+ import chokidar from "chokidar";
449
+ async function watchDeletes() {
450
+ const projectPath = path7.resolve("./app");
451
+ const watcher = chokidar.watch(projectPath, {
452
+ ignoreInitial: true
453
+ });
454
+ watcher.on("unlink", async (filepath) => {
455
+ if (!filepath.endsWith(".ts")) return;
456
+ const relative = path7.relative(process.cwd(), filepath);
457
+ const atBuildPath = path7.resolve(".orion/build", relative.replace(/.ts$/, ""));
458
+ try {
459
+ fs8.unlinkSync(`${atBuildPath}.js`);
460
+ fs8.unlinkSync(`${atBuildPath}.d.ts`);
461
+ } catch (error) {
462
+ console.log(
463
+ `Error cleaning ${atBuildPath}. Restar project is suggested. Error: ${error.message}`
464
+ );
465
+ }
466
+ });
562
467
  }
563
468
 
564
- // src/create/index.ts
565
- async function create_default({ name, kit }) {
566
- if (!name) {
567
- throw new Error("Please set the name of the app");
469
+ // src/start/watchAndCompile/writeEnvFile.ts
470
+ import { writeDtsFileFromConfigFile } from "@orion-js/env";
471
+ import chalk7 from "chalk";
472
+ import chokidar2 from "chokidar";
473
+ var envFilePath = process.env.ORION_ENV_FILE_PATH;
474
+ var dtsFilePath = "./app/env.d.ts";
475
+ var watchEnvFile = async (runner) => {
476
+ if (!envFilePath) return;
477
+ writeDtsFileFromConfigFile(envFilePath, dtsFilePath);
478
+ chokidar2.watch(envFilePath, { ignoreInitial: true }).on("change", async () => {
479
+ console.log(chalk7.bold("=> Environment file changed. Restarting..."));
480
+ writeDtsFileFromConfigFile(envFilePath, dtsFilePath);
481
+ runner.restart();
482
+ });
483
+ };
484
+
485
+ // src/start/watchAndCompile/index.ts
486
+ async function watchAndCompile(runner) {
487
+ const configPath = getConfigPath();
488
+ ensureConfigComplies(configPath);
489
+ await cleanDirectory();
490
+ watchDeletes();
491
+ watchEnvFile(runner);
492
+ spawn2("tsx", ["watch", "app/index.ts"], {
493
+ cwd: process.cwd(),
494
+ env: process.env,
495
+ gid: process.getgid(),
496
+ uid: process.getuid(),
497
+ stdio: "inherit"
498
+ });
499
+ }
500
+
501
+ // src/start/index.ts
502
+ async function start_default(options) {
503
+ console.log(chalk8.bold(`
504
+ Orionjs App ${chalk8.green(chalk8.bold("V4\n"))}`));
505
+ if (!options.omitCursorRule) {
506
+ await copyCursorRule().catch(console.error);
568
507
  }
569
- if (!kit) {
570
- throw new Error("Please select which kit to use");
508
+ if (!options.omitMcpServer) {
509
+ await copyMCP().catch(console.error);
571
510
  }
572
- const repo = `https://github.com/siturra/boilerplate-orionjs-${kit}`;
573
- console.log("Downloading starter kit...");
574
- await execute_default(`git clone ${repo} ${name}`);
575
- await execute_default(`cd ${name} && rm -rf .git`);
576
- console.log("Your starter kit is ready");
511
+ if (!options.omitMcpServer && !options.omitCursorRule) {
512
+ console.log(chalk8.bold("=> \u2728 Orionjs AI is ready\n"));
513
+ }
514
+ const runner = getRunner(options);
515
+ watchAndCompile(runner);
577
516
  }
578
517
 
579
- // src/index.ts
580
- import colors12 from "colors/safe";
581
-
582
518
  // src/test/index.ts
583
- import colors10 from "colors/safe";
519
+ import chalk9 from "chalk";
584
520
  function test_default() {
585
- console.log(colors10.bold(`To run tests run the following command`));
586
- console.log(colors10.bold(`ORION_DEV=LOCAL ORION_TEST=1 jest`));
521
+ console.log(chalk9.bold("To run tests run the following command"));
522
+ console.log(chalk9.bold("ORION_DEV=LOCAL ORION_TEST=1 jest"));
587
523
  process.exit(1);
588
524
  }
589
525
 
590
526
  // src/handleErrors.ts
591
- import colors11 from "colors";
527
+ import chalk10 from "chalk";
592
528
  process.on("unhandledRejection", (error) => {
593
529
  if (error.codeFrame) {
594
- console.error(colors11.red(error.message));
530
+ console.error(chalk10.red(error.message));
595
531
  console.log(error.codeFrame);
596
532
  } else {
597
- console.error(colors11.red(error.message), colors11.red("Unhandled promise rejection"));
533
+ console.error(chalk10.red(error.message), chalk10.red("Unhandled promise rejection"));
598
534
  }
599
535
  }).on("uncaughtException", (error) => {
600
- console.error(colors11.red(error.message));
536
+ console.error(chalk10.red(error.message));
601
537
  process.exit(1);
602
538
  });
603
539
 
604
540
  // src/version.ts
605
- var version_default = `3.0`;
541
+ var version_default = "3.0";
606
542
 
607
543
  // src/index.ts
608
544
  import "dotenv/config";
609
545
  var program = new Command();
610
- var run = function(action) {
611
- return async function(...args) {
612
- try {
613
- await action(...args);
614
- } catch (e) {
615
- console.error(colors12.red("Error: " + e.message));
616
- }
617
- };
546
+ var run = (action) => async (...args) => {
547
+ try {
548
+ await action(...args);
549
+ } catch (e) {
550
+ console.error(chalk11.red(`Error: ${e.message}`));
551
+ }
618
552
  };
619
553
  program.command("start").description("Run the Orionjs app").option("--shell", "Opens a shell in Chrome developer tools").option("--clean", "Build the typescript project from scratch").option("--omit-cursor-rule", "Omit the creation of the Orionjs Cursor rule").option("--omit-mcp-server", "Omit the creation of the Orionjs MCP server").action(run(start_default));
620
554
  program.command("test").allowUnknownOption().description("Deprecated command").action(run(test_default));