Skip to content

Commit

Permalink
Improve prettier setup (#378)
Browse files Browse the repository at this point in the history
* ignore CHANGELOG files in prettier commands

* externalize prettier config

* bump prettier
  • Loading branch information
dario-piotrowicz authored Jul 10, 2023
1 parent b630232 commit dc529d7
Show file tree
Hide file tree
Showing 56 changed files with 467 additions and 318 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-terms-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

ignore CHANGELOG.md files in prettier commands and fix prettier
8 changes: 4 additions & 4 deletions .github/version-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const { exec } = require('child_process');

try {
const nextOnPagesPackage = JSON.parse(
fs.readFileSync('./packages/next-on-pages/package.json')
fs.readFileSync('./packages/next-on-pages/package.json'),
);
const eslintPluginPackage = JSON.parse(
fs.readFileSync('./packages/eslint-plugin-next-on-pages/package.json')
fs.readFileSync('./packages/eslint-plugin-next-on-pages/package.json'),
);

exec('git rev-parse --short HEAD', (err, stdout) => {
Expand All @@ -26,11 +26,11 @@ try {

fs.writeFileSync(
'./packages/next-on-pages/package.json',
JSON.stringify(nextOnPagesPackage, null, '\t') + '\n'
JSON.stringify(nextOnPagesPackage, null, '\t') + '\n',
);
fs.writeFileSync(
'./packages/eslint-plugin-next-on-pages/package.json',
JSON.stringify(eslintPluginPackage, null, '\t') + '\n'
JSON.stringify(eslintPluginPackage, null, '\t') + '\n',
);
});
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/CHANGELOG.md
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 80,
"singleQuote": true,
"arrowParens": "avoid",
"semi": true
}
22 changes: 11 additions & 11 deletions internal-packages/docs-scraper/scripts/checkDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void (async function (): Promise<void> {
const undocumentedNextConfigs: NextConfig[] = [];
allNextConfigs.forEach(config => {
const configIsDocumented = nextOnPagesDocumentedNextConfigs.includes(
config.configName
config.configName,
);
if (!configIsDocumented) {
undocumentedNextConfigs.push(config);
Expand All @@ -21,7 +21,7 @@ void (async function (): Promise<void> {
const documentedNonNextConfigs: string[] = [];
nextOnPagesDocumentedNextConfigs.forEach(config => {
const configExists = allNextConfigs.find(
nextConfig => nextConfig.configName === config
nextConfig => nextConfig.configName === config,
);
if (!configExists) {
documentedNonNextConfigs.push(config);
Expand All @@ -33,13 +33,13 @@ void (async function (): Promise<void> {
nextOnPagesDocumentedNextConfigs.length;

console.log(
`The number of next configs is ${numOfNextConfigs} the next-on-pages documented next configs are ${numOfNextOnPagesDocumentedNextConfigs}`
`The number of next configs is ${numOfNextConfigs} the next-on-pages documented next configs are ${numOfNextOnPagesDocumentedNextConfigs}`,
);
console.log(
`The number of undocumented next configs is ${undocumentedNextConfigs.length}`
`The number of undocumented next configs is ${undocumentedNextConfigs.length}`,
);
console.log(
`The number of documented non-next configs is ${documentedNonNextConfigs.length}`
`The number of documented non-next configs is ${documentedNonNextConfigs.length}`,
);

if (
Expand All @@ -49,25 +49,25 @@ void (async function (): Promise<void> {
) {
console.log('\nThe next-on-pages documentation is out of date');
console.log(
`The number of next configs is ${numOfNextConfigs} the next-on-pages documented next configs are ${numOfNextOnPagesDocumentedNextConfigs}`
`The number of next configs is ${numOfNextConfigs} the next-on-pages documented next configs are ${numOfNextOnPagesDocumentedNextConfigs}`,
);
console.log('============================================');
console.log('The following configs are undocumented:');
console.log(undocumentedNextConfigs.map(config => config.configName));
console.log(
'The following configs are documented but do not exist in the nextjs documentation:'
'The following configs are documented but do not exist in the nextjs documentation:',
);
console.log(documentedNonNextConfigs);

if (fromGithub) {
setOutput('result', 'out-of-date');
setOutput(
'undocumented_next_configs',
`${undocumentedNextConfigs.map(config => config.configName).join(',')}`
`${undocumentedNextConfigs.map(config => config.configName).join(',')}`,
);
setOutput(
'documented_non_next_configs',
`${documentedNonNextConfigs.join(',')}`
`${documentedNonNextConfigs.join(',')}`,
);
}
} else {
Expand All @@ -81,7 +81,7 @@ void (async function (): Promise<void> {
const noNextConfigsDetected = allNextConfigs.length === 0;
if (noNextConfigsDetected) {
console.log(
'\nERROR! No next configs were detected, the next docs might have changed!'
'\nERROR! No next configs were detected, the next docs might have changed!',
);

if (fromGithub) {
Expand All @@ -93,7 +93,7 @@ void (async function (): Promise<void> {
nextOnPagesDocumentedNextConfigs.length === 0;
if (noNextOnPagesConfigsDetected) {
console.log(
'\nERROR! No next-on-pages configs were detected, the docs might have changed!'
'\nERROR! No next-on-pages configs were detected, the docs might have changed!',
);

if (fromGithub) {
Expand Down
8 changes: 4 additions & 4 deletions internal-packages/docs-scraper/scripts/createOrUpdateIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void (async function (): Promise<void> {

const issueBody = generateIssueBody(
undocumentedNextConfigs,
documentedNonNextConfigs
documentedNonNextConfigs,
);

if (issues.length === 0) {
Expand All @@ -71,22 +71,22 @@ void (async function (): Promise<void> {

function generateIssueBody(
undocumentedNextConfigs: string[],
documentedNonNextConfigs: string[]
documentedNonNextConfigs: string[],
): string {
let issueBody =
'### The next-on-pages documentation of the next.config.js options is out of date\n';

if (undocumentedNextConfigs.length > 0) {
issueBody += `\n\n${generateMdList(
'The following next.config.js configs are not documented in our supported doc',
undocumentedNextConfigs
undocumentedNextConfigs,
)}`;
}

if (documentedNonNextConfigs.length > 0) {
issueBody += `\n\n${generateMdList(
'The following configs present in our supported doc are not present in the next.config.js documentation pages',
documentedNonNextConfigs
documentedNonNextConfigs,
)}`;
}

Expand Down
24 changes: 12 additions & 12 deletions internal-packages/docs-scraper/scripts/utils/scrapeConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function scrapeConfigs(includeNextOnPages?: true): Promise<{
nextOnPagesDocumentedNextConfigs: string[];
}>;
export async function scrapeConfigs(
includeNextOnPages: false
includeNextOnPages: false,
): Promise<{ allNextConfigs: NextConfig[] }>;
export async function scrapeConfigs(includeNextOnPages = true): Promise<{
allNextConfigs: NextConfig[];
Expand All @@ -29,37 +29,37 @@ export async function scrapeConfigs(includeNextOnPages = true): Promise<{
}

async function getNextOnPagesDocumentedNextConfigs(
page: Page
page: Page,
): Promise<string[]> {
await page.goto(
'https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/docs/supported.md'
'https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/docs/supported.md',
);
const nextOnPagesDocumentedNextConfigs: string[] = await page.$$eval(
'h3:has( > a[href="#nextconfigjs-properties"]) ~ table > tbody > tr > td:first-child',
els =>
els.map(el => {
// Note: footnotes leave a number at the end of the text, so we remove it here
return el.textContent.replace(/\d*$/, '');
})
}),
);
return nextOnPagesDocumentedNextConfigs;
}

async function getNextConfigsFromNextDocs(page: Page): Promise<NextConfig[]> {
const pagesNextConfigsArray = await extractNextConfigsInfoFromNextDocsPage(
page,
'pages'
'pages',
);
const appNextConfigsArray = await extractNextConfigsInfoFromNextDocsPage(
page,
'app'
'app',
);

const commonNextConfigs = appNextConfigsArray
.map(config => ({
app: config,
pages: pagesNextConfigsArray.find(
pagesConfig => pagesConfig.configName === config.configName
pagesConfig => pagesConfig.configName === config.configName,
),
}))
.filter(configs => !!configs.pages)
Expand All @@ -71,14 +71,14 @@ async function getNextConfigsFromNextDocs(page: Page): Promise<NextConfig[]> {

const isCommonConfigName = (configName: string) =>
!!commonNextConfigs.find(
commonConfig => commonConfig.configName === configName
commonConfig => commonConfig.configName === configName,
);

const appSpecificNextConfigs = appNextConfigsArray.filter(
config => !isCommonConfigName(config.configName)
config => !isCommonConfigName(config.configName),
);
const pagesSpecificNextConfigs = pagesNextConfigsArray.filter(
config => !isCommonConfigName(config.configName)
config => !isCommonConfigName(config.configName),
);

const configs = [
Expand All @@ -91,7 +91,7 @@ async function getNextConfigsFromNextDocs(page: Page): Promise<NextConfig[]> {

async function extractNextConfigsInfoFromNextDocsPage(
page: Page,
type: 'app' | 'pages'
type: 'app' | 'pages',
): Promise<NextConfig[]> {
const url = `https://nextjs.org/docs/${type}/api-reference/next-config-js`;

Expand All @@ -108,7 +108,7 @@ async function extractNextConfigsInfoFromNextDocsPage(
};
return { configName, urls: [url] };
}),
type
type,
);
return configs;
}
Loading

0 comments on commit dc529d7

Please sign in to comment.