summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-06-01 12:23:41 -0300
committerSebastian <sebasjm@gmail.com>2023-06-01 12:24:07 -0300
commite9bdf7f312cff5d49b6a50e3722de38bb7238573 (patch)
treead829ed828530cc1f8d5f72f06af55a68f78b785
parentb916e53c68fc4e31fc7d945c450aaf9b0aeefc50 (diff)
downloadwallet-core-e9bdf7f312cff5d49b6a50e3722de38bb7238573.tar.gz
wallet-core-e9bdf7f312cff5d49b6a50e3722de38bb7238573.tar.bz2
wallet-core-e9bdf7f312cff5d49b6a50e3722de38bb7238573.zip
assets should have base directory to copy tree
-rwxr-xr-xpackages/taler-wallet-webextension/build.mjs2
-rw-r--r--packages/web-util/src/index.build.ts44
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;