codify-plugin-lib 1.0.182-beta41 → 1.0.182-beta43
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/plugin/plugin.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ApplyRequestData, GetResourceInfoRequestData, GetResourceInfoResponseData, ImportRequestData, ImportResponseData, InitializeRequestData, InitializeResponseData, MatchRequestData, MatchResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ResourceJson, ValidateRequestData, ValidateResponseData } from 'codify-schemas';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { BackgroundPty } from '../pty/background-pty.js';
|
|
4
|
+
import { Resource } from '../resource/resource.js';
|
|
4
5
|
import { ResourceController } from '../resource/resource-controller.js';
|
|
5
6
|
export declare class Plugin {
|
|
6
7
|
name: string;
|
|
7
|
-
version: string;
|
|
8
8
|
resourceControllers: Map<string, ResourceController<ResourceConfig>>;
|
|
9
9
|
planStorage: Map<string, Plan<any>>;
|
|
10
10
|
planPty: BackgroundPty;
|
|
11
|
-
constructor(name: string,
|
|
12
|
-
static create():
|
|
11
|
+
constructor(name: string, resourceControllers: Map<string, ResourceController<ResourceConfig>>);
|
|
12
|
+
static create(name: string, resources: Resource<any>[]): Plugin;
|
|
13
13
|
initialize(data: InitializeRequestData): Promise<InitializeResponseData>;
|
|
14
14
|
getResourceInfo(data: GetResourceInfoRequestData): GetResourceInfoResponseData;
|
|
15
15
|
match(data: MatchRequestData): Promise<MatchResponseData>;
|
package/dist/plugin/plugin.js
CHANGED
|
@@ -4,37 +4,23 @@ import { BackgroundPty } from '../pty/background-pty.js';
|
|
|
4
4
|
import { getPty } from '../pty/index.js';
|
|
5
5
|
import { SequentialPty } from '../pty/seqeuntial-pty.js';
|
|
6
6
|
import { ResourceController } from '../resource/resource-controller.js';
|
|
7
|
-
import { listAllResources } from '../utils/load-resources.js';
|
|
8
|
-
import { readNearestPackageJson } from '../utils/package-json-utils.js';
|
|
9
7
|
import { ptyLocalStorage } from '../utils/pty-local-storage.js';
|
|
10
8
|
import { VerbosityLevel } from '../utils/verbosity-level.js';
|
|
11
9
|
export class Plugin {
|
|
12
10
|
name;
|
|
13
|
-
version;
|
|
14
11
|
resourceControllers;
|
|
15
12
|
planStorage;
|
|
16
13
|
planPty = new BackgroundPty();
|
|
17
|
-
constructor(name,
|
|
14
|
+
constructor(name, resourceControllers) {
|
|
18
15
|
this.name = name;
|
|
19
|
-
this.version = version;
|
|
20
16
|
this.resourceControllers = resourceControllers;
|
|
21
17
|
this.planStorage = new Map();
|
|
22
18
|
}
|
|
23
|
-
static
|
|
24
|
-
const packageJson = readNearestPackageJson();
|
|
25
|
-
if (!packageJson) {
|
|
26
|
-
throw new Error('Failed to read nearest package.json');
|
|
27
|
-
}
|
|
28
|
-
const { name, version } = packageJson;
|
|
29
|
-
const resourceLocations = await listAllResources();
|
|
30
|
-
const resources = (await Promise.all(resourceLocations.map((l) => {
|
|
31
|
-
return import(l).then((r) => r.default ?? r);
|
|
32
|
-
}))).flat(1);
|
|
33
|
-
console.log(resources);
|
|
19
|
+
static create(name, resources) {
|
|
34
20
|
const controllers = resources
|
|
35
21
|
.map((resource) => new ResourceController(resource));
|
|
36
22
|
const controllersMap = new Map(controllers.map((r) => [r.typeId, r]));
|
|
37
|
-
return new Plugin(name,
|
|
23
|
+
return new Plugin(name, controllersMap);
|
|
38
24
|
}
|
|
39
25
|
async initialize(data) {
|
|
40
26
|
if (data.verbosityLevel) {
|
package/package.json
CHANGED
package/src/plugin/plugin.ts
CHANGED
|
@@ -22,12 +22,10 @@ import { Plan } from '../plan/plan.js';
|
|
|
22
22
|
import { BackgroundPty } from '../pty/background-pty.js';
|
|
23
23
|
import { getPty } from '../pty/index.js';
|
|
24
24
|
import { SequentialPty } from '../pty/seqeuntial-pty.js';
|
|
25
|
+
import { Resource } from '../resource/resource.js';
|
|
25
26
|
import { ResourceController } from '../resource/resource-controller.js';
|
|
26
|
-
import { listAllResources } from '../utils/load-resources.js';
|
|
27
|
-
import { findNearestPackageJson, readNearestPackageJson } from '../utils/package-json-utils.js';
|
|
28
27
|
import { ptyLocalStorage } from '../utils/pty-local-storage.js';
|
|
29
28
|
import { VerbosityLevel } from '../utils/verbosity-level.js';
|
|
30
|
-
import path from 'node:path';
|
|
31
29
|
|
|
32
30
|
export class Plugin {
|
|
33
31
|
planStorage: Map<string, Plan<any>>;
|
|
@@ -35,27 +33,12 @@ export class Plugin {
|
|
|
35
33
|
|
|
36
34
|
constructor(
|
|
37
35
|
public name: string,
|
|
38
|
-
public version: string,
|
|
39
36
|
public resourceControllers: Map<string, ResourceController<ResourceConfig>>
|
|
40
37
|
) {
|
|
41
38
|
this.planStorage = new Map();
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
static
|
|
45
|
-
const packageJson = readNearestPackageJson();
|
|
46
|
-
if (!packageJson) {
|
|
47
|
-
throw new Error('Failed to read nearest package.json');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { name, version } = packageJson;
|
|
51
|
-
|
|
52
|
-
const resourceLocations = await listAllResources();
|
|
53
|
-
const resources = (await Promise.all(resourceLocations.map((l) => {
|
|
54
|
-
return import(l).then((r) => r.default ?? r);
|
|
55
|
-
}))).flat(1);
|
|
56
|
-
|
|
57
|
-
console.log(resources);
|
|
58
|
-
|
|
41
|
+
static create(name: string, resources: Resource<any>[]) {
|
|
59
42
|
const controllers = resources
|
|
60
43
|
.map((resource) => new ResourceController(resource))
|
|
61
44
|
|
|
@@ -63,7 +46,7 @@ export class Plugin {
|
|
|
63
46
|
controllers.map((r) => [r.typeId, r] as const)
|
|
64
47
|
);
|
|
65
48
|
|
|
66
|
-
return new Plugin(name,
|
|
49
|
+
return new Plugin(name, controllersMap);
|
|
67
50
|
}
|
|
68
51
|
|
|
69
52
|
async initialize(data: InitializeRequestData): Promise<InitializeResponseData> {
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import * as url from 'node:url';
|
|
4
|
-
|
|
5
|
-
export const listAllResources = async (root = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '..', '..', '..', '..')) => {
|
|
6
|
-
console.log('Dirname', root);
|
|
7
|
-
|
|
8
|
-
const resourcesPath = path.join(root, 'src', 'resources')
|
|
9
|
-
|
|
10
|
-
const resourceDir = await fs.readdir(resourcesPath);
|
|
11
|
-
const dedupSet = new Set();
|
|
12
|
-
const result = new Set<string>();
|
|
13
|
-
|
|
14
|
-
for (const folder of resourceDir) {
|
|
15
|
-
if (await fs.stat(path.join(resourcesPath, folder)).then(s => s.isDirectory()).catch(() => false)) {
|
|
16
|
-
for (const folderContents of await fs.readdir(path.join(resourcesPath, folder))) {
|
|
17
|
-
const isDirectory = await fs.stat(path.join(resourcesPath, folder, folderContents)).then(s => s.isDirectory());
|
|
18
|
-
|
|
19
|
-
// console.log(folderContents, isDirectory);
|
|
20
|
-
if (isDirectory) {
|
|
21
|
-
for (const innerContents of await fs.readdir(path.join(resourcesPath, folder, folderContents))) {
|
|
22
|
-
if (!dedupSet.has(path.join(resourcesPath, folder, folderContents))) {
|
|
23
|
-
dedupSet.add(path.join(resourcesPath, folder, folderContents));
|
|
24
|
-
addResourceFromDir(path.join(resourcesPath, folder,folderContents), result);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
if (!dedupSet.has(path.join(resourcesPath, folder))) {
|
|
29
|
-
dedupSet.add(path.join(resourcesPath, folder));
|
|
30
|
-
addResourceFromDir(path.join(resourcesPath, folder), result);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
throw new Error('Only directories are allowed in resources folder')
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return [...result];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function addResourceFromDir(dir: string, result: Set<string>): void {
|
|
45
|
-
try {
|
|
46
|
-
const resourceFile = path.resolve(path.join(dir, 'resource.ts'));
|
|
47
|
-
if (!(fs.stat(resourceFile).then((s) => s.isFile())).catch(() => false)) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
result.add(resourceFile);
|
|
52
|
-
} catch {}
|
|
53
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Find the nearest package.json starting from a directory and walking upward.
|
|
6
|
-
* @param {string} startDir - Directory to start searching from
|
|
7
|
-
* @returns {string|null} Absolute path to package.json or null if not found
|
|
8
|
-
*/
|
|
9
|
-
export function findNearestPackageJson(startDir = process.cwd()) {
|
|
10
|
-
let currentDir = path.resolve(startDir);
|
|
11
|
-
|
|
12
|
-
while (true) {
|
|
13
|
-
const pkgPath = path.join(currentDir, "package.json");
|
|
14
|
-
|
|
15
|
-
if (fs.existsSync(pkgPath)) {
|
|
16
|
-
return pkgPath;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const parentDir = path.dirname(currentDir);
|
|
20
|
-
if (parentDir === currentDir) {
|
|
21
|
-
// Reached filesystem root
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
currentDir = parentDir;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Read and parse the nearest package.json
|
|
31
|
-
* @param {string} startDir
|
|
32
|
-
* @returns {object|null}
|
|
33
|
-
*/
|
|
34
|
-
export function readNearestPackageJson(startDir: string = process.cwd()) {
|
|
35
|
-
const pkgPath = findNearestPackageJson(startDir);
|
|
36
|
-
if (!pkgPath) return null;
|
|
37
|
-
|
|
38
|
-
const contents = fs.readFileSync(pkgPath, 'utf8');
|
|
39
|
-
return JSON.parse(contents);
|
|
40
|
-
}
|