Skip to content

✨ Before save flow #16

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

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"import/prefer-default-export": "warn",
"import/no-extraneous-dependencies": "off",
"@typescript-eslint/no-use-before-define": "off",
"unicorn/filename-case": "off"
"unicorn/filename-case": "off",
"max-classes-per-file": "off"
}
}
2 changes: 1 addition & 1 deletion messages/messages.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"errorParamNotFound": "Flow API name is missing.",
"errorUnsupportedFlow": "Currently, only process is supported. the other type of processes will be available soon.",
"errorUnsupportedFlow": "The flow is not supported now.",
"commandDescription": "generate pdf document",
"nameFlagDescription": "developer name of flow",
"localeFlagDescription": "locale of the document (en or ja)",
Expand Down
28 changes: 16 additions & 12 deletions src/commands/flowdoc/docx/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { Messages, SfdxError } from '@salesforce/core';
import * as fs from 'fs-extra';
import * as docx from 'docx';

import { Flow } from '../../../types/flow';
import FlowParser from '../../../lib/flowParser';
import buildDocxContent from '../../../lib/docx/docxBuilder';
import { Flow } from '../../../types/metadata/flow';
import {
ReadableProcessMetadataConverter,
ReadableFlowMetadataConverter,
} from '../../../lib/converter/metadataConverter';
import { isSupported, isProcess } from '../../../lib/util/flowUtils';
import DocxBuilder from '../../../lib/docx/docxBuilder';
import { API_VERSION } from '../../../lib/converter/helper/constants';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('sfdx-flowdoc-plugin', 'messages');

const API_VERSION = '48.0';
export default class Generate extends SfdxCommand {
public static description = messages.getMessage('commandDescription');

Expand Down Expand Up @@ -45,21 +49,22 @@ export default class Generate extends SfdxCommand {
const conn = this.org.getConnection();
conn.setApiVersion(API_VERSION);

const flow = await conn.metadata.read('Flow', this.args.file);

const flow = ((await conn.metadata.read('Flow', this.args.file)) as unknown) as Flow;
if (Object.keys(flow).length === 0) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorFlowNotFound'));
}
const fp = new FlowParser((flow as unknown) as Flow, this.args.file);
if (!fp.isSupportedFlow()) {

if (!isSupported(flow)) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorUnsupportedFlow'));
}
this.ux.stopSpinner();

const hrDoc = fp.createReadableProcess();
const doc = buildDocxContent(hrDoc, this.flags.locale);
const docxBuilder = new DocxBuilder(this.flags.locale);
const doc = isProcess(flow)
? new ReadableProcessMetadataConverter(flow, this.args.file).accept(docxBuilder)
: new ReadableFlowMetadataConverter(flow, this.args.file).accept(docxBuilder);

const outdir = this.flags.outdir ? this.flags.outdir : '.';
await fs.ensureDir(outdir);
Expand All @@ -68,8 +73,7 @@ export default class Generate extends SfdxCommand {
fs.writeFileSync(`${outdir}/${targetPath}`, buffer);
});

const label: string = fp.getLabel();
this.ux.log(`Documentation of '${label}' flow is successfully generated.`);
this.ux.log(`Documentation of '${flow.label}' flow is successfully generated.`);

return flow;
}
Expand Down
27 changes: 16 additions & 11 deletions src/commands/flowdoc/json/display.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';

import { Flow } from '../../../types/flow';
import FlowParser from '../../../lib/flowParser';
import buildLocalizedJson from '../../../lib/json/jsonBuilder';
import { Flow } from '../../../types/metadata/flow';
import { isSupported, isProcess } from '../../../lib/util/flowUtils';
import JsonBuilder from '../../../lib/json/jsonBuilder';
import {
ReadableProcessMetadataConverter,
ReadableFlowMetadataConverter,
} from '../../../lib/converter/metadataConverter';
import { API_VERSION } from '../../../lib/converter/helper/constants';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('sfdx-flowdoc-plugin', 'messages');

