forked from open-wc/open-wc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert-header.js
executable file
·31 lines (25 loc) · 1.4 KB
/
insert-header.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
/* eslint-disable consistent-return, no-console */
const fs = require('fs');
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
const filePath = `${process.cwd()}/README.md`;
const findPattern = escapeRegExp("[//]: # 'AUTO INSERT HEADER PREPUBLISH'");
const text = `
> Part of [Open Web Components](https://github.com/open-wc/open-wc/): guides, tools and libraries for modern web development and web components
[](https://circleci.com/gh/open-wc/open-wc)
[](https://www.browserstack.com/automate/public-build/M2UrSFVRang2OWNuZXlWSlhVc3FUVlJtTDkxMnp6eGFDb2pNakl4bGxnbz0tLUE5RjhCU0NUT1ZWa0NuQ3MySFFWWnc9PQ==--86f7fac07cdbd01dd2b26ae84dc6c8ca49e45b50)
[](https://renovatebot.com/)
`.trim();
fs.readFile(filePath, 'utf8', (readError, data) => {
if (readError) {
return console.log(readError);
}
const result = data.replace(new RegExp(findPattern), text);
fs.writeFile(filePath, result, 'utf8', writeError => {
if (writeError) {
return console.log(writeError);
}
});
});