Skip to content

Commit

Permalink
🩹 fix(none): readme generation (#2378)
Browse files Browse the repository at this point in the history
prettier@3.0.0 broke readme gen and create-bud-app because the `format` export is now async.



## Type of change

**NONE: internal change**
  • Loading branch information
kellymears committed Jul 18, 2023
1 parent 69078c8 commit eb34305
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h1 align="center"><strong>bud.js</strong></h1>

<p align="center">
Frontend build tools combining the best parts of Symfony Encore and Laravel Mix
Configurable, extensible build tools for modern single and multi-page web applications
</p>

---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bud",
"private": true,
"description": "⚡️ Lightning fast frontend build tools combining the best parts of Symfony Encore and Laravel Mix",
"description": "Configurable, extensible build tools for modern single and multi-page web applications",
"engines": {
"node": "18.16.1",
"yarn": "1.22.19",
Expand Down
2 changes: 1 addition & 1 deletion sources/@repo/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@repo/docs",
"private": true,
"description": "A frontend build tooling framework combining the best parts of Symfony Encore and Laravel Mix",
"description": "Configurable, extensible build tools for modern single and multi-page web applications",
"engines": {
"node": "^16.3.0"
},
Expand Down
32 changes: 26 additions & 6 deletions sources/@repo/markdown-kit/readme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import type {GrayMatterFile} from 'gray-matter'
import {path, projectConfig} from '@repo/constants'
import {Filesystem, json as Json} from '@roots/bud-support/filesystem'
import globby from '@roots/bud-support/globby'
import {Logger} from '@roots/bud-support/logger'
import matter from 'gray-matter'
import {format} from 'prettier'

import {templates} from './renderer/index.js'

const fs = new Filesystem()
const logger = new Logger({
logLevel: `info`,
})

type Chunks = Array<string> | Promise<Array<string>>
type File = GrayMatterFile<string>
Expand All @@ -33,9 +37,17 @@ const generateReadme = async (signifier: string) => {
path(`sources`, signifier, `docs`, `*.{md,mdx}`),
).then(
async files =>
await files.sort().reduce(async (files, path) => {
const body = await fs.read(path, `utf8`)
return [...(await files), matter(body)]
await files.sort().reduce(async (accumulator, path, i) => {
logger.log(`writing ${signifier} ${i + 1}/${files.length}`)
const body = await fs.read(path, `utf8`).catch(error => {
logger.error(error.message)
})
logger.log(
`${signifier} ${i + 1}/${files.length} body is ${
body.length
} characters`,
)
return [...(await accumulator), matter(body)]
}, Promise.resolve([])),
)

Expand All @@ -55,7 +67,7 @@ const generateReadme = async (signifier: string) => {

await fs.write(
path(`sources`, signifier, `README.md`),
format(templates.core(data), {parser: `markdown`}),
await format(templates.core(data), {parser: `markdown`}),
)
}

Expand Down Expand Up @@ -107,5 +119,13 @@ const data = {
...(await getProps(`@roots/bud`)),
name: `bud.js`,
}
const readme = format(templates.root(data), {parser: `markdown`})
await fs.write(outputPath, readme)
const body = templates.root(data)
logger.log(`repo readme.md is ${body.length} characters`)
const formatted = await format(templates.root(data), {
parser: `markdown`,
}).catch(error => logger.error(`repo readme.md`, error.message))
logger.log(formatted)
await fs
.write(outputPath, formatted)
.catch(error => logger.error(`repo readme.md`, error.message))
.finally(() => logger.log(`Wrote repo readme.md`))
4 changes: 2 additions & 2 deletions sources/@repo/markdown-kit/readme/renderer/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ handlebars.registerHelper(`dotPath`, function (context, options) {
return `${options.fn(this).replace(/\./, options.data.root.name)}`
})

handlebars.registerHelper(`raw`, function (options) {
return options.fn(this)
handlebars.registerHelper(`raw`, function (context) {
return context.fn(this)
})

export {handlebars, Handlebars}
Expand Down
2 changes: 2 additions & 0 deletions sources/@repo/yarn-plugin-bud/sources/command/docs.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class Docs extends Command {
`compiled/cli-examples/index.js`,
])
.catch(this.catch),

this.cli
.run([
`workspace`,
Expand All @@ -61,6 +62,7 @@ export class Docs extends Command {
`compiled/releases/index.js`,
])
.catch(this.catch),

this.cli
.run([
`workspace`,
Expand Down
35 changes: 22 additions & 13 deletions sources/@roots/bud-support/src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,34 @@ class Logger {
/**
* Class constructor
*/
public constructor(public options: SignaleOptions) {
if (args.log === false) this.options.disabled = true
options.logLevel = args.verbose ? `info` : args.log ? `log` : `warn`
public constructor(public options: SignaleOptions = {}) {
if (args.log === false || options?.disabled === true)
this.options.disabled = true

if (process.env) {
this.options.secrets = Object.entries(process.env)
.filter(
(
entry: [string, string | undefined],
): entry is [string, string] =>
!isUndefined(entry[1]) && entry[0].includes(`SECRET`),
)
.map(([k, v]): string => v)
this.options.secrets =
options?.secrets ??
Object.entries(process.env)
.filter(
(
entry: [string, string | undefined],
): entry is [string, string] =>
!isUndefined(entry[1]) && entry[0].includes(`SECRET`),
)
.map(([k, v]): string => v)
}

this.instance = new Signale.Signale(this.options)
this.instance.config({displayLabel: false})
if (args.verbose) this.verbose = true
if (args.log) this.enabled = true

if (args.verbose || this.options.logLevel === `info`)
this.verbose = true
if (
args.log ||
(this.options.logLevel &&
[`info`, `log`].includes(this.options.logLevel))
)
this.enabled = true
if (args.silent) this.enabled = false
}

Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-wordpress-theme-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bud.wptheme
theme
.set("typography.customFontSizes", true)
.set("typography.fontWeight", false)
.merge("spacing.units", ["px", "%", "em"])
.merge("spacing.units", ["px", "%", "em"]),
)
.enable();
```
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h1 align="center"><strong>@roots/bud</strong></h1>

<p align="center">
Frontend build tools combining the best parts of Symfony Encore and Laravel Mix
Configurable, extensible build tools for modern single and multi-page web applications
</p>

---
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@roots/bud",
"version": "0.0.0",
"description": "Frontend build tools combining the best parts of Symfony Encore and Laravel Mix",
"description": "Configurable, extensible build tools for modern single and multi-page web applications",
"engines": {
"node": ">=16.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion sources/create-bud-app/src/tasks/write.bud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default async function writeConfigTask(command: CreateCommand) {

await command.fs.write(
`bud.config.ts`,
formatSource(result, {parser: `typescript`}),
await formatSource(result, {parser: `typescript`}),
)

spinner.succeed()
Expand Down
40 changes: 20 additions & 20 deletions sources/create-bud-app/src/tasks/write.eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@ export default async function writeStylelintConfigTask(
)
}

try {
const configExtends = [`@roots/eslint-config`]
const configExtends = [`@roots/eslint-config`]

/** babel syntax */
command.support.includes(`babel`) &&
configExtends.push(`@roots/eslint-config/babel`)
/** babel syntax */
command.support.includes(`babel`) &&
configExtends.push(`@roots/eslint-config/babel`)

/** ts syntax */
;(command.support.includes(`typescript`) ||
command.support.includes(`swc`)) &&
configExtends.push(`@roots/eslint-config/typescript`)
/** ts syntax */
;(command.support.includes(`typescript`) ||
command.support.includes(`swc`)) &&
configExtends.push(`@roots/eslint-config/typescript`)

/** react syntax */
command.support.includes(`react`) &&
configExtends.push(`@roots/eslint-config/react`)
/** react syntax */
command.support.includes(`react`) &&
configExtends.push(`@roots/eslint-config/react`)

/** wordpress rules */
command.support.includes(`wordpress`) &&
configExtends.push(`@roots/eslint-config/wordpress`)
/** wordpress rules */
command.support.includes(`wordpress`) &&
configExtends.push(`@roots/eslint-config/wordpress`)

const source = await command.fs.read(
join(command.createRoot, `templates`, `eslint.config.js.hbs`),
`utf8`,
)
const source = await command.fs.read(
join(command.createRoot, `templates`, `eslint.config.js.hbs`),
`utf8`,
)

try {
const template = templateEngine.compile(source)

const result = template({extends: configExtends})

await command.fs.write(`eslint.config.js`, formatSource(result))
await command.fs.write(`eslint.config.js`, await formatSource(result))
} catch (error) {
spinner.fail()
throw error
Expand Down
2 changes: 1 addition & 1 deletion sources/create-bud-app/src/tasks/write.prettier.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function writeStylelintConfigTask(
const result = template({})

try {
await command.fs.write(`.prettierrc.cjs`, formatSource(result))
await command.fs.write(`.prettierrc.cjs`, await formatSource(result))
} catch (error) {
spinner.fail()
throw error
Expand Down
5 changes: 4 additions & 1 deletion sources/create-bud-app/src/tasks/write.stylelint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export default async function writeStylelintConfigTask(

const result = template({extends: configExtends})

await command.fs.write(`stylelint.config.cjs`, formatSource(result))
await command.fs.write(
`stylelint.config.cjs`,
await formatSource(result),
)
} catch (error) {
spinner.fail()
throw error
Expand Down
2 changes: 1 addition & 1 deletion sources/create-bud-app/src/tasks/write.tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async function writeTsConfig(command: CreateCommand) {

await command.fs.write(
`tsconfig.json`,
formatSource(source, {parser: `json`}),
await formatSource(source, {parser: `json`}),
)
} catch (error) {
spinner.fail()
Expand Down
4 changes: 2 additions & 2 deletions sources/create-bud-app/src/utilities/formatSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type {Options} from 'prettier'

import {format} from 'prettier'

export default (code: string, options: Partial<Options> = {}) => {
return format(code, {
export default async (code: string, options: Partial<Options> = {}) => {
return await format(code, {
bracketSpacing: false,
parser: `babel`,
printWidth: 75,
Expand Down

0 comments on commit eb34305

Please sign in to comment.