Skip to content
Open
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
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $ node bin/cli.js ./test/data/actions.csv
? Path to components directory to write files to ./test/output
? Wrap the component with `defineComponent()`? No
? Generate labels for component props? No
? eslint-disable props-description rule when missing a prop description? No
? Convert generated component to ESM? (Y/n)
```

Expand All @@ -30,12 +31,13 @@ ARGUMENTS
FILE csv file containing legacy action configs

OPTIONS
--outputType=js/csv Output actions as a csv file or js files
--out CSV output path
--componentsDirPath Path to components directory to write js files
--defineComponent Wrap the component with defineComponent()
--createLabel Generate labels for component props
--[no-]toEsm Convert generated component to ESM (default: Yes)
--outputType=js/csv Output actions as a csv file or js files
--out CSV output path
--componentsDirPath Path to components directory to write js files
--defineComponent Wrap the component with defineComponent()
--createLabel Generate labels for component props
--eslintDisablePropsDescription Disable props-description rule when missing a prop description
--[no-]toEsm Convert generated component to ESM (default: Yes)
```

## Lib
Expand Down
8 changes: 8 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ async function prompt() {
message: "Generate labels for component props?",
default: false,
},
{
type: "confirm",
name: "eslintDisablePropsDescription",
message: "eslint-disable props-description rule when missing a prop description?",
default: false,
},
{
type: "confirm",
name: "toEsm",
Expand Down Expand Up @@ -95,6 +101,7 @@ async function main() {
defineComponent,
createLabel,
toEsm,
eslintDisablePropsDescription,
} = answers;

const actionConfigs = await readCsvFile(csvPath);
Expand All @@ -105,6 +112,7 @@ async function main() {
defineComponent,
createLabel,
toEsm,
eslintDisablePropsDescription,
});
convertedActions.push(convertedAction);
}
Expand Down
8 changes: 8 additions & 0 deletions bin/gen-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ async function prompt() {
message: "Generate labels for component props?",
default: false,
},
{
type: "confirm",
name: "eslintDisablePropsDescription",
message: "eslint-disable props-description rule when missing a prop description?",
default: false,
},
{
type: "confirm",
name: "toEsm",
Expand Down Expand Up @@ -74,6 +80,7 @@ async function main() {
defineComponent,
createLabel,
toEsm,
eslintDisablePropsDescription,
} = answers;

const actionConfigs = await readCsvFile(csvPath);
Expand All @@ -83,6 +90,7 @@ async function main() {
defineComponent,
createLabel,
toEsm,
eslintDisablePropsDescription,
});

const { CODE_RAW: codeRaw } = actionConfig;
Expand Down
15 changes: 13 additions & 2 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ async function convert({
versionMinor = 0,
versionPatch = DEFAULT_VERSION_PATCH,
hashId,
}, { defineComponent=false, createLabel=false, toEsm=true }={}) {
}, {
defineComponent=false,
createLabel=false,
toEsm=true,
eslintDisablePropsDescription = false,
}={}) {
const { params_schema: paramsSchema } = JSON.parse(codeConfigString);

let source = wrapCodeWithFunctionExpr(codeRaw);
Expand All @@ -120,6 +125,9 @@ async function convert({

const componentSlug = makeComponentSlug(appSlug, namespace);
const componentKey = makeComponentKey(appSlug, componentSlug);

const hasPropWithoutDescription = props.find((p) => p.description === undefined);

const componentCode = generate({
code: transformedCode,
props,
Expand All @@ -128,7 +136,10 @@ async function convert({
key: componentKey,
version: `${versionMajor}.${versionMinor}.${versionPatch}`,
hashId,
}, { defineComponent });
}, {
defineComponent,
eslintDisablePropsDescription: eslintDisablePropsDescription && hasPropWithoutDescription
});

const lintedCode = await fix(componentCode, { toEsm });

Expand Down
18 changes: 14 additions & 4 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ Handlebars.registerHelper("tostring", function(variable) {
*/
function generateComponent(
{ code, props, name, description, key, version, hashId },
{ defineComponent } = {}
{ defineComponent, eslintDisablePropsDescription, } = {}
) {
const templateString = readFile(TEMPLATE_PATH, { relative: true });
const template = Handlebars.compile(templateString, { noEscape: true });
return template({ code, props, name, description, key, version, defineComponent, hashId });
return template({
code,
props,
name,
description,
key,
version,
defineComponent,
hashId,
eslintDisablePropsDescription
});
}

/**
Expand All @@ -34,11 +44,11 @@ function generateComponent(
*/
function generate(
{ code, props, name, description, key, version, hashId },
{ defineComponent } = {}
{ defineComponent, eslintDisablePropsDescription } = {}
) {
return generateComponent(
{ code, props, name, description, key, version, hashId },
{ defineComponent }
{ defineComponent, eslintDisablePropsDescription },
);
}

Expand Down
3 changes: 3 additions & 0 deletions resources/templates/action-cjs.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module.exports = {
description: {{tostring description}},
version: {{tostring version}},
type: "action",
{{#if eslintDisablePropsDescription}}
/* eslint-disable pipedream/props-description */
{{/if}}
props: {
{{#each props}}
{{> componentProp }}
Expand Down