gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 07/07: assets should have base directory to copy tre


From: gnunet
Subject: [taler-wallet-core] 07/07: assets should have base directory to copy tree
Date: Thu, 01 Jun 2023 17:24:51 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

commit e9bdf7f312cff5d49b6a50e3722de38bb7238573
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Jun 1 12:23:41 2023 -0300

    assets should have base directory to copy tree
---
 packages/taler-wallet-webextension/build.mjs |  2 +-
 packages/web-util/src/index.build.ts         | 44 +++++++++++++++++++---------
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/packages/taler-wallet-webextension/build.mjs 
b/packages/taler-wallet-webextension/build.mjs
index ee1bca7a1..d972ee610 100755
--- a/packages/taler-wallet-webextension/build.mjs
+++ b/packages/taler-wallet-webextension/build.mjs
@@ -15,8 +15,8 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
+import { build } from "@gnu-taler/web-util/build";
 import linaria from "@linaria/esbuild";
-import { build, getFilesInDirectory } from "@gnu-taler/web-util/build";
 
 await build({
   type: "production",
diff --git a/packages/web-util/src/index.build.ts 
b/packages/web-util/src/index.build.ts
index ad31afb5c..6ee1be20a 100644
--- a/packages/web-util/src/index.build.ts
+++ b/packages/web-util/src/index.build.ts
@@ -10,12 +10,17 @@ import postcssrc from "postcss-load-config";
 // the project is being built
 const BASE = process.cwd();
 
-export function getFilesInDirectory(
-  startPath: string,
-  regex?: RegExp,
-): string[] {
+type Assets = {
+  base: string;
+  files: string[];
+};
+
+export function getFilesInDirectory(startPath: string, regex?: RegExp): Assets 
{
   if (!fs.existsSync(startPath)) {
-    return [];
+    return {
+      base: startPath,
+      files: [],
+    };
   }
   const files = fs.readdirSync(startPath);
   const result = files
@@ -24,7 +29,7 @@ export function getFilesInDirectory(
 
       const stat = fs.lstatSync(filename);
       if (stat.isDirectory()) {
-        return getFilesInDirectory(filename, regex);
+        return getFilesInDirectory(filename, regex).files;
       }
       if (!regex || regex.test(filename)) {
         return [filename];
@@ -33,7 +38,10 @@ export function getFilesInDirectory(
     })
     .filter((x) => !!x);
 
-  return result;
+  return {
+    base: startPath,
+    files: result,
+  };
 }
 
 let GIT_ROOT = BASE;
@@ -66,22 +74,30 @@ function git_hash() {
 }
 
 // FIXME: Put this into some helper library.
-function copyFilesPlugin(files: Array<string>) {
+function copyFilesPlugin(assets: Assets | Assets[]) {
   return {
     name: "copy-files",
     setup(build: PluginBuild) {
-      if (!files || !files.length) {
+      if (!assets || (assets instanceof Array && !assets.length)) {
         return;
       }
+      const list = assets instanceof Array ? assets : [assets];
+
       const outDir = build.initialOptions.outdir;
       if (outDir === undefined) {
         throw Error("esbuild build options does not specify outdir");
       }
       build.onEnd(() => {
-        for (const file of files) {
-          const name = path.parse(file).base;
-          fs.copyFileSync(file, path.join(outDir, name));
-        }
+        list.forEach((as) => {
+          for (const file of as.files) {
+            const destination = path.join(outDir, path.relative(as.base, 
file));
+            const dirname = path.dirname(destination);
+            if (!fs.existsSync(dirname)) {
+              fs.mkdirSync(dirname, { recursive: true });
+            }
+            fs.copyFileSync(file, destination);
+          }
+        });
       });
     },
   };
@@ -175,7 +191,7 @@ const defaultEsBuildConfig: esbuild.BuildOptions = {
 export interface BuildParams {
   type: "development" | "test" | "production";
   source: {
-    assets: string[];
+    assets: Assets | Assets[];
     js: string[];
   };
   public?: string;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]