okai 0.0.3 → 0.0.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.js +236 -11153
- package/dist/info.js +59 -0
- package/dist/okai.js +2 -11179
- package/dist/openai.js +97 -0
- package/dist/types.js +1 -0
- package/dist/utils.js +32 -0
- package/package.json +2 -2
- package/dist/index.d.ts +0 -5
- package/dist/okai.d.ts +0 -5
package/dist/info.js
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
export function projectInfo(cwd) {
|
4
|
+
const config = fs.existsSync(path.join(cwd, "okai.json"))
|
5
|
+
? JSON.parse(fs.readFileSync(path.join(cwd, "okai.json")).toString())
|
6
|
+
: null;
|
7
|
+
const parentDir = path.dirname(cwd);
|
8
|
+
let slnDir = '';
|
9
|
+
let sln = fs.readdirSync(cwd).find(f => f.endsWith(".sln"));
|
10
|
+
if (sln) {
|
11
|
+
slnDir = cwd;
|
12
|
+
}
|
13
|
+
else {
|
14
|
+
sln = fs.readdirSync(parentDir).find(f => f.endsWith(".sln"));
|
15
|
+
if (sln) {
|
16
|
+
slnDir = parentDir;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
if (!sln) {
|
20
|
+
if (config)
|
21
|
+
return config;
|
22
|
+
throw new Error("No .sln file found");
|
23
|
+
}
|
24
|
+
const projectName = sln.substring(0, sln.length - 4);
|
25
|
+
function getDir(slnDir, match) {
|
26
|
+
if (fs.readdirSync(slnDir).find(match))
|
27
|
+
return slnDir;
|
28
|
+
const dirs = fs.readdirSync(slnDir).filter(f => fs.statSync(path.join(slnDir, f)).isDirectory());
|
29
|
+
for (let dir of dirs) {
|
30
|
+
const hasFile = fs.readdirSync(path.join(slnDir, dir)).find(match);
|
31
|
+
if (hasFile)
|
32
|
+
return path.join(slnDir, dir);
|
33
|
+
}
|
34
|
+
return null;
|
35
|
+
}
|
36
|
+
const hostDir = getDir(slnDir, f => f === `${projectName}.csproj`);
|
37
|
+
const serviceModelDirName = fs.readdirSync(slnDir).find(f => f.endsWith("ServiceModel"));
|
38
|
+
const serviceModelDir = serviceModelDirName
|
39
|
+
? path.join(slnDir, serviceModelDirName)
|
40
|
+
: null;
|
41
|
+
const serviceInterfaceDirName = fs.readdirSync(slnDir).find(f => f.endsWith("ServiceInterface"));
|
42
|
+
const serviceInterfaceDir = serviceInterfaceDirName
|
43
|
+
? path.join(slnDir, serviceInterfaceDirName)
|
44
|
+
: null;
|
45
|
+
const migrationsDir = hostDir && fs.readdirSync(hostDir).find(f => f === "Migrations")
|
46
|
+
? path.join(hostDir, "Migrations")
|
47
|
+
: null;
|
48
|
+
const info = {
|
49
|
+
projectName,
|
50
|
+
slnDir,
|
51
|
+
hostDir,
|
52
|
+
migrationsDir,
|
53
|
+
serviceModelDir,
|
54
|
+
serviceInterfaceDir,
|
55
|
+
};
|
56
|
+
return config
|
57
|
+
? Object.assign({}, info, config)
|
58
|
+
: info;
|
59
|
+
}
|