Skip to content

Commit

Permalink
Create project scaffolding.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Sep 19, 2021
0 parents commit 306cbb0
Show file tree
Hide file tree
Showing 25 changed files with 743 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**

dprint-plugin-dockerfile version: x.x.x

**Input Code**

```dockerfile
```

**Expected Output**

```dockerfile
```

**Actual Output**

```dockerfile
```
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/other.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Other
about: Something that doesn't fall in the other categories
title: ''
labels: ''
assignees: ''

---
146 changes: 146 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: CI

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.config.kind }} ${{ matrix.config.os }}
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- os: ubuntu-latest
kind: test_release
- os: ubuntu-latest
kind: test_debug

env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full

steps:
- uses: actions/checkout@v2
- name: Install wasm32 target
if: matrix.config.kind == 'test_release'
run: rustup target add wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v1

- name: Build debug
if: matrix.config.kind == 'test_debug'
run: cargo build --verbose
- name: Build release
if: matrix.config.kind == 'test_release'
run: cargo build --target wasm32-unknown-unknown --features wasm --release --verbose

- name: Test debug
if: matrix.config.kind == 'test_debug'
run: cargo test --verbose
- name: Test release
if: matrix.config.kind == 'test_release'
run: cargo test --release --verbose

- name: Get tag version
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
id: get_tag_version
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}

# NPM
- uses: actions/setup-node@v2
if: matrix.config.kind == 'test_release'
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'

- name: Setup and test npm deployment
if: matrix.config.kind == 'test_release'
run: |
cd deployment/npm
npm install
node setup.js ${{ steps.get_tag_version.outputs.TAG_VERSION }}
npm run test
- name: npm publish
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd deployment/npm
npm publish --access public
git reset --hard
# CARGO PUBLISH
- name: Cargo login
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: cargo login ${{ secrets.CRATES_TOKEN }}

- name: Cargo publish
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: cargo publish

