Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
create valid bat file for windows
Browse files Browse the repository at this point in the history
use .bat extension all the time because on windows we need the extension to be bat and on other platforms the extension does not matter because they use a shebang
  • Loading branch information
JakeChampion committed Mar 10, 2020
1 parent 62f75b4 commit 2d3e3b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Native Sass binaries for your platform",
"license": "MIT",
"repository": "Financial-times/sass",
"bin": "sass",
"bin": "sass.bat",
"optionalDependencies": {
"@financial-times/sass-linux-ia32": "*",
"@financial-times/sass-linux-x64": "*",
Expand Down
45 changes: 37 additions & 8 deletions postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,46 @@ if (process.platform === "win32" && process.arch === "x64") {
const platformSpecificSassPath = path.join(path.dirname(platformSpecificPackagePath), 'dart-sass')

// We need to remove the sass entrypoint file if it exists already.
if (fs.existsSync(path.join(__dirname, './sass'))) {
fs.unlinkSync(path.join(__dirname, './sass'));
if (fs.existsSync(path.join(__dirname, './sass.bat'))) {
fs.unlinkSync(path.join(__dirname, './sass.bat'));
}

// Create our own sass entrypoint which uses absolute paths to the dartvm and snapshot.
// This will ensure it works when symlinked to, which the entrypoint file in dart-sass
// does not support on macos.
fs.writeFileSync(path.join(__dirname, 'sass'), `
if (process.platform === "win32") {
fs.writeFileSync(
path.join(__dirname, "sass.bat"),
`
@echo off
REM This script drives the standalone dart-sass package, which bundles together a
REM Dart executable and a snapshot of dart-sass.
set SCRIPTPATH=%~dp0
set arguments=%*
"${path.join(platformSpecificSassPath, "/src/dart.exe")}" "${path.join(
platformSpecificSassPath,
"/src/sass.dart.snapshot"
)}" %arguments%
`,
{
encoding: "utf-8",
mode: 0o777
}
);
} else {
fs.writeFileSync(
path.join(__dirname, "sass.bat"),
`
#!/bin/sh
exec "${path.join(platformSpecificSassPath, '/src/dart')}" "${path.join(platformSpecificSassPath, '/src/sass.dart.snapshot')}" "$@"
`, {
encoding: 'utf-8',
mode: 0o777
})
exec "${path.join(platformSpecificSassPath, "/src/dart")}" "${path.join(
platformSpecificSassPath,
"/src/sass.dart.snapshot"
)}" "$@"
`,
{
encoding: "utf-8",
mode: 0o777
}
);
}
File renamed without changes.

0 comments on commit 2d3e3b9

Please sign in to comment.