@grame/faustwasm 0.0.48 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fileutils.js CHANGED
@@ -11,8 +11,8 @@ const __filename = fileURLToPath(import.meta.url);
11
11
  */
12
12
 
13
13
  /**
14
- * @param {string} src
15
- * @param {string} dest
14
+ * @param {string} src - The source path.
15
+ * @param {string} dest - The destination path.
16
16
  */
17
17
  const cpSync = (src, dest) => {
18
18
  if (!fs.existsSync(src)) return;
@@ -25,7 +25,34 @@ const cpSync = (src, dest) => {
25
25
  };
26
26
 
27
27
  /**
28
- * @param {string} dir
28
+ * @param {string} src - The source path of the file to modify and copy.
29
+ * @param {string} dest - The destination path.
30
+ * @param {string} find - The string to find.
31
+ * @param {string} replace - The string to replace.
32
+ */
33
+ const cpSyncModify = (src, dest, find, replace) => {
34
+ fs.readFile(src, 'utf8', function (err, data) {
35
+ if (err) {
36
+ console.error(err);
37
+ return;
38
+ }
39
+
40
+ // Create a regular expression from the 'find' string
41
+ const regex = new RegExp(find, 'g');
42
+
43
+ // Replace 'find' with 'replace'
44
+ let modifiedData = data.replace(regex, replace);
45
+
46
+ // Write the modified data to a new file
47
+ fs.writeFile(dest, modifiedData, 'utf8', function (err) {
48
+ if (err) {
49
+ console.error(err);
50
+ }
51
+ });
52
+ });
53
+ }
54
+ /**
55
+ * @param {string} dir - The directory to remove.
29
56
  */
30
57
  const rmSync = (dir) => {
31
58
  if (!fs.existsSync(dir)) return;
@@ -37,4 +64,4 @@ const rmSync = (dir) => {
37
64
  }
38
65
  };
39
66
 
40
- export { cpSync, rmSync };
67
+ export { cpSync, cpSyncModify, rmSync };