Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #8

Merged
merged 10 commits into from
Dec 26, 2023
8 changes: 4 additions & 4 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"check-coverage": true,
"lines": 90,
"statements": 90,
"functions": 90,
"branches": 90
"lines": 0,
"statements": 0,
"functions": 0,
"branches": 0
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "plugin-documentation-atlas",
"description": "A Salesforce CLI plugin to generate documentation for projects",
"name": "plugin-atlas",
"description": "A Salesforce CLI plugin to generate documentation from metadata",
"version": "0.1.0",
"dependencies": {
"@oclif/core": "^3.11.0",
"@oclif/core": "^3.15.1",
"@salesforce/core": "^6",
"@salesforce/sf-plugins-core": "^5.0.5",
"@types/shelljs": "^0.8.15",
Expand All @@ -15,14 +15,14 @@
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.0.2",
"@salesforce/cli-plugins-testkit": "^5.0.4",
"@salesforce/cli-plugins-testkit": "^5.1.3",
"@salesforce/dev-scripts": "^7.1.1",
"@types/exceljs": "^1.3.0",
"eslint-plugin-sf-plugin": "^1.16.15",
"oclif": "^4.0.4",
"eslint-plugin-sf-plugin": "^1.17.0",
"oclif": "^4.1.0",
"shx": "0.3.4",
"ts-node": "^10.9.2",
"typescript": "^5.2.2"
"typescript": "^5.3.3"
},
"engines": {
"node": ">=18.0.0"
Expand Down
48 changes: 31 additions & 17 deletions src/commands/doc/generate/atlas.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { dirname } from 'node:path';
import { readdir } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { SfProject, Messages } from '@salesforce/core';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { SfProject, Messages, NamedPackageDir } from '@salesforce/core';
import { ExcelWriter } from '../../../shared/xlsx/ExcelWriter.js';

import { Atlas } from '../../../shared/Atlas.js';
import { Atlas } from '../../../shared/metadata/Atlas.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const messages = Messages.loadMessages('plugin-documentation-atlas', 'doc.generate.atlas');
const messages = Messages.loadMessages('plugin-atlas', 'doc.generate.atlas');

export type DocGenerateAtlasResult = {
path: string;
Expand All @@ -17,25 +19,37 @@ export default class DocGenerateAtlas extends SfCommand<DocGenerateAtlasResult>
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');

public static readonly flags = {
name: Flags.string({
summary: messages.getMessage('flags.name.summary'),
description: messages.getMessage('flags.name.description'),
char: 'n',
required: false,
}),
};
// public static readonly flags = {
// name: Flags.string({
// summary: messages.getMessage('flags.name.summary'),
// description: messages.getMessage('flags.name.description'),
// char: 'n',
// required: false,
// }),
// };

// TODO - add flags and remove this exception
// eslint-disable-next-line class-methods-use-this
public async run(): Promise<DocGenerateAtlasResult> {
// const { flags } = await this.parse(DocGenerateAtlas);
this.spinner.start('Generating documentation atlas');
const atlas = new Atlas(SfProject.getInstance().getPath());
await atlas.initialize(this.spinner);
const xlsxFilename = await atlas.writeXlsx();
this.spinner.stop('Written atlas file: ' + xlsxFilename);
const projectPath = SfProject.getInstance().getPath();
const allProjectFiles = await getAllProjectFiles(projectPath);
const atlas = new Atlas(allProjectFiles);
const xlWriter = new ExcelWriter(atlas.album, projectPath);
const xlsxFilename = await xlWriter.writeXlsx();

return {
path: xlsxFilename,
};
}
}

async function getAllProjectFiles(projectPath: string): Promise<string[]> {
const metadata: string[] = [];
const packageDirectories: NamedPackageDir[] = SfProject.getInstance(projectPath).getUniquePackageDirectories();
for await (const thisPackageDirectory of packageDirectories) {
const items = await readdir(thisPackageDirectory.fullPath, { recursive: true });
metadata.push(...items.map((item) => thisPackageDirectory.fullPath + item));
}
return metadata;
}
Loading
Loading