MCPcopy Index your code
hub / github.com/subquery/subql / getProjectRootAndManifest

Function getProjectRootAndManifest

packages/common/src/project/utils.ts:60–124  ·  view source on GitHub ↗
(subquery: string)

Source from the content-addressed store, hash-verified

58}
59
60export function getProjectRootAndManifest(subquery: string): ProjectRootAndManifest {
61 const project: ProjectRootAndManifest = {
62 root: '',
63 manifests: [],
64 };
65
66 const stats = fs.statSync(subquery);
67
68 if (stats.isDirectory()) {
69 project.root = subquery;
70
71 if (fs.existsSync(path.resolve(subquery, DEFAULT_MANIFEST))) {
72 project.manifests.push(path.resolve(subquery, DEFAULT_MANIFEST));
73 }
74 // Then check for a 'multichain manifest'
75 else if (fs.existsSync(path.resolve(subquery, DEFAULT_MULTICHAIN_MANIFEST))) {
76 const multichainManifestContent: MultichainProjectManifest = yaml.load(
77 fs.readFileSync(path.resolve(subquery, DEFAULT_MULTICHAIN_MANIFEST), 'utf8')
78 ) as MultichainProjectManifest;
79
80 if (!multichainManifestContent.projects || !Array.isArray(multichainManifestContent.projects)) {
81 throw new Error('Multichain manifest does not contain a valid "projects" field');
82 }
83
84 addMultichainManifestProjects(subquery, multichainManifestContent, project);
85 } else {
86 throw new Error(`Unable to resolve manifest file from given directory: ${subquery}`);
87 }
88 } else if (stats.isFile()) {
89 const {dir, ext} = path.parse(subquery);
90 if (!extensionIsTs(ext) && !extensionIsYamlOrJSON(ext)) {
91 throw new Error(`Extension ${ext} not supported for project ${subquery}`);
92 }
93 project.root = dir;
94 let projectYamlPath = subquery;
95
96 if (extensionIsTs(ext)) {
97 projectYamlPath = tsProjectYamlPath(subquery);
98 if (!fs.existsSync(projectYamlPath)) {
99 throw new Error(
100 `Could not find manifest ${projectYamlPath}, if pointing to a typescript manifest, please ensure build successfully`
101 );
102 }
103 }
104
105 const multichainManifestContent = yaml.load(fs.readFileSync(projectYamlPath, 'utf8')) as MultichainProjectManifest;
106 // The project manifest could be empty
107 if (multichainManifestContent === null) {
108 throw new Error(`Read manifest content is null, ${projectYamlPath}`);
109 } else if (multichainManifestContent.projects && Array.isArray(multichainManifestContent.projects)) {
110 addMultichainManifestProjects(dir, multichainManifestContent, project);
111 } else {
112 project.manifests.push(projectYamlPath);
113 }
114 }
115
116 project.root = path.resolve(project.root);
117

Callers 8

publishAdapterFunction · 0.90
codegenAdapterFunction · 0.90
generateAdapterFunction · 0.90
defaultSubqueryNameFunction · 0.90
createMethod · 0.90

Calls 5

extensionIsTsFunction · 0.85
extensionIsYamlOrJSONFunction · 0.85
tsProjectYamlPathFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected