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

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