Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 7fdb302

Browse files
disruptedso1ve
andauthored
feat: publish on npm (#16)
Co-authored-by: so1ve <i@mk1.io>
1 parent 9fdfa88 commit 7fdb302

File tree

10 files changed

+165
-4
lines changed

10 files changed

+165
-4
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
name: CI
2-
# taken from main dprint plugins
3-
# without npm for now
42

53
on: [push, pull_request]
64

@@ -50,6 +48,30 @@ jobs:
5048
id: get_tag_version
5149
run: echo ::set-output name=TAG_VERSION::"${GITHUB_REF/refs\/tags\//}"
5250

51+
# NPM
52+
- uses: actions/setup-node@v2
53+
if: matrix.config.kind == 'test_release'
54+
with:
55+
node-version: '14.x'
56+
registry-url: 'https://registry.npmjs.org'
57+
58+
- name: Setup and test npm deployment
59+
if: matrix.config.kind == 'test_release'
60+
run: |
61+
npm install
62+
node setup.js ${{ steps.get_tag_version.outputs.TAG_VERSION }}
63+
npm run test
64+
working-directory: ./deployment/npm
65+
66+
- name: npm publish
67+
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
68+
env:
69+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
70+
run: |
71+
npm publish --access public
72+
git reset --hard
73+
working-directory: ./deployment/npm
74+
5375
# CARGO PUBLISH
5476
- name: Cargo login
5577
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
@@ -64,7 +86,7 @@ jobs:
6486
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
6587
run: |
6688
# update config schema to have version
67-
sed -i 's/0.0.0/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
89+
sed -i 's/css\/0.0.0/css\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
6890
# rename the wasm file
6991
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_css.wasm plugin.wasm)
7092
- name: Release
@@ -76,5 +98,33 @@ jobs:
7698
files: |
7799
target/wasm32-unknown-unknown/release/plugin.wasm
78100
deployment/schema.json
79-
body: ""
101+
body: |
102+
## Install
103+
104+
[Install](https://dprint.dev/install/) and [setup](https://dprint.dev/setup/) dprint.
105+
106+
Then in your project's dprint configuration file:
107+
108+
1. Specify the plugin url in the `"plugins"` array.
109+
2. Ensure `.css` file extensions are matched in an `"includes"` pattern.
110+
3. Add a `"css"` configuration property if desired.
111+
```jsonc
112+
{
113+
// ...etc...
114+
"css": {
115+
// css config goes here
116+
},
117+
"includes": [
118+
"**/*.{css}"
119+
],
120+
"plugins": [
121+
"https://github.com/disrupted/dprint-plugin-css/raw/${{ steps.get_tag_version.outputs.TAG_VERSION }}/deployment/npm/plugin.wasm"
122+
]
123+
}
124+
```
125+
126+
## JS Formatting API
127+
128+
* [JS Formatter](https://github.com/dprint/js-formatter) - Browser/Deno and Node
129+
* [npm package](https://www.npmjs.com/package/dprint-plugin-css)
80130
draft: false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/target
2+
deployment/npm/node_modules
3+
deployment/npm/plugin.wasm

deployment/npm/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
setup.js
2+
index.test.js

deployment/npm/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# dprint-plugin-css
2+
3+
npm distribution of [dprint-plugin-css](https://github.com/disrupted/dprint-plugin-css).
4+
5+
Use this with [@dprint/formatter](https://github.com/dprint/js-formatter) or just use @dprint/formatter and download the [dprint-plugin-json WASM file](https://github.com/disrupted/dprint-plugin-css/releases).
6+
7+
## Example
8+
9+
```ts
10+
import { createFromBuffer } from "@dprint/formatter";
11+
import { getPath } from "dprint-plugin-css";
12+
import * as fs from "fs";
13+
14+
const buffer = fs.readFileSync(getPath());
15+
const formatter = createFromBuffer(buffer);
16+
17+
console.log(formatter.formatText("test.css", ".test{color: red}"));
18+
```

deployment/npm/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** Gets an absolute path to the Wasm module. */
2+
export function getPath(): string;

deployment/npm/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Gets the path to the Wasm module.
3+
* @returns {string}
4+
*/
5+
function getPath() {
6+
return require("path").join(__dirname, "plugin.wasm");
7+
}
8+
9+
module.exports = {
10+
getPath,
11+
};

deployment/npm/index.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
const assert = require("assert");
3+
const createFromBuffer = require("@dprint/formatter").createFromBuffer;
4+
const getPath = require("./index").getPath;
5+
6+
const buffer = require("fs").readFileSync(getPath());
7+
const formatter = createFromBuffer(buffer);
8+
const result = formatter.formatText("file.json", ".test{color: red}");
9+
10+
assert.strictEqual(result, ".test {\n color: red;\n}\n");

deployment/npm/package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployment/npm/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "dprint-plugin-css",
3+
"version": "0.0.0",
4+
"description": "Wasm module for dprint-plugin-css.",
5+
"main": "./index.js",
6+
"types": "./index.d.ts",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/disrupted/dprint-plugin-css.git"
10+
},
11+
"keywords": [
12+
"css",
13+
"code",
14+
"formatter",
15+
"dprint"
16+
],
17+
"author": "Salomon Popp",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/disrupted/dprint-plugin-css/issues"
21+
},
22+
"homepage": "https://github.com/disrupted/dprint-plugin-css#readme",
23+
"scripts": {
24+
"test": "node index.test.js"
25+
},
26+
"devDependencies": {
27+
"@dprint/formatter": "~0.1.4"
28+
}
29+
}

deployment/npm/setup.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @ts-check
2+
const fs = require("fs");
3+
const path = require("path");
4+
const args = process.argv.slice(2);
5+
const wasmPath = path.join(__dirname, "../../target/wasm32-unknown-unknown/release/dprint_plugin_css.wasm");
6+
fs.copyFileSync(wasmPath, path.join(__dirname, "plugin.wasm"));
7+
8+
if (args.length > 0) {
9+
// update the version based on the first argument
10+
const packageJsonPath = path.join(__dirname, "package.json");
11+
const packageJsonText = fs.readFileSync(packageJsonPath, "utf8");
12+
const packageJson = JSON.parse(packageJsonText);
13+
packageJson.version = args[0];
14+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 2) + "\n");
15+
}

0 commit comments

Comments
 (0)