-
Notifications
You must be signed in to change notification settings - Fork 0
/
replaceScripts.js
42 lines (34 loc) · 1.15 KB
/
replaceScripts.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
32
33
34
35
36
37
38
39
40
41
42
const replace = require("replace-in-file")
const pkg = require("./package.json")
// README
const reVersion = new RegExp("(### version | )([0-9]+)(?:.([0-9]+))(?:.([0-9]+))")
const newVersion = " " + pkg.version
const reUpdate = new RegExp("(Updated | )([0-9]{4}-[0-9]{2}-[0-9]{2})")
const newUpdate = " " + pkg.date
const reCopyRightDate = new RegExp("(Copyright )([0-9]{4})")
const newCopyRightDate = "Copyright " + pkg.copyright
const readme = {
files: "./README.md",
from: [reVersion, reUpdate, reCopyRightDate],
to: [newVersion, newUpdate, newCopyRightDate],
}
// LICENCE
const reCopyDate = new RegExp("(Copyright \\(c\\) )([0-9]{4})")
const newCopyDate = "Copyright (c) " + pkg.copyright
const license = {
files: ["./LICENSE", "./public/LICENSE"],
from: [reCopyDate],
to: [newCopyDate],
}
;(async () => {
try {
const readmeResults = await replace(readme)
const licenseResults = await replace(license)
const results = { readmeResults, licenseResults }
console.log("Replacement results:", results)
} catch (error) {
console.error("Error occurred:", error)
}
})()
// DOCUMENTATION
// https://www.emgoto.com/nodejs-write-file/