const API_VERSION = '48.0';
export default class Display extends SfdxCommand {
public static description = messages.getMessage('commandDescription');

Expand Down Expand Up @@ -41,22 +45,23 @@ export default class Display extends SfdxCommand {
const conn = this.org.getConnection();
conn.setApiVersion(API_VERSION);

const flow = await conn.metadata.read('Flow', this.args.file);

const flow = ((await conn.metadata.read('Flow', this.args.file)) as unknown) as Flow;
if (Object.keys(flow).length === 0) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorFlowNotFound'));
}
const fp = new FlowParser((flow as unknown) as Flow, this.args.file);
if (!fp.isSupportedFlow()) {

if (!isSupported(flow)) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorUnsupportedFlow'));
}
this.ux.stopSpinner();

const readableFlow = fp.createReadableProcess();
const localizedJson = buildLocalizedJson(readableFlow, this.flags.locale);
this.ux.log(JSON.stringify(localizedJson, null, ' '));
const jsonBuilder = new JsonBuilder(this.flags.locale);
const json = isProcess(flow)
? new ReadableProcessMetadataConverter(flow, this.args.file).accept(jsonBuilder)
: new ReadableFlowMetadataConverter(flow, this.args.file).accept(jsonBuilder);
this.ux.log(JSON.stringify(json, null, ' '));

return flow;
}
Expand Down
30 changes: 17 additions & 13 deletions src/commands/flowdoc/json/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { flags, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
import * as fs from 'fs-extra';

import { Flow } from '../../../types/flow';
import FlowParser from '../../../lib/flowParser';
import buildLocalizedJson from '../../../lib/json/jsonBuilder';
import { Flow } from '../../../types/metadata/flow';
import { isSupported, isProcess } from '../../../lib/util/flowUtils';
import JsonBuilder from '../../../lib/json/jsonBuilder';
import {
ReadableProcessMetadataConverter,
ReadableFlowMetadataConverter,
} from '../../../lib/converter/metadataConverter';
import { API_VERSION } from '../../../lib/converter/helper/constants';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('sfdx-flowdoc-plugin', 'messages');

const API_VERSION = '48.0';
export default class Generate extends SfdxCommand {
public static description = messages.getMessage('commandDescription');

Expand Down Expand Up @@ -45,30 +49,30 @@ export default class Generate extends SfdxCommand {
const conn = this.org.getConnection();
conn.setApiVersion(API_VERSION);

const flow = await conn.metadata.read('Flow', this.args.file);

const flow = ((await conn.metadata.read('Flow', this.args.file)) as unknown) as Flow;
if (Object.keys(flow).length === 0) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorFlowNotFound'));
}
const fp = new FlowParser((flow as unknown) as Flow, this.args.file);
if (!fp.isSupportedFlow()) {

if (!isSupported(flow)) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorUnsupportedFlow'));
}
this.ux.stopSpinner();

const readableFlow = fp.createReadableProcess();
const localizedJson = buildLocalizedJson(readableFlow, this.flags.locale);
const jsonBuilder = new JsonBuilder(this.flags.locale);
const json = isProcess(flow)
? new ReadableProcessMetadataConverter(flow, this.args.file).accept(jsonBuilder)
: new ReadableFlowMetadataConverter(flow, this.args.file).accept(jsonBuilder);

const targetPath = `${this.args.file}.json`;

const outdir = this.flags.outdir ? this.flags.outdir : '.';
await fs.ensureDir(outdir);
fs.writeFileSync(`${outdir}/${targetPath}`, JSON.stringify(localizedJson, null, ' '));
fs.writeFileSync(`${outdir}/${targetPath}`, JSON.stringify(json, null, ' '));

const label: string = fp.getLabel();
this.ux.log(`Documentation of '${label}' flow is successfully generated.`);
this.ux.log(`Documentation of '${flow.label}' flow is successfully generated.`);

return flow;
}
Expand Down
27 changes: 16 additions & 11 deletions src/commands/flowdoc/pdf/generate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
import * as fs from 'fs-extra';
import { Flow } from '../../../types/flow';
import FlowParser from '../../../lib/flowParser';
import { Flow } from '../../../types/metadata/flow';
import fonts from '../../../style/font';
import buildPdfContent from '../../../lib/pdf/pdfBuilder';
import PdfBuilder from '../../../lib/pdf/pdfBuilder';
import {
ReadableProcessMetadataConverter,
ReadableFlowMetadataConverter,
} from '../../../lib/converter/metadataConverter';
import { isSupported, isProcess } from '../../../lib/util/flowUtils';
import { API_VERSION } from '../../../lib/converter/helper/constants';

const Pdf = require('pdfmake');

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('sfdx-flowdoc-plugin', 'messages');

const API_VERSION = '48.0';
export default class Generate extends SfdxCommand {
public static description = messages.getMessage('commandDescription');

Expand Down Expand Up @@ -44,20 +48,22 @@ export default class Generate extends SfdxCommand {
const conn = this.org.getConnection();
conn.setApiVersion(API_VERSION);

const flow = await conn.metadata.read('Flow', this.args.file);
const flow = ((await conn.metadata.read('Flow', this.args.file)) as unknown) as Flow;
if (Object.keys(flow).length === 0) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorFlowNotFound'));
}
const fp = new FlowParser((flow as unknown) as Flow, this.args.file);
if (!fp.isSupportedFlow()) {

if (!isSupported(flow)) {
this.ux.stopSpinner('failed.');
throw new SfdxError(messages.getMessage('errorUnsupportedFlow'));
}
this.ux.stopSpinner();

const hrDoc = fp.createReadableProcess();
const docDefinition = buildPdfContent(hrDoc, this.flags.locale);
const pdfBuilder = new PdfBuilder(this.flags.locale);
const docDefinition = isProcess(flow)
? new ReadableProcessMetadataConverter(flow, this.args.file).accept(pdfBuilder)
: new ReadableFlowMetadataConverter(flow, this.args.file).accept(pdfBuilder);

const printer = new Pdf(fonts);
const pdfDoc = printer.createPdfKitDocument(docDefinition);
Expand All @@ -67,8 +73,7 @@ export default class Generate extends SfdxCommand {
const targetPath = `${this.args.file}.pdf`;
pdfDoc.pipe(fs.createWriteStream(`${outdir}/${targetPath}`));
pdfDoc.end();
const label: string = fp.getLabel();
this.ux.log(`Documentation of '${label}' flow is successfully generated.`);
this.ux.log(`Documentation of '${flow.label}' flow is successfully generated.`);

return flow;
}
Expand Down
12 changes: 12 additions & 0 deletions src/config/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
"WHEN_THE_PROCESS_STARTS": "When the process starts",
"WHEN_A_RECORD_IS_CREATED_OR_EDITED": "When a record is created or edited",
"ONLY_WHEN_A_RECORD_IS_CREATED": "Only when a record is created",
"FLOW_TRIGGER_TYPE": "Flow Type",
"FLOW_TRIGGER_AUTO_LAUNCHED": "Auto Launched Flow",
"FLOW_TRIGGER_RECORD": "Record Change Flow",
"FLOW_TRIGGER_SCHEDULED": "Scheduled Flow",
"FLOW_TRIGGER_PLATFORM_EVENT": "Platform Event Flow",
"HEADER_FLOW_TRIGGER_RECORD": "Trigger the Flow When",
"FROW_TRIGGER_RECORD_CREATE_ONLY": "A record is created",
"FROW_TRIGGER_RECORD_UPDATE_ONLY": "A record is updated",
"FROW_TRIGGER_RECORD_CREATE_OR_UPDATE": "A record is created or updated",
"HEADER_FLOW_TRIGGER_RECORD_TYPE": "Run the Flow",
"FLOW_TRIGGER_BEFORE": "Before the record is saved",
"FLOW_TRIGGER_AFTER": "After the record is saved",
"ACTION_GROUP": "Action Group",
"CONDITION_NAME": "Condition Name",
"CRITERIA_FOR_EXECUTING_ACTIONS": "Criteria for Execution Actions",
Expand Down
12 changes: 12 additions & 0 deletions src/config/locale/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
"WHEN_THE_PROCESS_STARTS": "プロセスを開始",
"WHEN_A_RECORD_IS_CREATED_OR_EDITED": "レコードを作成したときのみ",
"ONLY_WHEN_A_RECORD_IS_CREATED": "レコードを作成または編集したとき",
"FLOW_TRIGGER_TYPE": "フローの種別",
"FLOW_TRIGGER_AUTOLAUNCHED": "自動起動",
"FLOW_TRIGGER_RECORD": "レコード変更フロー",
"FLOW_TRIGGER_SCHEDULED": "スケジュール済みフロー",
"FLOW_TRIGGER_PLATFORM_EVENT": "プラットフォームイベントフロー",
"HEADER_FLOW_TRIGGER_RECORD": "フローをトリガする条件",
"FROW_TRIGGER_RECORD_CREATE_ONLY": "レコードの作成時",
"FROW_TRIGGER_RECORD_UPDATE_ONLY": "レコードの更新時",
"FROW_TRIGGER_RECORD_CREATE_OR_UPDATE": "レコードの作成または更新時",
"HEADER_FLOW_TRIGGER_RECORD_TYPE": "フローを実行",
"FLOW_TRIGGER_BEFORE": "レコードが保存される前",
"FLOW_TRIGGER_AFTER": "レコードが保存された後",
"ACTION_GROUP": "アクショングループ",
"CONDITION_NAME": "条件名",
"CRITERIA_FOR_EXECUTING_ACTIONS": "アクションの実行条件",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ActionCall, InputParamValue } from '../types/flow';
import { RecordCreate, RecordUpdate, RecordFilter, RecordLookup } from '../types/flowRecordAction';
import { toArray } from './util/arrayUtils';
import { ProcessMetadataValue } from '../types/processMetadataValue';
import { ReadableCondition, ReadableActionItem, ReadableActionItemParameter } from '../types/parser';
import { ActionCall, InputParamValue } from '../../../types/metadata/flow';
import { RecordCreate, RecordUpdate, RecordFilter, RecordLookup } from '../../../types/metadata/flowRecordAction';
import { toArray } from '../../util/arrayUtils';
import { ProcessMetadataValue } from '../../../types/metadata/processMetadataValue';
import { ReadableCondition, ReadableActionItem, ReadableActionItemParameter } from '../../../types/converter/process';

const layout = require('./actionLayout.json');

Expand Down
3 changes: 3 additions & 0 deletions src/lib/converter/helper/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SUPPORTED_PROCESS = ['Workflow', 'CustomEvent', 'InvocableProcess'];
export const SUPPORTED_FLOW = ['AutoLaunchedFlow'];
export const API_VERSION = '49.0';
Loading