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