Files
docx-js/scripts/types-absolute-fixer.ts

19 lines
521 B
TypeScript
Raw Normal View History

2019-01-15 00:23:01 +00:00
import * as glob from "glob";
2021-09-28 19:56:29 +01:00
import { replaceInFile } from "replace-in-file";
2018-02-02 01:56:08 +00:00
const files = glob.sync("build/**/*.d.ts");
for (const file of files) {
2021-09-28 19:56:29 +01:00
replaceInFile({
2018-02-02 01:56:08 +00:00
files: file,
from: /"file[a-z/-]*"/gi,
to: (match) => {
const matchSlug = match.replace(/['"]+/g, "").trim();
const levelCount = file.split("/").length - 2;
2021-09-28 19:56:29 +01:00
const backLevels = Array(levelCount).fill("../").join("");
2018-02-02 01:56:08 +00:00
2019-01-15 00:23:01 +00:00
return `"${backLevels}${matchSlug}"`;
2018-02-02 01:56:08 +00:00
},
});
}