Skip to content

Commit

Permalink
chore: init
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed May 21, 2024
0 parents commit 21875df
Show file tree
Hide file tree
Showing 21 changed files with 877 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Check http://editorconfig.org for more information
# This is the main config file for this project:
root = true

[*]
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
indent_style = tab
insert_final_newline = true
indent_size = 4

[*.yml]
indent_style = space
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Auto detect text files and perform LF normalization
* text=auto
*.js linguist-detectable=false
*.ts linguist-detectable=false
*.mjs linguist-detectable=false
*.sh linguist-detectable=false

test_*/* linguist-detectable=false
test_*/**/* linguist-detectable=false
57 changes: 57 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Publish

on:
push:
tags:
- "v*"

jobs:
publish:
if: startsWith(github.ref, 'refs/tags/v')
permissions:
packages: write
contents: write
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
registry-url: "https://registry.npmjs.org"

- run: |
wget -P ${{ runner.temp }} https://github.com/tinygo-org/tinygo/releases/download/v0.31.2/tinygo_0.31.2_amd64.deb
yes | sudo dpkg -i ${{ runner.temp }}/tinygo_0.31.2_amd64.deb
- name: Build
run: scripts/build.sh
shell: bash

- name: Publish to npmjs
run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to jsr
run: npx jsr publish

- uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
registry-url: "https://npm.pkg.github.com"

- name: Publish to github packages
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Pack
run: npm pack

- name: Publish to Github Releases
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564
with:
files: |
wasm-fmt-*.tgz
yamlfmt.wasm
85 changes: 85 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Test

on:
push:
branches:
- "*"
pull_request:
types: ["opened", "reopened", "synchronize"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
name: Install Node
with:
node-version-file: ".node-version"

- run: |
wget -P ${{ runner.temp }} https://github.com/tinygo-org/tinygo/releases/download/v0.31.2/tinygo_0.31.2_amd64.deb
yes | sudo dpkg -i ${{ runner.temp }}/tinygo_0.31.2_amd64.deb
- name: Build
run: scripts/build.sh
shell: bash

- run: npm pack
- name: Upload
uses: actions/upload-artifact@v4
with:
name: build
path: |
yamlfmt.js
yamlfmt.wasm
*.tgz
deno-test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build
path: ./

- uses: denoland/setup-deno@v1
name: Install Deno
with:
deno-version: v1.x

- run: deno test test_deno --allow-read

node-test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build
path: ./

- uses: actions/setup-node@v4
name: Install Node
with:
node-version-file: ".node-version"

- run: node --test test_node

bun-test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build
path: ./

- uses: oven-sh/setup-bun@v1
name: Install bun

- run: bun test test_bun
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

yamlfmt.wasm
*.tgz
yamlfmt.js
jsr.jsonc

node_modules
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.13.1
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test_*
src
scripts
node_modules
jsr.jsonc
*.tgz
*.sh
*.patch
*.mod
.*
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=https://registry.npmjs.org/
always-auth=true
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"go.testEnvVars": {
"GOARCH": "wasm",
"GOOS": "js"
},
"go.toolsEnvVars": {
"GOARCH": "wasm",
"GOOS": "js"
},
"deno.enable": true,
"deno.enablePaths": [
"test_deno"
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 wasm-fmt

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.
23 changes: 23 additions & 0 deletions gen_patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
current_dir=$(pwd)
tmp_dir=$(mktemp -d)

cd $tmp_dir
git init

cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js $tmp_dir/yamlfmt.js
git add -f .
git commit -m "init"

cp $current_dir/yamlfmt.js $tmp_dir/yamlfmt.js
git add -f .

git diff \
--cached \
--no-color \
--ignore-space-at-eol \
--no-ext-diff \
--src-prefix=a/ \
--dst-prefix=b/ \
>$current_dir/yamlfmt.patch

rm -rf $tmp_dir
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/wasm-fmt/yamlfmt

go 1.22.3

require github.com/google/yamlfmt v0.12.1

require (
github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect
github.com/braydonk/yaml v0.7.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
)
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc=
github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/braydonk/yaml v0.7.0 h1:ySkqO7r0MGoCNhiRJqE0Xe9yhINMyvOAB3nFjgyJn2k=
github.com/braydonk/yaml v0.7.0/go.mod h1:hcm3h581tudlirk8XEUPDBAimBPbmnL0Y45hCRl47N4=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/yamlfmt v0.12.1 h1:55X62ZLOcdBepKlmc1PKhT9yqexR0IdKBbEasfPhps8=
github.com/google/yamlfmt v0.12.1/go.mod h1:y8JNH/2TqTaCSUjk/zhn0lYlibMvS0R+pbVUDo8oz9o=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
49 changes: 49 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@wasm-fmt/yamlfmt",
"description": "A wasm based yaml formatter",
"author": "magic-akari <[email protected]>",
"version": "0.4.9",
"license": "MIT",
"keywords": [
"wasm",
"yaml",
"formatter"
],
"repository": {
"type": "git",
"url": "https://github.com/wasm-fmt/yamlfmt"
},
"homepage": "https://github.com/wasm-fmt/yamlfmt",
"bugs": {
"url": "https://github.com/wasm-fmt/yamlfmt/issues"
},
"type": "module",
"main": "yamlfmt.js",
"module": "yamlfmt.js",
"types": "yamlfmt.d.ts",
"exports": {
".": {
"types": "./yamlfmt.d.ts",
"node": "./yamlfmt_node.js",
"default": "./yamlfmt.js"
},
"./vite": {
"types": "./yamlfmt.d.ts",
"default": "./yamlfmt_vite.js"
},
"./package.json": "./package.json",
"./*": "./*"
},
"scripts": {
"build": "./scripts/build.sh",
"test:node": "node --test test_node",
"test:deno": "deno test test_deno --allow-read",
"test:bun": "bun test test_bun"
},
"engines": {
"node": ">=16.17.0"
},
"publishConfig": {
"access": "public"
}
}
12 changes: 12 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set -Eeo pipefail

cd $(dirname $0)/..

echo "Building..."
tinygo build -o=yamlfmt.wasm -target=wasm -no-debug ./src/lib.go

echo "Generating JS..."
cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js ./yamlfmt.js
git apply ./yamlfmt.patch

./scripts/package.mjs ./package.json
Loading

0 comments on commit 21875df

Please sign in to comment.