Skip to content

Commit d13c163

Browse files
authored
fix: build script supports Windows (#276)
* chore: update gitHead in package.json Signed-off-by: Kevin Viglucci <kviglucci@gmail.com> * fix: build script supports windows Signed-off-by: Kevin Viglucci <kviglucci@gmail.com> --------- Signed-off-by: Kevin Viglucci <kviglucci@gmail.com>
1 parent 1dd3eb2 commit d13c163

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

scripts/build.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ const BUILD_DIR = 'build';
3535
const SRC_DIR = 'src';
3636
const ROOT_DIR = path.resolve(__dirname, '..');
3737
const PACKAGES_DIR = path.resolve(ROOT_DIR, 'packages');
38-
const JS_FILES_PATTERN = path.resolve(PACKAGES_DIR, '**/*.js');
38+
const JS_FILES_PATTERN = path.resolve(PACKAGES_DIR, '**/*.js')
39+
.split(path.sep)
40+
.join(path.posix.sep);
3941
const IGNORE_PATTERN = '**/__(mocks|snapshots|tests)__/**';
4042
const FLOW_EXTENSION = '.flow';
4143

@@ -103,7 +105,7 @@ function buildPackage(pkg) {
103105
const pattern = path.resolve(srcDir, '**/*');
104106
const files = glob.sync(pattern, {nodir: true});
105107

106-
files.forEach((file) => buildFile(file, true));
108+
files.forEach((file) => buildFile(file, false));
107109
process.stdout.write(`${chalk.green('=>')} ${path.basename(pkg)} (npm)\n`);
108110
}
109111

@@ -115,14 +117,20 @@ function buildFile(file, silent) {
115117
const destPath = path.resolve(packageBuildPath, relativeToSrcPath);
116118

117119
mkdirp.sync(path.dirname(destPath));
118-
if (micromatch.isMatch(file, IGNORE_PATTERN)) {
120+
121+
const isIgnored = micromatch.isMatch(file, IGNORE_PATTERN);
122+
// normalize paths to using posix format
123+
const normalizedPath = file.split(path.sep).join(path.posix.sep);
124+
const isJS = micromatch.isMatch(normalizedPath, JS_FILES_PATTERN);
125+
126+
if (isIgnored) {
119127
silent ||
120128
process.stdout.write(
121129
chalk.dim(' \u2022 ') +
122130
path.relative(PACKAGES_DIR, file) +
123131
' (ignore)\n'
124132
);
125-
} else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
133+
} else if (isJS === false) {
126134
fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
127135
silent ||
128136
process.stdout.write(

0 commit comments

Comments
 (0)