@orion-js/core 4.0.0-next.7 → 4.0.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.
package/dist/index.cjs CHANGED
@@ -26,9 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  var import_chalk11 = __toESM(require("chalk"), 1);
27
27
  var import_commander = require("commander");
28
28
 
29
- // src/build/index.ts
30
- var import_chalk2 = __toESM(require("chalk"), 1);
31
-
32
29
  // src/helpers/execute.ts
33
30
  var import_node_child_process = require("child_process");
34
31
  async function execute_default(command) {
@@ -43,48 +40,153 @@ async function execute_default(command) {
43
40
  });
44
41
  }
45
42
 
46
- // src/build/compile.ts
47
- var import_chalk = __toESM(require("chalk"), 1);
48
- var import_typescript4 = __toESM(require("typescript"), 1);
49
-
50
- // src/build/getOptions.ts
51
- var import_node_path2 = __toESM(require("path"), 1);
52
- var import_typescript3 = __toESM(require("typescript"), 1);
53
-
54
- // src/start/watchAndCompile/getConfigPath.ts
55
- var import_typescript = __toESM(require("typescript"), 1);
56
-
57
- // src/start/watchAndCompile/ensureConfigComplies.ts
58
- var import_comment_json = require("comment-json");
59
-
60
- // src/helpers/getFileContents.ts
61
- var import_node_fs = __toESM(require("fs"), 1);
62
- function readFile(filePath) {
63
- if (!import_node_fs.default.existsSync(filePath)) return null;
64
- return import_node_fs.default.readFileSync(filePath).toString();
43
+ // src/create/index.ts
44
+ async function create_default({ name, kit }) {
45
+ if (!name) {
46
+ throw new Error("Please set the name of the app");
47
+ }
48
+ if (!kit) {
49
+ throw new Error("Please select which kit to use");
50
+ }
51
+ const repo = `https://github.com/siturra/boilerplate-orionjs-${kit}`;
52
+ console.log("Downloading starter kit...");
53
+ await execute_default(`git clone ${repo} ${name}`);
54
+ await execute_default(`cd ${name} && rm -rf .git`);
55
+ console.log("Your starter kit is ready");
65
56
  }
66
57
 
58
+ // src/dev/runner/index.ts
59
+ var import_chalk = __toESM(require("chalk"), 1);
60
+
67
61
  // src/helpers/writeFile.ts
68
- var import_node_fs3 = __toESM(require("fs"), 1);
62
+ var import_node_fs2 = __toESM(require("fs"), 1);
69
63
 
70
64
  // src/helpers/ensureDirectory.ts
71
- var import_node_fs2 = __toESM(require("fs"), 1);
65
+ var import_node_fs = __toESM(require("fs"), 1);
72
66
  var import_node_path = __toESM(require("path"), 1);
73
67
  var ensureDirectory = (filePath) => {
74
68
  const dirname = import_node_path.default.dirname(filePath);
75
- if (import_node_fs2.default.existsSync(dirname)) return true;
69
+ if (import_node_fs.default.existsSync(dirname)) return true;
76
70
  ensureDirectory(dirname);
77
- import_node_fs2.default.mkdirSync(dirname);
71
+ import_node_fs.default.mkdirSync(dirname);
78
72
  };
79
73
  var ensureDirectory_default = ensureDirectory;
80
74
 
81
75
  // src/helpers/writeFile.ts
82
- async function writeFile_default(path8, content) {
83
- ensureDirectory_default(path8);
84
- import_node_fs3.default.writeFileSync(path8, content);
76
+ async function writeFile_default(path7, content) {
77
+ ensureDirectory_default(path7);
78
+ import_node_fs2.default.writeFileSync(path7, content);
85
79
  }
86
80
 
87
- // src/start/watchAndCompile/ensureConfigComplies.ts
81
+ // src/dev/runner/startProcess.ts
82
+ var import_node_child_process2 = require("child_process");
83
+
84
+ // src/dev/runner/getArgs.ts
85
+ function getArgs(options) {
86
+ let startCommand = process.env.START_COMMAND || "./node_modules/@orion-js/core/node_modules/.bin/tsx";
87
+ const args = [];
88
+ if (process.env.START_COMMAND) {
89
+ const [first, ...otherArgs] = process.env.START_COMMAND.split(" ");
90
+ startCommand = first;
91
+ args.push(...otherArgs);
92
+ console.log(`Using custom command: ${[startCommand, ...args].join(" ")}`);
93
+ } else if (options.shell) {
94
+ args.push("--inspect");
95
+ }
96
+ args.push("./app/index.ts");
97
+ return { startCommand, args };
98
+ }
99
+
100
+ // src/dev/runner/startProcess.ts
101
+ function startProcess(options) {
102
+ const { startCommand, args } = getArgs(options);
103
+ return (0, import_node_child_process2.spawn)(startCommand, args, {
104
+ env: {
105
+ ORION_DEV: "local",
106
+ ...process.env
107
+ },
108
+ cwd: process.cwd(),
109
+ stdio: "inherit",
110
+ detached: false
111
+ });
112
+ }
113
+
114
+ // src/dev/runner/index.ts
115
+ function getRunner(options) {
116
+ let appProcess = null;
117
+ if (options.clean) {
118
+ console.log(import_chalk.default.bold("=> Cleaning directory...\n"));
119
+ }
120
+ const start = () => {
121
+ console.log(import_chalk.default.bold("=> Starting app...\n"));
122
+ appProcess = startProcess(options);
123
+ appProcess.on("exit", (code, signal) => {
124
+ if (!code || code === 143 || code === 0 || signal === "SIGTERM" || signal === "SIGINT") {
125
+ } else {
126
+ console.log(import_chalk.default.bold(`=> Error running app. Exit code: ${code}`));
127
+ }
128
+ });
129
+ writeFile_default(".orion/process", `${appProcess.pid}`);
130
+ };
131
+ const stop = () => {
132
+ if (appProcess) {
133
+ appProcess.kill();
134
+ }
135
+ };
136
+ const restart = () => {
137
+ stop();
138
+ start();
139
+ };
140
+ return {
141
+ restart,
142
+ stop
143
+ };
144
+ }
145
+
146
+ // src/dev/watchAndCompile/index.ts
147
+ var import_typescript4 = __toESM(require("typescript"), 1);
148
+
149
+ // src/dev/watchAndCompile/cleanDirectory.ts
150
+ var import_node_fs3 = __toESM(require("fs"), 1);
151
+ var import_node_path2 = __toESM(require("path"), 1);
152
+ function rimraf(dir_path) {
153
+ if (import_node_fs3.default.existsSync(dir_path)) {
154
+ import_node_fs3.default.readdirSync(dir_path).map((entry) => {
155
+ const entry_path = import_node_path2.default.join(dir_path, entry);
156
+ if (import_node_fs3.default.lstatSync(entry_path).isDirectory()) {
157
+ rimraf(entry_path);
158
+ } else {
159
+ import_node_fs3.default.unlinkSync(entry_path);
160
+ }
161
+ });
162
+ import_node_fs3.default.rmdirSync(dir_path);
163
+ }
164
+ }
165
+ async function cleanDirectory() {
166
+ try {
167
+ const dirPath = import_node_path2.default.join(process.cwd(), ".orion", "build");
168
+ rimraf(dirPath);
169
+ } catch (_) {
170
+ }
171
+ }
172
+
173
+ // src/dev/watchAndCompile/getHost.ts
174
+ var import_typescript3 = __toESM(require("typescript"), 1);
175
+
176
+ // src/dev/watchAndCompile/getConfigPath.ts
177
+ var import_typescript = __toESM(require("typescript"), 1);
178
+
179
+ // src/dev/watchAndCompile/ensureConfigComplies.ts
180
+ var import_comment_json = require("comment-json");
181
+
182
+ // src/helpers/getFileContents.ts
183
+ var import_node_fs4 = __toESM(require("fs"), 1);
184
+ function readFile(filePath) {
185
+ if (!import_node_fs4.default.existsSync(filePath)) return null;
186
+ return import_node_fs4.default.readFileSync(filePath).toString();
187
+ }
188
+
189
+ // src/dev/watchAndCompile/ensureConfigComplies.ts
88
190
  function ensureConfigComplies(configPath) {
89
191
  var _a, _b;
90
192
  try {
@@ -94,8 +196,8 @@ function ensureConfigComplies(configPath) {
94
196
  ...config,
95
197
  compilerOptions: {
96
198
  ...config.compilerOptions,
97
- outDir: "./.orion/build/app",
98
- baseUrl: "./"
199
+ baseUrl: "./",
200
+ noEmit: true
99
201
  }
100
202
  };
101
203
  if (!((_a = config.compilerOptions) == null ? void 0 : _a.rootDir) && !((_b = config.compilerOptions) == null ? void 0 : _b.rootDirs)) {
@@ -107,7 +209,7 @@ function ensureConfigComplies(configPath) {
107
209
  }
108
210
  }
109
211
 
110
- // src/start/watchAndCompile/getConfigPath.ts
212
+ // src/dev/watchAndCompile/getConfigPath.ts
111
213
  function getConfigPath() {
112
214
  const appBasePath = process.cwd();
113
215
  const configPath = import_typescript.default.findConfigFile(appBasePath, import_typescript.default.sys.fileExists, "tsconfig.server.json") || import_typescript.default.findConfigFile(appBasePath, import_typescript.default.sys.fileExists, "tsconfig.json");
@@ -118,7 +220,7 @@ function getConfigPath() {
118
220
  return configPath;
119
221
  }
120
222
 
121
- // src/build/reports.ts
223
+ // src/dev/watchAndCompile/reports.ts
122
224
  var import_typescript2 = __toESM(require("typescript"), 1);
123
225
  var format = {
124
226
  getCanonicalFileName: (fileName) => fileName,
@@ -129,86 +231,91 @@ function reportDiagnostic(diagnostic) {
129
231
  console.log(import_typescript2.default.formatDiagnosticsWithColorAndContext([diagnostic], format));
130
232
  }
131
233
 
132
- // src/build/getOptions.ts
133
- function getCompilerOptionsJSONFollowExtends(filename) {
134
- let compopts = {};
135
- const config = import_typescript3.default.readConfigFile(filename, import_typescript3.default.sys.readFile).config;
136
- if (config.extends) {
137
- const rqrpath = require.resolve(config.extends);
138
- compopts = getCompilerOptionsJSONFollowExtends(rqrpath);
139
- }
140
- return {
141
- ...compopts,
142
- ...config.compilerOptions
234
+ // src/dev/watchAndCompile/getHost.ts
235
+ var import_chalk2 = __toESM(require("chalk"), 1);
236
+ function getHost(runner) {
237
+ const reportWatchStatusChanged = (diagnostic) => {
238
+ if (diagnostic.category !== 3) return;
239
+ if (diagnostic.code === 6032 || diagnostic.code === 6031) {
240
+ runner.stop();
241
+ }
242
+ console.log(import_chalk2.default.bold(`=> ${diagnostic.messageText}`));
243
+ if (diagnostic.code === 6194) {
244
+ if (/^Found .+ errors?/.test(diagnostic.messageText.toString())) {
245
+ if (!diagnostic.messageText.toString().includes("Found 0 errors.")) {
246
+ return;
247
+ }
248
+ }
249
+ runner.restart();
250
+ }
143
251
  };
144
- }
145
- function getOptions({ output }) {
146
252
  const configPath = getConfigPath();
147
- const config = getCompilerOptionsJSONFollowExtends(configPath);
148
- config.outDir = `${output}/app`;
149
- config.incremental = false;
150
- const { options, errors } = import_typescript3.default.convertCompilerOptionsFromJson(config, import_node_path2.default.dirname(configPath));
151
- if (errors.length) {
152
- errors.forEach(reportDiagnostic);
153
- process.exit(1);
154
- }
155
- return options;
253
+ const createProgram = import_typescript3.default.createEmitAndSemanticDiagnosticsBuilderProgram;
254
+ const host = import_typescript3.default.createWatchCompilerHost(
255
+ configPath,
256
+ {},
257
+ import_typescript3.default.sys,
258
+ createProgram,
259
+ reportDiagnostic,
260
+ reportWatchStatusChanged
261
+ );
262
+ return host;
156
263
  }
157
264
 
158
- // src/build/compile.ts
159
- function compile({ output }) {
160
- const options = getOptions({ output });
161
- const program2 = import_typescript4.default.createProgram(["./app/index.ts"], options);
162
- const preEmitDiagnostics = import_typescript4.default.getPreEmitDiagnostics(program2);
163
- if (preEmitDiagnostics.length > 0) {
164
- console.log(import_chalk.default.red("\n==> Error builing Orion app\n"));
165
- }
166
- preEmitDiagnostics.forEach(reportDiagnostic);
167
- if (preEmitDiagnostics.length > 0) {
168
- process.exit(1);
169
- }
170
- const emitResult = program2.emit();
171
- emitResult.diagnostics.forEach(reportDiagnostic);
172
- if (emitResult.emitSkipped) {
173
- process.exit(1);
174
- }
265
+ // src/dev/watchAndCompile/watchDeletes.ts
266
+ var import_node_fs5 = __toESM(require("fs"), 1);
267
+ var import_node_path3 = __toESM(require("path"), 1);
268
+ var import_chokidar = __toESM(require("chokidar"), 1);
269
+ async function watchDeletes() {
270
+ const projectPath = import_node_path3.default.resolve("./app");
271
+ const watcher = import_chokidar.default.watch(projectPath, {
272
+ ignoreInitial: true
273
+ });
274
+ watcher.on("unlink", async (filepath) => {
275
+ if (!filepath.endsWith(".ts")) return;
276
+ const relative = import_node_path3.default.relative(process.cwd(), filepath);
277
+ const atBuildPath = import_node_path3.default.resolve(".orion/build", relative.replace(/.ts$/, ""));
278
+ try {
279
+ import_node_fs5.default.unlinkSync(`${atBuildPath}.js`);
280
+ import_node_fs5.default.unlinkSync(`${atBuildPath}.d.ts`);
281
+ } catch (error) {
282
+ console.log(
283
+ `Error cleaning ${atBuildPath}. Restar project is suggested. Error: ${error.message}`
284
+ );
285
+ }
286
+ });
175
287
  }
176
288
 
177
- // src/build/index.ts
178
- async function build_default({ output }) {
179
- if (!output) {
180
- output = "./build";
181
- }
182
- console.log(import_chalk2.default.bold(`Cleaning directory ${output}...`));
183
- await execute_default(`rm -rf ${output}`);
184
- console.log(import_chalk2.default.bold("Compiling your app..."));
185
- compile({ output });
186
- console.log(import_chalk2.default.bold("Build created"));
187
- }
289
+ // src/dev/watchAndCompile/writeEnvFile.ts
290
+ var import_env = require("@orion-js/env");
291
+ var import_chalk3 = __toESM(require("chalk"), 1);
292
+ var import_chokidar2 = __toESM(require("chokidar"), 1);
293
+ var envFilePath = process.env.ORION_ENV_FILE_PATH;
294
+ var dtsFilePath = "./app/env.d.ts";
295
+ var watchEnvFile = async (runner) => {
296
+ if (!envFilePath) return;
297
+ (0, import_env.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
298
+ import_chokidar2.default.watch(envFilePath, { ignoreInitial: true }).on("change", async () => {
299
+ console.log(import_chalk3.default.bold("=> Environment file changed. Restarting..."));
300
+ (0, import_env.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
301
+ runner.restart();
302
+ });
303
+ };
188
304
 
189
- // src/create/index.ts
190
- async function create_default({ name, kit }) {
191
- if (!name) {
192
- throw new Error("Please set the name of the app");
193
- }
194
- if (!kit) {
195
- throw new Error("Please select which kit to use");
196
- }
197
- const repo = `https://github.com/siturra/boilerplate-orionjs-${kit}`;
198
- console.log("Downloading starter kit...");
199
- await execute_default(`git clone ${repo} ${name}`);
200
- await execute_default(`cd ${name} && rm -rf .git`);
201
- console.log("Your starter kit is ready");
305
+ // src/dev/watchAndCompile/index.ts
306
+ async function watchAndCompile(runner) {
307
+ await cleanDirectory();
308
+ const host = getHost(runner);
309
+ import_typescript4.default.createWatchProgram(host);
310
+ watchDeletes();
311
+ watchEnvFile(runner);
202
312
  }
203
313
 
204
- // src/start/index.ts
205
- var import_chalk8 = __toESM(require("chalk"), 1);
206
-
207
- // src/start/copyCursorRule/index.ts
314
+ // src/dev/copyCursorRule/index.ts
208
315
  var import_promises = __toESM(require("fs/promises"), 1);
209
316
  var import_node_https = __toESM(require("https"), 1);
210
- var import_node_path3 = __toESM(require("path"), 1);
211
- var import_chalk3 = __toESM(require("chalk"), 1);
317
+ var import_node_path4 = __toESM(require("path"), 1);
318
+ var import_chalk4 = __toESM(require("chalk"), 1);
212
319
  var rules = [
213
320
  "orionjs.mdx",
214
321
  "orionjs-component.mdx",
@@ -240,35 +347,37 @@ var downloadFile = (url) => {
240
347
  async function copyCursorRule() {
241
348
  const baseUrl = "https://raw.githubusercontent.com/orionjs/orionjs/refs/heads/master/mdc";
242
349
  try {
243
- const targetDir = import_node_path3.default.join(process.cwd(), ".cursor", "rules");
350
+ const targetDir = import_node_path4.default.join(process.cwd(), ".cursor", "rules");
244
351
  await import_promises.default.mkdir(targetDir, { recursive: true });
245
- for (const rule of rules) {
246
- const targetFileName = rule.replace(".mdx", ".mdc");
247
- const targetFile = import_node_path3.default.join(targetDir, targetFileName);
248
- const sourceUrl = `${baseUrl}/${rule}`;
249
- const content = await downloadFile(sourceUrl);
250
- await import_promises.default.writeFile(targetFile, content, "utf8");
251
- console.log(import_chalk3.default.bold(`=> \u2728 Successfully downloaded ${import_chalk3.default.cyan(targetFileName)}`));
252
- }
253
- console.log(import_chalk3.default.bold("=> \u2728 All rule files have been successfully copied"));
352
+ await Promise.all(
353
+ rules.map(async (rule) => {
354
+ const targetFileName = rule.replace(".mdx", ".mdc");
355
+ const targetFile = import_node_path4.default.join(targetDir, targetFileName);
356
+ const sourceUrl = `${baseUrl}/${rule}`;
357
+ const content = await downloadFile(sourceUrl);
358
+ await import_promises.default.writeFile(targetFile, content, "utf8");
359
+ console.log(import_chalk4.default.bold(`=> \u2728 Successfully downloaded ${import_chalk4.default.cyan(targetFileName)}`));
360
+ })
361
+ );
362
+ console.log(import_chalk4.default.bold("=> \u2728 All rule files have been successfully copied"));
254
363
  } catch (error) {
255
- console.error(import_chalk3.default.red(`Error copying rule files: ${error.message}`));
364
+ console.error(import_chalk4.default.red(`Error copying rule files: ${error.message}`));
256
365
  }
257
366
  }
258
367
 
259
- // src/start/copyMCP/index.ts
368
+ // src/dev/copyMCP/index.ts
260
369
  var import_promises3 = __toESM(require("fs/promises"), 1);
261
- var import_node_path5 = __toESM(require("path"), 1);
262
- var import_chalk5 = __toESM(require("chalk"), 1);
370
+ var import_node_path6 = __toESM(require("path"), 1);
371
+ var import_chalk6 = __toESM(require("chalk"), 1);
263
372
 
264
- // src/start/copyMCP/consts.ts
265
- var MCP_VERSION = "v1";
373
+ // src/dev/copyMCP/consts.ts
374
+ var MCP_VERSION = "v4";
266
375
  var VERSION_FILE = "version.txt";
267
376
 
268
- // src/start/copyMCP/isValidMCPRepo.ts
377
+ // src/dev/copyMCP/isValidMCPRepo.ts
269
378
  var import_promises2 = __toESM(require("fs/promises"), 1);
270
- var import_node_path4 = __toESM(require("path"), 1);
271
- var import_chalk4 = __toESM(require("chalk"), 1);
379
+ var import_node_path5 = __toESM(require("path"), 1);
380
+ var import_chalk5 = __toESM(require("chalk"), 1);
272
381
  async function isValidMCPRepository(directoryPath) {
273
382
  try {
274
383
  const stats = await import_promises2.default.stat(directoryPath);
@@ -276,17 +385,17 @@ async function isValidMCPRepository(directoryPath) {
276
385
  const expectedFiles = ["settings.js", "package.json"];
277
386
  for (const file of expectedFiles) {
278
387
  try {
279
- await import_promises2.default.access(import_node_path4.default.join(directoryPath, file));
388
+ await import_promises2.default.access(import_node_path5.default.join(directoryPath, file));
280
389
  } catch {
281
390
  return false;
282
391
  }
283
392
  }
284
393
  try {
285
- const versionPath = import_node_path4.default.join(directoryPath, VERSION_FILE);
394
+ const versionPath = import_node_path5.default.join(directoryPath, VERSION_FILE);
286
395
  const versionContent = await import_promises2.default.readFile(versionPath, "utf-8");
287
396
  if (versionContent.trim() !== MCP_VERSION) {
288
397
  console.log(
289
- import_chalk4.default.yellow(
398
+ import_chalk5.default.yellow(
290
399
  `=> \u2728 MCP version mismatch: installed=${versionContent.trim()}, required=${MCP_VERSION}`
291
400
  )
292
401
  );
@@ -301,14 +410,14 @@ async function isValidMCPRepository(directoryPath) {
301
410
  }
302
411
  }
303
412
 
304
- // src/start/copyMCP/index.ts
413
+ // src/dev/copyMCP/index.ts
305
414
  async function copyMCP() {
306
415
  const repoUrl = "https://github.com/orionjs/mcp-docs";
307
- const targetDir = import_node_path5.default.join(process.cwd(), ".orion", "mcp");
416
+ const targetDir = import_node_path6.default.join(process.cwd(), ".orion", "mcp");
308
417
  try {
309
- await import_promises3.default.mkdir(import_node_path5.default.join(process.cwd(), ".orion"), { recursive: true });
418
+ await import_promises3.default.mkdir(import_node_path6.default.join(process.cwd(), ".orion"), { recursive: true });
310
419
  if (await isValidMCPRepository(targetDir)) {
311
- console.log(import_chalk5.default.bold("=> \u2728 MCP documentation already installed"));
420
+ console.log(import_chalk6.default.bold("=> \u2728 MCP documentation already installed"));
312
421
  return;
313
422
  }
314
423
  try {
@@ -316,32 +425,34 @@ async function copyMCP() {
316
425
  if (stats.isDirectory()) {
317
426
  await import_promises3.default.rm(targetDir, { recursive: true, force: true });
318
427
  console.log(
319
- import_chalk5.default.bold(
428
+ import_chalk6.default.bold(
320
429
  "=> \u2728 Removed existing .orion/mcp directory (invalid, incomplete, or outdated)"
321
430
  )
322
431
  );
323
432
  }
324
433
  } catch (_) {
325
434
  }
326
- console.log(import_chalk5.default.bold(`=> \u2728 Downloading MCP documentation ${MCP_VERSION}...`));
435
+ console.log(import_chalk6.default.bold(`=> \u2728 Downloading MCP documentation ${MCP_VERSION}...`));
327
436
  await execute_default(`git clone ${repoUrl} ${targetDir}`);
328
- await execute_default(`rm -rf ${import_node_path5.default.join(targetDir, ".git")}`);
329
- await import_promises3.default.writeFile(import_node_path5.default.join(targetDir, VERSION_FILE), MCP_VERSION, "utf-8");
437
+ await execute_default(`rm -rf ${import_node_path6.default.join(targetDir, ".git")}`);
438
+ await import_promises3.default.writeFile(import_node_path6.default.join(targetDir, VERSION_FILE), MCP_VERSION, "utf-8");
330
439
  console.log(
331
- import_chalk5.default.bold(`=> \u2728 Successfully downloaded MCP documentation v${MCP_VERSION} to .orion/mcp`)
440
+ import_chalk6.default.bold(`=> \u2728 Successfully downloaded MCP documentation v${MCP_VERSION} to .orion/mcp`)
332
441
  );
333
- console.log(import_chalk5.default.bold("=> \u2728 Installing MCP dependencies..."));
442
+ console.log(import_chalk6.default.bold("=> \u2728 Installing MCP dependencies..."));
334
443
  await execute_default(`cd ${targetDir} && npm install`);
335
- console.log(import_chalk5.default.bold("=> \u2728 Successfully installed MCP dependencies"));
444
+ console.log(import_chalk6.default.bold("=> \u2728 Successfully installed MCP dependencies"));
445
+ const relativePath = import_node_path6.default.relative(process.cwd(), targetDir);
446
+ console.log(relativePath);
336
447
  const mcpServerConfig = {
337
448
  mcpServers: {
338
449
  "Orionjs documentation search": {
339
450
  command: "node",
340
- args: [import_node_path5.default.join(targetDir, "src", "index.js")]
451
+ args: [`./${import_node_path6.default.join(relativePath, "src", "index.js")}`]
341
452
  }
342
453
  }
343
454
  };
344
- const configPath = import_node_path5.default.join(process.cwd(), ".cursor", "mcp.json");
455
+ const configPath = import_node_path6.default.join(process.cwd(), ".cursor", "mcp.json");
345
456
  try {
346
457
  const existingConfig = await import_promises3.default.readFile(configPath, "utf-8");
347
458
  const parsedConfig = JSON.parse(existingConfig);
@@ -350,201 +461,83 @@ async function copyMCP() {
350
461
  ...mcpServerConfig.mcpServers
351
462
  };
352
463
  await import_promises3.default.writeFile(configPath, JSON.stringify(parsedConfig, null, 2), "utf-8");
353
- console.log(import_chalk5.default.bold("=> \u2728 Updated MCP server configuration in .cursor/mcp.json"));
464
+ console.log(import_chalk6.default.bold("=> \u2728 Updated MCP server configuration in .cursor/mcp.json"));
354
465
  } catch (_) {
355
- await import_promises3.default.mkdir(import_node_path5.default.dirname(configPath), { recursive: true });
466
+ await import_promises3.default.mkdir(import_node_path6.default.dirname(configPath), { recursive: true });
356
467
  await import_promises3.default.writeFile(configPath, JSON.stringify(mcpServerConfig, null, 2), "utf-8");
357
- console.log(import_chalk5.default.bold("=> \u2728 Created new MCP server configuration in .cursor/mcp.json"));
468
+ console.log(import_chalk6.default.bold("=> \u2728 Created new MCP server configuration in .cursor/mcp.json"));
358
469
  }
359
470
  } catch (error) {
360
- console.error(import_chalk5.default.red("=> \u2728 Error copying MCP documentation:"), error);
471
+ console.error(import_chalk6.default.red("=> \u2728 Error copying MCP documentation:"), error);
361
472
  throw error;
362
473
  }
363
474
  }
364
475
 
365
- // src/start/runner/index.ts
366
- var import_chalk6 = __toESM(require("chalk"), 1);
367
-
368
- // src/start/runner/startProcess.ts
369
- var import_node_child_process2 = require("child_process");
370
-
371
- // src/start/runner/getArgs.ts
372
- function getArgs(options) {
373
- let startCommand = process.env.START_COMMAND || "node";
374
- const args = [];
375
- if (process.env.START_COMMAND) {
376
- const [first, ...otherArgs] = process.env.START_COMMAND.split(" ");
377
- startCommand = first;
378
- args.push(...otherArgs);
379
- console.log(`Using custom command: ${[startCommand, ...args].join(" ")}`);
380
- } else if (options.shell) {
381
- args.push("--inspect");
476
+ // src/dev/index.ts
477
+ var import_chalk7 = __toESM(require("chalk"), 1);
478
+ async function dev_default(options) {
479
+ console.log(import_chalk7.default.bold(`
480
+ Orionjs App ${import_chalk7.default.green(import_chalk7.default.bold("V4"))} Dev mode
481
+ `));
482
+ if (!options.omitCursorRule) {
483
+ await copyCursorRule().catch(console.error);
382
484
  }
383
- args.push(".orion/build/index.js");
384
- return { startCommand, args };
485
+ if (!options.omitMcpServer) {
486
+ await copyMCP().catch(console.error);
487
+ }
488
+ if (!options.omitMcpServer && !options.omitCursorRule) {
489
+ console.log(import_chalk7.default.bold("=> \u2728 Orionjs AI is ready\n"));
490
+ }
491
+ const runner = getRunner(options);
492
+ watchAndCompile(runner);
385
493
  }
386
494
 
387
- // src/start/runner/startProcess.ts
388
- function startProcess(options) {
389
- const { startCommand, args } = getArgs(options);
390
- return (0, import_node_child_process2.spawn)(startCommand, args, {
495
+ // src/prod/index.ts
496
+ var import_chalk9 = __toESM(require("chalk"), 1);
497
+
498
+ // src/prod/runProd.ts
499
+ var import_node_child_process3 = require("child_process");
500
+ function runProd() {
501
+ (0, import_node_child_process3.spawn)("./node_modules/@orion-js/core/node_modules/.bin/tsx", ["./app/index.ts"], {
391
502
  env: {
392
- ORION_DEV: "local",
503
+ NODE_ENV: "production",
393
504
  ...process.env
394
505
  },
395
506
  cwd: process.cwd(),
396
507
  stdio: "inherit",
508
+ gid: process.getgid(),
509
+ uid: process.getuid(),
397
510
  detached: false
398
511
  });
399
512
  }
400
513
 
401
- // src/start/runner/index.ts
402
- function getRunner(options) {
403
- let appProcess = null;
404
- if (options.clean) {
405
- console.log(import_chalk6.default.bold("=> Cleaning directory...\n"));
406
- }
407
- const start = () => {
408
- console.log(import_chalk6.default.bold("=> Starting app...\n"));
409
- appProcess = startProcess(options);
410
- appProcess.on("exit", (code, signal) => {
411
- if (!code || code === 143 || code === 0 || signal === "SIGTERM" || signal === "SIGINT") {
412
- } else {
413
- console.log(import_chalk6.default.bold(`=> Error running app. Exit code: ${code}`));
414
- }
415
- });
416
- writeFile_default(".orion/process", `${appProcess.pid}`);
417
- };
418
- const stop = () => {
419
- if (appProcess) {
420
- appProcess.kill();
421
- }
422
- };
423
- const restart = () => {
424
- stop();
425
- start();
426
- };
427
- return {
428
- restart,
429
- stop,
430
- basePath: `${process.cwd()}/.orion/build`
431
- };
432
- }
433
-
434
- // src/start/watchAndCompile/index.ts
435
- var import_node_child_process3 = require("child_process");
436
-
437
- // src/start/watchAndCompile/cleanDirectory.ts
438
- var import_node_fs4 = __toESM(require("fs"), 1);
439
- var import_node_path6 = __toESM(require("path"), 1);
440
- function rimraf(dir_path) {
441
- if (import_node_fs4.default.existsSync(dir_path)) {
442
- import_node_fs4.default.readdirSync(dir_path).forEach((entry) => {
443
- const entry_path = import_node_path6.default.join(dir_path, entry);
444
- if (import_node_fs4.default.lstatSync(entry_path).isDirectory()) {
445
- rimraf(entry_path);
446
- } else {
447
- import_node_fs4.default.unlinkSync(entry_path);
448
- }
449
- });
450
- import_node_fs4.default.rmdirSync(dir_path);
451
- }
452
- }
453
- async function cleanDirectory() {
514
+ // src/prod/checkTs.ts
515
+ var import_chalk8 = __toESM(require("chalk"), 1);
516
+ var import_node_child_process4 = require("child_process");
517
+ function checkTs() {
454
518
  try {
455
- const dirPath = import_node_path6.default.join(process.cwd(), ".orion", "build");
456
- rimraf(dirPath);
457
- } catch (_) {
458
- }
459
- }
460
-
461
- // src/start/watchAndCompile/watchDeletes.ts
462
- var import_node_fs5 = __toESM(require("fs"), 1);
463
- var import_node_path7 = __toESM(require("path"), 1);
464
- var import_chokidar = __toESM(require("chokidar"), 1);
465
- async function watchDeletes() {
466
- const projectPath = import_node_path7.default.resolve("./app");
467
- const watcher = import_chokidar.default.watch(projectPath, {
468
- ignoreInitial: true
469
- });
470
- watcher.on("unlink", async (filepath) => {
471
- if (!filepath.endsWith(".ts")) return;
472
- const relative = import_node_path7.default.relative(process.cwd(), filepath);
473
- const atBuildPath = import_node_path7.default.resolve(".orion/build", relative.replace(/.ts$/, ""));
474
- try {
475
- import_node_fs5.default.unlinkSync(`${atBuildPath}.js`);
476
- import_node_fs5.default.unlinkSync(`${atBuildPath}.d.ts`);
477
- } catch (error) {
478
- console.log(
479
- `Error cleaning ${atBuildPath}. Restar project is suggested. Error: ${error.message}`
480
- );
481
- }
482
- });
483
- }
484
-
485
- // src/start/watchAndCompile/writeEnvFile.ts
486
- var import_env = require("@orion-js/env");
487
- var import_chalk7 = __toESM(require("chalk"), 1);
488
- var import_chokidar2 = __toESM(require("chokidar"), 1);
489
- var envFilePath = process.env.ORION_ENV_FILE_PATH;
490
- var dtsFilePath = "./app/env.d.ts";
491
- var watchEnvFile = async (runner) => {
492
- if (!envFilePath) return;
493
- (0, import_env.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
494
- import_chokidar2.default.watch(envFilePath, { ignoreInitial: true }).on("change", async () => {
495
- console.log(import_chalk7.default.bold("=> Environment file changed. Restarting..."));
496
- (0, import_env.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
497
- runner.restart();
498
- });
499
- };
500
-
501
- // src/start/watchAndCompile/index.ts
502
- async function watchAndCompile(runner) {
503
- const configPath = getConfigPath();
504
- ensureConfigComplies(configPath);
505
- await cleanDirectory();
506
- watchDeletes();
507
- watchEnvFile(runner);
508
- const child = (0, import_node_child_process3.spawn)("tsx", ["watch", "app/index.ts"], {
509
- cwd: process.cwd(),
510
- env: process.env,
511
- gid: process.getgid(),
512
- uid: process.getuid(),
513
- stdio: "inherit"
514
- });
515
- child.on("error", (_) => {
519
+ (0, import_node_child_process4.execSync)("tsc --noEmit", {
520
+ cwd: process.cwd(),
521
+ env: {
522
+ ...process.env
523
+ },
524
+ gid: process.getgid(),
525
+ uid: process.getuid(),
526
+ stdio: "inherit"
527
+ });
528
+ } catch {
529
+ console.log(import_chalk8.default.red.bold("TypeScript compilation failed"));
516
530
  process.exit(1);
517
- });
518
- child.on("exit", (code) => {
519
- if (code !== 0) {
520
- process.exit(code || 1);
521
- }
522
- });
523
- }
524
-
525
- // src/start/index.ts
526
- async function start_default(options) {
527
- console.log(import_chalk8.default.bold(`
528
- Orionjs App ${import_chalk8.default.green(import_chalk8.default.bold("V4\n"))}`));
529
- if (!options.omitCursorRule) {
530
- await copyCursorRule().catch(console.error);
531
- }
532
- if (!options.omitMcpServer) {
533
- await copyMCP().catch(console.error);
534
- }
535
- if (!options.omitMcpServer && !options.omitCursorRule) {
536
- console.log(import_chalk8.default.bold("=> \u2728 Orionjs AI is ready\n"));
537
531
  }
538
- const runner = getRunner(options);
539
- watchAndCompile(runner);
540
532
  }
541
533
 
542
- // src/test/index.ts
543
- var import_chalk9 = __toESM(require("chalk"), 1);
544
- function test_default() {
545
- console.log(import_chalk9.default.bold("To run tests run the following command"));
546
- console.log(import_chalk9.default.bold("ORION_DEV=LOCAL ORION_TEST=1 jest"));
547
- process.exit(1);
534
+ // src/prod/index.ts
535
+ async function prod_default() {
536
+ console.log(import_chalk9.default.bold(`
537
+ Orionjs App ${import_chalk9.default.green(import_chalk9.default.bold("V4"))} Prod mode
538
+ `));
539
+ checkTs();
540
+ runProd();
548
541
  }
549
542
 
550
543
  // src/handleErrors.ts
@@ -574,9 +567,8 @@ var run = (action) => async (...args) => {
574
567
  console.error(import_chalk11.default.red(`Error: ${e.message}`));
575
568
  }
576
569
  };
577
- 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));
578
- program.command("test").allowUnknownOption().description("Deprecated command").action(run(test_default));
579
- program.command("build").description("Compiles an Orionjs app and exports it to a simple nodejs app").option("-o, --output [output]", "Output directory").action(run(build_default));
570
+ program.command("dev").description("Run the Orionjs app in development mode").option("--shell", "Opens a shell in Chrome developer tools").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(dev_default));
571
+ program.command("prod").description("Run the Orionjs app in production mode").action(run(prod_default));
580
572
  program.command("create").description("Creates a new Orionjs project").option("--name [name]", "Name of the project").option("--kit [kit]", "Which starter kit to use").action(run(create_default));
581
573
  program.version(version_default, "-v --version");
582
574
  program.parse(process.argv);