|
8 | 8 | // Optionally, use `--restore` to restore default values |
9 | 9 |
|
10 | 10 | import fs from "fs"; |
| 11 | +import path from "path"; |
11 | 12 | import readline from "readline"; |
| 13 | +import { fileURLToPath } from "url"; |
12 | 14 |
|
| 15 | +const __filename = fileURLToPath(import.meta.url); |
| 16 | +const __dirname = path.dirname(__filename); |
| 17 | + |
| 18 | +const repoRoot = path.resolve(__dirname, ".."); |
13 | 19 | // List of files to be updated |
14 | 20 | const filesToUpdate = [ |
15 | 21 | // ui-library-filesharing-chat-composite |
16 | | - "../ui-library-filesharing-chat-composite/api/local.settings.json", |
17 | | - "../ui-library-filesharing-chat-composite/app/src/App.tsx", |
| 22 | + "ui-library-filesharing-chat-composite/api/local.settings.json", |
| 23 | + "ui-library-filesharing-chat-composite/app/src/App.tsx", |
18 | 24 |
|
19 | 25 | // ui-library-starting-with-chat-stateful |
20 | | - "../ui-library-starting-with-chat-stateful/src/App.tsx", |
| 26 | + "ui-library-starting-with-chat-stateful/src/App.tsx", |
21 | 27 |
|
22 | 28 | // ui-library-filesharing-ui-components |
23 | | - "../ui-library-filesharing-ui-components/api/local.settings.json", |
24 | | - "../ui-library-filesharing-ui-components/app/src/App.tsx", |
| 29 | + "ui-library-filesharing-ui-components/api/local.settings.json", |
| 30 | + "ui-library-filesharing-ui-components/app/src/App.tsx", |
25 | 31 |
|
26 | 32 | // ui-library-quickstart-teams-interop-meeting-chat |
27 | | - "../ui-library-quickstart-teams-interop-meeting-chat/src/App.tsx", |
| 33 | + "ui-library-quickstart-teams-interop-meeting-chat/src/App.tsx", |
28 | 34 |
|
29 | 35 | // ui-library-quickstart-composites-with-dependency-isolation |
30 | | - "../ui-library-quickstart-composites-with-dependency-isolation/src/App.tsx", |
| 36 | + "ui-library-quickstart-composites-with-dependency-isolation/src/App.tsx", |
31 | 37 |
|
32 | 38 | // Add more file paths as needed |
33 | 39 | ]; |
@@ -109,9 +115,11 @@ const defaultValues = { |
109 | 115 |
|
110 | 116 | function updateFiles(files, replacements) { |
111 | 117 | files.forEach((filePath) => { |
112 | | - fs.readFile(filePath, "utf8", (err, data) => { |
| 118 | + // Path to the file from the root of the repository |
| 119 | + const fullFilePath = path.join(repoRoot, filePath); |
| 120 | + fs.readFile(fullFilePath, "utf8", (err, data) => { |
113 | 121 | if (err) { |
114 | | - console.error(`Error reading file ${filePath}:`, err); |
| 122 | + console.error(`Error reading file ${fullFilePath}:`, err); |
115 | 123 | return; |
116 | 124 | } |
117 | 125 | // delete the next line after the update if it's multiLine string |
@@ -142,11 +150,11 @@ function updateFiles(files, replacements) { |
142 | 150 | .filter((line) => line !== "[TO BE REMOVED]") |
143 | 151 | .join("\n"); |
144 | 152 |
|
145 | | - fs.writeFile(filePath, updatedContent, "utf8", (err) => { |
| 153 | + fs.writeFile(fullFilePath, updatedContent, "utf8", (err) => { |
146 | 154 | if (err) { |
147 | | - console.error(`Error writing file ${filePath}:`, err); |
| 155 | + console.error(`Error writing file ${fullFilePath}:`, err); |
148 | 156 | } else { |
149 | | - console.log(`File ${filePath} updated successfully.`); |
| 157 | + console.log(`File ${fullFilePath} updated successfully.`); |
150 | 158 | } |
151 | 159 | }); |
152 | 160 | }); |
|
0 commit comments