File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 11/* eslint-env node */
22// eslint-disable console
3- import { promises } from "fs" ;
3+ import { promises , existsSync } from "fs" ;
44import path from "path" ;
55
66import ignored from "./ignore.js" ;
@@ -88,6 +88,34 @@ const main = async (cwd, level = 0) => {
8888
8989 const readmePath = path . join ( cwd , "README.md" ) ;
9090
91+ if ( existsSync ( readmePath ) ) {
92+ const contents = await readFileAsync ( readmePath , "utf-8" ) ;
93+
94+ const prefix = "<!-- DOCS:START - Do not remove or modify this section -->" ;
95+ const postfix = "<!-- DOCS:END -->" ;
96+
97+ const prefixIndex = contents . indexOf ( prefix ) ;
98+ const postfixIndex = contents . indexOf ( postfix ) ;
99+
100+ if ( prefixIndex !== - 1 && postfixIndex !== - 1 ) {
101+ const before = contents . substr ( 0 , prefixIndex ) ;
102+ const after = contents . substr ( postfixIndex + postfix . length ) ;
103+
104+ const padding = "" . padEnd ( 2 , "#" ) ;
105+
106+ const withAdjustedLevels = composedReadme . replace (
107+ / ( # + ) / gi,
108+ `${ padding } $1`
109+ ) ;
110+
111+ const replaced = `${ before } ${ prefix } \n${ withAdjustedLevels . trim ( ) } \n${ postfix } ${ after } ` ;
112+
113+ await writeFileAsync ( readmePath , replaced , "utf-8" ) ;
114+
115+ return ;
116+ }
117+ }
118+
91119 await writeFileAsync ( readmePath , composedReadme , "utf-8" ) ;
92120} ;
93121
You can’t perform that action at this time.
0 commit comments