@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 +322 -380
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +330 -388
- package/dist/index.js.map +1 -1
- package/package.json +7 -11
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/
|
|
13
|
-
import
|
|
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/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
24
|
+
resolve({ stdout, stderr });
|
|
84
25
|
}
|
|
85
26
|
});
|
|
86
|
-
|
|
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/
|
|
30
|
+
// src/build/compile.ts
|
|
31
|
+
import chalk from "chalk";
|
|
105
32
|
import ts4 from "typescript";
|
|
106
33
|
|
|
107
|
-
// src/
|
|
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
|
|
45
|
+
import fs from "fs";
|
|
139
46
|
function readFile(filePath) {
|
|
140
|
-
if (!
|
|
141
|
-
return
|
|
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:
|
|
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 =
|
|
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/
|
|
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/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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/
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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/
|
|
294
|
-
async function
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
|
304
|
-
import fs7 from "fs/promises";
|
|
192
|
+
import fs4 from "fs/promises";
|
|
305
193
|
import https from "https";
|
|
306
|
-
import
|
|
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 =
|
|
225
|
+
const baseUrl = "https://raw.githubusercontent.com/orionjs/orionjs/refs/heads/master/mdc";
|
|
337
226
|
try {
|
|
338
|
-
const targetDir =
|
|
339
|
-
await
|
|
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 =
|
|
231
|
+
const targetFile = path3.join(targetDir, targetFileName);
|
|
343
232
|
const sourceUrl = `${baseUrl}/${rule}`;
|
|
344
233
|
const content = await downloadFile(sourceUrl);
|
|
345
|
-
await
|
|
346
|
-
console.log(
|
|
234
|
+
await fs4.writeFile(targetFile, content, "utf8");
|
|
235
|
+
console.log(chalk3.bold(`=> \u2728 Successfully downloaded ${chalk3.cyan(targetFileName)}`));
|
|
347
236
|
}
|
|
348
|
-
console.log(
|
|
237
|
+
console.log(chalk3.bold("=> \u2728 All rule files have been successfully copied"));
|
|
349
238
|
} catch (error) {
|
|
350
|
-
console.error(
|
|
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
|
|
356
|
-
import
|
|
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
|
|
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
|
|
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 =
|
|
399
|
-
const versionContent = await
|
|
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
|
-
|
|
273
|
+
chalk4.yellow(
|
|
403
274
|
`=> \u2728 MCP version mismatch: installed=${versionContent.trim()}, required=${MCP_VERSION}`
|
|
404
275
|
)
|
|
405
276
|
);
|
|
@@ -417,204 +288,275 @@ 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 =
|
|
291
|
+
const targetDir = path5.join(process.cwd(), ".orion", "mcp");
|
|
421
292
|
try {
|
|
422
|
-
await
|
|
293
|
+
await fs6.mkdir(path5.join(process.cwd(), ".orion"), { recursive: true });
|
|
423
294
|
if (await isValidMCPRepository(targetDir)) {
|
|
424
|
-
console.log(
|
|
295
|
+
console.log(chalk5.bold("=> \u2728 MCP documentation already installed"));
|
|
425
296
|
return;
|
|
426
297
|
}
|
|
427
298
|
try {
|
|
428
|
-
const stats = await
|
|
299
|
+
const stats = await fs6.stat(targetDir);
|
|
429
300
|
if (stats.isDirectory()) {
|
|
430
|
-
await
|
|
301
|
+
await fs6.rm(targetDir, { recursive: true, force: true });
|
|
431
302
|
console.log(
|
|
432
|
-
|
|
433
|
-
|
|
303
|
+
chalk5.bold(
|
|
304
|
+
"=> \u2728 Removed existing .orion/mcp directory (invalid, incomplete, or outdated)"
|
|
434
305
|
)
|
|
435
306
|
);
|
|
436
307
|
}
|
|
437
|
-
} catch (
|
|
308
|
+
} catch (_) {
|
|
438
309
|
}
|
|
439
|
-
console.log(
|
|
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 ${
|
|
442
|
-
await
|
|
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
|
-
|
|
315
|
+
chalk5.bold(`=> \u2728 Successfully downloaded MCP documentation v${MCP_VERSION} to .orion/mcp`)
|
|
445
316
|
);
|
|
446
|
-
console.log(
|
|
317
|
+
console.log(chalk5.bold("=> \u2728 Installing MCP dependencies..."));
|
|
447
318
|
await execute_default(`cd ${targetDir} && npm install`);
|
|
448
|
-
console.log(
|
|
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: [
|
|
324
|
+
args: [path5.join(targetDir, "src", "index.js")]
|
|
454
325
|
}
|
|
455
326
|
}
|
|
456
327
|
};
|
|
457
|
-
const configPath =
|
|
328
|
+
const configPath = path5.join(process.cwd(), ".cursor", "mcp.json");
|
|
458
329
|
try {
|
|
459
|
-
const existingConfig = await
|
|
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
|
|
466
|
-
console.log(
|
|
467
|
-
} catch (
|
|
468
|
-
await
|
|
469
|
-
await
|
|
470
|
-
console.log(
|
|
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(
|
|
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
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
-
|
|
492
|
-
|
|
367
|
+
args.push(".orion/build/index.js");
|
|
368
|
+
return { startCommand, args };
|
|
493
369
|
}
|
|
494
370
|
|
|
495
|
-
// src/
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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/
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
513
|
-
|
|
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/
|
|
530
|
-
import
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
process.
|
|
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/
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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/
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
+
const child = 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
|
+
child.on("error", (_) => {
|
|
500
|
+
process.exit(1);
|
|
501
|
+
});
|
|
502
|
+
child.on("exit", (code) => {
|
|
503
|
+
if (code !== 0) {
|
|
504
|
+
process.exit(code || 1);
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// src/start/index.ts
|
|
510
|
+
async function start_default(options) {
|
|
511
|
+
console.log(chalk8.bold(`
|
|
512
|
+
Orionjs App ${chalk8.green(chalk8.bold("V4\n"))}`));
|
|
513
|
+
if (!options.omitCursorRule) {
|
|
514
|
+
await copyCursorRule().catch(console.error);
|
|
568
515
|
}
|
|
569
|
-
if (!
|
|
570
|
-
|
|
516
|
+
if (!options.omitMcpServer) {
|
|
517
|
+
await copyMCP().catch(console.error);
|
|
571
518
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
519
|
+
if (!options.omitMcpServer && !options.omitCursorRule) {
|
|
520
|
+
console.log(chalk8.bold("=> \u2728 Orionjs AI is ready\n"));
|
|
521
|
+
}
|
|
522
|
+
const runner = getRunner(options);
|
|
523
|
+
watchAndCompile(runner);
|
|
577
524
|
}
|
|
578
525
|
|
|
579
|
-
// src/index.ts
|
|
580
|
-
import colors12 from "colors/safe";
|
|
581
|
-
|
|
582
526
|
// src/test/index.ts
|
|
583
|
-
import
|
|
527
|
+
import chalk9 from "chalk";
|
|
584
528
|
function test_default() {
|
|
585
|
-
console.log(
|
|
586
|
-
console.log(
|
|
529
|
+
console.log(chalk9.bold("To run tests run the following command"));
|
|
530
|
+
console.log(chalk9.bold("ORION_DEV=LOCAL ORION_TEST=1 jest"));
|
|
587
531
|
process.exit(1);
|
|
588
532
|
}
|
|
589
533
|
|
|
590
534
|
// src/handleErrors.ts
|
|
591
|
-
import
|
|
535
|
+
import chalk10 from "chalk";
|
|
592
536
|
process.on("unhandledRejection", (error) => {
|
|
593
537
|
if (error.codeFrame) {
|
|
594
|
-
console.error(
|
|
538
|
+
console.error(chalk10.red(error.message));
|
|
595
539
|
console.log(error.codeFrame);
|
|
596
540
|
} else {
|
|
597
|
-
console.error(
|
|
541
|
+
console.error(chalk10.red(error.message), chalk10.red("Unhandled promise rejection"));
|
|
598
542
|
}
|
|
599
543
|
}).on("uncaughtException", (error) => {
|
|
600
|
-
console.error(
|
|
544
|
+
console.error(chalk10.red(error.message));
|
|
601
545
|
process.exit(1);
|
|
602
546
|
});
|
|
603
547
|
|
|
604
548
|
// src/version.ts
|
|
605
|
-
var version_default =
|
|
549
|
+
var version_default = "3.0";
|
|
606
550
|
|
|
607
551
|
// src/index.ts
|
|
608
552
|
import "dotenv/config";
|
|
609
553
|
var program = new Command();
|
|
610
|
-
var run =
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
};
|
|
554
|
+
var run = (action) => async (...args) => {
|
|
555
|
+
try {
|
|
556
|
+
await action(...args);
|
|
557
|
+
} catch (e) {
|
|
558
|
+
console.error(chalk11.red(`Error: ${e.message}`));
|
|
559
|
+
}
|
|
618
560
|
};
|
|
619
561
|
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
562
|
program.command("test").allowUnknownOption().description("Deprecated command").action(run(test_default));
|