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