# GITHUB RELEASE
- name: Pre-release
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: |
# update config schema to have version
sed -i 's/dockerfile-0.0.0.json/dockerfile-${{ steps.get_tag_version.outputs.TAG_VERSION }}.json/' deployment/schema.json
# rename the wasm file
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_dockerfile.wasm dockerfile.wasm)
- name: Release
uses: softprops/action-gh-release@v1
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
target/wasm32-unknown-unknown/release/dockerfile.wasm
deployment/schema.json
body: |
## Install
[Install](https://dprint.dev/install/) and [setup](https://dprint.dev/setup/) dprint.
Then in your project's dprint configuration file:
1. Specify the plugin url in the `"plugins"` array.
2. Ensure `.dockerfile` file extensions are matched in an `"includes"` pattern.
3. Add a `"dockerfile"` configuration property if desired.
```jsonc
{
// ...etc...
"dockerfile": {
// config goes here
},
"includes": [
"**/*.{dockerfile}"
],
"plugins": [
"https://plugins.dprint.dev/dockerfile-${{ steps.get_tag_version.outputs.TAG_VERSION }}.wasm"
]
}
```
## JS Formatting API
* [JS Formatter](https://github.com/dprint/js-formatter) - Browser/Deno and Node
* [npm package](https://www.npmjs.com/package/@dprint/dockerfile)
draft: false

# PLUGIN PUBLISH
- name: Checkout plugins repo
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
uses: actions/checkout@v2
with:
repository: dprint/plugins
token: ${{ secrets.CI_REPO_PAT }} # github.token is scoped to current repo, so use this to push to other repo
path: dprint-plugins
- name: Plugin publish
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: |
cd dprint-plugins
node scripts/replace-plugin.js dprint-plugin-dockerfile ${{ steps.get_tag_version.outputs.TAG_VERSION }} dockerfile-${{ steps.get_tag_version.outputs.TAG_VERSION }}
git add .
git config user.name "David Sherret"
git config user.email "[email protected]"
git commit -m "dprint-plugin-dockerfile ${{ steps.get_tag_version.outputs.TAG_VERSION }}"
git push origin main
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
Cargo.lock
deployment/npm/buffer.generated.js
deployment/npm/node_modules
35 changes: 35 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "dprint-plugin-dockerfile"
version = "0.0.1"
authors = ["David Sherret <[email protected]>"]
edition = "2018"
homepage = "https://github.com/dprint/dprint-plugin-dockerfile"
keywords = ["formatting", "formatter", "docker", "dockerfile"]
license = "MIT"
repository = "https://github.com/dprint/dprint-plugin-dockerfile"
description = "A WIP dockerfile formatter for dprint."

[lib]
crate-type = ["lib", "cdylib"]

[profile.release]
opt-level = 3
debug = false
lto = true
debug-assertions = false
overflow-checks = false
panic = "abort"

[features]
wasm = ["serde_json", "dprint-core/wasm"]
tracing = ["dprint-core/tracing"]

[dependencies]
dockerfile-parser = "0.7.1"
dprint-core = { version = "0.44.0", features = ["formatting"] }
serde = { version = "1.0.88", features = ["derive"] }
serde_json = { version = "1.0", optional = true }

[dev-dependencies]
dprint-development = "0.4.1"
serde_json = { version = "1.0" }
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 David Sherret

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.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# dprint-plugin-dockerfile

WIP - Future home of a dockerfile formatter.
2 changes: 2 additions & 0 deletions deployment/npm/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setup.js
index.test.js
16 changes: 16 additions & 0 deletions deployment/npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @dprint/dockerfile

npm distribution of [dprint-plugin-dockerfile](https://github.com/dprint/dprint-plugin-dockerfile).

Use this with [@dprint/formatter](https://github.com/dprint/js-formatter) or just use @dprint/formatter and download the [dprint-plugin-dockerfile WASM file](https://github.com/dprint/dprint-plugin-dockerfile/releases).

## Example

```ts
import { getBuffer } from "@dprint/dockerfile";
import { createFromBuffer } from "@dprint/formatter";

const formatter = createFromBuffer(getBuffer());

console.log(formatter.formatText("test.toml", "RUN /bin/bash"));
```
2 changes: 2 additions & 0 deletions deployment/npm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** Gets a buffer representing the WASM module. */
export function getBuffer(): ArrayBuffer;
34 changes: 34 additions & 0 deletions deployment/npm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Gets a buffer representing the WASM module.
* @returns {ArrayBuffer}
*/
function getBuffer() {
const encodedBuffer = require("./buffer.generated").encodedBuffer;
return decodeEncodedBuffer(encodedBuffer);
}

/**
* @param {string} encodedBuffer
* @returns {ArrayBuffer}
*/
function decodeEncodedBuffer(encodedBuffer) {
// https://stackoverflow.com/a/51473757/188246
const binaryString = toBinaryString();
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;

function toBinaryString() {
if (typeof atob === "function") {
return atob(encodedBuffer);
} else {
return Buffer.from(encodedBuffer, "base64").toString("binary");
}
}
}

module.exports = {
getBuffer,
};
9 changes: 9 additions & 0 deletions deployment/npm/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-check
const assert = require("assert");
const createFromBuffer = require("@dprint/formatter").createFromBuffer;
const getBuffer = require("./index").getBuffer;

const formatter = createFromBuffer(getBuffer());
const result = formatter.formatText("file.dockerfile", "RUN /bin/bash");

assert.strictEqual(result, "RUN /bin/bash\n");
14 changes: 14 additions & 0 deletions deployment/npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions deployment/npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@dprint/dockerfile",
"version": "0.0.0",
"description": "Wasm buffer for dprint-plugin-dockerfile.",
"main": "./index.js",
"types": "./index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/dprint/dprint-plugin-dockerfile.git"
},
"keywords": [
"dockerfile",
"code",
"formatter",
"dprint"
],
"author": "David Sherret",
"license": "MIT",
"bugs": {
"url": "https://github.com/dprint/dprint-plugin-dockerfile/issues"
},
"homepage": "https://github.com/dprint/dprint-plugin-dockerfile#readme",
"scripts": {
"test": "node index.test.js"
},
"devDependencies": {
"@dprint/formatter": "~0.1.4"
}
}
21 changes: 21 additions & 0 deletions deployment/npm/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check
const fs = require("fs");
const path = require("path");
const args = process.argv.slice(2);
const wasmPath = path.join(__dirname, "../../target/wasm32-unknown-unknown/release/dprint_plugin_dockerfile.wasm");
const wasmBytes = fs.readFileSync(wasmPath);

let output = "module.exports.encodedBuffer = \"";
output += wasmBytes.toString("base64");
output += "\";\n";

fs.writeFileSync(path.join(__dirname, "buffer.generated.js"), output);

if (args.length > 0) {
// update the version based on the first argument
const packageJsonPath = path.join(__dirname, "package.json");
const packageJsonText = fs.readFileSync(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonText);
packageJson.version = args[0];
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 2) + "\n");
}
Loading

0 comments on commit 306cbb0

Please sign in to comment.