Skip to content

Commit

Permalink
feat(semantic-release): add semantic release, workflows, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rolljee committed Sep 14, 2023
1 parent dd280ca commit 5e1bdd6
Show file tree
Hide file tree
Showing 11 changed files with 11,861 additions and 678 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
3 changes: 3 additions & 0 deletions .cz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "./node_modules/cz-conventional-changelog"
}
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# JS generated files from TS
app.js
app.d.ts
app.js.map
lib/**/*.d.ts
lib/**/*.js.map
lib/**/*.js
91 changes: 91 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"consistent-return": 0,
"curly": 2,
"dot-notation": 2,
"eqeqeq": 2,
"func-names": ["error", "always"],
"guard-for-in": 2,
"indent": [2, 2, {"SwitchCase": 1}],
"linebreak-style": [2, "unix"],
"new-cap": 1,
"no-caller": 2,
"no-catch-shadow": 2,
"no-console": 2,
"no-else-return": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-eval": 2,
"no-implicit-coercion": 2,
"no-implied-eval": 2,
"no-invalid-this": 2,
"no-irregular-whitespace": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 1,
"no-loop-func": 2,
"no-multi-spaces": 1,
"no-multiple-empty-lines": 1,
"no-native-reassign": 2,
"no-nested-ternary": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-throw-literal": 2,
"no-undef": 2,
"no-undef-init": 1,
"no-unreachable": 2,
"no-unused-expressions": [2, {"allowShortCircuit": true}],
"no-useless-call": 2,
"no-with": 2,
"quotes": [2, "single"],
"require-atomic-updates": 0,
"semi": [2, "always"],
"space-before-blocks": 2,
"strict": [2, "global"],
"vars-on-top": 2,
"yoda": [2, "never"],
"sort-keys": ["error", "asc"],
"keyword-spacing": ["error", { "before": true, "after": true }],
"object-curly-spacing": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"comma-spacing": 2,
"brace-style": ["error", "stroustrup"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false, "overrides": { "!": true } }],
"key-spacing": ["error", { "afterColon": true }]
},
"overrides": [
{
"files": [
"test/**/*.js",
"features-legacy/**/*.js",
"features/**/*.js"
],
"rules": {
"sort-keys": "off"
}
}
],
"env": {
"node": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": false
},
"ecmaVersion": 2018
},
"extends": "eslint:recommended"
}
12 changes: 0 additions & 12 deletions .github/workflows/publish.master.yaml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/pull_request.workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pull request checks

on: [pull_request]

jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@3
with:
node-version: "16"
- uses: ./.github/actions/lint
38 changes: 38 additions & 0 deletions .github/workflows/push_branches.workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Push checks

on:
push:
branches:
- master
- beta

jobs:
release:
name: Release process
runs-on: ubuntu-20.04
permissions:
contents: write
issues: write
pull-requests: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
registry-url: "https://registry.npmjs.org"
scope: "@kuzzleio"

