Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
chore: parser fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev committed Jan 9, 2024
1 parent 4bfb875 commit aa30beb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
23 changes: 11 additions & 12 deletions readme-parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ export const parse = (data: string) => {
const examples = exampleHeading
? getTextByHeader(children, exampleHeading, '\n')
: null;
if (!examples) {
throw new Error('Examples not found');
}
// if (!examples) {
// throw new Error('Examples not found');
// }

const applicabilityHeader = getHeading(children, 2, 'Applicability');
const applicability = applicabilityHeader
Expand Down Expand Up @@ -339,7 +339,7 @@ export const parse = (data: string) => {

const ownerHeader = getHeading(children, 3, 'Owner');
const owner = ownerHeader
? getTextByHeader(children, ownerHeader, '\n') ?? 'Intuita'
? getTextByHeader(children, ownerHeader, '\n') ?? 'Codemod.com'
: null;

const linksHeader = getHeading(children, 3, 'Links');
Expand Down Expand Up @@ -437,8 +437,7 @@ f_long-description: >-
## Description
\n
${description.replace(/\n/g, '\n ')}
\n
${examples.replace(/\n/g, '\n ')}${
${examples ? '\n\n ' + examples.replace(/\n/g, '\n ') : ''}${
path
? `\nf_github-link: https://github.com/codemod-com/codemod-registry/tree/main/${cleanPath}`
: ''
Expand All @@ -450,10 +449,10 @@ f_long-description: >-
framework ? `\nf_framework: cms/framework/${framework}.md` : ''
}
f_applicability-criteria: "${applicability}"
f_verified-codemod: ${owner === 'Intuita' ? 'true' : 'false'}
f_verified-codemod: ${owner === 'Codemod.com' ? 'true' : 'false'}
f_author: ${
owner === 'Intuita'
? 'cms/authors/intuita.md'
owner === 'Codemod.com'
? 'cms/authors/codemodcom.md'
: `cms/authors/${owner?.toLowerCase().replace(/ /g, '-') ?? ''}.md`
}
layout: "[automations].html"${slug ? `\nslug: ${slug}` : ''}
Expand All @@ -469,9 +468,9 @@ tags: automations
updated-on: ${new Date().toISOString()}
published-on: ${new Date().toISOString()}
seo:
title: ${titleWithVersion} | Intuita Automations
og:title: ${titleWithVersion} | Intuita Automations
twitter:title: ${titleWithVersion} | Intuita Automations
title: ${titleWithVersion} | Codemod.com Automations
og:title: ${titleWithVersion} | Codemod.com Automations
twitter:title: ${titleWithVersion} | Codemod.com Automations
description: ${shortDescription}
twitter:card: ${shortDescription}
`.trim();
Expand Down
24 changes: 17 additions & 7 deletions readme-parser/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const sync = async () => {
'website',
'https://github.com/codemod-com/website.git',
);
await git.addConfig('user.email', '[email protected]', false, 'local');
await git.addConfig('user.name', 'Intuita Team', false, 'local');
await git.addConfig('user.email', '[email protected]', false, 'local');
await git.addConfig('user.name', 'codemod.com', false, 'local');

await git.fetch(['website', 'master']);
await git.fetch(['origin', 'main', '--depth=2']);
Expand Down Expand Up @@ -94,7 +94,13 @@ export const sync = async () => {
continue;
}

const parsedNewFile = parse(newFile);
let parsedNewFile: ReturnType<typeof parse>;
try {
parsedNewFile = parse(newFile);
} catch (err) {
console.error(`Could not parse new README file under ${path}`);
continue;
}
const newFileShortDescription = parsedNewFile.description
.split('\n')
.at(0);
Expand Down Expand Up @@ -133,10 +139,14 @@ export const sync = async () => {
// the fields just like any other JS object, to perform the comparison.
// Not using valibot's safeParse, because we can just error if that's not an object and we don't care
// about the fields to be of a specific type.
const oldContent = valibotParse(
record(any()),
yaml.load(convertToYaml(parse(oldFile), path)),
);
let oldFileParsedYaml: unknown;
try {
oldFileParsedYaml = yaml.load(convertToYaml(parse(oldFile), path));
} catch (err) {
console.error(`Could not parse old README file under ${path}`);
continue;
}
const oldContent = valibotParse(record(any()), oldFileParsedYaml);
const newContent = valibotParse(
record(any()),
yaml.load(newReadmeYamlContent),
Expand Down

0 comments on commit aa30beb

Please sign in to comment.