Skip to content

Commit

Permalink
Merge pull request #347 from carstencodes/contrib/carstencodes/deploy…
Browse files Browse the repository at this point in the history
…ments/javascript

feat: Added support for distribution via NPM
  • Loading branch information
yoheimuta authored Dec 3, 2023
2 parents 6bd312a + 5f771c3 commit c72c4ac
Show file tree
Hide file tree
Showing 26 changed files with 1,566 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [go]
language: [go, javascript]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/publish_npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Publish NPM Package
on:
workflow_dispatch:
workflow_run:
workflows: [goreleaser]
types:
- completed

jobs:
publish_npm:
name: Publish NPM
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
fetch-tags: true
- name: Install node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
working-directory: ./bdist/js
run: npm install --ignore-scripts
- name: Set package version
working-directory: ./bdist/js
run: npm run version
- name: Pack NPM Package
working-directory: ./bdist/js
run: npm pack
- name: Issue warning if NPM_TOKEN is not set
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "::warning title=Missing authentication token::In order to publish an NPM package, you must set the NPM_TOKEN secret"
if: ${{ env.NODE_AUTH_TOKEN == '' }}
- name: Publish NPM package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
if: ${{ env.NODE_AUTH_TOKEN != '' }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ atlassian-ide-plugin.xml
# Gradle files
/.gradle
/build

# JS files
/bdist/js/bin/protolint
/bdist/js/bin/protoc-gen-protolint
/bdist/js/node_modules/
/bdist/js/node_modules/*.tgz

41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,46 @@ However, I recommend using one of the pre-built binaries instead because it does
go install github.com/yoheimuta/protolint/cmd/protolint@latest
```

### Within JavaScript / TypeScript

You can use `protolint` using your nodejs package manager like `npm` or `yarn`.

```sh
$ npm install protolint --save-dev
```

This will add a reference to a development dependency to your local `package.json`.

During install, the [install.mjs](bdist/js/install.mjs) script will be called. It will download the matching `protolint` from github. Just like [@electron/get](https://github.com/electron/get/), you can bypass the download using the following environment variables:

| Environment Variable | Default value | Description |
|-------------------------------|---------------------------------------|-----------------------------------------------|
| PROTOLINT_MIRROR_HOST | https://github.com | HTTP/Web server base url hosting the binaries |
| PROTOLINT_MIRROR_REMOTE_PATH | yoheimuta/protolint/download/releases | Path to the archives on the remote host |
| PROTOLINT_MIRROR_USERNAME | | HTTP Basic auth user name |
| PROTOLINT_MIRROR_PASSWORD | | HTTP Basic auth password |
| PROTOLINT_PROXY | | HTTP(S) Proxy with optional auth data |

Within the remote path, the archives from the [releases](https://github.com/yoheimuta/protolint/releases/latest/) page must be
mirrored.

After that, you can use `npx protolint` (with all supplied protolint arguments) within your dev-scripts.

```json
{
...
"scripts": {
"protoc": "....",
"preprotoc": "npx protolint"
},
...
}
```

You can add a `protolint` node to your `package.json` which may contain the content of `protolint.yml` below the `lint` node, i.e. the root element of the configuration will be `protolint`.

If you want to get an output that matches the TSC compiler, use reporter `tsc`.

## Usage

```sh
Expand Down Expand Up @@ -437,6 +477,7 @@ The built-in reporter options are:
- sarif
- sonar (SonarQube generic issue format)
- unix
- tsc (compatible to TypeScript compiler)

## Configuring

Expand Down
12 changes: 12 additions & 0 deletions _testdata/js_config/non_pure_package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "protolint_user",
"version": "0.1.0",
"protolint": {
"rules_option":{
"indent": {
"style": "\t",
"newline": "\n"
}
}
}
}
10 changes: 10 additions & 0 deletions _testdata/js_config/package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"protolint": {
"rules_option":{
"indent": {
"style": "\t",
"newline": "\n"
}
}
}
}
2 changes: 2 additions & 0 deletions _testdata/js_config/package_no_protolint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
10 changes: 10 additions & 0 deletions _testdata/js_config/package_with_yaml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"protolint": {
"rules_option":{
"indent": {
"style": "\t",
"newline": "\r\n"
}
}
}
}
6 changes: 6 additions & 0 deletions _testdata/js_config/package_with_yaml/protolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
lint:
rules_option:
indent:
style: tab
newline: "\n"
10 changes: 10 additions & 0 deletions _testdata/js_config/package_with_yaml_parent/child/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"protolint": {
"rules_option":{
"indent": {
"style": "\t",
"newline": "\r\n"
}
}
}
}
6 changes: 6 additions & 0 deletions _testdata/js_config/package_with_yaml_parent/protolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
lint:
rules_option:
indent:
style: tab
newline: "\n"
21 changes: 21 additions & 0 deletions bdist/js/bin/protoc-gen-protolint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

'use strict';

var path = require('path');
var execFile = require('child_process').execFile;

var exe_ext = process.platform === 'win32' ? '.exe' : '';

var protoc = path.resolve(__dirname, 'protoc-gen-protolint' + exe_ext);

var args = process.argv.slice(2);

var child_process = execFile(protoc, args, null);

child_process.stdout.pipe(process.stdout);
child_process.stderr.pipe(process.stderr);

child_process.on("exit", (exit_code, _) => {
process.exit(exit_code);
});
22 changes: 22 additions & 0 deletions bdist/js/bin/protolint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

'use strict';

var path = require('path');
var execFile = require('child_process').execFile;

var exe_ext = process.platform === 'win32' ? '.exe' : '';

var protoc = path.resolve(__dirname, 'protolint' + exe_ext);

var args = process.argv.slice(2);

var child_process = execFile(protoc, args, null);

child_process.stdout.pipe(process.stdout);
child_process.stderr.pipe(process.stderr);

child_process.on("exit", (exit_code, _) => {
process.exit(exit_code);
});

8 changes: 8 additions & 0 deletions bdist/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* package.json requires this file to be present. In the future, this can
* export useful information about the included tools.
*/

module.exports = {};
Loading

0 comments on commit c72c4ac

Please sign in to comment.