- name: Build
run: npm run build

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GHP }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEMANTIC_RELEASE_NPM_PUBLISH: "true"
SEMANTIC_RELEASE_SLACK_WEBHOOK: ${{ secrets.SEMANTIC_RELEASE_SLACK_WEBHOOK }}
run: npx semantic-release
7 changes: 7 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["semantic-release-config-kuzzle"],
"branches": [
"master",
{ "name": "beta", "prerelease": true }
]
}
60 changes: 30 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var BSI = require('bindings')('BoostSpatialIndex');
/**
* @constructor
*/
function BoostSpatialIndex() {
function BoostSpatialIndex () {
this.spatialIndex = new BSI.SpatialIndex();
return this;
}
Expand All @@ -18,8 +18,8 @@ function BoostSpatialIndex() {
* @param {Number} max_lon
* @return {boolean}
*/
BoostSpatialIndex.prototype.addBoundingBox = function addBoundingBox(id, min_lat, min_lon, max_lat, max_lon) {
if (!id || typeof id !== 'string' || id.length === 0) {
BoostSpatialIndex.prototype.addBoundingBox = function addBoundingBox (id, min_lat, min_lon, max_lat, max_lon) {
if (! id || typeof id !== 'string' || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

Expand All @@ -28,15 +28,15 @@ BoostSpatialIndex.prototype.addBoundingBox = function addBoundingBox(id, min_lat
}

if (min_lat >= max_lat) {
throw new Error('min_lat argument cannot be greater or equal max_lat')
throw new Error('min_lat argument cannot be greater or equal max_lat');
}

if (min_lon >= max_lon) {
throw new Error('min_lon argument cannot be greater or equal max_lon')
throw new Error('min_lon argument cannot be greater or equal max_lon');
}

return this.spatialIndex.addBBox(id, min_lat, min_lon, max_lat, max_lon);
}
};

/**
* Adds a circle shape to the index
Expand All @@ -47,8 +47,8 @@ BoostSpatialIndex.prototype.addBoundingBox = function addBoundingBox(id, min_lat
* @param {Number} radius in meters
* @return {boolean}
*/
BoostSpatialIndex.prototype.addCircle = function addCircle(id, lat, lon, radius) {
if (!id || typeof id !== 'string' || id.length === 0) {
BoostSpatialIndex.prototype.addCircle = function addCircle (id, lat, lon, radius) {
if (! id || typeof id !== 'string' || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

Expand All @@ -57,7 +57,7 @@ BoostSpatialIndex.prototype.addCircle = function addCircle(id, lat, lon, radius)
}

return this.spatialIndex.addCircle(id, lat, lon, radius);
}
};

/**
* Adds an annulus shape to the index
Expand All @@ -69,21 +69,21 @@ BoostSpatialIndex.prototype.addCircle = function addCircle(id, lat, lon, radius)
* @param {Number} innerRadius in meters
* @return {boolean}
*/
BoostSpatialIndex.prototype.addAnnulus = function addAnnulus(id, lat, lon, outer, inner) {
if (!id || typeof id !== 'string' || id.length === 0) {
BoostSpatialIndex.prototype.addAnnulus = function addAnnulus (id, lat, lon, outer, inner) {
if (! id || typeof id !== 'string' || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

if ([lat, lon, outer, inner].findIndex(v => typeof v !== 'number') !== -1) {
throw new Error('Invalid coordinates parameter');
}

if (outer <= inner) {
if (outer <= inner) {
throw new Error('Outer radius must be strictly greater than the inner one');
}

return this.spatialIndex.addAnnulus(id, lat, lon, outer, inner);
}
};

/**
* Adds a polygon shape to the index
Expand All @@ -97,21 +97,21 @@ BoostSpatialIndex.prototype.addAnnulus = function addAnnulus(id, lat, lon, outer
* @param {Array<Array<Number>>} points
* @return {boolean}
*/
BoostSpatialIndex.prototype.addPolygon = function addPolygon(id, points) {
BoostSpatialIndex.prototype.addPolygon = function addPolygon (id, points) {
var idx;

if (!id || typeof id !== 'string' || id.length === 0) {
if (! id || typeof id !== 'string' || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

if (!points || typeof points !== 'object' || !Array.isArray(points)) {
if (! points || typeof points !== 'object' || ! Array.isArray(points)) {
throw new Error('Invalid points arguments');
}

idx = points.findIndex(v => {
return !v ||
return ! v ||
typeof v !== 'object' ||
!Array.isArray(v) ||
! Array.isArray(v) ||
v.length !== 2 ||
v.find(coord => typeof coord !== 'number');
});
Expand All @@ -121,7 +121,7 @@ BoostSpatialIndex.prototype.addPolygon = function addPolygon(id, points) {
}

return this.spatialIndex.addPolygon(id, points);
}
};

/**
* Gets all shapes identifiers covering the provided coordinates
Expand All @@ -130,7 +130,7 @@ BoostSpatialIndex.prototype.addPolygon = function addPolygon(id, points) {
* @param {Number} lon
* @return {Array<string>}
*/
BoostSpatialIndex.prototype.queryPoint = function queryPoint(lat, lon) {
BoostSpatialIndex.prototype.queryPoint = function queryPoint (lat, lon) {
if (typeof lat !== 'number') {
throw new Error('Invalid lat parameter');
}
Expand All @@ -140,7 +140,7 @@ BoostSpatialIndex.prototype.queryPoint = function queryPoint(lat, lon) {
}

return this.spatialIndex.queryPoint(lat, lon);
}
};

/**
* Gets all shape identifiers intersecting the polygon
Expand All @@ -154,16 +154,16 @@ BoostSpatialIndex.prototype.queryPoint = function queryPoint(lat, lon) {
* @param {Array<Array<Number>>} points
* @return {Array<string>}
*/
BoostSpatialIndex.prototype.queryIntersect = function queryIntersect(points) {
BoostSpatialIndex.prototype.queryIntersect = function queryIntersect (points) {

if (!points || typeof points !== 'object' || !Array.isArray(points)) {
if (! points || typeof points !== 'object' || ! Array.isArray(points)) {
throw new Error('Invalid points arguments');
}

idx = points.findIndex(v => {
return !v ||
let idx = points.findIndex(v => {
return ! v ||
typeof v !== 'object' ||
!Array.isArray(v) ||
! Array.isArray(v) ||
v.length !== 2 ||
v.find(coord => typeof coord !== 'number');
});
Expand All @@ -173,20 +173,20 @@ BoostSpatialIndex.prototype.queryIntersect = function queryIntersect(points) {
}

return this.spatialIndex.queryIntersect(points);
}
};

/**
* Removes an id from the spatial index
*
* @param {string} id - shape identifier to remove
* @return {boolean}
*/
BoostSpatialIndex.prototype.remove = function remove(id) {
if (!id || typeof id !== 'string' || id.length === 0) {
BoostSpatialIndex.prototype.remove = function remove (id) {
if (! id || typeof id !== 'string' || id.length === 0) {
throw new Error('Invalid id parameter');
}

return this.spatialIndex.remove(id);
}
};

module.exports = BoostSpatialIndex;
Loading

0 comments on commit 5e1bdd6

Please sign in to comment.