Skip to content

Commit 60c9d3c

Browse files
authored
refactor: rewrite with deno_core (dprint#14)
1 parent 9395b0b commit 60c9d3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+236192
-5884
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212

1313
*.jpg binary
1414
*.png binary
15+
16+
js/startup.js linguist-generated=true

.github/workflows/ci.yml

+107-25
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,134 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
tags:
9+
- '*'
410

511
jobs:
612
build:
7-
name: test_release
8-
runs-on: ubuntu-latest
13+
name: ${{ matrix.config.kind }} ${{ matrix.config.os }}
14+
runs-on: ${{ matrix.config.os }}
15+
strategy:
16+
matrix:
17+
config:
18+
# uses an older version of ubuntu because of issue dprint/#483
19+
- os: ubuntu-18.04
20+
kind: test_release
21+
- os: macOS-latest
22+
kind: test_release
23+
- os: windows-2019
24+
kind: test_release
25+
26+
outputs:
27+
LINUX_ZIP_CHECKSUM: ${{steps.linux_pre_release.outputs.ZIP_CHECKSUM}}
28+
MAC_ZIP_CHECKSUM: ${{steps.mac_pre_release.outputs.ZIP_CHECKSUM}}
29+
WINDOWS_ZIP_CHECKSUM: ${{steps.windows_pre_release.outputs.ZIP_CHECKSUM}}
30+
31+
env:
32+
CARGO_INCREMENTAL: 0
33+
RUST_BACKTRACE: full
34+
CFG_RELEASE_CHANNEL: nightly
935

36+
steps:
37+
# Setup
38+
- uses: actions/checkout@v2
39+
- uses: dtolnay/rust-toolchain@stable
40+
- uses: Swatinem/rust-cache@v1
41+
42+
# Build
43+
- name: Build release
44+
if: matrix.config.kind == 'test_release'
45+
run: cargo build --release
46+
47+
- name: Test release
48+
if: matrix.config.kind == 'test_release'
49+
run: cargo test --release
50+
51+
# Release
52+
- name: Pre-release (Linux)
53+
id: linux_pre_release
54+
if: startsWith(matrix.config.os, 'ubuntu') && matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
55+
run: |
56+
cd target/release
57+
zip -r dprint-plugin-prettier-x86_64-unknown-linux-gnu.zip dprint-plugin-prettier dprint-plugin-prettier
58+
echo "::set-output name=ZIP_CHECKSUM::$(shasum -a 256 dprint-plugin-prettier-x86_64-unknown-linux-gnu.zip | awk '{print $1}')"
59+
- name: Pre-release (Mac)
60+
id: mac_pre_release
61+
if: startsWith(matrix.config.os, 'macOS') && matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
62+
run: |
63+
cd target/release
64+
zip -r dprint-plugin-prettier-x86_64-apple-darwin.zip dprint-plugin-prettier dprint-plugin-prettier
65+
echo "::set-output name=ZIP_CHECKSUM::$(shasum -a 256 dprint-plugin-prettier-x86_64-apple-darwin.zip | awk '{print $1}')"
66+
- name: Pre-release (Windows)
67+
id: windows_pre_release
68+
if: startsWith(matrix.config.os, 'windows') && matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
69+
run: |
70+
cd target/release
71+
Compress-Archive -CompressionLevel Optimal -Force -Path dprint-plugin-prettier.exe -DestinationPath dprint-plugin-prettier-x86_64-pc-windows-msvc.zip
72+
echo "::set-output name=ZIP_CHECKSUM::$(shasum -a 256 dprint-plugin-prettier-x86_64-pc-windows-msvc.zip | awk '{print $1}')"
73+
74+
# Upload Artifacts
75+
- name: Upload Artifacts (Linux)
76+
uses: actions/upload-artifact@v2
77+
if: startsWith(matrix.config.os, 'ubuntu') && matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
78+
with:
79+
name: linux-artifacts
80+
path: target/release/dprint-plugin-prettier-x86_64-unknown-linux-gnu.zip
81+
- name: Upload Artifacts (Mac)
82+
uses: actions/upload-artifact@v2
83+
if: startsWith(matrix.config.os, 'macOS') && matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
84+
with:
85+
name: mac-artifacts
86+
path: target/release/dprint-plugin-prettier-x86_64-apple-darwin.zip
87+
- name: Upload Artifacts (Windows)
88+
uses: actions/upload-artifact@v2
89+
if: startsWith(matrix.config.os, 'windows') && matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
90+
with:
91+
name: windows-artifacts
92+
path: target/release/dprint-plugin-prettier-x86_64-pc-windows-msvc.zip
93+
94+
95+
draft_release:
96+
name: draft_release
97+
if: startsWith(github.ref, 'refs/tags/')
98+
needs: build
99+
runs-on: ubuntu-latest
10100
steps:
11101
- name: Checkout
12102
uses: actions/checkout@v2
13-
- name: Cache node_modules
14-
uses: actions/cache@v2
15-
with:
16-
path: |
17-
**/node_modules
18-
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
103+
- uses: denoland/setup-deno@v1
104+
- name: Download artifacts
105+
uses: actions/download-artifact@v2
19106

20-
- name: NPM install
21-
run: npm ci
22-
- name: Build
23-
run: npm run build
107+
- name: Move downloaded artifacts
108+
run: |
109+
mv linux-artifacts/dprint-plugin-prettier-x86_64-unknown-linux-gnu.zip .
110+
mv mac-artifacts/dprint-plugin-prettier-x86_64-apple-darwin.zip .
111+
mv windows-artifacts/dprint-plugin-prettier-x86_64-pc-windows-msvc.zip .
24112
25-
- name: Package
113+
- name: Output checksums
26114
run: |
27-
mv index-macos dprint-plugin-prettier
28-
zip -r dprint-plugin-prettier-x86_64-apple-darwin.zip dprint-plugin-prettier
29-
rm dprint-plugin-prettier
30-
mv index-linux dprint-plugin-prettier
31-
zip -r dprint-plugin-prettier-x86_64-unknown-linux-gnu.zip dprint-plugin-prettier
32-
mv index-win.exe dprint-plugin-prettier.exe
33-
zip -r dprint-plugin-prettier-x86_64-pc-windows-msvc.zip dprint-plugin-prettier.exe
115+
echo "Linux zip: ${{needs.build.outputs.LINUX_ZIP_CHECKSUM}}"
116+
echo "Mac zip: ${{needs.build.outputs.MAC_ZIP_CHECKSUM}}"
117+
echo "Windows zip: ${{needs.build.outputs.WINDOWS_ZIP_CHECKSUM}}"
34118
35119
- name: Create plugin file
36-
run: node scripts/createPluginFile.js
120+
run: deno run --allow-read=. --allow-write=. scripts/create_plugin_file.ts
37121

38122
- name: Get tag version
39-
if: startsWith(github.ref, 'refs/tags/')
40123
id: get_tag_version
41124
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}
42125

43126
- name: Get plugin file checksum
44-
if: startsWith(github.ref, 'refs/tags/')
45127
id: get_plugin_file_checksum
46128
run: echo "::set-output name=CHECKSUM::$(shasum -a 256 plugin.exe-plugin | awk '{print $1}')"
47129

48130
- name: Release
49131
uses: softprops/action-gh-release@v1
50-
if: startsWith(github.ref, 'refs/tags/')
51132
env:
52133
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53134
with:
@@ -67,6 +148,7 @@ jobs:
67148
{
68149
// etc...
69150
"plugins": [
151+
// ...add other dprint plugins here that you want to take precedence over prettier...
70152
"https://plugins.dprint.dev/prettier-${{ steps.get_tag_version.outputs.TAG_VERSION }}.exe-plugin@${{ steps.get_plugin_file_checksum.outputs.CHECKSUM }}"
71153
]
72154
}

.gitignore

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
node_modules
2-
dist
3-
index-linux
4-
index-macos
5-
index-win.exe
1+
js/node/node_modules
2+
js/node/dist
3+
target

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"deno.enable": true,
3+
"deno.lint": false,
4+
"deno.unstable": false
5+
}

0 commit comments

Comments
 (0)