From d13c16357bcfb8675e05f7522a1d7c467aa316f8 Mon Sep 17 00:00:00 2001 From: Kevin Viglucci Date: Tue, 5 Mar 2024 19:13:15 -0600 Subject: [PATCH] fix: build script supports Windows (#276) * chore: update gitHead in package.json Signed-off-by: Kevin Viglucci * fix: build script supports windows Signed-off-by: Kevin Viglucci --------- Signed-off-by: Kevin Viglucci --- scripts/build.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 8c103fef..9664b2d6 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -35,7 +35,9 @@ const BUILD_DIR = 'build'; const SRC_DIR = 'src'; const ROOT_DIR = path.resolve(__dirname, '..'); const PACKAGES_DIR = path.resolve(ROOT_DIR, 'packages'); -const JS_FILES_PATTERN = path.resolve(PACKAGES_DIR, '**/*.js'); +const JS_FILES_PATTERN = path.resolve(PACKAGES_DIR, '**/*.js') + .split(path.sep) + .join(path.posix.sep); const IGNORE_PATTERN = '**/__(mocks|snapshots|tests)__/**'; const FLOW_EXTENSION = '.flow'; @@ -103,7 +105,7 @@ function buildPackage(pkg) { const pattern = path.resolve(srcDir, '**/*'); const files = glob.sync(pattern, {nodir: true}); - files.forEach((file) => buildFile(file, true)); + files.forEach((file) => buildFile(file, false)); process.stdout.write(`${chalk.green('=>')} ${path.basename(pkg)} (npm)\n`); } @@ -115,14 +117,20 @@ function buildFile(file, silent) { const destPath = path.resolve(packageBuildPath, relativeToSrcPath); mkdirp.sync(path.dirname(destPath)); - if (micromatch.isMatch(file, IGNORE_PATTERN)) { + + const isIgnored = micromatch.isMatch(file, IGNORE_PATTERN); + // normalize paths to using posix format + const normalizedPath = file.split(path.sep).join(path.posix.sep); + const isJS = micromatch.isMatch(normalizedPath, JS_FILES_PATTERN); + + if (isIgnored) { silent || process.stdout.write( chalk.dim(' \u2022 ') + path.relative(PACKAGES_DIR, file) + ' (ignore)\n' ); - } else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) { + } else if (isJS === false) { fs.createReadStream(file).pipe(fs.createWriteStream(destPath)); silent || process.stdout.write(