Skip to content

Commit

Permalink
chore: add shared node config
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Jan 28, 2021
1 parent 603ffa8 commit 40df566
Show file tree
Hide file tree
Showing 18 changed files with 15,051 additions and 8,069 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
max_line_length = 120
trim_trailing_whitespace = true
insert_final_newline = true
56 changes: 51 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
const { overrides } = require('@netlify/eslint-config-node');

module.exports = {
parser: 'babel-eslint',
plugins: ['prettier'],
extends: '@netlify/eslint-config-node',
parserOptions: {
sourceType: 'module',
},
env: {
browser: true,
node: true,
es6: true,
jest: true,
},
extends: ['plugin:import/errors', 'plugin:import/warnings', 'eslint:recommended', 'prettier'],
rules: {
// eslint-plugin-ava needs to know where test files are located
'ava/no-ignored-test-files': [2, { files: ['tests/**/*.js'] }],

// TODO: enable these rules
'consistent-this': 0,
'func-style': 0,
'no-throw-literal': 0,
'no-param-reassign': 0,
'no-magic-numbers': 0,
'fp/no-mutation': 0,
'fp/no-let': 0,
'fp/no-class': 0,
'fp/no-this': 0,
'fp/no-loops': 0,
'fp/no-delete': 0,
'fp/no-mutating-assign': 0,
'no-console': ['warn', { allow: ['warn', 'error'] }],
'no-unused-vars': ['error', { vars: 'all', args: 'none', ignoreRestSiblings: true }],
'no-underscore-dangle': 0,
complexity: 0,
'max-depth': 0,
'max-lines': 0,
'promise/prefer-await-to-then': 0,
'promise/no-return-wrap': 0,
'promise/no-nesting': 0,
'node/no-unsupported-features/es-syntax': 0,
camelcase: 0,
},
overrides: [
...overrides,
{
files: ['*.ts'],
parser: '@typescript-eslint/parser',
Expand All @@ -23,7 +51,25 @@ module.exports = {
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
]
],
},
{
files: ['tests/**/*.js'],
rules: {
'node/no-unpublished-import': 0,
},
},
{
// TODO: remove this
files: ['README.md'],
rules: {
'node/no-missing-import': 0,
'no-console': 0,
'promise/always-return': 0,
'require-await': 0,
'node/exports-style': 0,
'no-shadow': 0,
},
},
],
};
18 changes: 10 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
38 changes: 21 additions & 17 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,33 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node-version: [12.x]
node-version: [15.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: log versions
run: node --version && npm --version && yarn --version
- name: install dependencies
run: yarn --frozen-lockfile
- name: run tests
run: yarn test
run: node --version && npm --version
- name: Install dependencies
run: npm ci
- name: compile code
run: yarn babelify

run: npm run babelify
- name: Linting
run: npm run format:ci
- name: Tests
run: npm run test:ci
- name: Get test coverage flags
id: test-coverage-flags
run: |-
os=${{ matrix.os }}
node=${{ matrix.node-version }}
echo "::set-output name=os::${os/-latest/}"
echo "::set-output name=node::node_${node//./}"
shell: bash
- uses: codecov/codecov-action@v1
with:
file: coverage/coverage-final.json
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/
node_modules/
.eslintcache
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@netlify/eslint-config-node/.prettierrc.json"
58 changes: 25 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ Example usage:
```js
auth
.confirm(token, true)
.then(function (response) {
.then((response) => {
console.log('Confirmation email sent', JSON.stringify({ response }));
})
.catch(function (e) {
console.log(e);
.catch((error) => {
console.log(error);
});
```

Expand Down Expand Up @@ -176,14 +176,14 @@ Example usage:
auth
.login(email.value, password.value, true)
.then((response) => {
showMessage('Success! Response: ' + JSON.stringify({ response }), form);
showMessage(`Success! Response: ${JSON.stringify({ response })}`, form);
})
.catch((error) => showMessage('Failed :( ' + JSON.stringify(error), form));
.catch((error) => showMessage(`Failed :( ${JSON.stringify(error)}`, form));
```

Example response object:

```js
```json
{
"response": {
"api": {
Expand Down Expand Up @@ -492,30 +492,28 @@ exports.handler = async (event, context) => {
const { identity, user } = context.clientContext;
const userID = user.sub;
const userUrl = `${identity.url}/admin/users/{${userID}}`;
const adminAuthHeader = 'Bearer ' + identity.token;
const adminAuthHeader = `Bearer ${ identity.token}`;

try {
return fetch(userUrl, {
method: 'GET',
headers: { Authorization: adminAuthHeader },
})
.then((response) => {
return response.json();
})
.then((response) => response.json())
.then((data) => {
console.log('data', JSON.stringify(data));
return { statusCode: 204 };
})
.catch((e) => {
.catch((error) => {
console.log('Failed to get user! 500! Internal.');
return {
statusCode: 500,
body: 'Internal Server Error: ' + e,
body: `Internal Server Error: ${ error}`,
};
});
} catch (e) {
} catch (error) {
console.log('GOT HERE! 500! outer');
return { statusCode: 500, body: 'Internal Server Error: ' + e };
return { statusCode: 500, body: `Internal Server Error: ${ error}` };
}
};
```
Expand Down Expand Up @@ -743,7 +741,7 @@ exports.handler = async (event, context) => {
const { identity, user } = context.clientContext;
const userID = user.sub;
const userUrl = `${identity.url}/admin/users/{${userID}}`;
const adminAuthHeader = 'Bearer ' + identity.token;
const adminAuthHeader = `Bearer ${identity.token}`;

try {
return fetch(userUrl, {
Expand All @@ -758,14 +756,12 @@ exports.handler = async (event, context) => {
console.log({ data });
return { statusCode: 204 };
})
.catch((e) => {
return {
.catch((error) => ({
statusCode: 500,
body: 'Internal Server Error: ' + e,
};
});
} catch (e) {
return e;
body: `Internal Server Error: ${error}`,
}));
} catch (error) {
return error;
}
};
```
Expand Down Expand Up @@ -797,28 +793,24 @@ import fetch from 'node-fetch';
exports.handler = async (event, context) => {
const { identity, user } = context.clientContext;
const usersUrl = `${identity.url}/admin/users`;
const adminAuthHeader = 'Bearer ' + identity.token;
const adminAuthHeader = `Bearer ${identity.token}`;

try {
return fetch(usersUrl, {
method: 'GET',
headers: { Authorization: adminAuthHeader },
})
.then((response) => {
return response.json();
})
.then((response) => response.json())
.then((data) => {
console.log('data', JSON.stringify(data));
return { statusCode: 204 };
})
.catch((e) => {
return {
.catch((error) => ({
statusCode: 500,
body: 'Internal Server Error: ' + e,
};
});
} catch (e) {
return e;
body: `Internal Server Error: ${error}`,
}));
} catch (error) {
return error;
}
};
```
Expand Down
8 changes: 8 additions & 0 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = {
files: ['tests/*.js'],
verbose: true,
babel: true,
require: ['esm'],
};

export default config;
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
Loading

0 comments on commit 40df566

Please sign in to comment.