tsdoc/ts/aidocs_classes/projectcontext.ts

86 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-04-03 11:34:26 +00:00
import * as plugins from '../plugins.js';
export class ProjectContext {
public static async fromDir(dirArg: string) {}
// INSTANCE
public projectDir: string;
constructor(projectDirArg: string) {
this.projectDir = projectDirArg;
}
public async gatherFiles() {
const smartfilePackageJSON = await plugins.smartfile.SmartFile.fromFilePath(
plugins.path.join(this.projectDir, 'package.json'),
this.projectDir
);
const smartfilesReadme = await plugins.smartfile.SmartFile.fromFilePath(
plugins.path.join(this.projectDir, 'readme.md'),
this.projectDir
);
2024-04-12 13:28:55 +00:00
const smartfilesReadmeHints = await plugins.smartfile.SmartFile.fromFilePath(
plugins.path.join(this.projectDir, 'readme.hints.md'),
this.projectDir
);
2024-04-03 11:34:26 +00:00
const smartfilesNpmextraJSON = await plugins.smartfile.SmartFile.fromFilePath(
plugins.path.join(this.projectDir, 'npmextra.json'),
this.projectDir
);
const smartfilesMod = await plugins.smartfile.fs.fileTreeToObject(
this.projectDir,
2024-04-20 21:14:13 +00:00
'ts*/**/*.ts'
2024-04-03 11:34:26 +00:00
);
const smartfilesTest = await plugins.smartfile.fs.fileTreeToObject(
this.projectDir,
'test/**/*.ts'
);
return {
smartfilePackageJSON,
smartfilesReadme,
2024-04-12 13:28:55 +00:00
smartfilesReadmeHints,
2024-04-03 11:34:26 +00:00
smartfilesNpmextraJSON,
smartfilesMod,
smartfilesTest,
};
}
public async convertFilesToContext(filesArg: plugins.smartfile.SmartFile[]) {
2024-04-20 21:14:13 +00:00
console.log(`Using the following files for the documentation:`)
filesArg.map(fileArg => {
console.log(` -> ${fileArg.relative}`);
})
2024-04-03 11:34:26 +00:00
return filesArg
.map((smartfile) => {
return `
====== START OF FILE ${smartfile.relative} ======
${smartfile.contents.toString()}
====== END OF FILE ${smartfile.relative} ======
`;
})
.join('\n');
}
private async buildContext(dirArg: string) {
const files = await this.gatherFiles();
let context = await this.convertFilesToContext([
files.smartfilePackageJSON,
files.smartfilesReadme,
2024-04-12 13:28:55 +00:00
files.smartfilesReadmeHints,
2024-04-03 11:34:26 +00:00
files.smartfilesNpmextraJSON,
...files.smartfilesMod,
...files.smartfilesTest,
]);
2024-04-20 21:14:13 +00:00
// console.log(context);
2024-04-03 11:34:26 +00:00
return context;
}
public async update() {
const result = await this.buildContext(this.projectDir);
return result;
}
}