-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d68058c
Showing
22 changed files
with
1,247 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Greatly inspired from | ||
# https://github.com/paskausks/rust-bin-github-workflows/blob/894a4f2debade42f8d7b5b95f493eaa33fdeb81b/.github/workflows/release.yml | ||
|
||
name: Create release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
env: | ||
RELEASE_BIN: esbuild-config | ||
RELEASE_ADDS: README.md LICENSE | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
build: [linux, macos, windows] | ||
include: | ||
- build: linux | ||
os: ubuntu-latest | ||
rust: stable | ||
- build: macos | ||
os: macos-latest | ||
rust: stable | ||
- build: windows | ||
os: windows-latest | ||
rust: stable | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install Rust (rustup) | ||
run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} | ||
shell: bash | ||
|
||
- name: Build | ||
run: cargo build --verbose --release | ||
|
||
- name: Create artifact directory | ||
run: mkdir artifacts | ||
|
||
- name: Create archive for Linux | ||
run: 7z a -ttar -so -an ./target/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_ADDS }} | 7z a -si ./artifacts/${{ env.RELEASE_BIN }}-linux-x86_64.tar.gz | ||
if: matrix.os == 'ubuntu-latest' | ||
|
||
- name: Create archive for Windows | ||
run: | | ||
7z a ./tmp/${{ env.RELEASE_BIN }}-windows-x86_64.tar ./target/release/${{ env.RELEASE_BIN }}.exe ${{ env.RELEASE_ADDS }} | ||
7z a ./artifacts/${{ env.RELEASE_BIN }}-windows-x86_64.tar.gz ./tmp/${{ env.RELEASE_BIN }}-windows-x86_64.tar | ||
if: matrix.os == 'windows-latest' | ||
|
||
- name: Install p7zip | ||
# 7Zip not available on MacOS, install p7zip via homebrew. | ||
run: brew install p7zip | ||
if: matrix.os == 'macos-latest' | ||
|
||
- name: Create archive for MacOS | ||
run: 7z a -ttar -so -an ./target/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_ADDS }} | 7z a -si ./artifacts/${{ env.RELEASE_BIN }}-macos-x86_64.tar.gz | ||
if: matrix.os == 'macos-latest' | ||
|
||
# This will double-zip | ||
# See - https://github.com/actions/upload-artifact/issues/39 | ||
- uses: actions/upload-artifact@v1 | ||
name: Upload archive | ||
with: | ||
name: ${{ runner.os }} | ||
path: artifacts/ |
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,8 @@ | ||
/target | ||
**/*.rs.bk | ||
node_modules/ | ||
yarn.lock | ||
|
||
/npm/esbuild-config-linux-64/bin/esbuild-config | ||
/npm/esbuild-config-darwin-64/bin/esbuild-config | ||
/npm/esbuild-config-windows-64/esbuild-config.exe |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 @@ | ||
[package] | ||
name = "esbuild-config" | ||
version = "0.1.0" | ||
edition = "2018" | ||
description = "A short description of my package" | ||
authors = ["Pierre Bertet <hello@pierre.world>"] | ||
repository = "https://github.com/bpierre/esbuild-config" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
json = "0.12.4" | ||
snailquote = "0.3.0" | ||
|
||
[[bin]] | ||
name = "esbuild-config" | ||
path = "src/main.rs" | ||
test = false | ||
|
||
[lib] | ||
name = "esbuild_config_lib" | ||
path = "src/lib/mod.rs" | ||
doctest = false |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Pierre Bertet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,110 @@ | ||
# esbuild-config | ||
|
||
Config files for [esbuild](https://github.com/evanw/esbuild). | ||
|
||
## Why? | ||
|
||
esbuild is an incredible tool, that is [exclusively using command line parameters](https://github.com/evanw/esbuild/issues/39) as a configuration syntax. Some people prefer configuration files, so IÂ thought it could be a good idea to provide a solution for this. It is also for me a pretext to use Rust while learning it :) | ||
|
||
## Usage | ||
|
||
The esbuild-config command outputs a list of parameters based on a `esbuild.config.json` file, that can get passed to esbuild directly: | ||
|
||
```console | ||
esbuild $(esbuild-config) | ||
``` | ||
|
||
It detects the presence of `esbuild.config.json` in the current directory, or the project root (using the presence of a `package.json` file). Any file can also get provided as a parameter: | ||
|
||
```console | ||
esbuild $(esbuild-config ./my-conf.json) | ||
``` | ||
|
||
## Install | ||
|
||
You have different options to install esbuild-config. | ||
|
||
### npm | ||
|
||
Install globally with npm using the following command: | ||
|
||
```console | ||
npm install --global esbuild-config | ||
``` | ||
|
||
You can also add it to your project: | ||
|
||
```console | ||
npm install --save-dev esbuild-config | ||
``` | ||
|
||
### Cargo | ||
|
||
Install it with [Cargo](https://github.com/rust-lang/cargo) using the following command: | ||
|
||
```console | ||
cargo install esbuild-config | ||
``` | ||
|
||
### Binaries | ||
|
||
You can download the precompiled binaries [from the release page](https://github.com/bpierre/esbuild-config/releases). | ||
|
||
### From source | ||
|
||
To clone the repository and build esbuild-config, run these commands ([after having installed Rust](https://www.rust-lang.org/tools/install)): | ||
|
||
```console | ||
git clone git@github.com:bpierre/esbuild-config.git | ||
cd esbuild-config | ||
cargo build --release | ||
``` | ||
|
||
The compiled binary is at `target/release/esbuild-config`. | ||
|
||
## Syntax | ||
|
||
esbuild-config doesn’t do any validation on the configuration values: it only converts JSON types into arguments that are compatible with the format esbuild uses for its arguments. This makes it independent from esbuild versions, assuming the format doesn’t change. | ||
|
||
The only exception to this is the `entry` field, which gets converted into a list of file names (when an array is provided) or a single file name (when a string is provided). | ||
|
||
This is how JSON types get converted: | ||
|
||
```json | ||
{ | ||
"entry": "./index.js", | ||
"outfile": "./bundle.js", | ||
"external": ["react", "react-dom"], | ||
"loader": { ".js": "jsx", ".png": "base64" }, | ||
"minify": true | ||
} | ||
``` | ||
|
||
Output: | ||
|
||
```console | ||
--outfile=./bundle.js --minify --external:react --external:react-dom --loader:.js=jsx --loader:.png=base64 ./index.js | ||
``` | ||
|
||
Notice how the entry, `./index.js`, has been moved to the end. esbuild-config also takes care of escaping the parameters as needed (e.g. by adding quotes). | ||
|
||
## Contribute | ||
|
||
```console | ||
# Run the app | ||
cargo run | ||
|
||
# Run the tests | ||
cargo test | ||
|
||
# Generate the code coverage report | ||
cargo tarpaulin -o Html | ||
``` | ||
|
||
## Special thanks | ||
|
||
[esbuild](https://github.com/evanw/esbuild) and [its author](https://github.com/evanw) obviously, not only for esbuild itself but also for its approach to [install a platform-specific binary through npm](https://github.com/evanw/esbuild/blob/1336fbcf9bcca2f2708f5f575770f13a8440bde3/lib/install.ts), that esbuild-config is also using. | ||
|
||
## License | ||
|
||
[MIT](./LICENSE) |
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,3 @@ | ||
# esbuild-config | ||
|
||
This is the macOS 64-bit binary for esbuild-config. See https://github.com/bpierre/esbuild-config for details. |
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,11 @@ | ||
{ | ||
"name": "esbuild-config-darwin-64", | ||
"description": "The macOS 64-bit binary for esbuild-config.", | ||
"version": "0.1.0", | ||
"repository": "https://github.com/bpierre/esbuild-config", | ||
"author": "Pierre Bertet <hello@pierre.world>", | ||
"license": "MIT", | ||
"os": ["darwin"], | ||
"cpu": ["x64"], | ||
"directories": { "bin": "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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# esbuild-config | ||
|
||
This is the Linux 64-bit binary for esbuild-config. See https://github.com/bpierre/esbuild-config for details. |
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,11 @@ | ||
{ | ||
"name": "esbuild-config-linux-64", | ||
"description": "The Linux 64-bit binary for esbuild-config.", | ||
"version": "0.1.0", | ||
"repository": "https://github.com/bpierre/esbuild-config", | ||
"author": "Pierre Bertet <hello@pierre.world>", | ||
"license": "MIT", | ||
"os": ["linux"], | ||
"cpu": ["x64"], | ||
"directories": { "bin": "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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# esbuild-config | ||
|
||
This is the Windows 64-bit binary for esbuild-config. See https://github.com/bpierre/esbuild-config for details. |
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,17 @@ | ||
#!/usr/bin/env node | ||
|
||
// From esbuild: | ||
// https://github.com/evanw/esbuild/blob/1336fbcf9bcca2f2708f5f575770f13a8440bde3/npm/esbuild-windows-64/bin/esbuild | ||
|
||
// Unfortunately even though npm shims "bin" commands on Windows with auto- | ||
// generated forwarding scripts, it doesn't strip the ".exe" from the file name | ||
// first. So it's possible to publish executables via npm on all platforms | ||
// except Windows. I consider this a npm bug. | ||
// | ||
// My workaround is to add this script as another layer of indirection. It'll | ||
// be slower because node has to boot up just to shell out to the actual exe, | ||
// but Windows is somewhat of a second-class platform to npm so it's the best | ||
// I can do I think. | ||
const esbuild_exe = require.resolve('esbuild-windows-64/esbuild-config.exe'); | ||
const child_process = require('child_process'); | ||
child_process.spawnSync(esbuild_exe, 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "esbuild-config-windows-64", | ||
"description": "The Windows 64-bit binary for esbuild-config.", | ||
"version": "0.1.0", | ||
"repository": "https://github.com/bpierre/esbuild-config", | ||
"author": "Pierre Bertet <hello@pierre.world>", | ||
"license": "MIT", | ||
"os": ["win32"], | ||
"cpu": ["x64"], | ||
"directories": { "bin": "bin" } | ||
} |
Oops, something went wrong.