-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dworthen/feature/windows
Add support for windows
- Loading branch information
Showing
9 changed files
with
728 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/ | ||
node_modules/ | ||
bin/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
...require('gts/.prettierrc.json') | ||
} | ||
...require('gts/.prettierrc.json'), | ||
bracketSpacing: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* This file is a pass-through for the actual just binary. It exists because for two reasons: | ||
* | ||
* - Yarn does not allow references to anything other than .js files in the "bin" field in package.json. | ||
* - Windows does not allow executing binaries that don't end in .exe, and we need the package.json "bin" field to | ||
* point to the same file on all platforms. | ||
*/ | ||
|
||
import child_process from 'node:child_process'; | ||
import path from 'node:path'; | ||
import process from 'node:process'; | ||
import url from "url"; | ||
|
||
const ext = process.platform === 'win32' ? '.exe' : ''; | ||
|
||
const __filename = url.fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
child_process.execFileSync( | ||
path.resolve(__dirname, 'just' + ext), | ||
process.argv.slice(2), | ||
{ stdio: 'inherit' } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,74 @@ | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
const child_process = require('child_process'); | ||
#!/usr/bin/env node | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import child_process from 'node:child_process'; | ||
import fetch from 'node-fetch'; | ||
import extract from 'extract-zip'; | ||
import url from "url"; | ||
|
||
const url = 'https://just.systems/install.sh'; | ||
const __filename = url.fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
try { | ||
fs.unlinkSync('./bin/just'); | ||
} catch (err) { | ||
// ignore | ||
} | ||
const binDir = path.resolve(__dirname, 'bin'); | ||
|
||
async function installNix() { | ||
const justInstallShScriptUrl = 'https://just.systems/install.sh'; | ||
|
||
const IS_YARN = process.env.npm_execpath.includes('yarn'); | ||
const res = await fetch(justInstallShScriptUrl); | ||
|
||
https.get(url, res => { | ||
res.setEncoding('utf8'); | ||
let body = ''; | ||
res.on('data', data => { | ||
body += data; | ||
const buffer = await res.arrayBuffer(); | ||
fs.writeFileSync('./install.sh', new DataView(buffer)); | ||
fs.chmodSync('./install.sh', '755'); | ||
|
||
child_process.execFileSync('./install.sh', ['-f', '--to', './bin'], { | ||
stdio: 'inherit', | ||
}); | ||
res.on('end', () => { | ||
fs.writeFileSync('./install.sh', body); | ||
fs.chmodSync('./install.sh', '755'); | ||
|
||
child_process.execFileSync('./install.sh', ['--to', './bin'], { | ||
stdio: 'inherit', | ||
}); | ||
fs.rmSync('./install.sh'); | ||
} | ||
|
||
if (IS_YARN) { | ||
// move bin/just to bin/justbin | ||
fs.renameSync('./bin/just', './bin/justbin'); | ||
async function installWindows() { | ||
const baseDownloadUrl = 'https://github.com/casey/just/releases/latest'; | ||
const windowsZipName = 'just-{TAG}-x86_64-pc-windows-msvc.zip'; | ||
|
||
// copy just-yarn.js to /bin/just | ||
fs.copyFileSync('./just-yarn.js', './bin/just'); | ||
// Get asset url | ||
// Redirects to the latest release tag. | ||
// e.g., https://github.com/casey/just/releases/tag/1.13.0 | ||
const assetUrlRes = await fetch(baseDownloadUrl, { redirect: 'manual' }); | ||
const tag = assetUrlRes.headers.get('location').split('/').pop(); | ||
const assetName = windowsZipName.replace('{TAG}', tag); | ||
const assetUrl = `${baseDownloadUrl}/download/${assetName}`; | ||
|
||
// chmod +x bin/just | ||
fs.chmodSync('./bin/just', '755'); | ||
} | ||
}); | ||
}); | ||
// Create ./extract directory | ||
const extractPath = path.resolve(__dirname, 'extract'); | ||
fs.rmSync(extractPath, { force: true, recursive: true }); | ||
fs.mkdirSync(extractPath); | ||
|
||
// Download archive to ./extract/[assetName].zip | ||
const archivePath = path.resolve(extractPath, path.basename(assetUrl)); | ||
const downloadRes = await fetch(assetUrl, { maxRedirections: 5 }); | ||
const archiveBuffer = await downloadRes.arrayBuffer(); | ||
fs.writeFileSync(archivePath, new DataView(archiveBuffer)); | ||
|
||
// Unpack archive into ./extract | ||
await extract(archivePath, { dir: extractPath }); | ||
|
||
// Move ./extract/just.exe to ./bin/just.exe | ||
fs.copyFileSync( | ||
path.resolve(extractPath, 'just.exe'), | ||
path.resolve(binDir, 'just.exe') | ||
); | ||
|
||
// Delete ./extract | ||
fs.rmSync(extractPath, { force: true, recursive: true }); | ||
} | ||
|
||
async function install() { | ||
if (process.platform === 'win32') { | ||
await installWindows(); | ||
} else { | ||
await installNix(); | ||
} | ||
} | ||
|
||
void install(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.