-
Notifications
You must be signed in to change notification settings - Fork 0
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
undefined
committed
Aug 6, 2024
0 parents
commit d26ba0a
Showing
27 changed files
with
1,447 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,88 @@ | ||
name: Squish CI/CD | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
release: | ||
types: [ created ] | ||
|
||
jobs: | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... | ||
|
||
release: | ||
name: Release | ||
needs: test | ||
if: github.event_name == 'release' && github.event.action == 'created' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Build | ||
run: | | ||
GOOS=linux GOARCH=amd64 go build -o squish-linux-amd64 | ||
GOOS=darwin GOARCH=amd64 go build -o squish-darwin-amd64 | ||
GOOS=windows GOARCH=amd64 go build -o squish-windows-amd64.exe | ||
- name: Upload Release Assets | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ github.event.release.upload_url }} | ||
asset_path: ./squish-linux-amd64 | ||
asset_name: squish-linux-amd64 | ||
asset_content_type: application/octet-stream | ||
|
||
- name: Upload Release Assets (MacOS) | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ github.event.release.upload_url }} | ||
asset_path: ./squish-darwin-amd64 | ||
asset_name: squish-darwin-amd64 | ||
asset_content_type: application/octet-stream | ||
|
||
- name: Upload Release Assets (Windows) | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ github.event.release.upload_url }} | ||
asset_path: ./squish-windows-amd64.exe | ||
asset_name: squish-windows-amd64.exe | ||
asset_content_type: application/octet-stream | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Publish to npm | ||
run: pnpm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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 @@ | ||
.DS_Store | ||
node_modules | ||
/squish |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
# Go parameters | ||
GOCMD=go | ||
GOBUILD=$(GOCMD) build | ||
GOCLEAN=$(GOCMD) clean | ||
GOTEST=$(GOCMD) test | ||
GOGET=$(GOCMD) get | ||
GOMOD=$(GOCMD) mod | ||
BINARY_NAME=squish | ||
BINARY_UNIX=$(BINARY_NAME)_unix | ||
|
||
all: test build | ||
|
||
build: | ||
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/squish | ||
|
||
test: | ||
$(GOTEST) -v ./... | ||
|
||
clean: | ||
$(GOCLEAN) | ||
rm -f $(BINARY_NAME) | ||
rm -f $(BINARY_UNIX) | ||
|
||
run: | ||
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/squish | ||
./$(BINARY_NAME) | ||
|
||
deps: | ||
$(GOGET) ./... | ||
$(GOMOD) tidy | ||
|
||
# Cross compilation | ||
build-linux: | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v ./cmd/squish | ||
|
||
# Linting | ||
lint: | ||
golangci-lint run | ||
|
||
# Format code | ||
fmt: | ||
gofmt -s -w . | ||
|
||
# Check if code is formatted | ||
fmt-check: | ||
test -z $$(gofmt -l .) | ||
|
||
# Generate mocks for testing | ||
mocks: | ||
mockgen -source=pkg/esbuild/plugin.go -destination=pkg/esbuild/mocks/mock_plugin.go | ||
|
||
# Self-bundle (assuming squish can bundle itself) | ||
self-bundle: build | ||
./$(BINARY_NAME) --src ./cmd/squish --dist ./dist | ||
|
||
# Install golangci-lint | ||
install-linter: | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.1 | ||
|
||
.PHONY: all build test clean run deps build-linux lint fmt fmt-check mocks self-bundle install-linter |
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,103 @@ | ||
# Squish 🍊 | ||
|
||
Squish is a minimalistic package bundler for TypeScript, built with Go. It's designed to be fast, efficient, and incredibly easy to use, with zero configuration required to get started. | ||
|
||
![Squish Logo](https://via.placeholder.com/150x150.png?text=Squish) | ||
|
||
## Features | ||
|
||
- 🚀 Lightning-fast bundling | ||
- 📦 TypeScript support out of the box | ||
- 🔧 Zero configuration needed to start | ||
- 🎛️ Customizable when you need it | ||
- 👀 Watch mode for development | ||
- 🔍 Source map generation | ||
- 🧹 Clean dist directory option | ||
- 🔌 Plugin system for extensibility | ||
|
||
## Why Squish? | ||
|
||
Squish stands out from other bundlers by prioritizing simplicity and ease of use. With Squish, you can start building your TypeScript project immediately, without the need for complex configuration files or setup processes. | ||
|
||
### Zero Configuration | ||
|
||
Squish works out of the box with zero configuration. It automatically reads your `package.json` file to determine: | ||
|
||
- Entry points | ||
- Output formats | ||
- Package type (CommonJS or ES Module) | ||
- TypeScript configuration (using `tsconfig.json` if present) | ||
|
||
This means you can focus on writing code, not configuring your build tool. | ||
|
||
## Installation | ||
|
||
To install Squish, you need to have Go installed on your system. Then, run: | ||
|
||
```bash | ||
go get -u github.com/foxycorps/squish | ||
``` | ||
|
||
## Quick Start | ||
|
||
1. Navigate to your TypeScript project directory. | ||
2. Ensure your `package.json` file is set up with the appropriate `main`, `module`, `types`, and/or `exports` fields. | ||
3. Run Squish: | ||
|
||
```bash | ||
squish | ||
``` | ||
|
||
That's it! Squish will automatically bundle your TypeScript files based on your `package.json` configuration. | ||
|
||
## Usage | ||
|
||
While Squish works without configuration, you can customize its behavior when needed: | ||
|
||
``` | ||
squish [flags] | ||
``` | ||
|
||
### Flags | ||
|
||
- `--src string`: Source directory (default "./src") | ||
- `--dist string`: Output directory (default "./dist") | ||
- `--minify`: Minify output | ||
- `--watch, -w`: Watch mode | ||
- `--target stringSlice`: Environments to support (default [es2022]) | ||
- `--tsconfig string`: Custom tsconfig.json file path | ||
- `--env stringSlice`: Compile-time environment variables (e.g., --env NODE_ENV=production) | ||
- `--export-condition stringSlice`: Export conditions for resolving dependency export and import maps | ||
- `--sourcemap string`: Sourcemap generation. Provide 'inline' for inline sourcemap | ||
- `--clean-dist`: Clean dist before bundling | ||
|
||
## Configuration | ||
|
||
Squish is designed to work without a dedicated configuration file. Instead, it intelligently reads your project's `package.json` file to determine the entry points and output formats. It supports various package.json fields including `main`, `module`, `types`, and `exports`. | ||
|
||
This approach allows you to manage your project configuration in one place, reducing complexity and potential conflicts. | ||
|
||
## Plugin System | ||
|
||
While Squish aims for simplicity, it also provides a flexible plugin system for when you need to extend its functionality. Built-in plugins include: | ||
|
||
- Create Require Plugin | ||
- Externalize Node Builtins Plugin | ||
- Patch Binary Plugin | ||
- Strip Hashbang Plugin | ||
|
||
## Contributing | ||
|
||
We welcome contributions to Squish! Please see our [Contributing Guide](CONTRIBUTING.md) for more details. | ||
|
||
## License | ||
|
||
Squish is [MIT licensed](LICENSE). | ||
|
||
## Support | ||
|
||
If you encounter any issues or have questions, please file an issue on the [GitHub issue tracker](https://github.com/yourusername/squish/issues). | ||
|
||
## Acknowledgements | ||
|
||
Squish is built with the awesome [esbuild](https://github.com/evanw/esbuild) under the hood. Many thanks to the esbuild team and all our contributors! |
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,14 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"squish/internal/cli" | ||
) | ||
|
||
func main() { | ||
if err := cli.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
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,15 @@ | ||
module squish | ||
|
||
go 1.22 | ||
|
||
require ( | ||
github.com/evanw/esbuild v0.23.0 | ||
github.com/fsnotify/fsnotify v1.7.0 | ||
github.com/spf13/cobra v1.8.1 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/sys v0.4.0 // indirect | ||
) |
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 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/evanw/esbuild v0.23.0 h1:PLUwTn2pzQfIBRrMKcD3M0g1ALOKIHMDefdFCk7avwM= | ||
github.com/evanw/esbuild v0.23.0/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= | ||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= | ||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= | ||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= | ||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,54 @@ | ||
const { execSync } = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fetch = require('node-fetch'); | ||
|
||
const version = require('./package.json').version; | ||
const binPath = path.join(__dirname, 'bin'); | ||
|
||
async function getLatestRelease() { | ||
const response = await fetch('https://api.github.com/repos/foxycorps/squish/releases/latest'); | ||
const data = await response.json(); | ||
return data.tag_name.replace('v', ''); | ||
} | ||
|
||
async function install() { | ||
const latestVersion = await getLatestRelease(); | ||
const platform = process.platform; | ||
const arch = process.arch === 'x64' ? 'amd64' : process.arch; | ||
|
||
let filename; | ||
switch (platform) { | ||
case 'linux': | ||
filename = `squish-linux-${arch}`; | ||
break; | ||
case 'darwin': | ||
filename = `squish-darwin-${arch}`; | ||
break; | ||
case 'win32': | ||
filename = `squish-windows-${arch}.exe`; | ||
break; | ||
default: | ||
throw new Error(`Unsupported platform: ${platform}`); | ||
} | ||
|
||
const url = `https://github.com/foxycorps/squish/releases/download/v${latestVersion}/${filename}`; | ||
const outputPath = path.join(binPath, platform === 'win32' ? 'squish.exe' : 'squish'); | ||
|
||
if (!fs.existsSync(binPath)) { | ||
fs.mkdirSync(binPath, { recursive: true }); | ||
} | ||
|
||
console.log(`Downloading Squish v${latestVersion} for ${platform} ${arch}...`); | ||
|
||
try { | ||
execSync(`curl -L ${url} -o ${outputPath}`); | ||
fs.chmodSync(outputPath, 0o755); // Make the file executable | ||
console.log('Squish has been installed successfully!'); | ||
} catch (error) { | ||
console.error('Failed to download Squish:', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
install().catch(console.error); |
Oops, something went wrong.